Пример #1
0
 /// <summary>
 /// Creates a new cylinder cast based wheel shape.
 /// </summary>
 /// <param name="radius">Radius of the wheel.</param>
 /// <param name="width">Width of the wheel.</param>
 /// <param name="localWheelOrientation">Unsteered orientation of the wheel in the vehicle's local space.</param>
 /// <param name="localGraphicTransform">Local graphic transform of the wheel shape.
 /// This transform is applied first when creating the shape's worldTransform.</param>
 /// <param name="includeSteeringTransformInCast">Whether or not to include the steering transform in the wheel shape cast. If false, the casted wheel shape will always point straight forward.
 /// If true, it will rotate with steering. Sometimes, setting this to false is helpful when the cast shape would otherwise become exposed when steering.</param>
 public CylinderCastWheelShape(float radius, float width, Quaternion localWheelOrientation, Matrix localGraphicTransform, bool includeSteeringTransformInCast)
 {
     shape = new CylinderShape(width, radius);
     this.LocalWheelOrientation = localWheelOrientation;
     LocalGraphicTransform = localGraphicTransform;
     this.IncludeSteeringTransformInCast = includeSteeringTransformInCast;
 }
        /// <summary>
        /// Draws the display object.
        /// </summary>
        /// <param name="viewMatrix">Current view matrix.</param>
        /// <param name="projectionMatrix">Current projection matrix.</param>
        public override void Draw(Matrix viewMatrix, Matrix projectionMatrix)
        {
            //This is not a particularly fast method of drawing.
            //It's used very rarely in the demos.
            model.CopyAbsoluteBoneTransformsTo(transforms);
            for (int i = 0; i < Model.Meshes.Count; i++)
            {
                for (int j = 0; j < Model.Meshes[i].Effects.Count; j++)
                {
                    var effect = Model.Meshes[i].Effects[j] as BasicEffect;
                    if (effect != null)
                    {
                        effect.World = transforms[Model.Meshes[i].ParentBone.Index] * MathConverter.Convert(WorldTransform);
                        effect.View = MathConverter.Convert(viewMatrix);
                        effect.Projection = MathConverter.Convert(projectionMatrix);
                        effect.AmbientLightColor = Color;

                        if (Texture != null)
                        {
                            effect.TextureEnabled = true;
                            effect.Texture = Texture;
                        }
                        else
                            effect.TextureEnabled = false;
                    }
                }
                Model.Meshes[i].Draw();
            }
        }
Пример #3
0
 public JointForceWeld(Entity one, Entity two)
 {
     One = one;
     Two = two;
     Matrix worldTrans = Matrix.CreateFromQuaternion(One.GetOrientation()) * Matrix.CreateTranslation(One.GetPosition().ToBVector());
     Matrix.Invert(ref worldTrans, out worldTrans);
     Relative = (Matrix.CreateFromQuaternion(two.GetOrientation())
         * Matrix.CreateTranslation(two.GetPosition().ToBVector()))
         * worldTrans;
 }
Пример #4
0
 /// <summary>
 /// Sets the direction of the entity.
 /// </summary>
 /// <param name="rot">The new angles.</param>
 public override void SetOrientation(Quaternion rot)
 {
     if (Body != null)
     {
         Body.Orientation = rot;
     }
     else
     {
         WorldTransform = Matrix.CreateFromQuaternion(rot) * Matrix.CreateTranslation(WorldTransform.Translation);
     }
 }
Пример #5
0
 /// <summary>
 /// Destroys the body, removing it from the physics world.
 /// </summary>
 public virtual void DestroyBody()
 {
     LVel = new Location(Body.LinearVelocity);
     AVel = new Location(Body.AngularVelocity);
     Friction = GetFriction();
     // TODO: Gravity = new Location(Body.Gravity.X, Body.Gravity.Y, Body.Gravity.Z);
     WorldTransform = Body.WorldTransform;
     for (int i = 0; i < Joints.Count; i++)
     {
         if (Joints[i] is BaseJoint)
         {
             BaseJoint joint = (BaseJoint)Joints[i];
             TheRegion.PhysicsWorld.Remove(joint.CurrentJoint);
         }
     }
     TheRegion.PhysicsWorld.Remove(Body);
     Body = null;
 }
 /// <summary>
 /// Updates the display object.
 /// </summary>
 public override void Update()
 {
     WorldTransform = LocalTransform * Entity.WorldTransform;
 }
Пример #7
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            //This 1x1x1 cube model will represent the box entities in the space.
            CubeModel = Content.Load <Model>("cube");

            PlaygroundModel = Content.Load <Model>("playground");

            //Construct a new space for the physics simulation to occur within.
            space = new Space();

            //Set the gravity of the simulation by accessing the simulation settings of the space.
            //It defaults to (0,0,0); this changes it to an 'earth like' gravity.
            //Try looking around in the space's simulationSettings to familiarize yourself with the various options.
            space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0);

            //Make a box representing the ground and add it to the space.
            //The Box is an "Entity," the main simulation object type of BEPUphysics.
            //Examples of other entities include cones, spheres, cylinders, and a bunch more (a full listing is in the BEPUphysics.Entities namespace).

            //Every entity has a set of constructors.  Some half a parameter for mass, others don't.
            //Constructors that allow the user to specify a mass create 'dynamic' entiites which fall, bounce around, and generally work like expected.
            //Constructors that have no mass parameter create a create 'kinematic' entities.  These can be thought of as having infinite mass.
            //This box being added is representing the ground, so the width and length are extended and it is kinematic.
            Box ground = new Box(Vector3.Zero, 30, 1, 30);

            space.Add(ground);


            //Now that we have something to fall on, make a few more boxes.
            //These need to be dynamic, so give them a mass- in this case, 1 will be fine.
            space.Add(new Box(new Vector3(0, 4, 0), 1, 1, 1, 1));
            space.Add(new Box(new Vector3(0, 8, 0), 1, 1, 1, 1));
            space.Add(new Box(new Vector3(0, 12, 0), 1, 1, 1, 1));

            //Create a physical environment from a triangle mesh.
            //First, collect the the mesh data from the model using a helper function.
            //This special kind of vertex inherits from the TriangleMeshVertex and optionally includes
            //friction/bounciness data.
            //The StaticTriangleGroup requires that this special vertex type is used in lieu of a normal TriangleMeshVertex array.
            Vector3[] vertices;
            int[]     indices;
            ModelDataExtractor.GetVerticesAndIndicesFromModel(PlaygroundModel, out vertices, out indices);
            //Give the mesh information to a new StaticMesh.
            //Give it a transformation which scoots it down below the kinematic box entity we created earlier.
            var mesh = new StaticMesh(vertices, indices, new AffineTransform(new Vector3(0, -40, 0)));

            //Add it to the space!
            space.Add(mesh);
            //Make it visible too.
            Components.Add(new StaticModel(PlaygroundModel, mesh.WorldTransform.Matrix, this));

            //Hook an event handler to an entity to handle some game logic.
            //Refer to the Entity Events documentation for more information.
            Box deleterBox = new Box(new Vector3(5, 2, 0), 3, 3, 3);

            space.Add(deleterBox);
            deleterBox.CollisionInformation.Events.InitialCollisionDetected += HandleCollision;


            //Go through the list of entities in the space and create a graphical representation for them.
            foreach (Entity e in space.Entities)
            {
                Box box = e as Box;
                if (box != null)                                                                 //This won't create any graphics for an entity that isn't a box since the model being used is a box.
                {
                    Matrix      scaling = Matrix.CreateScale(box.Width, box.Height, box.Length); //Since the cube model is 1x1x1, it needs to be scaled to match the size of each individual box.
                    EntityModel model   = new EntityModel(e, CubeModel, scaling, this);
                    //Add the drawable game component for this entity to the game.
                    Components.Add(model);
                    e.Tag = model; //set the object tag of this entity to the model so that it's easy to delete the graphics component later if the entity is removed.
                }
            }
        }
 /// <summary>
 /// Draws the display object.
 /// </summary>
 /// <param name="viewMatrix">Current view matrix.</param>
 /// <param name="projectionMatrix">Current projection matrix.</param>
 public abstract void Draw(Matrix viewMatrix, Matrix projectionMatrix);