Пример #1
0
        internal void Update(GameObject otherGO, Contact c)
        {
            if (this.gameObject == null)
            {
                this.gameObject = otherGO;
                this.collider   = this.gameObject.GetComponent <TSCollider>();
                this.rigidbody  = this.gameObject.GetComponent <TSRigidBody>();
                this.transform  = this.collider.tsTransform;
            }

            if (c != null)
            {
                if (contacts[0] == null)
                {
                    contacts[0] = new TSContactPoint();
                }

                this.relativeVelocity = c.CalculateRelativeVelocity();

                contacts[0].normal = c.Normal;
                contacts[0].point  = c.p1;
            }
        }
Пример #2
0
 /// <summary>
 /// Calculates the dot product of both vectors.
 /// </summary>
 /// <param name="vector1">The first vector.</param>
 /// <param name="vector2">The second vector.</param>
 /// <returns>Returns the dot product of both vectors.</returns>
 public static FP Dot(ref TSVector vector1, ref TSVector vector2)
 {
     return(((vector1.x * vector2.x) + (vector1.y * vector2.y)) + (vector1.z * vector2.z));
 }
Пример #3
0
        private static void InitializeGameObject(GameObject go, TSVector position, TSQuaternion rotation)
        {
            MonoBehaviour[] monoBehaviours = go.GetComponentsInChildren <MonoBehaviour>();
            for (int index = 0, length = monoBehaviours.Length; index < length; index++)
            {
                MonoBehaviour bh = monoBehaviours[index];

                if (bh is IFrameSyncBehaviour)
                {
                    instance.queuedBehaviours.Add(instance.NewManagedBehavior((IFrameSyncBehaviour)bh));
                }
            }


            ICollider[] tsColliders = go.GetComponentsInChildren <ICollider>();
            if (tsColliders != null)
            {
                for (int index = 0, length = tsColliders.Length; index < length; index++)
                {
                    PhysicsManager.instance.AddBody(tsColliders[index]);
                }
            }

            FPTransform rootFPTransform = go.GetComponent <FPTransform>();

            if (rootFPTransform != null)
            {
                rootFPTransform.Initialize();

                rootFPTransform.position = position;
                rootFPTransform.rotation = rotation;
            }

            FPTransform[] FPTransforms = go.GetComponentsInChildren <FPTransform>();
            if (FPTransforms != null)
            {
                for (int index = 0, length = FPTransforms.Length; index < length; index++)
                {
                    FPTransform FPTransform = FPTransforms[index];

                    if (FPTransform != rootFPTransform)
                    {
                        FPTransform.Initialize();
                    }
                }
            }

            FPTransform2D rootFPTransform2D = go.GetComponent <FPTransform2D>();

            if (rootFPTransform2D != null)
            {
                rootFPTransform2D.Initialize();

                rootFPTransform2D.position = new TSVector2(position.x, position.y);
                rootFPTransform2D.rotation = rotation.ToQuaternion().eulerAngles.z;
            }

            FPTransform2D[] FPTransforms2D = go.GetComponentsInChildren <FPTransform2D>();
            if (FPTransforms2D != null)
            {
                for (int index = 0, length = FPTransforms2D.Length; index < length; index++)
                {
                    FPTransform2D FPTransform2D = FPTransforms2D[index];

                    if (FPTransform2D != rootFPTransform2D)
                    {
                        FPTransform2D.Initialize();
                    }
                }
            }
        }
Пример #4
0
 /**
  *  @brief Rotates game object based on provided axis angles of rotation.
  **/
 public void Rotate(TSVector eulerAngles)
 {
     Rotate(eulerAngles, Space.Self);
 }
Пример #5
0
 /**
  *  @brief Moves game object based on provided translation vector and a relative {@link TSTransform}.
  *
  *  The game object will move based on TSTransform's forward vector.
  **/
 public void Translate(TSVector translation, TSTransform relativeTo)
 {
     this.position += TSVector.Transform(translation, TSMatrix.CreateFromQuaternion(relativeTo.rotation));
 }
Пример #6
0
 /**
  *  @brief Rotates game object to point forward vector to a target position.
  *
  *  @param target Target position.
  **/
 public void LookAt(TSVector target)
 {
     this.rotation = TSQuaternion.CreateFromMatrix(TSMatrix.CreateFromLookAt(position, target));
 }
Пример #7
0
 /**
  *  @brief Moves the body to a new position.
  **/
 public void MovePosition(TSVector position)
 {
     this.position = position;
 }
Пример #8
0
        /**
         *  @brief Returns the velocity of the body at some position in world space.
         **/
        public TSVector GetPointVelocity(TSVector worldPoint)
        {
            TSVector directionPoint = position - tsCollider.Body.TSPosition;

            return(TSVector.Cross(tsCollider.Body.TSAngularVelocity, directionPoint) + tsCollider.Body.TSLinearVelocity);
        }
Пример #9
0
        protected override Vector3 GetGizmosSize()
        {
            TSVector size3 = new TSVector(size.x, size.y, 1);

            return(TSVector.Scale(size3, lossyScale).ToVector());
        }
Пример #10
0
 public static FP Angle(TSVector a, TSVector b)
 {
     return(FP.Acos(a.normalized * b.normalized) * FP.Rad2Deg);
 }
Пример #11
0
        /// <summary>
        /// Adds two vectors.
        /// </summary>
        /// <param name="value1">The first vector.</param>
        /// <param name="value2">The second vector.</param>
        /// <returns>The sum of both vectors.</returns>
        #region public static JVector operator +(JVector value1, JVector value2)
        public static TSVector operator +(TSVector value1, TSVector value2)
        {
            TSVector result; TSVector.Add(ref value1, ref value2, out result);

            return(result);
        }
Пример #12
0
        /// <summary>
        /// Subtracts two vectors.
        /// </summary>
        /// <param name="value1">The first vector.</param>
        /// <param name="value2">The second vector.</param>
        /// <returns>The difference of both vectors.</returns>
        #region public static JVector operator -(JVector value1, JVector value2)
        public static TSVector operator -(TSVector value1, TSVector value2)
        {
            TSVector result; TSVector.Subtract(ref value1, ref value2, out result);

            return(result);
        }
Пример #13
0
 /// <summary>
 /// Calculates the dot product of two vectors.
 /// </summary>
 /// <param name="value1">The first vector.</param>
 /// <param name="value2">The second vector.</param>
 /// <returns>Returns the dot product of both.</returns>
 #region public static FP operator *(JVector value1, JVector value2)
 public static FP operator *(TSVector value1, TSVector value2)
 {
     return(TSVector.Dot(ref value1, ref value2));
 }
Пример #14
0
 /// <summary>
 /// Multiply a vector with a factor.
 /// </summary>
 /// <param name="value1">The vector to multiply.</param>
 /// <param name="scaleFactor">The scale factor.</param>
 /// <param name="result">Returns the multiplied vector.</param>
 public static void Multiply(ref TSVector value1, FP scaleFactor, out TSVector result)
 {
     result.x = value1.x * scaleFactor;
     result.y = value1.y * scaleFactor;
     result.z = value1.z * scaleFactor;
 }
Пример #15
0
 /// <summary>
 /// Divides a vector by a factor.
 /// </summary>
 /// <param name="value1">The vector to divide.</param>
 /// <param name="scaleFactor">The scale factor.</param>
 /// <param name="result">Returns the scaled vector.</param>
 public static void Divide(ref TSVector value1, FP scaleFactor, out TSVector result)
 {
     result.x = value1.x / scaleFactor;
     result.y = value1.y / scaleFactor;
     result.z = value1.z / scaleFactor;
 }
Пример #16
0
 /**
  *  @brief Applies the provided force in the body.
  *
  *  @param force A {@link TSVector} representing the force to be applied.
  **/
 public void AddForce(TSVector force)
 {
     AddForce(force, ForceMode.Force);
 }
Пример #17
0
 /**
  *  @brief Applies the provided force in the body.
  *
  *  @param force A {@link TSVector} representing the force to be applied.
  *  @param position Indicates the location where the force should hit.
  **/
 public void AddForceAtPosition(TSVector force, TSVector position)
 {
     AddForceAtPosition(force, position, ForceMode.Impulse);
 }
Пример #18
0
 public FrameUser(CMD cmd, TSVector p)
 {
     e.cmd_type = (Byte)cmd;
     movement   = p;
 }
Пример #19
0
 /**
  *  @brief Simulates the provided tourque in the body.
  *
  *  @param torque A {@link TSVector} representing the torque to be applied.
  **/
 public void AddTorque(TSVector torque)
 {
     tsCollider.Body.TSApplyTorque(torque);
 }
Пример #20
0
 public FrameBox(CMD cmd, TSVector p, bool sp)
 {
     e.cmd_type = (Byte)cmd;
     movement   = p;
     space      = sp;
 }
Пример #21
0
 /**
  * @brief Adds a new TSVector value.
  **/
 internal void AddTSVector(byte key, TSVector value)
 {
     this.tsVectorTable[key] = value;
 }
Пример #22
0
 public FrameMouse(CMD cmd, TSVector p)
 {
     e.cmd_type = (Byte)cmd;
     point      = p;
 }
Пример #23
0
 /**
  *  @brief Moves game object based on provided translation vector.
  **/
 public void Translate(TSVector translation)
 {
     Translate(translation, Space.Self);
 }
Пример #24
0
 public override void PareseFrom(ENTITY_DATA e)
 {
     this.e = e;
     s.setBuffer(e.datas);
     point = s.readTSVector();
 }
Пример #25
0
 /**
  *  @brief Rotates game object based on provided axis and angle of rotation.
  **/
 public void RotateAround(TSVector axis, FP angle)
 {
     Rotate(axis, angle);
 }
Пример #26
0
 public void writeTSVector(TSVector v)
 {
     writeFP(v.x);
     writeFP(v.y);
     writeFP(v.z);
 }
Пример #27
0
 /**
  *  @brief Rotates game object based on provided axis and angle of rotation.
  **/
 public void Rotate(TSVector axis, FP angle)
 {
     Rotate(axis, angle, Space.Self);
 }
Пример #28
0
 /**
  *  @brief Create the internal shape used to represent a TSBoxCollider.
  **/
 public override Shape CreateShape()
 {
     return(new BoxShape(TSVector.Scale(size, lossyScale)));
 }
        public bool Raycast(TSVector rayOrigin, TSVector rayDirection, RaycastCallback raycast, out IBody body, out TSVector normal, out FP fraction)
        {
            RigidBody rb;
            bool      result = world.CollisionSystem.Raycast(rayOrigin, rayDirection, raycast, out rb, out normal, out fraction);

            body = rb;

            return(result);
        }
Пример #30
0
 protected override Vector3 GetGizmosSize()
 {
     return(TSVector.Scale(size, lossyScale).ToVector());
 }