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); }
public Asteroid(Game game, Vector3 pos, string id) : this(game) { physicsObject = new BEPUphysics.Entities.Prefabs.Box(MathConverter.Convert(pos), 1, 1, 1); physicsObject.AngularDamping = 0f; physicsObject.LinearDamping = 0f; //physicsObject.CollisionInformation.Events.InitialCollisionDetected += Events_InitialCollisionDetected; physicsObject.Tag = id; Game.Services.GetService <Space>().Add(physicsObject); }
/// <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(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); dfont = Content.Load <SpriteFont>("File"); // Load the ship model and make a physics object for it ship = Content.Load <Model>("Models\\p1_wedge"); physCapsule = new BEPUphysics.Entities.Prefabs.Capsule(MathConverter.Convert(modelPosition), 1.2f, 0.9f, 1f); physCapsule.AngularDamping = 0f; physCapsule.LinearDamping = 0f; physCapsule.Tag = "Spaceship"; // Assign a collision event to the physics object physCapsule.CollisionInformation.Events.InitialCollisionDetected += Events_InitialCollisionDetected; this.Services.GetService <Space>().Add(physCapsule); aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio; }
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); }
public Asteroid(Game game, Vector3 pos, string id, float mass, Vector3 linMomentum) : this(game, pos, id, mass) { physicsObject.LinearMomentum = MathConverter.Convert(linMomentum); }