/// <summary> /// Moves a point current in a straight line towards a target point. /// </summary> public static Vector4_ MoveTowards(Vector4_ current, Vector4_ target, double maxDistanceDelta) { var a = target - current; var magnitude = a.magnitude; return (magnitude <= maxDistanceDelta || magnitude == 0) ? target : current + a / magnitude * maxDistanceDelta; }
public static PVETriggerCollider Create(SCreateTriggerBehaviour b) { if (!Level.currentRoot) { return(null); } if (!triggerParent) { triggerParent = Level.currentRoot.AddNewChild(); triggerParent.name = "trigger_parent"; } Transform t = triggerParent.AddNewChild(); t.name = Util.Format("trigger_{0}", b.triggerId.ToString("D2")); var c = t.GetComponentDefault <PVETriggerCollider>(); //必须要返回的示例,避免修改内存中的备份 SCreateTriggerBehaviour b_new = new SCreateTriggerBehaviour(b.behaviour.DeepClone(), null); Vector4_ range = b_new.range; if (b_new.isRandom) { range.x = (new PseudoRandom()).Range(b_new.range.x, b_new.range.y); range.y = 0; } c.InitComponent(b_new, range); c.RefreshScenePlayers(); return(c); }
private void ResetMotion() { m_motion = ConfigManager.Get <AnimMotionInfo>((int)(info.animMotion.x)); motionOffset = Vector3_.zero; if (m_motion) { var count = m_motion.points.Length; if (count < 2) { count = 0; } m_motionFrame.x = Mathd.Clamp(info.animMotion.y, 1, count - 1); m_motionFrame.y = info.animMotion.z < 1 ? count - 1 : Mathd.Clamp(info.animMotion.z, info.animMotion.x, count - 1); m_motionFrame.z = (m_motionFrame.y - m_motionFrame.x + 1); m_motionFrame.w = m_motionFrame.z * 0.01; // cm -> m if (m_motion.offset != Vector3_.zero) { motionOffset += m_motion.offset * 0.01; } motionOffset.Set(motionOffset.z, motionOffset.y, motionOffset.x); } else { m_motionFrame = Vector4_.zero; } }
public void Scale(Vector4_ scale) { m_x *= scale.x; m_y *= scale.y; m_z *= scale.z; m_w *= scale.w; _CalculateParams(); }
private void InitComponent(SCreateTriggerBehaviour b, Vector4_ range) { behaviour = b; CreateEffectNode(); isTrigger = true; layer = 0; AddLayerToTarget(Creature.COLLIDER_LAYER_HIT); SetRange(range); PlayParticle(); }
/// <summary> /// Returns a vector that is made from the largest components of two vectors. /// </summary> public static Vector4_ Max(Vector4_ lhs, Vector4_ rhs) { return new Vector4_(Mathd.Max(lhs.x, rhs.x), Mathd.Max(lhs.y, rhs.y), Mathd.Max(lhs.z, rhs.z), Mathd.Max(lhs.w, rhs.w)); }
/// <summary> /// Linearly interpolates between two vectors. /// </summary> public static Vector4_ LerpUnclamped(Vector4_ a, Vector4_ b, double t) { return new Vector4_(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t, a.w + (b.w - a.w) * t); }
/// <summary> /// Linearly interpolates between two vectors. /// </summary> public static Vector4_ Lerp(Vector4_ a, Vector4_ b, double t) { t = Mathd.Clamp01(t); return new Vector4_(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t, a.w + (b.w - a.w) * t); }
/// <summary> /// Dot Product of two vectors. /// </summary> public static double Dot(Vector4_ a, Vector4_ b) { return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; }
/// <summary> /// Returns the distance between a and b. /// </summary> public static double Distance(Vector4_ a, Vector4_ b) { var vector = a - b; return vector.magnitude; }
/// <summary> /// Cross Product of two vectors. /// </summary> public static Vector4_ Cross(Vector4_ lhs, Vector4_ rhs) { return new Vector4_(lhs.y * rhs.z - lhs.z * rhs.y, lhs.z * rhs.x - lhs.x * rhs.z, lhs.x * rhs.y - lhs.y * rhs.x); }
/// <summary> /// Returns a copy of vector with its magnitude clamped to maxLength. /// </summary> public static Vector4_ ClampMagnitude(Vector4_ vector, double maxLength) { return vector.sqrMagnitude > maxLength * maxLength ? vector.normalized * maxLength : vector; }
/// <summary> /// Multiplies two vectors component-wise. /// </summary> public static Vector4_ Scale(Vector4_ a, Vector4_ b) { return new Vector4_(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); }
/// <summary> /// Reflects a vector off the plane defined by a normal. /// </summary> public static Vector4_ Reflect(Vector4_ inDirection, Vector4_ inNormal) { return -2 * Dot(inNormal, inDirection) * inNormal + inDirection; }
/// <summary> /// Projects a vector onto a plane defined by a normal orthogonal to the plane. /// </summary> public static Vector4_ ProjectOnPlane(Vector4_ vector, Vector4_ planeNormal) { return vector - Project(vector, planeNormal); }
/// <summary> /// Projects a vector onto another vector. /// </summary> public static Vector4_ Project(Vector4_ vector, Vector4_ onNormal) { var dot = Dot(onNormal, onNormal); return dot < Mathd.Epsilon ? zero : onNormal * Dot(vector, onNormal) / dot; }