/// <summary> /// Divides a vector by a factor. /// </summary> /// <param name="value1">The vector to divide.</param> /// <param name="scaleFactor">The scale factor.</param> /// <returns>Returns the scaled vector.</returns> public static FPVector Divide(FPVector value1, FP scaleFactor) { FPVector result; FPVector.Divide(ref value1, scaleFactor, out result); return(result); }
/// <summary> /// Transforms a vector by the given matrix. /// </summary> /// <param name="position">The vector to transform.</param> /// <param name="matrix">The transform matrix.</param> /// <returns>The transformed vector.</returns> #region public static JVector Transform(JVector position, JMatrix matrix) public static FPVector Transform(FPVector position, FPMatrix matrix) { FPVector result; FPVector.Transform(ref position, ref matrix, out result); return(result); }
/// <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 void Add(JVector value1, JVector value2) public static FPVector Add(FPVector value1, FPVector value2) { FPVector result; FPVector.Add(ref value1, ref value2, out result); return(result); }
/** * @brief Adds a FPVector value in player's input. **/ public static void SetFPVector(byte key, FPVector value) { if (currentInputData != null) { currentInputData.AddFPVector(key, value); } }
public static FP DistanceSquared(FPVector value1, FPVector value2) { FP result; DistanceSquared(ref value1, ref value2, out result); return(result); }
public static FP Distance(FPVector v1, FPVector v2) { FP result; DistanceSquared(ref v1, ref v2, out result); return(FP.Sqrt(result)); }
/// <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 Subtract(JVector value1, JVector value2) public static FPVector Subtract(FPVector value1, FPVector value2) { FPVector result; FPVector.Subtract(ref value1, ref value2, out result); return(result); }
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); }
/** * @brief Instantiates a new prefab in a deterministic way. * * @param prefab GameObject's prefab to instantiate. * @param position Position to place the new GameObject. * @param rotation Rotation to set in the new GameObject. **/ public static GameObject SyncedInstantiate(GameObject prefab, FPVector position, FPQuaternion rotation) { if (instance != null && instance.lockstep != null) { GameObject go = GameObject.Instantiate(prefab, position.ToVector(), rotation.ToQuaternion()) as GameObject; if (ReplayRecord.replayMode != ReplayMode.LOAD_REPLAY) { AddGameObjectOnSafeMap(go); } 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)); } } InitializeGameObject(go, position, rotation); return(go); } return(null); }
/// <summary> /// Divides a vector by a factor. /// </summary> /// <param name="value1">The vector to divide.</param> /// <param name="scaleFactor">The scale factor.</param> /// <returns>Returns the scaled vector.</returns> public static FPVector operator /(FPVector value1, FP value2) { FPVector result; FPVector.Divide(ref value1, value2, out result); return(result); }
/// <summary> /// The cross product of two vectors. /// </summary> /// <param name="vector1">The first vector.</param> /// <param name="vector2">The second vector.</param> /// <returns>The cross product of both vectors.</returns> #region public static JVector Cross(JVector vector1, JVector vector2) public static FPVector Cross(FPVector vector1, FPVector vector2) { FPVector result; FPVector.Cross(ref vector1, ref vector2, out result); return(result); }
/// <summary> /// Multiply a vector with a factor. /// </summary> /// <param name="value1">The vector to multiply.</param> /// <param name="scaleFactor">The scale factor.</param> /// <returns>Returns the multiplied vector.</returns> #region public static JVector Multiply(JVector value1, FP scaleFactor) public static FPVector Multiply(FPVector value1, FP scaleFactor) { FPVector result; FPVector.Multiply(ref value1, scaleFactor, out result); return(result); }
/// <summary> /// Multiplies a vector by a scale factor. /// </summary> /// <param name="value2">The vector to scale.</param> /// <param name="value1">The scale factor.</param> /// <returns>Returns the scaled vector.</returns> #region public static JVector operator *(FP value1, JVector value2) public static FPVector operator *(FP value1, FPVector value2) { FPVector result; FPVector.Multiply(ref value2, value1, out result); return(result); }
/// <summary> /// Normalizes the given vector. /// </summary> /// <param name="value">The vector which should be normalized.</param> /// <returns>A normalized vector.</returns> #region public static JVector Normalize(JVector value) public static FPVector Normalize(FPVector value) { FPVector result; FPVector.Normalize(ref value, out result); return(result); }
public void Update() { if (!Application.isPlaying) { lossyScale = FPVector.Abs(transform.lossyScale.ToFPVector()); } }
/// <summary> /// Inverses the direction of a vector. /// </summary> /// <param name="value">The vector to inverse.</param> /// <returns>The negated vector.</returns> public static FPVector Negate(FPVector value) { FPVector result; FPVector.Negate(ref value, out result); return(result); }
/** * @brief Create the internal shape used to represent a TSBoxCollider. **/ public override KBEngine.Physics2D.Shape CreateShape() { FPVector size3 = new FPVector(size.x, size.y, 1); FPVector sizeScaled = FPVector.Scale(size3, lossyScale); return(new KBEngine.Physics2D.PolygonShape(KBEngine.Physics2D.PolygonTools.CreateRectangle(sizeScaled.x * FP.Half, sizeScaled.y * FP.Half), 1)); }
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(); } } } }
public void ChangeForward(FPVector toForward) { // Debug.Log("this.rotation____before____before____before:::" + this.rotation.ToQuaternion() + ","+ this.forward.ToVector() + " ,::"+ toForward.ToVector()); this.rotation *= FPQuaternion.FromToRotation(this.forward, toForward); // Debug.Log("this.rotation____late____late___late:::" + this.rotation.ToQuaternion()); this.UpdateRotation(); // this.UpdateForward(); }
// Transforms a direction by this matrix. public FPVector MultiplyVector(FPVector vector) { FPVector res; res.x = this.m00 * vector.x + this.m01 * vector.y + this.m02 * vector.z; res.y = this.m10 * vector.x + this.m11 * vector.y + this.m12 * vector.z; res.z = this.m20 * vector.x + this.m21 * vector.y + this.m22 * vector.z; return(res); }
// Transforms a position by this matrix, without a perspective divide. (fast) public FPVector MultiplyPoint3x4(FPVector point) { FPVector res; res.x = this.m00 * point.x + this.m01 * point.y + this.m02 * point.z + this.m03; res.y = this.m10 * point.x + this.m11 * point.y + this.m12 * point.z + this.m13; res.z = this.m20 * point.x + this.m21 * point.y + this.m22 * point.z + this.m23; return(res); }
/// <summary> /// Normalizes the given vector. /// </summary> /// <param name="value">The vector which should be normalized.</param> /// <param name="result">A normalized vector.</param> public static void Normalize(ref FPVector value, out FPVector result) { FP num2 = ((value.x * value.x) + (value.y * value.y)) + (value.z * value.z); FP num = FP.One / FP.Sqrt(num2); result.x = value.x * num; result.y = value.y * num; result.z = value.z * num; }
public FPVector ChangeVec3ToTSVec(Vector3 dataVec3) { FPVector dataTSVec = FPVector.zero; dataTSVec.x = dataVec3.x; dataTSVec.y = dataVec3.y; dataTSVec.z = dataVec3.z; return(dataTSVec); }
public bool Raycast(FPVector rayOrigin, FPVector rayDirection, RaycastCallback raycast, out IBody body, out FPVector normal, out FP fraction) { RigidBody rb; bool result = world.CollisionSystem.Raycast(rayOrigin, rayDirection, raycast, out rb, out normal, out fraction); body = rb; return(result); }
/// <summary> /// Subtracts to vectors. /// </summary> /// <param name="value1">The first vector.</param> /// <param name="value2">The second vector.</param> /// <param name="result">The difference of both vectors.</param> public static void Subtract(ref FPVector value1, ref FPVector value2, out FPVector result) { FP num0 = value1.x - value2.x; FP num1 = value1.y - value2.y; FP num2 = value1.z - value2.z; result.x = num0; result.y = num1; result.z = num2; }
/// <summary> /// The cross product of two vectors. /// </summary> /// <param name="vector1">The first vector.</param> /// <param name="vector2">The second vector.</param> /// <param name="result">The cross product of both vectors.</param> public static void Cross(ref FPVector vector1, ref FPVector vector2, out FPVector result) { FP num3 = (vector1.y * vector2.z) - (vector1.z * vector2.y); FP num2 = (vector1.z * vector2.x) - (vector1.x * vector2.z); FP num = (vector1.x * vector2.y) - (vector1.y * vector2.x); result.x = num3; result.y = num2; result.z = num; }
public static FPQuaternion FromToRotation(FPVector fromVector, FPVector toVector) { FPVector w = FPVector.Cross(fromVector, toVector); FPQuaternion q = new FPQuaternion(w.x, w.y, w.z, FPVector.Dot(fromVector, toVector)); q.w += FP.Sqrt(fromVector.sqrMagnitude * toVector.sqrMagnitude); q.Normalize(); return(q); }
/// <summary> /// Inverses the direction of a vector. /// </summary> /// <param name="value">The vector to inverse.</param> /// <param name="result">The negated vector.</param> public static void Negate(ref FPVector value, out FPVector result) { FP num0 = -value.x; FP num1 = -value.y; FP num2 = -value.z; result.x = num0; result.y = num1; result.z = num2; }
/** * @brief Creates a new {@link FPRigidBody} when there is no one attached to this GameObject. **/ public void Awake() { FPTransform = this.GetComponent <FPTransform2D>(); FPRigidBody = this.GetComponent <FPRigidBody2D>(); if (lossyScale == FPVector.one) { lossyScale = FPVector.Abs(transform.localScale.ToFPVector()); } }
// Creates a translation matrix. public static FPMatrix4x4 Translate(FPVector vector) { FPMatrix4x4 m; m.m00 = 1F; m.m01 = 0F; m.m02 = 0F; m.m03 = vector.x; m.m10 = 0F; m.m11 = 1F; m.m12 = 0F; m.m13 = vector.y; m.m20 = 0F; m.m21 = 0F; m.m22 = 1F; m.m23 = vector.z; m.m30 = 0F; m.m31 = 0F; m.m32 = 0F; m.m33 = 1F; return(m); }