public static TheVector3 operator *(TheQuaternion rotation, TheVector3 point) { //float num = rotation.x * 2f; //float num2 = rotation.y * 2f; //float num3 = rotation.z * 2f; //float num4 = rotation.x * num; //float num5 = rotation.y * num2; //float num6 = rotation.z * num3; //float num7 = rotation.x * num2; //float num8 = rotation.x * num3; //float num9 = rotation.y * num3; //float num10 = rotation.w * num; //float num11 = rotation.w * num2; //float num12 = rotation.w * num3; //TheVector3 result = new TheVector3(); //result.x = (1f - (num5 + num6)) * point.x + (num7 - num12) * point.y + (num8 + num11) * point.z; //result.y = (num7 + num12) * point.x + (1f - (num4 + num6)) * point.y + (num9 - num10) * point.z; //result.z = (num8 - num11) * point.x + (num9 + num10) * point.y + (1f - (num4 + num5)) * point.z; //return result; // Extract the vector part of the quaternion TheVector3 u = new TheVector3(rotation.x, rotation.y, rotation.z); // Extract the scalar part of the quaternion float s = rotation.w; // Do the math TheVector3 vprime = 2.0f * TheVector3.DotProduct(u, point) * u + (s * s - TheVector3.DotProduct(u, u)) * point + 2.0f * s * TheVector3.CrossProduct(u, point); return(vprime); }
public static TheVector3 SLerp(TheVector3 start, TheVector3 end, float value) { float dot = DotProduct(start, end); Math.Math.Clamp(dot, -1, 1); float theta = Math.Math.Acos(dot) * value; TheVector3 relative_vector = end - start * dot; return((start * Math.Math.Cos(theta)) + (relative_vector.Normalized * Math.Math.Sin(theta))); }
public TheVector3 ToEulerAngles() { TheVector3 ret = new TheVector3 { x = Math.Math.Atan2(2 * (x * y + w * z), w * w + x * x - y * y - z * z), y = Math.Math.Asin(-2 * (x * z - w * y)), z = Math.Math.Atan2(2 * (y * z + w * x), w * w - x * x - y * y + z * z) }; return(ret); }
public static TheQuaternion FromAngleAxis(float angle, TheVector3 axis) { TheVector3 tmp = axis * Math.Math.Sin(angle / 2); TheQuaternion ret = new TheQuaternion { x = tmp.x, y = tmp.y, z = tmp.z, w = Math.Math.Cos(angle / 2) }; return(ret); }
public static TheVector3 Normalize(TheVector3 vector) { TheVector3 ret; float magnitude = Magnitude(vector); if (magnitude > 1E-05f) { ret = vector / magnitude; } else { ret = Zero; } return(ret); }
public static TheVector3 Project(TheVector3 vector, TheVector3 normal) { TheVector3 ret; float dot = DotProduct(normal, normal); if (dot < Math.Math.Epsilon) { ret = Zero; } else { ret = normal * DotProduct(vector, normal) / dot; } return(ret); }
public override bool Equals(object other) { bool ret; if (other == null || !(other is TheVector3)) { ret = false; } else { TheVector3 vector = (TheVector3)other; ret = (x == vector.x && y == vector.y && z == vector.z); } return(ret); }
public static void ToAngleAxis(TheQuaternion a, out float angle, out TheVector3 axis) { angle = Math.Math.Acos(a.w); float sin_theta_inv = 1.0f / Math.Math.Sin(angle); axis = new TheVector3 { x = a.x * sin_theta_inv, y = a.y * sin_theta_inv, z = a.z * sin_theta_inv }; angle *= 2; }
public static TheVector3 MoveTowards(TheVector3 position, TheVector3 target, float step) { TheVector3 diff = target - position; float magnitude = diff.Length; TheVector3 ret; if (magnitude <= step || magnitude < Math.Math.Epsilon) { ret = target; } else { ret = position + diff / magnitude * step; } return(ret); }
public static TheQuaternion FromEulerAngles(TheVector3 angles) { float cos_z_2 = Math.Math.Cos(0.5f * angles.z); float cos_y_2 = Math.Math.Cos(0.5f * angles.y); float cos_x_2 = Math.Math.Cos(0.5f * angles.x); float sin_z_2 = Math.Math.Sin(0.5f * angles.z); float sin_y_2 = Math.Math.Sin(0.5f * angles.y); float sin_x_2 = Math.Math.Sin(0.5f * angles.x); TheQuaternion ret = new TheQuaternion { x = cos_z_2 * cos_y_2 * sin_x_2 - sin_z_2 * sin_y_2 * cos_x_2, y = cos_z_2 * sin_y_2 * cos_x_2 + sin_z_2 * cos_y_2 * sin_x_2, z = sin_z_2 * cos_y_2 * cos_x_2 - cos_z_2 * sin_y_2 * sin_x_2, w = cos_z_2 * cos_y_2 * cos_x_2 + sin_z_2 * sin_y_2 * sin_x_2 }; return(ret); }
public static TheQuaternion LookRotation(TheVector3 direction) { TheVector3 up = TheVector3.Up; return(lookRotation(direction, up)); }
public void ToAngleAxis(out float angle, out TheVector3 axis) { TheVector3 tmp = new TheVector3(x, y, z); ToAngleAxis(this, out angle, out axis); }
private extern void SetPosition(TheVector3 value);
public extern void SetSpawnPosition(TheVector3 position);
private extern void SetRotation(TheVector3 value);
public static TheVector3 NLerp(TheVector3 start, TheVector3 end, float value) { return(Lerp(start, end, value).Normalized); }
public void Scale(TheVector3 scale) { x *= scale.x; y *= scale.y; z *= scale.z; }
public static TheVector3 CrossProduct(TheVector3 vector_1, TheVector3 vector_2) { return(new TheVector3(vector_1.y * vector_2.z - vector_1.z * vector_2.y, vector_1.z * vector_2.x - vector_1.x * vector_2.z, vector_1.x * vector_2.y - vector_1.y * vector_2.x)); }
public static TheVector3 Reflect(TheVector3 direction, TheVector3 normal) { return(-2f * DotProduct(normal, direction) * normal + direction); }
public extern void LookAt(TheVector3 value);
public extern void SetSpawnRotation(TheVector3 rotation);
public extern void SetSpawnScale(TheVector3 scale);
public static float Magnitude(TheVector3 vector) { return(Math.Math.Sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z)); }
public static float DotProduct(TheVector3 vector_1, TheVector3 vector_2) { return(vector_1.x * vector_2.x + vector_1.y * vector_2.y + vector_1.z * vector_2.z); }
private static extern TheQuaternion lookRotation(TheVector3 direction, TheVector3 up);
public static TheVector3 Scale(TheVector3 a, TheVector3 b) { return(new TheVector3(a.x * b.x, a.y * b.y, a.z * b.z)); }
public static float AngleBetween(TheVector3 vector_1, TheVector3 vector_2) { return(Math.Math.Acos(DotProduct(vector_1, vector_2) / DotProduct(vector_1.Normalized, vector_2.Normalized)) * Math.Math.RadToDeg); }
public static TheVector3 Lerp(TheVector3 start, TheVector3 end, float value) { return(start + value * (end - start)); }
public static float Distance(TheVector3 vector_1, TheVector3 vector_2) { TheVector3 vector = new TheVector3(vector_1.x - vector_2.x, vector_1.y - vector_2.y, vector_1.z - vector_2.z); return(Math.Math.Sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z)); }
private extern void SetScale(TheVector3 value);