Esempio n. 1
0
        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
            });
        }
Esempio n. 2
0
 public Vector Interpolate(Vector v, float factor) {
     return this + (v - this) * factor;
 }
Esempio n. 3
0
 public float Dot(Vector v) {
     return X * v.X + Y * v.Y + Z * v.Z;
 }
Esempio n. 4
0
 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);
 }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
 public void DrawPoint(Vector point, Color color) {
     DrawPoint((int)point.X, (int)point.Y, point.Z, color);
 }
Esempio n. 7
0
 public void DrawLine(Vector p0, Vector p1, Color color) {
     canvasGraphics.DrawLine(new Pen(color), p0, p1);
 }
Esempio n. 8
0
 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;
 }
Esempio n. 9
0
 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;
 }
Esempio n. 10
0
 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);
 }
Esempio n. 11
0
 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);
 }
Esempio n. 12
0
 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);
 }