public override void Draw(GameTime gameTime) { GraphicsDevice.BlendState = BlendState.Opaque; GraphicsDevice.DepthStencilState = DepthStencilState.Default; GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; //Copy any parent transforms Matrix[] transforms = new Matrix[myModel.Bones.Count]; myModel.CopyAbsoluteBoneTransformsTo(transforms); //Draw the model. A model can have multiple meshes, so loop. foreach (ModelMesh mesh in myModel.Meshes) { //This is where the mesh orientation is set, as well as our camera and projection foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); effect.DirectionalLight0.DiffuseColor = new Vector3(10, 10, 10); effect.DirectionalLight1.DiffuseColor = new Vector3(10, 10, 10); effect.DirectionalLight2.DiffuseColor = new Vector3(10, 10, 10); effect.PreferPerPixelLighting = true; ///effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(modelYaw) * Matrix.CreateRotationX(modelPitch) * Matrix.CreateRotationZ(modelRoll) * Matrix.CreateTranslation(modelPosition); effect.World = MathConverter.Convert(physicsObject.WorldTransform); effect.View = Matrix.CreateLookAt(Game1.CameraPosition, Game1.CameraDirection, Game1.CameraUp); effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f); effect.Alpha = 0.1f; } //draw the mesh using the effects set above mesh.Draw(); } base.Draw(gameTime); }
public Asteroid(Game game, Vector3 pos) : this(game) { //first param is motionstate (I think the position?), and the secondParam is the radius physicsObject = new BEPUphysics.Entities.Prefabs.Sphere(MathConverter.Convert(pos), 1); //this is friction slowing down a rotation physicsObject.AngularDamping = 0f; //this is friction slowing down movement physicsObject.LinearDamping = 0f; //adds this object into the space of the game? Game.Services.GetService <Space>().Add(physicsObject); }
public override void Update(GameTime gameTime) { //Get some input UpdateInput(); Vector3 upwardOffest = MathConverter.Convert(physicsObject.WorldTransform.Up); Game1.CameraPosition = MathConverter.Convert(physicsObject.Position) + upwardOffest; Game1.CameraDirection = MathConverter.Convert(physicsObject.Position) + upwardOffest + MathConverter.Convert(physicsObject.WorldTransform.Forward); Game1.CameraUp = MathConverter.Convert(physicsObject.WorldTransform.Up); //Game1.CameraDirection = MathConverter.Convert(physicsObject.WorldTransform.Forward); //Add Velocity to the current position for both the physics object and the model //modelPosition += modelVelocity; //physicsObject.Position += MathConverter.Convert(modelVelocity); //bleed off velocity over time from both the model and the physics object //modelVelocity *= 0.95f; //physicsObject.LinearMomentum *= 0.95f; }
public override void Draw(GameTime gameTime) { foreach (var mesh in model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); effect.DirectionalLight0.DiffuseColor = new Vector3(10, 10, 10); effect.DirectionalLight1.DiffuseColor = new Vector3(10, 10, 10); effect.DirectionalLight2.DiffuseColor = new Vector3(10, 10, 10); effect.PreferPerPixelLighting = true; //effect.Alpha = 0.3f; effect.World = MathConverter.Convert(physicsObject.WorldTransform); effect.View = Matrix.CreateLookAt(Game1.CameraPosition, Game1.CameraDirection, Game1.CameraUp); float aspectRatio = Game.GraphicsDevice.Viewport.AspectRatio; float fieldOfView = Microsoft.Xna.Framework.MathHelper.PiOver4; float nearClipPlane = 0.3f; float farClipPlane = 400f; effect.Projection = Matrix.CreatePerspectiveFieldOfView(fieldOfView, aspectRatio, nearClipPlane, farClipPlane); } mesh.Draw(); } base.Draw(gameTime); }
public Asteroid(Game game, Vector3 pos, float mass, Vector3 linMomentum, Vector3 angMomentum) : this(game, pos, mass, linMomentum) { physicsObject.AngularMomentum = MathConverter.Convert(angMomentum); }
public Asteroid(Game game, Vector3 pos, float mass, Vector3 linMomentum) : this(game, pos, mass) { physicsObject.LinearMomentum = MathConverter.Convert(linMomentum); }
public Fighter(Game game, Vector3 pos, float mass, Vector3 linMomentum) : this(game, pos, mass) { physicsObject.LinearMomentum = MathConverter.Convert(linMomentum); //modelVelocity = linMomentum / 50; }