private void UpdateChildRotation() { FPMatrix matrix = FPMatrix.CreateFromQuaternion(_rotation); foreach (FPTransform child in tsChildren) { child.localRotation = FPQuaternion.CreateFromMatrix(FPMatrix.Inverse(matrix)) * _rotation; child.localPosition = FPVector.Transform(child.localPosition, FPMatrix.CreateFromQuaternion(child.localRotation)); child.position = TransformPoint(child.localPosition); } }
/** * @brief Initializes internal properties based on whether there is a {@link FPCollider} attached. **/ public void Initialize() { if (initialized) { return; } FPCollider = GetComponent <FPCollider>(); if (transform.parent != null) { tsParent = transform.parent.GetComponent <FPTransform>(); } foreach (Transform child in transform) { FPTransform tsChild = child.GetComponent <FPTransform>(); if (tsChild != null) { tsChildren.Add(tsChild); } } if (!_serialized) { UpdateEditMode(); } if (FPCollider != null) { if (FPCollider.IsBodyInitialized) { FPCollider.Body.FPPosition = _position + scaledCenter; FPCollider.Body.FPOrientation = FPMatrix.CreateFromQuaternion(_rotation); } } else { // StateTracker.AddTracking(this); } initialized = true; }
private void UpdatePlayMode() { if (tsParent != null) { _localPosition = tsParent.InverseTransformPoint(position); FPMatrix matrix = FPMatrix.CreateFromQuaternion(tsParent.rotation); _localRotation = FPQuaternion.CreateFromMatrix(FPMatrix.Inverse(matrix)) * rotation; } else { _localPosition = position; _localRotation = rotation; } if (rb != null) { if (rb.interpolation == FPRigidBody.InterpolateMode.Interpolate) { transform.position = Vector3.Lerp(transform.position, position.ToVector(), Time.deltaTime * DELTA_TIME_FACTOR); transform.rotation = Quaternion.Lerp(transform.rotation, rotation.ToQuaternion(), Time.deltaTime * DELTA_TIME_FACTOR); transform.localScale = Vector3.Lerp(transform.localScale, localScale.ToVector(), Time.deltaTime * DELTA_TIME_FACTOR); return; } else if (rb.interpolation == FPRigidBody.InterpolateMode.Extrapolate) { transform.position = (position + rb.FPCollider.Body.FPLinearVelocity * Time.deltaTime * DELTA_TIME_FACTOR).ToVector(); transform.rotation = Quaternion.Lerp(transform.rotation, rotation.ToQuaternion(), Time.deltaTime * DELTA_TIME_FACTOR); transform.localScale = Vector3.Lerp(transform.localScale, localScale.ToVector(), Time.deltaTime * DELTA_TIME_FACTOR); return; } } transform.position = position.ToVector(); transform.rotation = rotation.ToQuaternion(); transform.localScale = localScale.ToVector(); _scale = transform.lossyScale.ToFPVector(); }
/** * @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)); }