Exemplo n.º 1
0
        private void CreateComposite()
        {
            var        compositeRigidBodyDescriptor = new RigidBodyDescriptor(MotionType.Dynamic, Matrices.Translate(0f, 10, 0), true);
            IRigidBody composite     = _simulator.ActorsFactory.CreateRigidBody(compositeRigidBodyDescriptor);
            var        sphereFixture =
                composite.FixtureFactory.CreateSimpleFixture(new FixtureDescriptor(Matrices.I));

            sphereFixture.MaterialFactory.CreateMaterial(new MaterialDescriptor(0.01f, 1.01f));
            var compositeShape =
                sphereFixture.ShapeFactory.CreateComposite(new CompositeShapeDescriptor());
            var shapePositionerCenter =
                compositeShape.ShapePositionerFactory.CreateShapePositioner(
                    new ShapePositionerDescriptor(Matrices.I));

            shapePositionerCenter.ShapeFactory.CreateSphere(new SphereShapeDescriptor(1.5f));
            var shapePositionerLeft =
                compositeShape.ShapePositionerFactory.CreateShapePositioner(
                    new ShapePositionerDescriptor(Matrices.Translate(-2.5f, 0, 0)));

            shapePositionerLeft.ShapeFactory.CreateSphere(new SphereShapeDescriptor(0.5f));
            var shapePositionerRight =
                compositeShape.ShapePositionerFactory.CreateShapePositioner(
                    new ShapePositionerDescriptor(Matrices.Translate(2.5f, 0, 0)));

            shapePositionerRight.ShapeFactory.CreateSphere(new SphereShapeDescriptor(0.5f));
        }
Exemplo n.º 2
0
        protected virtual void DeviceTransporter_Collided(IRigidBody impactB)
        {
            if (impactB is DeviceTransporter)
            {
                //lol. explode maybe?
            }
            else if (impactB is Bomb)
            {
                //loololol!
            }
            else if (impactB is DeviceCarrierActor)
            {
                //transfer payload to other body upon impact
                var target = (DeviceCarrierActor)impactB;

                foreach (Device device in GetDevices())
                {
                    target.AddDevice(device);
                    device.Suppressed = false;
                }
                this.ClearDevices();

                selfdestruct();
            }
        }
Exemplo n.º 3
0
 public Contact()
 {
     Bodies = new IRigidBody[2];
       Restitution = 1f;
       Friction = 0f;
       DiscoveryHint = ContactDiscoveryHint.None;
 }
Exemplo n.º 4
0
 public GameScroller(IRigidBody centeredObject, GFXContainer gfxContainer, FrameworkElement viewWindow)
 {
     this.CenteredObject     = centeredObject;
     this.GContainer         = gfxContainer;
     this.ViewWindow         = viewWindow;
     GContainer.UpdateFrame += Update;
 }
Exemplo n.º 5
0
        private Vector3[] timeStep(IRigidBody rigidBody, float factor)
        {
            Vector3 accel    = rigidBody.m_PreviousFrameAcceleration;
            Vector3 velocity = rigidBody.m_PreviousFrameVelocity;
            Vector3 pos      = rigidBody.m_PreviousFramePosition;

            if (rigidBody.m_Kinematic)
            {
                if (accel != new Vector3())
                {
                    accel = rigidBody.m_PreviousFrameAcceleration.ReturnMultipleByScalar((float)Constant.elapsedTime * factor);
                }
                if (rigidBody.m_Drag > 0.0f)
                {
                    Vector3 Temp = accel.ReturnMultipleByScalar(rigidBody.m_Drag);
                    accel.SubtractVector(Temp);
                }

                velocity.AddScalarVector(rigidBody.m_PreviousFrameAcceleration, ((float)Constant.elapsedTime * factor));
                pos.AddScalarVector(rigidBody.m_PreviousFrameVelocity, (float)Constant.elapsedTime * factor);

                return(new Vector3[] { velocity, pos });
            }
            else
            {
                Vector3 vectorChange = rigidBody.m_Position.ReturnSubtractVector(pos);
                pos.AddVector(vectorChange.ReturnMultipleByScalar(factor));
                return(new Vector3[] { velocity, pos });
            }
        }
Exemplo n.º 6
0
        internal DigitalRuneHingeJoint(HingeJointDescriptor descriptor)
        {
            WrappedHingeJoint = new HingeJoint();

            #region set RigidBodies
            if (!(descriptor.RigidBodyA is RigidBody))
            {
                throw new ArgumentException(String.Format("The type of the property 'RigidBodyA' must be '{0}'.", typeof(RigidBody)));
            }
            WrappedHingeJoint.BodyA = ((RigidBody)descriptor.RigidBodyA).WrappedRigidBody;
            _rigidBodyA             = descriptor.RigidBodyA;

            if (!(descriptor.RigidBodyB is RigidBody))
            {
                throw new ArgumentException("The type of the property 'RigidBodyB' must be 'System.Physics.DigitalRune.RigidBody'.");
            }
            WrappedHingeJoint.BodyB = ((RigidBody)descriptor.RigidBodyB).WrappedRigidBody;
            _rigidBodyB             = descriptor.RigidBodyB;
            #endregion
            WrappedHingeJoint.AnchorPoseALocal = descriptor.AnchorPoseALocal.ToDigitalRune();
            WrappedHingeJoint.AnchorPoseBLocal = descriptor.AnchorPoseBLocal.ToDigitalRune();
            WrappedHingeJoint.Maximum          = descriptor.MaximumAngle;
            WrappedHingeJoint.Minimum          = descriptor.MinimumAngle;

            Descriptor = descriptor;
        }
Exemplo n.º 7
0
 void Astroid_Collided(IRigidBody impactBody)
 {
     if (impactBody is Player)// /*|| impactBody is BombRoid || impactBody is GoodRoid*/ || impactBody is Bomb)
     {
         this.TriggerFuse(FuseTime);
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Computes the impulse of a collision of 2 rigid bodies, given the other body, the impact position,
        /// and the surface normal of this body at the impact position.
        /// </summary>
        public static Vector2 ComputeImpulse(this IRigidBody body, IRigidBody other, Vector2 pos, Vector2 normal)
        {
            Vector2 vrel      = body.VelocityAt(pos) - other.VelocityAt(pos);
            float   vrelOrtho = -Vector2.Dot(vrel, normal);

            // We don't want to consider collisions where objects move away from each other.
            // (Or with negligible velocity. Let repulsive forces handle these.)
            if (vrelOrtho > -0.001f)
            {
                return(Vector2.Zero);
            }

            float impulseMagnitude = -(1.0f + body.Restitution) * vrelOrtho;

            impulseMagnitude /= body.ImpulseDenominator(pos, normal) + other.ImpulseDenominator(pos, normal);

            //impulseMagnitude = Math.Max(impulseMagnitude - 0.01f, 0.0f);

            Vector2 impulse = -normal * impulseMagnitude;

            // Add "friction" to the impulse. We arbitrarily reduce the planar velocity relative to the impulse magnitude.
            Vector2 vrelPlanar       = vrel + vrelOrtho * normal;
            float   vrelPlanarLength = vrelPlanar.Length;

            if (vrelPlanarLength > 0)
            {
                impulse -= vrelPlanar * Math.Min(impulseMagnitude * 0.05f * body.FrictionCoefficient * other.FrictionCoefficient / vrelPlanarLength, body.Mass);
            }

            return(impulse);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Checks for and records all collisions with another body. If collisions were found,
        /// their aggregate is handled.
        /// </summary>
        public bool CheckAndHandleCollisionWith(IRigidBody other)
        {
            if (!other.ScreenSpaceDrawQuad.AABB.IntersectsWith(ScreenSpaceDrawQuad.AABB))
            {
                return(false);
            }

            bool didCollide = false;

            for (int i = 0; i < Vertices.Count; ++i)
            {
                if (other.BodyContains(Vector2Extensions.Transform(Vertices[i], SimulationToScreenSpace)))
                {
                    // Compute both impulse responses _before_ applying them, such that
                    // they do not influence each other.
                    Vector2 impulse      = this.ComputeImpulse(other, Vertices[i], Normals[i]);
                    Vector2 impulseOther = other.ComputeImpulse(this, Vertices[i], -Normals[i]);

                    ApplyImpulse(impulse, Vertices[i]);
                    other.ApplyImpulse(impulseOther, Vertices[i]);

                    didCollide = true;
                }
            }

            return(didCollide);
        }
Exemplo n.º 10
0
 public void OnCollided(IRigidBody impactB)
 {
     if (Collided != null)
     {
         Collided(impactB);
     }
 }
Exemplo n.º 11
0
        public static void SetForceEffectScene(ISimulator simulator)
        {
            int echelonCount = 7;
            var chain        = new IRigidBody[echelonCount];

            for (int i = 0; i < echelonCount; i++)
            {
                chain[i] = SetSimpleRigidBody <ISphereShape, SphereShapeDescriptor>(simulator, new RigidBodyDescriptor(i == 0 ? MotionType.Static : MotionType.Dynamic, Matrices.Translate(-i, 10, 0), _motionColor), new SphereShapeDescriptor(0.4f), new MaterialDescriptor(0.5f, 0.5f));
                if (i > 0)
                {
                    simulator.ConstraintsFactory.CreateSphericalJoint(
                        new SphericalJointDescriptor(
                            new Vector3(1f, 0, 0), new Vector3(), chain[i], chain[i - 1]));
                }
            }

            for (int i = 0; i < 2 * echelonCount; i++)
            {
                SetSimpleRigidBody <IBoxShape, BoxShapeDescriptor>(simulator, new RigidBodyDescriptor(MotionType.Dynamic, Matrices.Translate(-i, (i + 1) * 0.1f / 2, 10), _motionColor), new BoxShapeDescriptor((i + 1) * 0.1f, (i + 1) * 0.1f, (i + 1) * 0.1f), new MaterialDescriptor(0.5f, 0.5f));
            }

            simulator.AddForceEffect(new AttractionForceEffect(chain[echelonCount - 1]));

            SetGround(simulator, new MaterialDescriptor(0.5f, 0.5f));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Helper function for code brevity in <see cref="ComputeImpulse(IRigidBody, IRigidBody, Vector2, Vector2)"/>.
        /// Can be moved into the function as a nested method once C# 7 is out.
        /// </summary>
        public static float ImpulseDenominator(this IRigidBody body, Vector2 pos, Vector2 normal)
        {
            Vector2 diff    = pos - body.Centre;
            float   perpDot = Vector2.Dot(normal, diff.PerpendicularRight);

            return(1.0f / body.Mass + perpDot * perpDot / body.MomentOfInertia);
        }
Exemplo n.º 13
0
 /*
  * Player Logic
  */
 void Player_Collided(IRigidBody impactB)
 {
     //    if (body1 is Treasure && body2 == this)
     //        ((GameObjects.Actor)body1).Destroy();
     if (impactB is Treasure)
         ((GameObjects.Actor)impactB).Destroy();
 }
Exemplo n.º 14
0
        private void CreateChain <TShape, TShapeDescriptor>(MaterialDescriptor materialDescriptor,
                                                            TShapeDescriptor shapeDescriptor,
                                                            DistanceRangeJointDescriptor constraintDescriptor,
                                                            int count, float space, int staticBall, float xOffset, float yOffset, float zOffset)
            where TShapeDescriptor : struct, IDescriptor
            where TShape : IShape, IDescriptible <TShapeDescriptor>
        {
            var bodies = new IRigidBody[count];
            var rigidBodyDescriptor = new RigidBodyDescriptor(MotionType.Static, Matrices.I, true);

            for (int i = 0; i < count; i++)
            {
                rigidBodyDescriptor.Pose = Matrices.Translate(xOffset + (space + i * space - ((count - 1) * space / 2)), yOffset, zOffset);
                bodies[i]          = _simulator.ActorsFactory.Create <IRigidBody, RigidBodyDescriptor>(rigidBodyDescriptor);
                bodies[i].UserData = String.Format("chain {0}", i);
                var fixture = bodies[i].FixtureFactory.Create <ISimpleFixture, FixtureDescriptor>(new FixtureDescriptor(Matrices.I));
                fixture.ShapeFactory.Create <TShape, TShapeDescriptor>(shapeDescriptor);
                fixture.MaterialFactory.Create <IMaterial, MaterialDescriptor>(materialDescriptor);
                if (i > 0)
                {
                    constraintDescriptor.RigidBodyA = bodies[i - 1];
                    constraintDescriptor.RigidBodyB = bodies[i];
                    _simulator.ConstraintsFactory.Create <IDistanceRangeJoint, DistanceRangeJointDescriptor>(
                        constraintDescriptor);
                }
                else
                {
                    rigidBodyDescriptor.MotionType = MotionType.Static;
                }
            }
        }
Exemplo n.º 15
0
        protected virtual void DeviceTransporter_Collided(IRigidBody impactB)
        {
            if (impactB is DeviceTransporter)
            {
                //lol. explode maybe?
            }
            else if (impactB is Bomb)
            {
                //loololol!
            }
            else if (impactB is DeviceCarrierActor)
            {
                //transfer payload to other body upon impact
                var target = (DeviceCarrierActor)impactB;

                foreach (Device device in GetDevices())
                {
                    target.AddDevice(device);
                    device.Suppressed = false;
                }
                this.ClearDevices();

                selfdestruct();
            }
        }
Exemplo n.º 16
0
 void Player_Collided(IRigidBody impactedBody)
 {
     if (impactedBody is Bomb)
     {
         this.Hurt(20);
     }
 }
Exemplo n.º 17
0
        public CollisionData(IRigidBody targetB, Vector2 dpos, Vector2 dvel, float dangvel)
        {
            TargetBody = targetB;

            dPos = dpos;
            dVel = dvel;
            dAngVel = dangvel;
        }
        public TilingPlaneEntity(IRigidBody body, IGeometryData geometryData)
        {
            if (geometryData.Prim.PrimType != CollideType.Plane) {throw new InvalidOperationException("You may not use this class with a CollideType other than CollideType.Plane");}

            this.body = body;
            this.geometryData = geometryData;
            //this.Texture = texture;
        }
 public NoRotationJointDescriptor(Matrix3x3 anchorOrientationALocal, Matrix3x3 anchorOrientationBLocal, IRigidBody rigidBodyA = null, IRigidBody rigidBodyB = null, object userData = null) : this()
 {
     AnchorOrientationALocal = anchorOrientationALocal;
     AnchorOrientationBLocal = anchorOrientationBLocal;
     RigidBodyA = rigidBodyA;
     RigidBodyB = rigidBodyB;
     UserData   = userData;
 }
Exemplo n.º 20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="targetB">The body which is being hit. Normal is with respect to this body. (outward from TargetBody)</param>
 /// <param name="impactB">The body impacting TargetBody.</param>
 /// <param name="conpt"></param>
 /// <param name="norm">with respect to this body. (outward from TargetBody)</param>
 /// <param name="disp"></param>
 public Contact(IRigidBody targetB, IRigidBody impactB, Vector2 conpt, Vector2 norm, float disp)
 {
     TargetBody = targetB;
     ImpactBody = impactB;
     ConPoint   = conpt;
     Normal     = norm;
     Disp       = disp;
 }
 public SphericalJointDescriptor(Vector3 anchorPositionALocal, Vector3 anchorPositionBLocal, IRigidBody rigidBodyA = null, IRigidBody rigidBodyB = null, object userData = null) : this()
 {
     AnchorPositionALocal = anchorPositionALocal;
     AnchorPositionBLocal = anchorPositionBLocal;
     RigidBodyA           = rigidBodyA;
     RigidBodyB           = rigidBodyB;
     UserData             = userData;
 }
Exemplo n.º 22
0
        public CollisionData(IRigidBody targetB, Vector2 dpos, Vector2 dvel, float dangvel)
        {
            TargetBody = targetB;

            dPos    = dpos;
            dVel    = dvel;
            dAngVel = dangvel;
        }
 public NoRotationJointDescriptor(Matrix3x3 anchorOrientationALocal, Matrix3x3 anchorOrientationBLocal, IRigidBody rigidBodyA = null, IRigidBody rigidBodyB = null, object userData = null) : this()
 {
     AnchorOrientationALocal = anchorOrientationALocal;
     AnchorOrientationBLocal = anchorOrientationBLocal;
     RigidBodyA = rigidBodyA;
     RigidBodyB = rigidBodyB;
     UserData = userData;
 }
 public SphericalJointDescriptor(Vector3 anchorPositionALocal, Vector3 anchorPositionBLocal, IRigidBody rigidBodyA = null, IRigidBody rigidBodyB = null, object userData = null) : this()
 {
     AnchorPositionALocal = anchorPositionALocal;
     AnchorPositionBLocal = anchorPositionBLocal;
     RigidBodyA = rigidBodyA;
     RigidBodyB = rigidBodyB;
     UserData = userData;
 }
Exemplo n.º 25
0
        /*
         * Player Logic
         */

        void Player_Collided(IRigidBody impactB)
        {
            //    if (body1 is Treasure && body2 == this)
            //        ((GameObjects.Actor)body1).Destroy();
            if (impactB is Treasure)
            {
                ((GameObjects.Actor)impactB).Destroy();
            }
        }
Exemplo n.º 26
0
 public FixedJointDescriptor(Matrix4x4 anchorPoseALocal, Matrix4x4 anchorPoseBLocal, IRigidBody rigidBodyA = null, IRigidBody rigidBodyB = null, object userData = null)
     : this()
 {
     AnchorPoseALocal = anchorPoseALocal;
     AnchorPoseBLocal = anchorPoseBLocal;
     RigidBodyA       = rigidBodyA;
     RigidBodyB       = rigidBodyB;
     UserData         = userData;
 }
Exemplo n.º 27
0
        public ModelEntity(Model model, IRigidBody body, EntityGeometryData geoData)
        {
            this.body = body;
            this.Model = model;

            this.GeometryData = geoData;
            DebugCompass = new DebugCompass(this.CenterOfMass);
            DebugCompass.LoadContent(null);
        }
Exemplo n.º 28
0
 public FixedJointDescriptor(Matrix4x4 anchorPoseALocal, Matrix4x4 anchorPoseBLocal, IRigidBody rigidBodyA = null, IRigidBody rigidBodyB = null,  object userData = null)
     : this()
 {
     AnchorPoseALocal = anchorPoseALocal;
     AnchorPoseBLocal = anchorPoseBLocal;
     RigidBodyA = rigidBodyA;
     RigidBodyB = rigidBodyB;
     UserData = userData;
 }
 public DistanceRangeJointDescriptor(Vector3 anchorPositionALocal, Vector3 anchorPositionBLocal, float minDistance, float maxDistance, IRigidBody rigidBodyA = null, IRigidBody rigidBodyB = null, object userData = null) : this()
 {
     RigidBodyA = rigidBodyA;
     RigidBodyB = rigidBodyB;
     UserData = userData;
     AnchorPositionALocal = anchorPositionALocal;
     AnchorPositionBLocal = anchorPositionBLocal;
     MinimumDistance = minDistance;
     MaximumDistance = maxDistance;
 }
Exemplo n.º 30
0
 public HingeJointDescriptor(Matrix4x4 anchorPoseALocal, Matrix4x4 anchorPoseBLocal, float maximumAngle, float minimumAngle, IRigidBody rigidBodyA = null, IRigidBody rigidBodyB = null, object userData = null) : this()
 {
     AnchorPoseALocal = anchorPoseALocal;
     AnchorPoseBLocal = anchorPoseBLocal;
     MaximumAngle = maximumAngle;
     MinimumAngle = minimumAngle;
     RigidBodyA = rigidBodyA;
     RigidBodyB = rigidBodyB;
     UserData = userData;
 }
Exemplo n.º 31
0
 public DistanceRangeJointDescriptor(Vector3 anchorPositionALocal, Vector3 anchorPositionBLocal, float minDistance, float maxDistance, IRigidBody rigidBodyA = null, IRigidBody rigidBodyB = null, object userData = null) : this()
 {
     RigidBodyA           = rigidBodyA;
     RigidBodyB           = rigidBodyB;
     UserData             = userData;
     AnchorPositionALocal = anchorPositionALocal;
     AnchorPositionBLocal = anchorPositionBLocal;
     MinimumDistance      = minDistance;
     MaximumDistance      = maxDistance;
 }
Exemplo n.º 32
0
        private void CreateMassTesting(float xPosition, float side, float mass)
        {
            var        rigidBodyDescriptor = new RigidBodyDescriptor(MotionType.Dynamic, Matrices.Translate(xPosition, 10, 0), true);
            IRigidBody rigidBody           = _simulator.ActorsFactory.Create <IRigidBody, RigidBodyDescriptor>(rigidBodyDescriptor);
            var        fixture             = rigidBody.FixtureFactory.Create <ISimpleFixture, FixtureDescriptor>(new FixtureDescriptor(Matrices.I));

            fixture.MaterialFactory.Create <IMaterial, MaterialDescriptor>(new MaterialDescriptor(0.01f, 1.01f));
            fixture.ShapeFactory.Create <IBoxShape, BoxShapeDescriptor>(new BoxShapeDescriptor(side, side, side));
            rigidBody.MassFrame.Mass = mass;
        }
Exemplo n.º 33
0
 public Sphere(TestableGameObject obj,
               IRigidBody body,
               ISphereCollider collider,
               [Resource("mesh/sphere")] TestableGameObject sphere)
 {
     this.obj                = obj;
     this.collider           = collider;
     this.body               = body;
     sphere.transform.Parent = obj.transform;
 }
Exemplo n.º 34
0
 public Sphere(TestableGameObject obj,
     IRigidBody body,
     ISphereCollider collider,
     [Resource("mesh/sphere")] TestableGameObject sphere)
 {
     this.obj = obj;
     this.collider = collider;
     this.body = body;
     sphere.transform.Parent = obj.transform;
 }
Exemplo n.º 35
0
 public HingeJointDescriptor(Matrix4x4 anchorPoseALocal, Matrix4x4 anchorPoseBLocal, float maximumAngle, float minimumAngle, IRigidBody rigidBodyA = null, IRigidBody rigidBodyB = null, object userData = null) : this()
 {
     AnchorPoseALocal = anchorPoseALocal;
     AnchorPoseBLocal = anchorPoseBLocal;
     MaximumAngle     = maximumAngle;
     MinimumAngle     = minimumAngle;
     RigidBodyA       = rigidBodyA;
     RigidBodyB       = rigidBodyB;
     UserData         = userData;
 }
Exemplo n.º 36
0
 public static float InvMass(this IRigidBody rigidBody)
 {
     if (rigidBody.HasInfiniteMass)
     {
         return(0.0f);
     }
     else
     {
         return(1.0f / rigidBody.Mass);
     }
 }
Exemplo n.º 37
0
    public TestableExample(TestableGameObject parent, ISphereCollider collider, IRigidBody body,
                           IResourceLoader loader) : base(parent)
    {
        this.collider = collider;
        this.body     = body;

        this.collider.radius = 5.0f;
        this.body.mass       = 4.0f;

        loader.instantiate("Sphere").transform.Parent = Obj.transform;
    }
Exemplo n.º 38
0
 protected void Bomb_Collided(IRigidBody impactB)
 {
     if (impactB == _launcher)
         return;
     else if (impactB is Asteroid)
     {
         this.Destroy();
     }
     else
     {
         ((Charge)this.GetDevices()[0]).Detonate();
     }
 }
Exemplo n.º 39
0
 protected void Bomb_Collided(IRigidBody impactB)
 {
     if (impactB == _launcher)
     {
         return;
     }
     else if (impactB is Asteroid)
     {
         this.Destroy();
     }
     else
     {
         ((Charge)this.GetDevices()[0]).Detonate(DamageConstant);
     }
 }
 public PointOnPlaneJointDescriptor(Vector3 anchorPositionALocal, Vector3 xAxisALocal, Vector3 yAxisALocal, Vector3 anchorPositionBLocal, float maximumDistanceX, float minimumDistanceX, float maximumDistanceY, float minimumDistanceY, IRigidBody rigidBodyA = null, IRigidBody rigidBodyB = null, object userData = null)
     : this()
 {
     AnchorPositionALocal = anchorPositionALocal;
     YAxisALocal = yAxisALocal;
     AnchorPositionBLocal = anchorPositionBLocal;
     MaximumDistanceX = maximumDistanceX;
     MinimumDistanceX = minimumDistanceX;
     MaximumDistanceY = maximumDistanceY;
     MinimumDistanceY = minimumDistanceY;
     RigidBodyA = rigidBodyA;
     RigidBodyB = rigidBodyB;
     UserData = userData;
     XAxisALocal = xAxisALocal;
 }
Exemplo n.º 41
0
 public PointOnPlaneJointDescriptor(Vector3 anchorPositionALocal, Vector3 xAxisALocal, Vector3 yAxisALocal, Vector3 anchorPositionBLocal, float maximumDistanceX, float minimumDistanceX, float maximumDistanceY, float minimumDistanceY, IRigidBody rigidBodyA = null, IRigidBody rigidBodyB = null, object userData = null)
     : this()
 {
     AnchorPositionALocal = anchorPositionALocal;
     YAxisALocal          = yAxisALocal;
     AnchorPositionBLocal = anchorPositionBLocal;
     MaximumDistanceX     = maximumDistanceX;
     MinimumDistanceX     = minimumDistanceX;
     MaximumDistanceY     = maximumDistanceY;
     MinimumDistanceY     = minimumDistanceY;
     RigidBodyA           = rigidBodyA;
     RigidBodyB           = rigidBodyB;
     UserData             = userData;
     XAxisALocal          = xAxisALocal;
 }
Exemplo n.º 42
0
 public ScanningLaser(TestableGameObject obj,
                      Box box,
                      [GameObjectBoundary] Sphere sphere,
                      IPhysics physics,
                      IRigidBody body,
                      ILayerMask layerMask) : base(obj)
 {
     this.physics                 = physics;
     this.sphere                  = sphere;
     body.useGravity              = false;
     sphere.collider.enabled      = false;
     box.Obj.transform.localScale = new UnityEngine.Vector3(10, 1, 1);
     sphere.body.isKinematic      = true;
     body.AddTorque(new UnityEngine.Vector3(0, 5, 0), UnityEngine.ForceMode.Impulse);
     mask = 1 << layerMask.NameToLayer("Default");
 }
Exemplo n.º 43
0
        void Astroid_Collided(IRigidBody impactB)
        {
            if ((impactB is Player || impactB is Astroid) && isRoid)
            {
                var PE = ((GameStates.IPlayable)GameEngine.Singleton
                          .FindGameState(x => x is GameStates.IPlayable))
                         .PhysicsManager;

                this.Destroy();

                var brad      = this.Radius * 1.2f;
                var explosion = ParticleSystemFactory.GetDirtyBomb(this.Position, brad);
                PE.AddParticleSystems(explosion);
                PE.AddInstantaneousForceField(new InstantaneousForceField(this.Position, brad, DefaultForces.GenerateExplosiveField(brad, 1)));
            }
        }
Exemplo n.º 44
0
 public ScanningLaser(TestableGameObject obj,
                      Box box,
                      [GameObjectBoundary] Sphere sphere,
                      IPhysics physics,
                      IRigidBody body,
                      ILayerMask layerMask)
     : base(obj)
 {
     this.physics = physics;
     this.sphere = sphere;
     body.useGravity = false;
     sphere.collider.enabled = false;
     box.Obj.transform.localScale = new UnityEngine.Vector3(10, 1, 1);
     sphere.body.isKinematic = true;
     body.AddTorque(new UnityEngine.Vector3(0, 5, 0), UnityEngine.ForceMode.Impulse);
     mask = 1 << layerMask.NameToLayer("Default");
 }
Exemplo n.º 45
0
    public Character(TestableGameObject obj,
                     IRigidBody body,
                     IBoxCollider collider
                     /*[Resource("Characters/char")] TestableGameObject character*/
                     ) : base(obj)
    {
        this.obj         = obj;
        this.collider    = collider;
        this.body        = body;
        body.isKinematic = true;
        TestableGameObject character = new UnityGameObject(GameManager.instance.Character);

        character.transform.Parent        = obj.transform;
        character.transform.LocalPosition = Vector3.zero;
        obj.transform.Position            = GameManager.instance.LevelController.StartTransform.position;
        GameManager.instance.CanRun       = true; //старт
    }
Exemplo n.º 46
0
        public void ApplyExternalForce(IRigidBody rigidBody, float timeStep)
        {
            Vector3 currentGravity;
            rigidBody.GetGravity(out currentGravity);

            Vector3 buoyancy;
            Vector3.Negate(ref currentGravity, out buoyancy);

            var volume = rigidBody.CollisionBounds.Volume;
            buoyancy *= (Density * volume);

            rigidBody.ApplyForce(ref buoyancy);

            // 抗力 (D: Drag)
            //
            // D = (1 / 2) * P * V^2 * S * Cd
            //
            // P: 流体の密度 (浮力で用いる流体の密度と同じなので、このクラスでは Density)
            // V: 物体と流体の相対速度
            // S: 物体の代表面積 (ここでは簡易にするために衝突形状の全体の面積で代用)
            // Cd: 抗力係数 (算出が大変なようなので、このクラスでは任意の設定値として調整)

            Vector3 rigidBodyVelocity;
            rigidBody.GetVeclocity(out rigidBodyVelocity);

            // 相対速度
            //var relativeVelocity = Velocity - rigidBodyVelocity;
            var relativeVelocity = rigidBodyVelocity - Velocity;

            // 相対速度の二乗 (速度ベクトルの大きさの二乗)
            var v2 = relativeVelocity.LengthSquared();

            // 抗力
            var drag = Density * v2 * rigidBody.CollisionBounds.SurfaceArea * DragCoefficient;

            // 抗力の方向 (単位ベクトル)
            var direction = Velocity;
            if (direction.LengthSquared() != 0)
            {
                direction.Normalize();
            }
            var dragVector = direction * drag;

            rigidBody.ApplyForce(ref dragVector);
        }
Exemplo n.º 47
0
        public void Update()
        {
            IRigidBody[] rockArray = new IRigidBody[rockCount];
            for (int i = 0; i < rockCount; i++)
            {
                rockArray[i] = m_GameCommand.RequestData<IComponent>(Constant.enumMessage.GET_GAMEOBJECTCOMPONENTS, new Object[] { "rock_" + i.ToString(), new Constant.enumComponent[] { Constant.enumComponent.RIGIDBODY } }).OfType<IRigidBody>().FirstOrDefault();
            }

            IPositionComponent3D[] rockPosArray = new IPositionComponent3D[rockCount];
            for (int i = 0; i < rockCount; i++)
            {
                rockPosArray[i] = m_GameCommand.RequestData<IComponent>(Constant.enumMessage.GET_GAMEOBJECTCOMPONENTS, new Object[] { "rock_" + i.ToString(), new Constant.enumComponent[] { Constant.enumComponent.POSITIONCOMPONENT3D } }).OfType<IPositionComponent3D>().FirstOrDefault();
            }

            for (int i = 0;i<rockCount;i++)
            {
                IRigidBody rock= rockArray[i];
                if (rock.m_Position.ReturnAnyLessThen(new Vector3()) || rock.m_Position.ReturnAnyGreaterThen(new Vector3(m_ScreenWidth, m_ScreenHeight, 0)))
                {
                    rockPosArray[i].m_Position = new Vector3(m_ScreenWidth - 1, m_Random.Next((int)m_ScreenHeight), 0);
                    Vector3 test = new Vector3(30,30,0);
                    Boolean wrongPlace = true;
                    while (wrongPlace)
                    {
                        wrongPlace = false;
                        foreach(IPositionComponent3D rockPos in rockPosArray.Where(r=>r.m_GameObjectId != rock.m_GameObjectId))
                        {
                            float distance = Math.Abs(rockPos.m_Position.y - rockPosArray[i].m_Position.y);
                            if(distance< 60 && distance>0)
                            {
                                wrongPlace = true;
                                rockPosArray[i].m_Position = new Vector3(m_ScreenWidth - 1, m_Random.Next((int)m_ScreenHeight), 0);
                            }
                        }
                    }
                    rock.m_Velocity = new Vector3();
                    rock.AddForce(new Vector3(-30000, m_Random.Next(-3,3)*10000, 0));
                }
            }
        }
Exemplo n.º 48
0
        internal DigitalRuneHingeJoint(HingeJointDescriptor descriptor)
        {
            WrappedHingeJoint = new HingeJoint();

            #region set RigidBodies
            if (!(descriptor.RigidBodyA is RigidBody))
                throw new ArgumentException(String.Format("The type of the property 'RigidBodyA' must be '{0}'.", typeof(RigidBody)));
            WrappedHingeJoint.BodyA = ((RigidBody)descriptor.RigidBodyA).WrappedRigidBody;
            _rigidBodyA = descriptor.RigidBodyA;

            if (!(descriptor.RigidBodyB is RigidBody))
                throw new ArgumentException("The type of the property 'RigidBodyB' must be 'System.Physics.DigitalRune.RigidBody'.");
            WrappedHingeJoint.BodyB = ((RigidBody)descriptor.RigidBodyB).WrappedRigidBody;
            _rigidBodyB = descriptor.RigidBodyB;
            #endregion
            WrappedHingeJoint.AnchorPoseALocal = descriptor.AnchorPoseALocal.ToDigitalRune();
            WrappedHingeJoint.AnchorPoseBLocal = descriptor.AnchorPoseBLocal.ToDigitalRune();
            WrappedHingeJoint.Maximum = descriptor.MaximumAngle;
            WrappedHingeJoint.Minimum = descriptor.MinimumAngle;

            Descriptor = descriptor;
        }
 public AnimationLinearTranslation(IRigidBody _sprite)
     : base(_sprite)
 {
 }
 void Tele(IRigidBody body, Vector3 position)
 {
     Teleport(body, position);
 }
Exemplo n.º 51
0
 public Sphere(IRigidBody b, Matrix o, float r)
     : base(b, o)
 {
     primType = CollideType.Sphere;
       radius = r;
 }
Exemplo n.º 52
0
 public Box(IRigidBody b, Matrix off, Vector3 half_sizes)
     : base(b, off)
 {
     halfSizes = half_sizes;
       primType = CollideType.Box;
 }
Exemplo n.º 53
0
 public Primitive(IRigidBody b, Matrix off)
 {
     body = b;
       offset = off;
 }
Exemplo n.º 54
0
 public Primitive(IRigidBody b, Vector3 off)
 {
     body = b;
 }
Exemplo n.º 55
0
 public Plane(IRigidBody b, Vector3 p, Vector3 n)
     : base(b, p)
 {
     primType = CollideType.Plane;
       normal = n;
       point = p;
       offset = Matrix.Identity;
 }
Exemplo n.º 56
0
        void Droid_Collided(IRigidBody impactB)
        {
            if (_alertness > 0)
            {
                if (impactB is Player)
                {
                    ((SwarmGame)GameCore.GameEngine.Singleton.ActiveState).PlayerManger.Health -= _damage;
                    Alertness = 0;

                    Map map = ((SwarmGame)GameCore.GameEngine.Singleton.ActiveState).ActiveMap;
                    foreach (WorldObject obj in map.WorldObjects)
                    {
                        if (obj is Droid && ((Droid)obj).Alertness > 0 && isWithinSight(obj, conversiontRadiusSq))
                            ((Droid)obj).Alertness = 0;
                    }
                }
                else if (impactB is Droid)
                    Alertness = 1;
            }
        }
Exemplo n.º 57
0
 public AttractionForceEffect(IRigidBody attractor, float acceleration = 10)
 {
     Attractor = attractor;
     Acceleration = acceleration;
 }
Exemplo n.º 58
0
 void BadRoid_Collided(IRigidBody impactB)
 {
     //
 }
Exemplo n.º 59
0
 void Astroid_Collided(IRigidBody impactBody)
 {
     if (impactBody is Player || impactBody is BombRoid || impactBody is GoodRoid || impactBody is Bomb)
         this.TriggerFuse(FuseTime);
 }
 void Teleport(IRigidBody body,Vector3 position)
 {
     body.Translate(position - body.Position);
 }