/// <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); }
/// <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); }
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); }
/// <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> /// 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); }
protected override void RenderUpdate() { if (!Application.isPlaying) { lossyScale = FPVector.Abs(transform.lossyScale.ToFPVector()); } }
public void Update() { if (!Application.isPlaying) { lossyScale = FPVector.Abs(transform.lossyScale.ToFPVector()); } }
/// <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> /// 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> /// 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> /// 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); }
/// <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); }
/// <summary> /// Transforms a vector by the given matrix. /// </summary> /// <param name="vector">The vector to transform.</param> /// <param name="matrix">The transform matrix.</param> /// <param name="result">The transformed vector.</param> public static void Transform(ref FPVector vector, ref FPMatrix4x4 matrix, out FPVector4 result) { result.x = vector.x * matrix.M11 + vector.y * matrix.M12 + vector.z * matrix.M13 + matrix.M14; result.y = vector.x * matrix.M21 + vector.y * matrix.M22 + vector.z * matrix.M23 + matrix.M24; result.z = vector.x * matrix.M31 + vector.y * matrix.M32 + vector.z * matrix.M33 + matrix.M34; result.w = vector.x * matrix.M41 + vector.y * matrix.M42 + vector.z * matrix.M43 + matrix.M44; }
/// <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); }
// The smaller of the two possible angles between the two vectors is returned, therefore the result will never be greater than 180 degrees or smaller than -180 degrees. // If you imagine the from and to vectors as lines on a piece of paper, both originating from the same point, then the /axis/ vector would point up out of the paper. // The measured angle between the two vectors would be positive in a clockwise direction and negative in an anti-clockwise direction. public static FP SignedAngle(FPVector from, FPVector to, FPVector axis) { FPVector fromNorm = from.normalized, toNorm = to.normalized; FP unsignedAngle = FPMath.Acos(FPMath.Clamp(Dot(fromNorm, toNorm), -FP.ONE, FP.ONE)) * FPMath.Rad2Deg; FP sign = FPMath.Sign(Dot(axis, Cross(fromNorm, toNorm))); return(unsignedAngle * sign); }
public bool Raycast(FPVector rayOrigin, FPVector rayDirection, RaycastCallback raycast, int layerMask, out IBody body, out FPVector normal, out FP fraction) { RigidBody rb; bool result = world.CollisionSystem.Raycast(rayOrigin, rayDirection, raycast, layerMask, out rb, out normal, out fraction); body = rb; return(result); }
/// <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; }
/// <summary> /// Tests if an object is equal to this vector. /// </summary> /// <param name="obj">The object to test.</param> /// <returns>Returns true if they are euqal, otherwise false.</returns> #region public override bool Equals(object obj) public override bool Equals(object obj) { if (!(obj is FPVector)) { return(false); } FPVector other = (FPVector)obj; return(((x == other.x) && (y == other.y)) && (z == other.z)); }
/** * @brief Creates a new {@link FPRigidBody} when there is no one attached to this GameObject. **/ protected override void OnAwake() { FPTransform = this.GetComponent <FPTransform2D>(); FPRigidBody = this.GetComponent <FPRigidBody2D>(); if (lossyScale == FPVector.one) { lossyScale = FPVector.Abs(transform.localScale.ToFPVector()); } }
/// <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; }
/// <summary> /// Multiplies each component of the vector by the same components of the provided vector. /// </summary> public static FPVector Scale(FPVector vecA, FPVector vecB) { FPVector result; result.x = vecA.x * vecB.x; result.y = vecA.y * vecB.y; result.z = vecA.z * vecB.z; return(result); }
/// <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; }
/// <summary> /// Transforms a vector by the transposed of the given Matrix. /// </summary> /// <param name="position">The vector to transform.</param> /// <param name="matrix">The transform matrix.</param> /// <param name="result">The transformed vector.</param> public static void TransposedTransform(ref FPVector position, ref FPMatrix matrix, out FPVector result) { FP num0 = ((position.x * matrix.M11) + (position.y * matrix.M12)) + (position.z * matrix.M13); FP num1 = ((position.x * matrix.M21) + (position.y * matrix.M22)) + (position.z * matrix.M23); FP num2 = ((position.x * matrix.M31) + (position.y * matrix.M32)) + (position.z * matrix.M33); result.x = num0; result.y = num1; result.z = num2; }
/// <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> /// Adds to vectors. /// </summary> /// <param name="value1">The first vector.</param> /// <param name="value2">The second vector.</param> /// <param name="result">The sum of both vectors.</param> public static void Add(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; }
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); }
/** * @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()); } }
/** * @brief Rotates game object based on provided axis, point and angle of rotation. **/ public void RotateAround(FPVector point, FPVector axis, FP angle) { FPVector vector = this.position; FPVector vector2 = vector - point; vector2 = FPVector.Transform(vector2, FPMatrix.AngleAxis(angle * FP.Deg2Rad, axis)); vector = point + vector2; this.position = vector; Rotate(axis, angle); }
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 Moves game object based on provided translation vector and a relative space. * * If relative space is SELF then the game object will move based on its forward vector. **/ public void Translate(FPVector translation, Space relativeTo) { if (relativeTo == Space.Self) { Translate(translation, this); } else { this.position += translation; } }