Esempio n. 1
0
        public bool UnProject(ref Vector3G win, out Vector3G objectCoordinate)
        {
            objectCoordinate = new Vector3G();
            Matrix4x4G matrix4x4G;
            Matrix4x4G matrix4x4G1;
            Vector4G   vector4G = new Vector4G();
            Vector4G   vector4G1;

            Matrix4x4G.Mult(ref this.projection, ref this.modelview, out matrix4x4G);
            if (!Matrix4x4G.Inverse(ref matrix4x4G, out matrix4x4G1))
            {
                objectCoordinate = new Vector3G();
                return(false);
            }
            vector4G.x = (win.x - this.offset.x) / this.size.x * 2 - 1;
            vector4G.y = (win.y - this.offset.y) / this.size.y * 2 - 1;
            vector4G.z = -win.z;
            vector4G.w = 1;
            Matrix4x4G.Mult(ref vector4G, ref matrix4x4G1, out vector4G1);
            if (vector4G1.w == 0)
            {
                objectCoordinate = new Vector3G();
                return(false);
            }
            vector4G1.w        = 1 / vector4G1.w;
            objectCoordinate.x = vector4G1.x * vector4G1.w;
            objectCoordinate.y = vector4G1.y * vector4G1.w;
            objectCoordinate.z = vector4G1.z * vector4G1.w;
            return(true);
        }
Esempio n. 2
0
        public bool Project(ref Vector3G obj, out Vector3G windowCoordinate)
        {
            windowCoordinate = new Vector3G();
            Vector4G vector4G  = new Vector4G();
            Vector4G vector4G1 = new Vector4G();

            vector4G.x  = this.modelview.m00 * obj.x + this.modelview.m01 * obj.y + this.modelview.m02 * obj.z + this.modelview.m03;
            vector4G.y  = this.modelview.m10 * obj.x + this.modelview.m11 * obj.y + this.modelview.m12 * obj.z + this.modelview.m13;
            vector4G.z  = this.modelview.m20 * obj.x + this.modelview.m21 * obj.y + this.modelview.m22 * obj.z + this.modelview.m23;
            vector4G.w  = this.modelview.m30 * obj.x + this.modelview.m31 * obj.y + this.modelview.m32 * obj.z + this.modelview.m33;
            vector4G1.x = this.projection.m00 * vector4G.x + this.projection.m01 * vector4G.y + this.projection.m02 * vector4G.z + this.projection.m03 * vector4G.w;
            vector4G1.y = this.projection.m10 * vector4G.x + this.projection.m11 * vector4G.y + this.projection.m12 * vector4G.z + this.projection.m13 * vector4G.w;
            vector4G1.z = this.projection.m20 * vector4G.x + this.projection.m21 * vector4G.y + this.projection.m22 * vector4G.z + this.projection.m23 * vector4G.w;
            vector4G1.w = -vector4G.z;
            if (vector4G1.w == 0)
            {
                windowCoordinate = new Vector3G();
                return(false);
            }
            vector4G1.w        = 1 / vector4G1.w;
            vector4G1.x        = vector4G1.x * vector4G1.w;
            vector4G1.y        = vector4G1.y * vector4G1.w;
            windowCoordinate.x = (vector4G1.x * 0.5 + 0.5) * this.size.x + this.offset.x;
            windowCoordinate.y = (vector4G1.y * 0.5 + 0.5) * this.size.y + this.offset.y;
            windowCoordinate.z = vector4G1.z;
            return(true);
        }
Esempio n. 3
0
 public bool UnProject(ref Vector3G win, out Vector3G objectCoordinate)
 {
     objectCoordinate = new Vector3G();
     Matrix4x4G matrix4x4G;
     Matrix4x4G matrix4x4G1;
     Vector4G vector4G = new Vector4G();
     Vector4G vector4G1;
     Matrix4x4G.Mult(ref this.projection, ref this.modelview, out matrix4x4G);
     if (!Matrix4x4G.Inverse(ref matrix4x4G, out matrix4x4G1))
     {
         objectCoordinate = new Vector3G();
         return false;
     }
     vector4G.x = (win.x - this.offset.x) / this.size.x * 2 - 1;
     vector4G.y = (win.y - this.offset.y) / this.size.y * 2 - 1;
     vector4G.z = -win.z;
     vector4G.w = 1;
     Matrix4x4G.Mult(ref vector4G, ref matrix4x4G1, out vector4G1);
     if (vector4G1.w == 0)
     {
         objectCoordinate = new Vector3G();
         return false;
     }
     vector4G1.w = 1 / vector4G1.w;
     objectCoordinate.x = vector4G1.x * vector4G1.w;
     objectCoordinate.y = vector4G1.y * vector4G1.w;
     objectCoordinate.z = vector4G1.z * vector4G1.w;
     return true;
 }
Esempio n. 4
0
 public bool Project(ref Vector3G obj, out Vector3G windowCoordinate)
 {
     windowCoordinate = new Vector3G();
     Vector4G vector4G = new Vector4G();
     Vector4G vector4G1 = new Vector4G();
     vector4G.x = this.modelview.m00 * obj.x + this.modelview.m01 * obj.y + this.modelview.m02 * obj.z + this.modelview.m03;
     vector4G.y = this.modelview.m10 * obj.x + this.modelview.m11 * obj.y + this.modelview.m12 * obj.z + this.modelview.m13;
     vector4G.z = this.modelview.m20 * obj.x + this.modelview.m21 * obj.y + this.modelview.m22 * obj.z + this.modelview.m23;
     vector4G.w = this.modelview.m30 * obj.x + this.modelview.m31 * obj.y + this.modelview.m32 * obj.z + this.modelview.m33;
     vector4G1.x = this.projection.m00 * vector4G.x + this.projection.m01 * vector4G.y + this.projection.m02 * vector4G.z + this.projection.m03 * vector4G.w;
     vector4G1.y = this.projection.m10 * vector4G.x + this.projection.m11 * vector4G.y + this.projection.m12 * vector4G.z + this.projection.m13 * vector4G.w;
     vector4G1.z = this.projection.m20 * vector4G.x + this.projection.m21 * vector4G.y + this.projection.m22 * vector4G.z + this.projection.m23 * vector4G.w;
     vector4G1.w = -vector4G.z;
     if (vector4G1.w == 0)
     {
         windowCoordinate = new Vector3G();
         return false;
     }
     vector4G1.w = 1 / vector4G1.w;
     vector4G1.x = vector4G1.x * vector4G1.w;
     vector4G1.y = vector4G1.y * vector4G1.w;
     windowCoordinate.x = (vector4G1.x * 0.5 + 0.5) * this.size.x + this.offset.x;
     windowCoordinate.y = (vector4G1.y * 0.5 + 0.5) * this.size.y + this.offset.y;
     windowCoordinate.z = vector4G1.z;
     return true;
 }