public static Vector3 GetOrthogonalVector(this Vector3 vector) { Vector3 v = new Vector3(0, 0, 0); v.X = (float)MathTool.Random(); v.Y = (float)MathTool.Random(false); v.Z = -Vector3.Dot(vector, v) / vector.Z; return(Vector3.Normalize(v)); }
public static void GetInCubeVertexs(this VertexTriangle triangle, List <Vertex> outVertex) { foreach (var vertex in triangle.Vertexs) { if (MathTool.IsInCube(vertex.WorldPosition, 1, -1, 1, -1, 1, -1) == false) { outVertex.Add(vertex); } } }
public static bool IsContain(this VertexTriangle triangle, Vector3 screenPosition) { double d1 = MathTool.Sign(screenPosition - triangle.Vertexs[1].WorldPosition, triangle.Vertexs[0].WorldPosition - triangle.Vertexs[1].WorldPosition); double d2 = MathTool.Sign(screenPosition - triangle.Vertexs[2].WorldPosition, triangle.Vertexs[1].WorldPosition - triangle.Vertexs[2].WorldPosition); double d3 = MathTool.Sign(screenPosition - triangle.Vertexs[0].WorldPosition, triangle.Vertexs[2].WorldPosition - triangle.Vertexs[0].WorldPosition); bool hasNeg = (d1 < 0) || (d2 < 0) || (d3 < 0); bool hasPos = (d1 > 0) || (d2 > 0) || (d3 > 0); return(!(hasNeg && hasPos)); }
public void Execute() { _outVertexs.Clear(); foreach (var vertex in RenderingPipelineRegister.Instance.VertexList) { if (MathTool.IsInCube(vertex.WorldPosition, 1, -1, 1, -1, 1, -1) == false) { _outVertexs.Add(vertex); } } }
public static void GetMinRect(this VertexTriangle triangle, out int minX, out int maxX, out int minY, out int maxY) { minX = int.MaxValue; maxX = int.MinValue; minY = int.MaxValue; maxY = int.MinValue; foreach (var v in triangle.Vertexs) { MathTool.CompareMinMax(v.WorldPosition.X, ref minX, ref maxX); MathTool.CompareMinMax(v.WorldPosition.Y, ref minY, ref maxY); } }
public static Matrix CreateRotationZMatrix(float angle) { var cos = MathTool.Cos(angle); var sin = MathTool.Sin(angle); Matrix m = new Matrix(4, 4); m.TrySetValue(0, 0, cos); m.TrySetValue(1, 0, -sin); m.TrySetValue(0, 1, sin); m.TrySetValue(1, 1, cos); m.TrySetValue(2, 2, 1); m.TrySetValue(3, 3, 1); return(m); }
public static Quaternion VectorToQuaternion(Vector3 v) { Quaternion quaternion = new Quaternion(); double num9 = MathTool.DegToRad(v.Z) * 0.5f; double num6 = Math.Sin(num9); double num5 = Math.Cos(num9); double num8 = MathTool.DegToRad(v.X) * 0.5f; double num4 = Math.Sin(num8); double num3 = Math.Cos(num8); double num7 = MathTool.DegToRad(v.Y) * 0.5f; double num2 = Math.Sin(num7); double num = Math.Cos(num7); quaternion.X = (float)(((num * num4) * num5) + ((num2 * num3) * num6)); quaternion.Y = (float)(((num2 * num3) * num5) - ((num * num4) * num6)); quaternion.Z = (float)(((num * num3) * num6) - ((num2 * num4) * num5)); quaternion.W = (float)(((num * num3) * num5) + ((num2 * num4) * num6)); return(quaternion); }
public static Vector3 GetPointOnLine(this MathLine line) { return(line.Point + (float)MathTool.Random() * line.Direction); }
private bool CheckRange(int x, int y) { return(MathTool.IsInRange(0, Width, x, true, false) && MathTool.IsInRange(0, Height, y, true, false)); }