Ejemplo n.º 1
0
        public Body CreateBoxBody(float length, float height, float width, Vector3 position, bool isStatic = false)
        {
            var shape = new BoxShape(length, height, width);
            var rigidBody = CreateRigidBody(shape, isStatic);

            rigidBody.Position = Conversion.ToJitterVector(ref position);

            var body = new Body(rigidBody);
            rigidBody.Tag = body;

            Bodies.Add(body);

            PhysicsWorld.AddBody(rigidBody);

            return body;
        }
Ejemplo n.º 2
0
        public Body CreateMeshBody(Resources.Mesh mesh, Vector3 position, bool isStatic = false)
        {
            var shape = mesh.Shape;
            var rigidBody = CreateRigidBody(shape, isStatic);

            rigidBody.Position = Conversion.ToJitterVector(ref position);

            var body = new Body(rigidBody);
            rigidBody.Tag = body;

            Bodies.Add(body);

            PhysicsWorld.AddBody(rigidBody);

            return body;
        }
Ejemplo n.º 3
0
        public bool Raycast(Vector3 origin, Vector3 direction, RaycastCallback callback, out Body body, out Vector3 normal, out float fraction)
        {
            RigidBody rigidBody;
            JVector jitterNormal;

            Jitter.Collision.RaycastCallback jitterCallback = (RigidBody body1, JVector normal1, float fraction1) =>
            {
                return callback((Body)body1.Tag, Conversion.ToTritonVector(ref normal1), fraction1);
            };

            var res = PhysicsWorld.CollisionSystem.Raycast(Conversion.ToJitterVector(ref origin), Conversion.ToJitterVector(ref direction), jitterCallback, out rigidBody, out jitterNormal, out fraction);

            normal = Conversion.ToTritonVector(ref jitterNormal);
            if (rigidBody != null)
            {
                body = (Body)rigidBody.Tag;
            }
            else
            {
                body = null;
            }

            return res;
        }
Ejemplo n.º 4
0
 public void RemoveBody(Body body)
 {
     PhysicsWorld.RemoveBody(body.RigidBody);
     Bodies.Remove(body);
 }
Ejemplo n.º 5
0
        public Body CreateSphereBody(float radius, Vector3 position, bool isStatic = false)
        {
            var shape = new SphereShape(radius);
            var rigidBody = CreateRigidBody(shape, isStatic);

            rigidBody.Position = Conversion.ToJitterVector(ref position);

            var body = new Body(rigidBody);
            rigidBody.Tag = body;

            Bodies.Add(body);

            PhysicsWorld.AddBody(rigidBody);

            return body;
        }