/// <summary> /// Create a new car device, and load the mesh data for it /// </summary> /// <param name="device">D3D device to use</param> public Car(Device device) { // Create our car mesh carMesh = DriverGame.LoadMesh(device, @"..\..\car.x", ref carMaterials, ref carTextures); // We need to calculate a bounding sphere for our car VertexBuffer vb = carMesh.VertexBuffer; try { // We need to lock the entire buffer to calculate this GraphicsStream stm = vb.Lock(0, 0, LockFlags.None); Vector3 center; // We won't use the center, but it's required float radius = Geometry.ComputeBoundingSphere(stm, carMesh.NumberVertices, carMesh.VertexFormat, out center); // All we care about is the diameter. Store that carDiameter = (radius * 2) * Scale; } finally { // No matter what, make sure we unlock and dispose this vertex // buffer. vb.Unlock(); vb.Dispose(); } }
static void Main() { using (DriverGame frm = new DriverGame()) { frm.Show(); frm.InitializeGraphics(); Application.Run(frm); frm.SaveHighScores(); } }
public Obstacle(Device device, float x, float y, float z) { //create our obstacle mesh from the car obstacleMesh = DriverGame.LoadMesh(device, @"..\..\car.x", ref obstacleMaterials, ref obstacleTextures); // Store our position position = new Vector3(x, y, z); // Set the obstacle color //obsMaterials = new Material(); //Color objColor = ObstacleColors[Utility.Rnd.Next(ObstacleColors.Length)]; //obstacleMaterials[0].Ambient = objColor; //obstacleMaterials[0].Diffuse = objColor; }