Пример #1
0
        /**
         *  @brief Initializes internal properties based on whether there is a {@link TSCollider} attached.
         **/
        public void Initialize()
        {
            if (initialized)
            {
                return;
            }

            tsCollider = GetComponent <FPCollider>();
            if (transform.parent != null)
            {
                tsParent = transform.parent.GetComponent <FPTransform>();
            }

            if (!_serialized)
            {
                UpdateEditMode();
            }

            if (tsCollider != null)
            {
                if (tsCollider.IsBodyInitialized)
                {
                    tsCollider.Body.TSPosition    = _position + scaledCenter;
                    tsCollider.Body.TSOrientation = FPMatrix.CreateFromQuaternion(_rotation);
                }
            }
            else
            {
                StateTracker.AddTracking(this);
            }

            initialized = true;
        }
Пример #2
0
        public FPRaycastHit Raycast(FPRay ray, FP maxDistance, RaycastCallback callback = null)
        {
            IBody    hitBody;
            FPVector hitNormal;
            FP       hitFraction;

            FPVector origin    = ray.origin;
            FPVector direction = ray.direction;

            if (Raycast(origin, direction, callback, out hitBody, out hitNormal, out hitFraction))
            {
                if (hitFraction <= maxDistance)
                {
                    GameObject  other              = PhysicsManager.instance.GetGameObject(hitBody);
                    FPRigidBody bodyComponent      = other.GetComponent <FPRigidBody>();
                    FPCollider  colliderComponent  = other.GetComponent <FPCollider>();
                    FPTransform transformComponent = other.GetComponent <FPTransform>();
                    return(new FPRaycastHit(bodyComponent, colliderComponent, transformComponent, hitNormal, ray.origin, ray.direction, hitFraction));
                }
            }
            else
            {
                direction *= maxDistance;
                if (Raycast(origin, direction, callback, out hitBody, out hitNormal, out hitFraction))
                {
                    GameObject  other              = PhysicsManager.instance.GetGameObject(hitBody);
                    FPRigidBody bodyComponent      = other.GetComponent <FPRigidBody>();
                    FPCollider  colliderComponent  = other.GetComponent <FPCollider>();
                    FPTransform transformComponent = other.GetComponent <FPTransform>();
                    return(new FPRaycastHit(bodyComponent, colliderComponent, transformComponent, hitNormal, ray.origin, direction, hitFraction));
                }
            }
            return(null);
        }
Пример #3
0
        private static void InitializeGameObject(GameObject go, FPVector position, FPQuaternion rotation)
        {
            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 FPVector2(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
 public FPRaycastHit(FPRigidBody rigidbody, FPCollider collider, FPTransform transform, FPVector normal, FPVector origin, FPVector direction, FP fraction)
 {
     this.rigidbody = rigidbody;
     this.collider  = collider;
     this.transform = transform;
     this.normal    = normal;
     this.point     = origin + direction * fraction;
     this.distance  = fraction * direction.magnitude;
 }
Пример #5
0
        /**
         *  @brief Creates a new {@link FPRigidBody} when there is no one attached to this GameObject.
         **/
        public void Awake()
        {
            FPTransform = this.GetComponent <FPTransform>();
            FPRigidBody = this.GetComponent <FPRigidBody>();

            if (lossyScale == FPVector.one)
            {
                lossyScale = FPVector.Abs(transform.localScale.ToFPVector());
            }
        }
Пример #6
0
        internal void Update(GameObject otherGO, Contact c)
        {
            if (this.gameObject == null)
            {
                this.gameObject = otherGO;
                this.collider   = this.gameObject.GetComponent <FPCollider>();
                this.rigidbody  = this.gameObject.GetComponent <FPRigidBody>();
                this.transform  = this.collider.FPTransform;
            }

            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;
            }
        }
Пример #7
0
 /**
  *  @brief Moves game object based on provided translation vector and a relative {@link FPTransform}.
  *
  *  The game object will move based on FPTransform's forward vector.
  **/
 public void Translate(FPVector translation, FPTransform relativeTo)
 {
     this.position += FPVector.Transform(translation, FPMatrix.CreateFromQuaternion(relativeTo.rotation));
 }
Пример #8
0
 /**
  *  @brief Moves game object based on provided axis values and a relative {@link FPTransform}.
  *
  *  The game object will move based on FPTransform's forward vector.
  **/
 public void Translate(FP x, FP y, FP z, FPTransform relativeTo)
 {
     Translate(new FPVector(x, y, z), relativeTo);
 }
Пример #9
0
 /**
  *  @brief Rotates game object to point forward vector to a target position.
  *
  *  @param other TSTrasform used to get target position.
  **/
 public void LookAt(FPTransform other)
 {
     LookAt(other.position);
 }