int nodes = di.readByte() + (di.readByte() << 8) +
(di.readByte() << 16) + (di.readByte() << 24);
package sandbox;
import java.io.File;
import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class ReadXMLDocument {
private String filename;
public ReadXMLDocument(String xmlFilename) {
filename = xmlFilename;
}
public void run() {
try {
File xmlFile = new File(filename);
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.parse(xmlFile);
NodeList nodes = document.getChildNodes();
DefaultMutableTreeNode root = new DefaultMutableTreeNode(xmlFile.getName());
populateNodeFromDOM(root, nodes);
JTree tree = new JTree(root);
JFrame frame = new JFrame();
frame.getContentPane().add(tree);
frame.validate();
frame.pack();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
private void populateNodeFromDOM(DefaultMutableTreeNode parentNode, NodeList domNodes) {
for(int i = 0; i < domNodes.getLength(); i++) {
Node currNode = domNodes.item(i);
String nodeName = null;
if(currNode.getNodeName().startsWith("#")) {
nodeName = currNode.getNodeName() + ": " + currNode.getTextContent();
} else {
nodeName = currNode.getNodeName();
}
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(nodeName);
populateNodeFromDOM(newNode, currNode.getChildNodes());
parentNode.add(newNode);
}
}
static public void main(String[] args) {
ReadXMLDocument reader = new ReadXMLDocument(args[0]);
reader.run();
}
}
java -cp "lib/foo.jar;finances" FinancesStart
java -cp "lib/foo.jar;." finances.FinancesStart
<event>
<track name="Monza" configuration="2005 F1"/>
<qualify startTime="1176910077">
<drivers>
<driver name="Rob Heiser" car="BMW Sauber">
<lap number=1 time="80345"/>
<lap number=2 time="101988">
<pit time="10656"/>
</lap>
</driver>
<driver name="John Doe" car="BMW Sauber">
<lap number=1 time="0">
<dnf/>
</driver>
</drivers>
</qualify>
<race>
.
. Similar to qualifying
.
</race>
</event>
// private float ANGLE_CONSTANT = 65536.0f/360.0f;
CompCar challenger = event.getChallenger();
SetDirectCameraRequest request = new SetDirectCameraRequest();
request.setCameraType(StateResponse.CUSTOM_VIEW);
request.setFlags((short)(StateResponse.ISS_SHIFTU | StateResponse.ISS_VIEW_OVERRIDE | StateResponse.ISS_SHIFTU_NO_OPT));
InSimVector pos2 = new InSimVector(0, 65536 * 10, 65536 * 10);
InSimVector cameraPosition = challenger.getPosition().add(pos2);
request.setPosition(cameraPosition);
double heading = Math.toDegrees(Math.atan2((cameraPosition.getY()- challenger.getPosition().getY()),(cameraPosition.getX()- challenger.getPosition().getX())));
double pitch = Math.toDegrees(Math.atan2((cameraPosition.getZ()- challenger.getPosition().getZ()), (cameraPosition.getY()- challenger.getPosition().getY())));
request.setHeading((short)(heading * ANGLE_CONSTANT));
request.setPitch((short)(pitch * ANGLE_CONSTANT));
send(request);