Esempio n. 1
0
        // Construct a perspective projection matrix offset from the centre
        public static m4x4 ProjectionPerspective(float l, float r, float t, float b, float zn, float zf, bool righthanded)
        {
            Debug.Assert(Math_.IsFinite(l) && Math_.IsFinite(r) && Math_.IsFinite(t) && Math_.IsFinite(b) && (r - l) > 0 && (t - b) > 0, "invalid view rect");
            Debug.Assert(Math_.IsFinite(zn) && Math_.IsFinite(zf) && zn > 0 && zf > 0 && (zn - zf) != 0, "invalid near/far planes");
            var rh  = Math_.SignF(righthanded);
            var mat = new m4x4 {
            };

            mat.x.x = 2.0f * zn / (r - l);
            mat.y.y = 2.0f * zn / (t - b);
            mat.z.x = rh * (r + l) / (r - l);
            mat.z.y = rh * (t + b) / (t - b);
            mat.z.w = -rh;
            mat.z.z = rh * zf / (zn - zf);
            mat.w.z = zn * zf / (zn - zf);
            return(mat);
        }
Esempio n. 2
0
 public static m4x4 Translation(v4 translation)
 {
     Debug.Assert(Math_.FEql(translation.w, 1f), "'translation' must be a position vector");
     return(new m4x4(m3x4.Identity, translation));
 }
Esempio n. 3
0
 /// <summary>
 /// Return an object to world transform for a position along the spline
 /// 'axis' is the axis id that will lie along the tangent of the spline
 /// By default, the z axis is aligned to the spline with Y as up.</summary>
 public m4x4 O2W(float time, int axis, v4 up)
 {
     return(Math_.TxfmFromDir(axis, Velocity(time), Position(time), up));
 }
Esempio n. 4
0
 public static m4x4 operator *(m4x4 lhs, m4x4 rhs)
 {
     Math_.Transpose(ref lhs);
     return(new m4x4(
                new v4(Math_.Dot(lhs.x, rhs.x), Math_.Dot(lhs.y, rhs.x), Math_.Dot(lhs.z, rhs.x), Math_.Dot(lhs.w, rhs.x)),
                new v4(Math_.Dot(lhs.x, rhs.y), Math_.Dot(lhs.y, rhs.y), Math_.Dot(lhs.z, rhs.y), Math_.Dot(lhs.w, rhs.y)),
                new v4(Math_.Dot(lhs.x, rhs.z), Math_.Dot(lhs.y, rhs.z), Math_.Dot(lhs.z, rhs.z), Math_.Dot(lhs.w, rhs.z)),
                new v4(Math_.Dot(lhs.x, rhs.w), Math_.Dot(lhs.y, rhs.w), Math_.Dot(lhs.z, rhs.w), Math_.Dot(lhs.w, rhs.w))));
 }
Esempio n. 5
0
 // Construct from
 public static BBox From(v4 min, v4 max)
 {
     return(new BBox((max + min) * 0.5f, Math_.Abs(max - min) * 0.5f));
 }