/// <summary> /// DrawModel is a helper function that takes a model, world matrix, and /// bone transforms. It does just what its name implies, and draws the model. /// </summary> /// <param name="model">the model to draw</param> /// <param name="worldTransform">where to draw the model</param> /// <param name="absoluteBoneTransforms">the model's bone transforms. this can /// be calculated using the function Model.CopyAbsoluteBoneTransformsTo</param> private void DrawModel(Model model, Matrix worldTransform, Matrix[] absoluteBoneTransforms, bool drawBoundingSphere) { // nothing tricky in here; this is the same model drawing code that we see // everywhere. we'll loop over all of the meshes in the model, set up their // effects, and then draw them. foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); effect.View = viewMatrix; effect.Projection = projectionMatrix; effect.World = absoluteBoneTransforms[mesh.ParentBone.Index] * worldTransform; } mesh.Draw(); if (drawBoundingSphere) { // the mesh's BoundingSphere is stored relative to the mesh itself. // (Mesh space). We want to get this BoundingSphere in terms of world // coordinates. To do this, we calculate a matrix that will transform // from coordinates from mesh space into world space.... Matrix world = absoluteBoneTransforms[mesh.ParentBone.Index] * worldTransform; // ... and then transform the BoundingSphere using that matrix. BoundingSphere sphere = TransformBoundingSphere(mesh.BoundingSphere, world); // now draw the sphere with our renderer BoundingSphereRenderer.Draw(sphere, viewMatrix, projectionMatrix); } } }
/// <summary> /// Load your graphics content. /// </summary> protected override void LoadContent() { // load all of the models that will appear on the table: for (int i = 0; i < ModelFilenames.Length; i++) { // load the actual model, using ModelFilenames to determine what // file to load. models[i] = Content.Load <Model>(ModelFilenames[i]); // create an array of matrices to hold the absolute bone transforms, // calculate them, and copy them in. modelAbsoluteBoneTransforms[i] = new Matrix[models[i].Bones.Count]; models[i].CopyAbsoluteBoneTransformsTo( modelAbsoluteBoneTransforms[i]); } // now that we've loaded in the models that will sit on the table, go // through the same procedure for the table itself. table = Content.Load <Model>("Table"); tableAbsoluteBoneTransforms = new Matrix[table.Bones.Count]; table.CopyAbsoluteBoneTransformsTo(tableAbsoluteBoneTransforms); // create a spritebatch and load the font, which we'll use to draw the // models' names. spriteBatch = new SpriteBatch(graphics.GraphicsDevice); spriteFont = Content.Load <SpriteFont>("hudFont"); // calculate the projection matrix now that the graphics device is created. projectionMatrix = Matrix.CreatePerspectiveFieldOfView( MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, .01f, 1000); // Initialize the renderer for our bounding spheres BoundingSphereRenderer.Initialize(GraphicsDevice, 45); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); var device = graphics.GraphicsDevice; //Sphere sp = new Sphere(3, GraphicsDevice); // Copy any parent transforms. //Matrix[] transforms = new Matrix[myModel.Bones.Count]; //myModel.CopyAbsoluteBoneTransformsTo(transforms); //var cam = new Camera(); //graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineStrip, ; //sp.Draw(cam); BoundingSphereRenderer.InitializeGraphics(device, 100); var look = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up); var projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f); BoundingSphereRenderer.Render(new BoundingSphere(center, 2), device, look, projection, Color.Red, Color.Blue, Color.Green); // TODO: Add your drawing code here base.Draw(gameTime); }
protected override void Initialize() { Application.Idle += delegate { Refresh(); }; Application.Idle += delegate { Invalidate(); }; BoundingSphereRenderer.InitializeGraphics(GraphicsDevice, 49); m_SceneView = Form1.g_SceneView; }
private void DrawBoundingElements() { foreach (Tank tank in tankController.TanksInGame) { foreach (BoundingSphere boundingSphere in tank.BoundingSpheres) { BoundingSphereRenderer.Render(boundingSphere, GraphicsDevice, camera.View, projection, Color.Red); } } BoundingSphereRenderer.Render(tankController.MissleInGame.BoundingSphere, GraphicsDevice, camera.View, projection, Color.Red); BoundingFrustumRenderer.Render(camera.Frustum, GraphicsDevice, camera.View, projection, Color.Red); }
//draw the vehicle virtual public void draw(ChaseCamera cameraPosition, Viewport currentViewPort, GameTime gameTime) { //update smoke particles smoke.SetCamera(cameraPosition.view, cameraPosition.projection); smoke.Draw(gameTime); if (drawSpheres) { BoundingSphereRenderer.Render(waypointSpheres[point], graphics.GraphicsDevice, cameraPosition.view, cameraPosition.projection, Color.Red); } graphics.GraphicsDevice.Viewport = currentViewPort; graphics.GraphicsDevice.RenderState.DepthBufferWriteEnable = true; // Copy any parent transforms. Matrix[] transforms = new Matrix[carModel.Bones.Count]; carModel.CopyAbsoluteBoneTransformsTo(transforms); foreach (ModelMesh mesh in carModel.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.Begin(); effect.EnableDefaultLighting(); float direction = speed / Math.Abs(speed); /*Vector3 pointToRotateAround = rotationMatrix.Translation + * rotationMatrix.Right * (position - previousPosition); * * transforms[mesh.ParentBone.Index].Translation -= pointToRotateAround; * transforms[mesh.ParentBone.Index] *= transformationMatrix; * transforms[mesh.ParentBone.Index].Translation += pointToRotateAround;*/ effect.World = transforms[mesh.ParentBone.Index] /* Matrix.CreateRotationY((direction > 0 || direction < 0 ? direction : 1) * currentRotation / 100)*/ * Matrix.CreateRotationY(carGlobalRotation) * transformationMatrix; effect.View = cameraPosition.view; effect.Projection = cameraPosition.projection; effect.End(); } mesh.Draw(); } //BoundingSphereRenderer.Render(collisionSphere, graphics.GraphicsDevice, cameraPosition.view, cameraPosition.projection, Color.Blue); }
protected override void Initialize() { Global.game = this; Global.networkManager = new NetworkManager(); Global.graphics = graphics; Global.graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default; Global.viewPort = Global.graphics.GraphicsDevice.Viewport.Bounds; Global.titleSafe = GetTitleSafeArea(.85f); axisReference = new Axis_Reference(GraphicsDevice, 1.0f); BoundingSphereRenderer.Initialize(GraphicsDevice, 45); Global.heatmapKills = new Heatmap(Color.Black); Global.heatmapDeaths = new Heatmap(Color.Red); Global.heatmapUsedJetpack = new Heatmap(Color.Green); this.IsMouseVisible = true; base.Initialize(); }