Exemple #1
0
        public Caligo (GameState state, AIManager aiManager, RendererContext rendererContext,
            CompositorWarpingNode warpingNode)
        {
            caligoEmitter = new CaligoParticleEmitter ();
            particleCaligo = new ParticleSceneObject (caligoEmitter.ParticleCount);
            particleCaligo.Priority = 7000;
            state.Scene.AddObject (particleCaligo);
            caligoEmitter.Init (particleCaligo, rendererContext);

            CaligoGameState = state;

            CaligoEntity = EntityFactory.Instance.CreateWith ("Caligo." + InstanceCount++, state.MessageProxy,
                new[] { typeof (ArtificialIntelligenceComponent) },
                new[] { typeof (ParticleSystem), typeof (PhysicsSystem) });

            CaligoEntity.GetComponent<ParticleComponent> ().Emitter = caligoEmitter;
            CaligoEntity.GetComponent<ParticleComponent> ().Particle = particleCaligo;

            RigidBody caligoBody = new RigidBody (new SphereShape (1.2f));
            caligoBody.AffectedByGravity = false;
            caligoBody.AllowDeactivation = false;
            caligoBody.Mass = 20;
            CaligoEntity.GetComponent<PhysicsComponent> ().RigidBody = caligoBody;
            CaligoEntity.GetComponent<PhysicsComponent> ().World = state.PhysicsManager.World;
            CaligoEntity.GetComponent<PhysicsComponent> ().PhysicsApplying = AffectedByPhysics.Position;

            state.PhysicsManager.World.AddBody (caligoBody);

            var AIcomp = CaligoEntity.GetComponent<ArtificialIntelligenceComponent>();
            AIcomp.AIManager = aiManager;
            AIcomp.ArtificialIntelligence = new CaligoAI (CaligoEntity, state, warpingNode);
            aiManager.RegisterEntity (CaligoEntity);
        }
        public void objectCollisionOccured(RigidBody rb, string command)
        {
            cRigidBodyGameObject obj = cPhysics.Instance.getOwnerOf(rb);
            if (obj == null)
            {
                Console.WriteLine("gettin null");
                return;
            }
            if (command == "fire")
            {

                if (obj.Equals(cPlayer.Instance))
                {
                    if (cPlayer.Instance.State == (int)cPlayer.STATES.DIEING) { return; }
                    cParticleEngine.Instance.spawnParticleEffect("ObjectDeath", obj.Position, Vector2.Zero);
                    cPlayer.Instance.respawn();
                    cPlayer.Instance.LivesRemain = cPlayer.Instance.LivesRemain - 1;
                    cPostProcessor.Instance.goBrightThenDark(3000);
                }
                else
                {
                    cParticleEngine.Instance.spawnParticleEffect("ObjectDeath", obj.Position, Vector2.Zero);
                    cParticleEngine.Instance.spawnParticleEffect("ObjectDeath", obj.Position, Vector2.Zero);
                    cPhysics.Instance.removeObject(obj);
                    cScene.Instance.removeSceneObject(obj);
                    obj = null;
                }
            }
        }
Exemple #3
0
    /// <summary>
    /// Initializes the 1-dimensional constraint.
    /// </summary>
    public void Prepare(RigidBody bodyA, RigidBody bodyB, Vector3F jLinA, Vector3F jAngA, Vector3F jLinB, Vector3F jAngB)
    {
      JLinA = jLinA;
      JAngA = jAngA;
      JLinB = jLinB;
      JAngB = jAngB;

      WJTLinA.X = bodyA.MassInverse * jLinA.X;
      WJTLinA.Y = bodyA.MassInverse * jLinA.Y;
      WJTLinA.Z = bodyA.MassInverse * jLinA.Z;
      Matrix33F matrix = bodyA.InertiaInverseWorld;
      WJTAngA.X = matrix.M00 * jAngA.X + matrix.M01 * jAngA.Y + matrix.M02 * jAngA.Z;
      WJTAngA.Y = matrix.M10 * jAngA.X + matrix.M11 * jAngA.Y + matrix.M12 * jAngA.Z;
      WJTAngA.Z = matrix.M20 * jAngA.X + matrix.M21 * jAngA.Y + matrix.M22 * jAngA.Z;
      WJTLinB.X = bodyB.MassInverse * jLinB.X;
      WJTLinB.Y = bodyB.MassInverse * jLinB.Y;
      WJTLinB.Z = bodyB.MassInverse * jLinB.Z;
      matrix = bodyB.InertiaInverseWorld;
      WJTAngB.X = matrix.M00 * jAngB.X + matrix.M01 * jAngB.Y + matrix.M02 * jAngB.Z;
      WJTAngB.Y = matrix.M10 * jAngB.X + matrix.M11 * jAngB.Y + matrix.M12 * jAngB.Z;
      WJTAngB.Z = matrix.M20 * jAngB.X + matrix.M21 * jAngB.Y + matrix.M22 * jAngB.Z;

      float JWJT = jLinA.X * WJTLinA.X + jLinA.Y * WJTLinA.Y + jLinA.Z * WJTLinA.Z
                   + jAngA.X * WJTAngA.X + jAngA.Y * WJTAngA.Y + jAngA.Z * WJTAngA.Z
                   + jLinB.X * WJTLinB.X + jLinB.Y * WJTLinB.Y + jLinB.Z * WJTLinB.Z
                   + jAngB.X * WJTAngB.X + jAngB.Y * WJTAngB.Y + jAngB.Z * WJTAngB.Z;

      JWJT += Softness;
      JWJTInverse = 1 / JWJT;
    }
        protected override void LoadContent()
        {
            boxModel = Content.Load<Model>("box");
            torusModel = Content.Load<Model>("torus");

            // Get the vertex information out of the model
            List<JVector> positions = new List<JVector>();
            List<JOctree.TriangleVertexIndices> indices = new List<JOctree.TriangleVertexIndices>();
            ExtractData(positions, indices, torusModel);

            // Build an octree of it
            JOctree octree = new JOctree(positions, indices);
            octree.BuildOctree();

            // Pass it to a new instance of the triangleMeshShape
            TriangleMeshShape triangleMeshShape = new TriangleMeshShape(octree);

            // Create a body, using the triangleMeshShape
            RigidBody triangleBody = new RigidBody(triangleMeshShape);
            triangleBody.Tag = Color.LightGray;
            triangleBody.Position = new JVector(0, 3, 0);
            
            // Add the mesh to the world.
            world.AddBody(triangleBody);

            base.LoadContent();
        }
Exemple #5
0
		internal JitterBody(RigidBody jitterBody)
			: base(null)
		{
			this.jitterBody = jitterBody;
			this.jitterBody.Tag = this;
			jitterShape = jitterBody.Shape;
		}
Exemple #6
0
        public Passus (CompositorColorCorrectionNode colorCorrectionNode,
            GameState state, AIManager aiManager, RendererContext rendererContext)
        {
            passusEmitter = new PassusGhostParticleEmitter ();

            PassusGameState = state;

            particlePassus = new ParticleSceneObject (passusEmitter.ParticleCount);
            particlePassus.Priority = 7001;
            state.Scene.AddObject (particlePassus);
            passusEmitter.Init (particlePassus, rendererContext);

            PassusEntity = EntityFactory.Instance.CreateWith ("Passus." + InstanceCount++, state.MessageProxy,
                new[] { typeof (ArtificialIntelligenceComponent) },
                new[] { typeof (ParticleSystem), typeof (PhysicsSystem) });

            PassusEntity.GetComponent<ParticleComponent> ().Emitter = passusEmitter;
            PassusEntity.GetComponent<ParticleComponent> ().Particle = particlePassus;

            RigidBody passusBody = new RigidBody (new SphereShape (1.2f));
            passusBody.AffectedByGravity = false;
            passusBody.AllowDeactivation = false;
            passusBody.Mass = 20;
            PassusEntity.GetComponent<PhysicsComponent> ().RigidBody = passusBody;
            PassusEntity.GetComponent<PhysicsComponent> ().World = state.PhysicsManager.World;
            PassusEntity.GetComponent<PhysicsComponent> ().PhysicsApplying = AffectedByPhysics.Position;

            state.PhysicsManager.World.AddBody (passusBody);

            var AIcomp = PassusEntity.GetComponent<ArtificialIntelligenceComponent>();
            AIcomp.AIManager = aiManager;
            AIcomp.ArtificialIntelligence = new PassusAI (PassusEntity, state, colorCorrectionNode);
            aiManager.RegisterEntity (PassusEntity);
        }
 public cRigidBodyGameObject(float mass, Vertices v)
 {
     _rigidBody = new PolygonRigidBody(mass, v);
     cPhysics.Instance.addObject(this);
     _canAttachPortalTo = false;
     _portaling = false;
 }
        public bool CanJump(RigidBody body)
        {
            Body = WorldItems[body];

            Jitter.Dynamics.RigidBody resultingBody = null;
            JVector normal;
            float fraction;

            var positions = new JVector[] { new JVector(body.Position.X, body.Position.Y, body.Position.Z),
                                            new JVector(body.Position.X + 0.5f, body.Position.Y, body.Position.Z),
                                            new JVector(body.Position.X - 0.5f, body.Position.Y, body.Position.Z),
                                            new JVector(body.Position.X, body.Position.Y, body.Position.Z - 0.5f),
                                            new JVector(body.Position.X, body.Position.Y, body.Position.Z + 0.5f)};

            for (int i = 0; i < positions.Length; i++)
            {
                bool result = World.CollisionSystem.Raycast(new JVector(positions[i].X, positions[i].Y, positions[i].Z),
                                                            new JVector(0, -1, 0),
                                                            RaycastCallback,
                                                            out resultingBody,
                                                            out normal,
                                                            out fraction);

                if (result && fraction <= 1.3f && Body.LinearVelocity.Y < 0.5f)
                {
                    return true;
                }
            }

            return false;
        }
Exemple #9
0
        public override void Build()
        {
            AddGround();

            for (int i = 0; i < 30; i++)
            {
                for (int e = i; e < 30; e++)
                {
                    RigidBody body = new RigidBody(new BoxShape(new JVector(1.0f, 1.0f, 1.0f)));
                    body.Position = new JVector((e - i * 0.5f) * 1.01f + 7, 0.5f + i * 1.0f, 3.0f);
                    Demo.World.AddBody(body);
                    //body.IsParticle = true;
                    //body.AffectedByGravity = false;
                    body.Material.Restitution = 0.0f;
                }
            }

            //BoxShape shape = new BoxShape(JVector.One);

            //for (int i = 0; i < 20; i++)
            //{
            //    for (int e = 0; e < 20; e++)
            //    {
            //        for (int k = 0; k < 20; k++)
            //        {
            //            RigidBody b = new RigidBody(shape);
            //            Demo.World.AddBody(b);
            //            b.Position = new JVector(i, e, k) * 2.0f;
            //            b.AffectedByGravity = false;
            //        }
            //    }
            //}
        }
Exemple #10
0
 public HNode(HNode parent, BoundingSphere volume, RigidBody body = null)
 {
     Parent = parent;
     Volume = volume;
     Body = body;
     Children = new HNode[2];
 }
        public CollisionDetectedMessage (RigidBody body1, RigidBody body2)
        {
            Body1 = body1;
            Body2 = body2;

            MessageId = (int) FreezingArcher.Messaging.MessageId.CollisionDetected;
        }
        public override void Build()
        {
            AddGround();

            for (int i = 0; i < 11; i++)
            {
                RigidBody box = new RigidBody(new BoxShape(1,0.01f,1));
                this.Demo.World.AddBody(box);
                JVector boxPos = new JVector(-15 + i * 3 + 1, 5, 0);

                box.Position = boxPos;
                box.IsStatic = true;

                RigidBody sphere = new RigidBody(new SphereShape(0.5f));
                this.Demo.World.AddBody(sphere);

                sphere.Position = boxPos + JVector.Up * 30;
                sphere.EnableSpeculativeContacts = true;

                // set restitution
                sphere.Material.Restitution = box.Material.Restitution = 1.0f / 10.0f * i;
                sphere.LinearVelocity = new JVector(0, 0, 0);
    

                sphere.Damping = RigidBody.DampingType.Angular;
            }

         
        }
        public BlockObject(PrehenderGame bbg,Vector3 pLocation, Vector3 pSize, Vector3 pVelocity)
        {
            _Location = pLocation;
            _Size = pSize;
            _Velocity = pVelocity;
            FaceTextures = new Dictionary<BlockFaceConstants, string>(){
                {BlockFaceConstants.Front, "Generic_1"},
                {BlockFaceConstants.Back, "Generic_2"},
                {BlockFaceConstants.Top, "Generic_3"},
                {BlockFaceConstants.Bottom,"Generic_4"},
                {BlockFaceConstants.Left,"Invincible"},
                {BlockFaceConstants.Right,"Strong1"}};

            foreach (var iterate in Enum.GetValues(typeof(BlockFaceConstants)))
            {
                FaceColors.Add((BlockFaceConstants)iterate, Color.FromArgb(128,Color.White));
            }
            foreach (var iterate in Enum.GetValues(typeof(BlockFaceConstants)))
            {
                ActiveFaceColors.Add((BlockFaceConstants)iterate, Color.FromArgb(128, Color.Orange));
            }
            BlockBody = new RigidBody(new BoxShape(_Size.X, _Size.Y, _Size.Z));
            BlockBody.AffectedByGravity = false;
            BlockBody.IsStatic = true;
            BlockBody.Mass = 5;
            BlockBody.Tag = this;
            BlockBody.Position = new JVector(_Location.X, _Location.Y, _Location.Z);

            //bbg.PhysicsWorld.AddBody(BlockBody);
        }
Exemple #14
0
        public override void Build()
        {
            model = Demo.Content.Load<Model>("staticmesh");
            boneTransforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(boneTransforms);

            List<TriangleVertexIndices> indices = new List<TriangleVertexIndices>();
            List<Vector3> vertices = new List<Vector3>();

            ExtractData(vertices, indices, model);

            List<JVector> jvertices = new List<JVector>(vertices.Count);
            foreach(Vector3 vertex in vertices) jvertices.Add(Conversion.ToJitterVector(vertex));

            Octree octree = new Octree(jvertices, indices);

            TriangleMeshShape tms = new TriangleMeshShape(octree);
            RigidBody body = new RigidBody(tms);
            body.IsStatic = true;
            //body.EnableDebugDraw = true;
            body.Tag = BodyTag.DontDrawMe;

            Demo.World.AddBody(body);

            AddCar(new JVector(-20, 20, 0));
        }
Exemple #15
0
        public override void Build()
        {
            AddGround();

            for (int i = 0; i < 15; i++)
            {
                bool even = (i % 2 == 0);

                for (int e = 0; e < 3; e++)
                {
                    JVector size = (even) ? new JVector(1, 1, 3) : new JVector(3, 1, 1);
                    RigidBody body = new RigidBody(new BoxShape(size));
                    body.Position = new JVector(3.0f + (even ? e : 1.0f), i + 0.5f,-13.0f +  (even ? 1.0f : e));

                   Demo.World.AddBody(body);
                }

            }

            //BoxShape bs = new BoxShape(10, 10, 0.01f);
            //RigidBody bb = new RigidBody(bs);

            //bb.Position = new JVector(10, 5, 0);

            //Demo.World.AddBody(bb);
            //bb.IsStatic = true;
            
        }
Exemple #16
0
 public TraceResult(RigidBody body, float distance, JVector position, JVector normal)
 {
     this.Body = body;
     this.Distance = distance;
     this.Position = position;
     this.Normal = normal;
 }
        private void BuildScene()
        {
            // creating two boxShapes with different sizes
            Shape boxShape = new BoxShape(JVector.One);
            Shape groundShape = new BoxShape(new JVector(10, 1, 10));

            // create new instances of the rigid body class and pass 
            // the boxShapes to them
            RigidBody boxBody1 = new RigidBody(boxShape);
            RigidBody boxBody2 = new RigidBody(boxShape);

            boxBody1.Tag = Color.LightPink;
            boxBody2.Tag = Color.LightSkyBlue;

            RigidBody groundBody = new RigidBody(groundShape);

            groundBody.Tag = Color.LightGreen;

            // set the position of the box size=(1,1,1)
            // 2 and 5 units above the ground box size=(10,1,10)
            boxBody1.Position = new JVector(0, 2, 0.0f);
            boxBody2.Position = new JVector(0, 5, 0.2f);
            
            // make the body static, so it can't be moved
            groundBody.IsStatic = true;

            // add the bodies to the world.
            world.AddBody(boxBody1);
            world.AddBody(boxBody2);
            world.AddBody(groundBody);
        }
Exemple #18
0
        //protected CarObject car = null;
        public void AddGround(bool solid)
        {
            if (solid)
            {
                ground = new RigidBody(new BoxShape(3600, 1f));
                //ground.SetMassProperties(float.MaxValue, float.MaxValue, false);
                ground.Position = new JVector(0, 0);
                ground.IsStatic = true;
                Demo.World.AddBody(ground);
                ground.Material.DynamicFriction = 1.0f;
                ground.Material.StaticFriction = 1.0f;
                ground.Material.Restitution = 0.0f;
            }
            else
            {
                List<JVector> groundLine = new List<JVector> { new JVector(-40f, 0f), new JVector(40f, 0f) };

                ground = new RigidBody(new BoxShape(new JVector(1.0f, 1.0f)));
                ground.Position = new JVector(0, -10);
                ground.Orientation = 0;
                ground.IsStatic = true;
                ground.SetMassProperties(float.MaxValue, float.MaxValue, false);
                Demo.World.AddBody(ground);
                ground.Material.DynamicFriction = 1.0f;
                ground.Material.Restitution = 0.0f;
            }
        }
        /// <summary>
        /// Initializes a new instance of the DistanceConstraint class.
        /// </summary>
        /// <param name="body1">The first body.</param>
        /// <param name="body2">The second body.</param>
        /// <param name="anchor1">The anchor point of the first body in world space. 
        /// The distance is given by the initial distance between both anchor points.</param>
        /// <param name="anchor2">The anchor point of the second body in world space.
        /// The distance is given by the initial distance between both anchor points.</param>
        public PointOnPoint(RigidBody body, JVector localAnchor)
            : base(body, null)
        {
            localAnchor1 = localAnchor;

            this.anchor = body.position + JVector.Transform(localAnchor, body.orientation);
        }
Exemple #20
0
        public Roaches (GameState state, AIManager aiManager, RendererContext rendererContext)
        {
            RoachGameState = state;

            roachGroup = new RoachGroup (state.Scene);

            RoachEntity = EntityFactory.Instance.CreateWith("Roach." + InstanceCount++, state.MessageProxy,
                new[] { typeof (ArtificialIntelligenceComponent) },
                new[] { typeof (PhysicsSystem), typeof (RoachGroupSystem) });

            RoachEntity.GetComponent<RoachGroupComponent>().RoachGroup = roachGroup;

            RigidBody roachBody = new RigidBody (new CylinderShape (0.05f, 1));
            roachBody.AffectedByGravity = false;
            roachBody.AllowDeactivation = false;
            roachBody.Mass = 20;
            roachBody.Tag = roachGroup;
            RoachEntity.GetComponent<PhysicsComponent> ().RigidBody = roachBody;
            RoachEntity.GetComponent<PhysicsComponent> ().World = state.PhysicsManager.World;
            RoachEntity.GetComponent<PhysicsComponent> ().PhysicsApplying = AffectedByPhysics.Position;

            state.PhysicsManager.World.AddBody (roachBody);

            RoachEntity.GetComponent<ArtificialIntelligenceComponent>().AIManager = aiManager;
            RoachEntity.GetComponent<ArtificialIntelligenceComponent>().ArtificialIntelligence =
                new RoachesAI (roachGroup, RoachEntity, state);
            aiManager.RegisterEntity (RoachEntity);
        }
 public RigidBodyMassFrame(RigidBody rigidBody)
 {
     _rigidBody = rigidBody;
     var defaultMassFrameDescriptor = new MassFrameDescriptor();
     defaultMassFrameDescriptor.ToDefault();
     Descriptor = defaultMassFrameDescriptor;
 }
Exemple #22
0
        public override void Build()
        {
            AddGround();

            RigidBody last = null;

            for (int i = 0; i < 12; i++)
            {
                RigidBody body = new RigidBody(new BoxShape(JVector.One));
                body.Position = new JVector(i * 1.5f-20, 0.5f, 0);

                JVector jpos2 = body.Position;

                Demo.World.AddBody(body);
                body.Update();

                if (last != null)
                {
                    JVector jpos3 = last.Position;

                    JVector dif; JVector.Subtract(ref jpos2, ref jpos3, out dif);
                    JVector.Multiply(ref dif, 0.5f, out dif);
                    JVector.Subtract(ref jpos2, ref dif, out dif);

                    Constraint cons = new PointOnPoint(last, body, dif);
                    Demo.World.AddConstraint(cons);
                }

                last = body;
            }
           
        }
 private void CreateCube(int height)
 {
     var boxShape = new BoxShape(JVector.One);
     var boxBody = new RigidBody(boxShape);
     boxBody.Position = new JVector(0, 0.5f + height * 2.2f, height * 0.1f);
     world.AddBody(boxBody);
 }
Exemple #24
0
        public override void Build()
        {

            AddGround();

            // we need some of them!
            Demo.World.SetIterations(5);

            PseudoCloth pc = new PseudoCloth(Demo.World, 20,20, 0.5f);

            BoxShape boxShape = new BoxShape(JVector.One);

            RigidBody[] boxes = new RigidBody[4];

            int size = 19;

            for(int i=0;i<4;i++)
            {
                boxes[i] = new RigidBody(boxShape);
                boxes[i].Position = new JVector(i % 2 == 0 ? 10.0f : -0.5f, 10.5f, (i < 2) ? 10.0f : -0.5f);
               // Demo.World.AddBody(boxes[i]);



                if (i == 0)
                {

                    pc.GetCorner(size, size).IsStatic = true;
                }
                else if (i == 1)
                {

                    pc.GetCorner(size, 0).IsStatic = true;
                }
                else if (i == 2)
                {

                    pc.GetCorner(0, size).IsStatic = true;
                }
                else if (i == 3)
                {
                 
                   pc.GetCorner(0, 0).IsStatic = true;
                }

                boxes[i].IsStatic = true;
            }

            RigidBody sphereBody = new RigidBody(new SphereShape(2.0f));
            Demo.World.AddBody(sphereBody);
            sphereBody.Mass = 10.0f;
            sphereBody.Position = new JVector(5, 20, 5);

            //ConvexHullObject2 obj2 = new ConvexHullObject2(this.Demo);
            //Demo.Components.Add(obj2);

            //obj2.body.Position = new JVector(5, 30, 5);
            //Demo.World.AddBody(obj2.body);

        }
 public void CanCreateAndDisposeCleanly()
 {
     RigidBody rb = new RigidBody();
     Assert.IsTrue(rb.Handle != IntPtr.Zero);
     rb.Dispose();
     Assert.IsTrue(rb.Handle == IntPtr.Zero);
 }
        public void Rope()
        {
    RigidBody last = null;

    for (int i = 0; i < RopeSize; i++)
    {
        RigidBody body = new RigidBody(new BoxShape(JVector.One));
        body.Position = new JVector(i * 1.5f, 0.5f, 0);

        JVector jpos2 = body.Position;

        body.Position = jpos2;

        world.AddBody(body);
        body.Update();

        if (last != null)
        {
            JVector jpos3 = last.Position;

            JVector dif; JVector.Subtract(ref jpos2, ref jpos3, out dif);
            JVector.Multiply(ref dif, 0.5f, out dif);
            JVector.Subtract(ref jpos2, ref dif, out dif);

            Constraint cons = new PointConstraint(last, body, dif);
            world.AddConstraint(cons);
        }

        last = body;
    }
        }
        public override void Build()
        {
            AddGround();

            RigidBody body1 = new RigidBody(new BoxShape(1, 1, 1));
            RigidBody body2 = new RigidBody(new BoxShape(1, 1, 1));

            body1.Position = new JVector(0, 7, 0);
            body2.Position = new JVector(0, 4, 0);

            // add a prismatic joint.
            // the minimum allowed distance is 3
            // the maximum allowed distance is also 3
            // => the body should be fixed on the slider
            PrismaticJoint pj = new PrismaticJoint(Demo.World, body1, body2, 3, 3);

            // but we set very heigh softness (1.0f) to the minimum distance
            // so we have something like a suspension effect.
            pj.MaximumDistanceConstraint.Softness = 0.0f;
            pj.MinimumDistanceConstraint.Softness = 1.0f;
            pj.Activate();

            Demo.World.AddBody(body1);
            Demo.World.AddBody(body2);
        }
Exemple #28
0
        /// <summary>
        /// This method handles explicit object collision logic. Is registered to physics engine CollisionDetected event handler.
        /// Fired on any detected collision, so must check if the collision applies to this object
        /// </summary>
        /// <param name="body1"></param>
        /// <param name="body2"></param>
        /// <param name="point1"></param>
        /// <param name="point2"></param>
        /// <param name="normal"></param>
        /// <param name="penetration"></param>
        virtual public void HandleCollision(RigidBody body1, RigidBody body2, JVector point1, JVector point2, JVector normal, float penetration)
        {
            // work out which, if any, of the collided bodies is this object, and name them semantically
            RigidBody other;
            var self = this.PhysicsDescription;
            if (body1 == self)
                other = body2;
            else if (body2 == self)
                other = body1;
            else return;

            if (other == this.flock.level.endGoal.PhysicsDescription) // we've collided with the end zone
            {
                // be careful of what you modify in this handler as it may be called during an Update()
                // attempting to modify any list (such as destroying game objects, etc) will cause an exception

                if (!ToDestroy) // incremement score once before destroy
                {
                    this.game.incScore(10);
                }
                this.Destroy(true); // remove self
            }    

            Collision(other); // do other collision stuff
        }
Exemple #29
0
    /// <summary>
    /// Applies the given constraint impulse.
    /// </summary>
    public void ApplyImpulse(RigidBody bodyA, RigidBody bodyB, float impulse)
    {
      var linearVelocityA = bodyA.LinearVelocity;
      linearVelocityA.X += WJTLinA.X * impulse;
      linearVelocityA.Y += WJTLinA.Y * impulse;
      linearVelocityA.Z += WJTLinA.Z * impulse;
      bodyA.LinearVelocity = linearVelocityA;

      var angularVelocityA = bodyA.AngularVelocity;
      angularVelocityA.X += WJTAngA.X * impulse;
      angularVelocityA.Y += WJTAngA.Y * impulse;
      angularVelocityA.Z += WJTAngA.Z * impulse;
      bodyA.AngularVelocity = angularVelocityA;

      var linearVelocityB = bodyB.LinearVelocity;
      linearVelocityB.X += WJTLinB.X * impulse;
      linearVelocityB.Y += WJTLinB.Y * impulse;
      linearVelocityB.Z += WJTLinB.Z * impulse;
      bodyB.LinearVelocity = linearVelocityB;

      var angularVelocityB = bodyB.AngularVelocity;
      angularVelocityB.X += WJTAngB.X * impulse;
      angularVelocityB.Y += WJTAngB.Y * impulse;
      angularVelocityB.Z += WJTAngB.Z * impulse;
      bodyB.AngularVelocity = angularVelocityB;
    }
        /// <summary>
        /// Hit the specified item, rigidBody, normal and fraction.
        /// </summary>
        /// <param name="item">Item.</param>
        /// <param name="rigidBody">Rigid body.</param>
        /// <param name="normal">Normal.</param>
        /// <param name="fraction">Fraction.</param>
        public void Hit (ItemComponent item, RigidBody rigidBody, Vector3 normal, float fraction)
        {
            var entity = rigidBody.Tag as Entity;

            if (entity != null)
            {
                var model = entity.GetComponent<ModelComponent>().Model;
                var health = entity.GetComponent<HealthComponent>();
                var wallcomp = entity.GetComponent<WallComponent>();
                health.Health = (health.Health - item.AttackStrength) < 0 ? 0 : health.Health - item.AttackStrength;
                var tmp = (health.MaximumHealth - health.Health) / health.MaximumHealth;
                var pos = model.Position;
                pos.Y = 7.5f * tmp + 0.25f;

                if (wallcomp.IsOverworld)
                    pos.Y *= -2;

                model.Position = pos;
                var rbpos = rigidBody.Position;
                rbpos.Y = pos.Y + 8;
                rigidBody.Position = rbpos;
                item.Usage = item.Usage <= (1 - item.UsageDeltaPerUsage) ? item.Usage + item.UsageDeltaPerUsage : 1f;
                wallcomp.IsMoveable = false;
                return;
            }
        }