public void SetRow(int i, Vector4L v) { this[i, 0] = v.x; this[i, 1] = v.y; this[i, 2] = v.z; this[i, 3] = v.w; }
public void Scale(Vector4L scale) { this.x *= scale.x; this.y *= scale.y; this.z *= scale.z; this.w *= scale.w; }
public void SetColumn(int i, Vector4L v) { this[0, i] = v.x; this[1, i] = v.y; this[2, i] = v.z; this[3, i] = v.w; }
public override bool Equals(object other) { if (!(other is Vector4L)) { return(false); } Vector4L vector = (Vector4L)other; return(this.x.Equals(vector.x) && this.y.Equals(vector.y) && this.z.Equals(vector.z) && this.w.Equals(vector.w)); }
public static Vector4L Normalize(Vector4L a) { FloatL num = Vector4L.Magnitude(a); if (num > FloatL.Epsilon) { return(a / num); } return(Vector4L.zero); }
public static Vector4L operator *(Matrix4x4L lhs, Vector4L v) { Vector4L result = new Vector4L(); result.x = lhs.m00 * v.x + lhs.m01 * v.y + lhs.m02 * v.z + lhs.m03 * v.w; result.y = lhs.m10 * v.x + lhs.m11 * v.y + lhs.m12 * v.z + lhs.m13 * v.w; result.z = lhs.m20 * v.x + lhs.m21 * v.y + lhs.m22 * v.z + lhs.m23 * v.w; result.w = lhs.m30 * v.x + lhs.m31 * v.y + lhs.m32 * v.z + lhs.m33 * v.w; return(result); }
public static Vector4L MoveTowards(Vector4L current, Vector4L target, FloatL maxDistanceDelta) { Vector4L a = target - current; FloatL magnitude = a.magnitude; if (magnitude <= maxDistanceDelta || magnitude == 0f) { return(target); } return(current + a / magnitude * maxDistanceDelta); }
public void Normalize() { FloatL num = Vector4L.Magnitude(this); if (num > 1E-05f) { this /= num; } else { this = Vector4L.zero; } }
static Vector3L RotateTo(Vector3L from, Vector3L to, FloatL angle) { //如果两向量角度为0 if (Vector3L.Angle(from, to) == 0) { return(from); } //旋转轴 Vector3L n = Vector3L.Cross(from, to); //旋转轴规范化 n.Normalize(); //旋转矩阵 Matrix4x4L rotateMatrix = new Matrix4x4L(); //旋转的弧度 double radian = (angle * FixPointMath.PI / 180).ToDouble(); FloatL cosAngle = FixPointMath.Cos(radian); FloatL sinAngle = FixPointMath.Sin(radian); //矩阵的数据 //这里看不懂的自行科普矩阵知识 rotateMatrix.SetRow(0, new Vector4L(n.x * n.x * (1 - cosAngle) + cosAngle, n.x * n.y * (1 - cosAngle) + n.z * sinAngle, n.x * n.z * (1 - cosAngle) - n.y * sinAngle, 0)); rotateMatrix.SetRow(1, new Vector4L(n.x * n.y * (1 - cosAngle) - n.z * sinAngle, n.y * n.y * (1 - cosAngle) + cosAngle, n.y * n.z * (1 - cosAngle) + n.x * sinAngle, 0)); rotateMatrix.SetRow(2, new Vector4L(n.x * n.z * (1 - cosAngle) + n.y * sinAngle, n.y * n.z * (1 - cosAngle) - n.x * sinAngle, n.z * n.z * (1 - cosAngle) + cosAngle, 0)); rotateMatrix.SetRow(3, new Vector4L(0, 0, 0, 1)); Vector4L v = Vector3L.ToVector4(from); Vector3L vector = new Vector3L(); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; j++) { vector[i] += v[j] * rotateMatrix[j, i]; } } return(vector); }
public static Vector4L Max(Vector4L lhs, Vector4L rhs) { return(new Vector4L(FixPointMath.Max(lhs.x, rhs.x), FixPointMath.Max(lhs.y, rhs.y), FixPointMath.Max(lhs.z, rhs.z), FixPointMath.Max(lhs.w, rhs.w))); }
public FloatL SqrMagnitude() { return(Vector4L.Dot(this, this)); }
public static FloatL SqrMagnitude(Vector4L a) { return(Vector4L.Dot(a, a)); }
public static FloatL Distance(Vector4L a, Vector4L b) { return(Vector4L.Magnitude(a - b)); }
public static Vector4L Project(Vector4L a, Vector4L b) { return(b * Vector4L.Dot(a, b) / Vector4L.Dot(b, b)); }
public static FloatL Dot(Vector4L a, Vector4L b) { return(a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w); }
public static Vector4L Scale(Vector4L a, Vector4L b) { return(new Vector4L(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w)); }
public static FloatL Magnitude(Vector4L a) { return(FixPointMath.Sqrt(Vector4L.Dot(a, a))); }
public static Vector4L Lerp(Vector4L from, Vector4L to, FloatL t) { t = FixPointMath.Clamp01(t); return(new Vector4L(from.x + (to.x - from.x) * t, from.y + (to.y - from.y) * t, from.z + (to.z - from.z) * t, from.w + (to.w - from.w) * t)); }