public static Matrix LookAtLH(Vector eye, Vector target, Vector up) { var axisZ = (target - eye).Normalize(); var axisX = up.Cross(axisZ).Normalize(); var axisY = axisZ.Cross(axisX).Normalize(); var eyeX = -axisX.Dot(eye); var eyeY = -axisY.Dot(eye); var eyeZ = -axisZ.Dot(eye); return new Matrix(new[] { axisX.X, axisY.X, axisZ.X, 0, axisX.Y, axisY.Y, axisZ.Y, 0, axisX.Z, axisY.Z, axisZ.Z, 0, eyeX, eyeY, eyeZ, 1 }); }
public Vector Interpolate(Vector v, float factor) { return this + (v - this) * factor; }
public float Dot(Vector v) { return X * v.X + Y * v.Y + Z * v.Z; }
public Vector Cross(Vector v) { return new Vector(Y * v.Z - Z * v.Y, Z * v.X - X * v.Z, X * v.Y - Y * v.X); }
public void DrawTriangle(Vector pa, Vector pb, Vector pc, Color color) { var a = pa - pb; var b = pc - pb; var n = a.Cross(b); var v = camera.Target - camera.Position; if (n.Dot(v) >= 0) { return; } DrawLine(pa, pb, color); DrawLine(pa, pc, color); DrawLine(pc, pb, color); }
public void DrawPoint(Vector point, Color color) { DrawPoint((int)point.X, (int)point.Y, point.Z, color); }
public void DrawLine(Vector p0, Vector p1, Color color) { canvasGraphics.DrawLine(new Pen(color), p0, p1); }
private Vector Project(Vector coord, Matrix transformMatrix) { var p = transformMatrix.Transform(coord); p.X = p.X * Width + Width / 2f; p.Y = -p.Y * Height + Height / 2f; return p; }
public static Matrix Rotation(Vector r) { var x = RotationX(r.X); var y = RotationY(r.Y); var z = RotationZ(r.Z); return z * x * y; }
public Vector Transform(Vector v) { var x = v.X * Values[0 * 4 + 0] + v.Y * Values[1 * 4 + 0] + v.Z * Values[2 * 4 + 0] + Values[3 * 4 + 0]; var y = v.X * Values[0 * 4 + 1] + v.Y * Values[1 * 4 + 1] + v.Z * Values[2 * 4 + 1] + Values[3 * 4 + 1]; var z = v.X * Values[0 * 4 + 2] + v.Y * Values[1 * 4 + 2] + v.Z * Values[2 * 4 + 2] + Values[3 * 4 + 2]; var w = v.X * Values[0 * 4 + 3] + v.Y * Values[1 * 4 + 3] + v.Z * Values[2 * 4 + 3] + Values[3 * 4 + 3]; return new Vector(x / w, y / w, z / w); }
public static Matrix Translation(Vector t) { var values = new[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, t.X, t.Y, t.Z, 1 }; return new Matrix(values); }
public static Matrix Scale(Vector s) { var values = new[] { s.X, 0, 0, 0, 0, s.Y, 0, 0, 0, 0, s.Z, 0, 0, 0, 0, 1 }; return new Matrix(values); }