public override void Draw(GameTime gameTime) { foreach (var mesh in model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.Alpha = 1f; effect.PreferPerPixelLighting = true; effect.World = MathConverter.Convert(physicsObject.WorldTransform); effect.View = Matrix.CreateLookAt(MathConverter.Convert(Game1.cameraPositionBepu), MathConverter.Convert(Game1.physCapsule.Position), MathConverter.Convert(Game1.physCapsule.OrientationMatrix.Up)); float aspectRatio = Game.GraphicsDevice.Viewport.AspectRatio; float fieldOfView = Microsoft.Xna.Framework.MathHelper.PiOver4; float nearClipPlane = 1; float farClipPlane = 2000; effect.Projection = Matrix.CreatePerspectiveFieldOfView(fieldOfView, aspectRatio, nearClipPlane, farClipPlane); } mesh.Draw(); } base.Draw(gameTime); }
public Asteroid(Game game, Vector3 pos, string id, float mass, Vector3 linMomentum, Vector3 angMomentum) : this(game, pos, id, mass, linMomentum) { physicsObject.AngularMomentum = MathConverter.Convert(angMomentum); }
/// <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.Black); //GraphicsDevice.BlendState = BlendState.Opaque; GraphicsDevice.DepthStencilState = DepthStencilState.Default; // Copy any parent transforms. Matrix[] transforms = new Matrix[ship.Bones.Count]; ship.CopyAbsoluteBoneTransformsTo(transforms); // Draw the model. A model can have multiple meshes, so loop. cameraPositionBepu = physCapsule.Position + 5 * BEPUutilities.Vector3.Normalize(physCapsule.OrientationMatrix.Backward); if (BEPUutilities.Vector3.Normalize(physCapsule.OrientationMatrix.Backward) == BEPUutilities.Vector3.Up) { var modelRight = -0.01f * physCapsule.OrientationMatrix.Right; physCapsule.ApplyAngularImpulse(ref modelRight); } cameraPositionBepu = cameraPositionBepu + 1.5f * BEPUutilities.Vector3.Normalize(physCapsule.OrientationMatrix.Up); foreach (ModelMesh mesh in ship.Meshes) { // This is where the mesh orientation is set, as well // as our camera and projection. foreach (BasicEffect effect in mesh.Effects) { effect.Alpha = 1f; effect.LightingEnabled = false; effect.World = Matrix.CreateScale(0.001f) * MathConverter.Convert(physCapsule.WorldTransform);//MathConverter.Convert(BEPUutilities.Matrix.Multiply(modelRotationBepu, physCapsule.WorldTransform));// MathConverter.Convert(physCapsule.WorldTransform); effect.View = Matrix.CreateLookAt(MathConverter.Convert(cameraPositionBepu), MathConverter.Convert(physCapsule.Position), MathConverter.Convert(physCapsule.OrientationMatrix.Up)); effect.Projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f); } // Draw the mesh, using the effects set above. mesh.Draw(); } base.Draw(gameTime); // Draw info about current speed spriteBatch.Begin(); spriteBatch.DrawString(dfont, "Current speed:" + speed + " m/s", Vector2.Zero, Color.White); spriteBatch.DrawString(dfont, "Land at <6 m/s! ", new Vector2(0, 15), Color.White); if (goalReached) { spriteBatch.DrawString(dfont, "Goal reached!", new Vector2(350, 150), Color.Gold); if (goalReachedTooFast) { spriteBatch.DrawString(dfont, "Too fast - crash landing!", new Vector2(320, 165), Color.Red); } else { spriteBatch.DrawString(dfont, "Mission complete!", new Vector2(340, 165), Color.Red); } } spriteBatch.End(); }
public Asteroid(Game game, Vector3 pos, string id, float mass, Vector3 linMomentum) : this(game, pos, id, mass) { physicsObject.LinearMomentum = MathConverter.Convert(linMomentum); }
public override void Draw(GameTime gameTime) { Matrix[] transforms = new Matrix[skybox.Bones.Count]; skybox.CopyAbsoluteBoneTransformsTo(transforms); foreach (ModelMesh mesh in skybox.Meshes) { // This is where the mesh orientation is set, as well // as our camera and projection. foreach (BasicEffect effect in mesh.Effects) { effect.Alpha = 1f; effect.LightingEnabled = false; effect.TextureEnabled = true; effect.Texture = skyboxTexture; effect.World = Matrix.CreateScale(100f) * transforms[mesh.ParentBone.Index]; effect.View = Matrix.CreateLookAt(MathConverter.Convert(Game1.cameraPositionBepu), MathConverter.Convert(Game1.physCapsule.Position), MathConverter.Convert(Game1.physCapsule.OrientationMatrix.Up)); effect.Projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 100000000.0f); } // Draw the mesh, using the effects set above. mesh.Draw(); } base.Draw(gameTime); }