コード例 #1
0
        public static Matrix Matrix_PointAt(Vec3D pos, Vec3D target, Vec3D up)
        {
            Vec3D newForward = Vec3D.VectorSub(target, pos);

            newForward = Vec3D.VectorNormalise(newForward);

            Vec3D a     = Vec3D.VectorMul(newForward, Vec3D.VectorDotProduct(up, newForward));
            Vec3D newUp = Vec3D.VectorSub(up, a);

            newUp = Vec3D.VectorNormalise(newUp);

            Vec3D newRight = Vec3D.VectorCrossProduct(newUp, newForward);

            Matrix matrix = new Matrix(4);

            matrix.matrix[0, 0] = newRight.x; matrix.matrix[0, 1] = newRight.y; matrix.matrix[0, 2] = newRight.z; matrix.matrix[0, 3] = 0.0f;
            matrix.matrix[1, 0] = newUp.x; matrix.matrix[1, 1] = newUp.y; matrix.matrix[1, 2] = newUp.z; matrix.matrix[1, 3] = 0.0f;
            matrix.matrix[2, 0] = newForward.x; matrix.matrix[2, 1] = newForward.y; matrix.matrix[2, 2] = newForward.z; matrix.matrix[2, 3] = 0.0f;
            matrix.matrix[3, 0] = pos.x; matrix.matrix[3, 1] = pos.y; matrix.matrix[3, 2] = pos.z; matrix.matrix[3, 3] = 1.0f;

            return(matrix);
        }
コード例 #2
0
 public Light(Vec3D lightDirection)
 {
     this.lightDirection = lightDirection;
     this.lightDirection = Vec3D.VectorNormalise(lightDirection);
 }