예제 #1
0
 public GLCamera()
 {
     viewmat = new Matrix3D();
     deg2rad = (float)(2.0 * Math.PI / 360.0);
     m_zaxis = new Vector3d(0, 0, 1);
     m_dx = m_dy = m_dz = 0;
     m_dir = 1.0f;
     m_bvscalexy = 4.0f;
     m_bvscaleh = 1.2f;
 }
예제 #2
0
        public void  Rotate ( float Xa, float Ya, float Za )
        {
            Matrix3D Rmat = new Matrix3D();
            Matrix3D RMatrix = new Matrix3D();
            float sinxa = (float)Math.Sin(Xa);
            float cosxa = (float)Math.Cos(Xa);
            float sinza = (float)Math.Sin(Za);
            float cosza = (float)Math.Cos(Za);
            float sinya = (float)Math.Sin(Ya);
            float cosya = (float)Math.Cos(Ya);
            Rmat.Identity();
            RMatrix.Identity();

            // Initialize Z rotation matrix - Note: we perform Z
            // rotation first to align the 3D Z axis with the 2D Z axis.
            Rmat.Matrix[0,0]=cosza;    Rmat.Matrix[0,1]=sinza;    Rmat.Matrix[0,2]=0;    Rmat.Matrix[0,3]=0;
            Rmat.Matrix[1,0]=-sinza;   Rmat.Matrix[1,1]=cosza;    Rmat.Matrix[1,2]=0;    Rmat.Matrix[1,3]=0;
            Rmat.Matrix[2,0]=0;        Rmat.Matrix[2,1]=0;        Rmat.Matrix[2,2]=1;    Rmat.Matrix[2,3]=0;
            Rmat.Matrix[3,0]=0;        Rmat.Matrix[3,1]=0;        Rmat.Matrix[3,2]=0;    Rmat.Matrix[3,3]=1;

            // Merge matrix with master matrix:
            MergeMatrices (ref RMatrix, Rmat );

            // Initialize X rotation matrix:
            Rmat.Matrix[0,0]=1;  Rmat.Matrix[0,1]=0;        Rmat.Matrix[0,2]=0;       Rmat.Matrix[0,3]=0;
            Rmat.Matrix[1,0]=0;  Rmat.Matrix[1,1]=cosxa;    Rmat.Matrix[1,2]=sinxa;   Rmat.Matrix[1,3]=0;
            Rmat.Matrix[2,0]=0;  Rmat.Matrix[2,1]=-sinxa;   Rmat.Matrix[2,2]=cosxa;   Rmat.Matrix[2,3]=0;
            Rmat.Matrix[3,0]=0;  Rmat.Matrix[3,1]=0;        Rmat.Matrix[3,2]=0;       Rmat.Matrix[3,3]=1;

            // Merge matrix with master matrix:
            MergeMatrices(ref RMatrix, Rmat);

            // Initialize Y rotation matrix:
            Rmat.Matrix[0,0]=cosya;   Rmat.Matrix[0,1]=0;   Rmat.Matrix[0,2]=-sinya;   Rmat.Matrix[0,3]=0;
            Rmat.Matrix[1,0]=0;       Rmat.Matrix[1,1]=1;   Rmat.Matrix[1,2]=0;        Rmat.Matrix[1,3]=0;
            Rmat.Matrix[2,0]=sinya;   Rmat.Matrix[2,1]=0;   Rmat.Matrix[2,2]=cosya;    Rmat.Matrix[2,3]=0;
            Rmat.Matrix[3,0]=0;       Rmat.Matrix[3,1]=0;   Rmat.Matrix[3,2]=0;        Rmat.Matrix[3,3]=1;

            // Merge matrix with master matrix:
            MergeMatrices (ref RMatrix, Rmat );

            MergeMatrix ( RMatrix ); // now merge with this one.

        }
예제 #3
0
 public static void MergeMatrices(ref Matrix3D Dest , Matrix3D Source  )
 {
     // Multiply Source by Dest; store result in Temp:
        double [,] Temp  = new double [ 4 , 4 ];
        for (int i = 0; i < 4; i++)
        {
        for (int j = 0; j < 4; j++)
        {
            Temp[i, j] = (Source.Matrix[i, 0] * Dest.Matrix[0, j])
                          + (Source.Matrix[i, 1] * Dest.Matrix[1, j])
                          + (Source.Matrix[i, 2] * Dest.Matrix[2, j])
                          + (Source.Matrix[i, 3] * Dest.Matrix[3, j]);
        }
        }
        // Copy Temp to Dest.Matrix:
     for (int i = 0; i < 4; i++)
     {
         Dest.Matrix [ i , 0 ] = Temp [ i , 0 ];
         Dest.Matrix [ i , 1 ] = Temp [ i , 1 ];
         Dest.Matrix [ i , 2 ] = Temp [ i , 2 ];
         Dest.Matrix [ i , 3 ] = Temp [ i , 3 ];
     }
 }
예제 #4
0
        void MergeMatrix (Matrix3D NewMatrix )
        {
            // Multiply NewMatirx by Matrix; store result in TempMatrix
            float [,] TempMatrix  = new float [ 4 , 4 ];
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    TempMatrix[i, j] = (Matrix[i, 0] * NewMatrix.Matrix[0, j])
                    + (Matrix[i, 1] * NewMatrix.Matrix[1, j])
                    + (Matrix[i, 2] * NewMatrix.Matrix[2, j])
                    + (Matrix[i, 3] * NewMatrix.Matrix[3, j]);
                }
            }

            // Copy TempMatrix to Matrix:
            for (int i = 0; i < 4; i++)
            {
                Matrix[i,0] = TempMatrix[i,0];
                Matrix[i,1] = TempMatrix[i,1];
                Matrix[i,2] = TempMatrix[i,2];
                Matrix[i,3] = TempMatrix[i,3];
            }   
        }
예제 #5
0
        public void Rotate(float x, float y, float z) 
        {
            Point3d center = CalcCenter();
            Translate((float)-center.x, (float)-center.y, (float)-center.z);

            Matrix3D rotmat = new Matrix3D();
            rotmat.Identity();
            rotmat.Rotate(x, y, z);
            for(int c = 0; c< m_lstpoints.Count;c++)            
            {
                Point3d p = (Point3d)m_lstpoints[c];
                Point3d p1 = rotmat.Transform(p);
                p.x = p1.x;
                p.y = p1.y;
                p.z = p1.z;
            }
            Translate((float)center.x, (float)center.y, (float)center.z);
        }
예제 #6
0
        void UpdateView()
        {
            // Create a 4x4 orientation matrix from the right, up, and at vectors
            Matrix3D orientation = new Matrix3D(new float [] {
                m_right.x,  m_right.y,  m_right.z,  0,
                m_up.x,     m_up.y,     m_up.z,     0,
                -m_target.x, -m_target.y, -m_target.z, 0,
                0,          0,          0,          1
            });

            viewmat = orientation;
        }
예제 #7
0
        // rotate eye deg degrees arround rotAxis pivoting at target (m_lookat)
        protected Matrix3D Rotate(Vector3d rotAxis, float deg)
        {
            float rad = deg2rad * deg;
            float c = (float)Math.Cos(rad);
            float s = (float)Math.Sin(rad);
            float t = 1.0f - c;
            float x = rotAxis.x;
            float y = rotAxis.y;
            float z = rotAxis.z;
            Matrix3D rotMat= new Matrix3D(new float [] {
                t*x*x+c, t*x*y-s*z, t*x*z+s*y, 0,
                t*x*y+s*z, t*y*y+c, t*y*z-s*x, 0,
                t*x*z-s*y, t*y*z+s*x, t*z*z+c, 0,
                0,0,0,1
            });

            m_eye = rotMat.Transform(m_eye - m_lookat);
            m_eye = m_eye + m_lookat;
            return rotMat;
        }
예제 #8
0
 public Camera()
 {
     viewmat  = new Matrix3D();
     m_scalex = 22;
     m_scaley = 22;
 }
예제 #9
0
 private void TransformRange(Matrix3D tMat, int startidx, int endidx)
 {
     for (int c = startidx; c < endidx; c++)
     {
         Point3d p3 = tMat.Transform(m_lstpoints[c]);
         m_lstpoints[c].x = p3.x;
         m_lstpoints[c].y = p3.y;
         m_lstpoints[c].z = p3.z;
     }
        // Update(); // not necessary
     m_listid = -1; // regenerate the list id
 }
예제 #10
0
 public void Transform(Matrix3D tMat)
 {
     switch (m_seltype)
     {
         case eSelType.eBase:
             TransformRange(tMat, s1i, s2i);
             break;
         case eSelType.eTip:
             TransformRange(tMat, s4i, m_lstpoints.Count);
             break;
         case eSelType.eWhole:
             TransformRange(tMat, 0, m_lstpoints.Count);
             break;
     }
     base.Translate(0, 0, 0);
     // Update();
 }
예제 #11
0
        /// <summary>
        /// This functiuon positions the base at the location 'intersect'
        /// The idir is the direction that was used to intersect
        /// </summary>
        /// <param name="intersect"></param>
        /// <param name="idir"></param>
        /// <param name="inorm"></param>
        public void PositionBottom(ISectData dat)
        {
            // the bottom could be a tip or base
            // need to orient the bottom and position it.
            Point3d center;
            // for a base support, just slide it around
            if (m_subtype == eSubType.eBase)
            {
                center = Centroid(); // get the centroid of the selected portion of the object
                MinMax mm = CalcMinMaxRange(s1i, s4i);
                float dist = (float)((mm.m_max - mm.m_min) / 2);
                Translate(
                    (float)(dat.intersect.x - center.x),
                    (float)(dat.intersect.y - center.y),
                    (float)(dat.intersect.z - center.z + dist));
            }
            else if (m_subtype == eSubType.eIntra)  // bottom tip
            {
                // for a base tip, find the angle and angle it in
                Vector3d isectnorm = new Vector3d();
                //save the polygon intersection normal
                isectnorm.x = dat.poly.m_normal.x;
                isectnorm.y = dat.poly.m_normal.y;
                isectnorm.z = dat.poly.m_normal.z;
                isectnorm.Normalize();

                if (isectnorm.z < 0)
                {
                    isectnorm.z *= -1.0f;
                }
                // limit the z down to 45 degrees
                if (isectnorm.z < .75)
                {
                    isectnorm.z = .75f;
                }

                // re-genrate the points on the bottom of the foot
                ReGenSegmentPoints(mSC.htrad, mSC.cdivs, s1i, 0, true); // bottom of foot is the tip radius
                Matrix3D tMat = new Matrix3D();
                Vector3d vup = new Vector3d(0, 1, 0);
                Vector3d dir = new Vector3d(isectnorm.x, isectnorm.y, isectnorm.z);
                dir.Normalize();

                //direction should be upward at this point.
                //create a matrix transform
                tMat.LookAt(dir, vup);
                //transform the si1-s2i points to look at the vector
                TransformRange(tMat, s1i, s2i);
                //move the range of points to be touching the intersection point
                STranslateRange(dat.intersect.x, dat.intersect.y, dat.intersect.z, s1i, s2i);

                //now, get the center of s4i to s5i
                Point3d cnt = CalcCentroid(s2i, s4i);
                //translate to 0,0,0
                STranslateRange(-cnt.x, -cnt.y, -cnt.z, s2i, s4i);
                //reset the points,
                ReGenSegmentPoints(mSC.hbrad, mSC.cdivs, s2i, 0, false); // top of foot
                ReGenSegmentPoints(mSC.hbrad, mSC.cdivs, s3i, 0, false); // top of foot
                Point3d newp = new Point3d();
                newp.x = dat.intersect.x + (isectnorm.x * 2);
                newp.y = dat.intersect.y + (isectnorm.y * 2);
                newp.z = dat.intersect.z + (isectnorm.z * 2);
                STranslateRange(newp.x,newp.y,newp.z, s2i, s4i);

                Update();
            }
            //Update();
        }
예제 #12
0
        public void MoveFromTip(ISectData dat)
        {
            Point3d center;
            center = Centroid(); // get the centroid of the selected portion of the object
            Vector3d isectnorm = new Vector3d();
            //save the polygon intersection normal
            isectnorm.x = dat.poly.m_normal.x;
            isectnorm.y = dat.poly.m_normal.y;
            isectnorm.z = dat.poly.m_normal.z;

            MinMax mm = CalcMinMaxRange(s4i, m_lstpoints.Count);
            float dist = (float)((mm.m_max - mm.m_min) );
            ResetTip();
            Matrix3D tMat = new Matrix3D();
            Vector3d vup = new Vector3d(0,1,0);
            //always make sure the z is heading downward
            if (isectnorm.z > 0)
            {
                isectnorm.z *= -1.0f;
            }
            // limit the z down to 45 degrees
            if (isectnorm.z > -.75)
            {
                isectnorm.z = -.75f;
            }
            //reverse the direction to get the reflection
            Vector3d dir = new Vector3d(-isectnorm.x, -isectnorm.y, -isectnorm.z);
            dir.Normalize();
            //create a matrix transform
            tMat.LookAt(dir, vup);
            Transform(tMat);
            Translate(
                (float)(dat.intersect.x),
                (float)(dat.intersect.y),
                (float)(dat.intersect.z));

            //now, get the center of s4i to s5i
            Point3d cnt = CalcCentroid(s4i, s5i);
            //translate to 0
            TranslateRange(-cnt.x, -cnt.y, -cnt.z, s4i, s5i);
            //reset the points,
            ReGenSegmentPoints(mSC.hbrad, mSC.cdivs, s4i, 0, false); // bottom of head
            //move back
            TranslateRange(cnt.x, cnt.y, cnt.z, s4i, s5i);
            Update();

            //
        }
예제 #13
0
파일: Object3d.cs 프로젝트: tojoevan/BGC-CW
        public void Rotate(float x, float y, float z) 
        {
            Point3d center = CalcCenter();
            float cz = center.z;
            if ((x == 0) && (y == 0))
                cz = 0;
            // else - i think we need to delete all supports -SHS
            Translate((float)-center.x, (float)-center.y, (float)-cz);

            Matrix3D rotmat = new Matrix3D();
            rotmat.Identity();
            rotmat.Rotate(x, y, z);
            Rotate(rotmat);
            if ((x == 0) && (y == 0))
            {
                foreach (Object3d sup in m_supports)
                    sup.Rotate(rotmat);
            }
            Translate((float)center.x, (float)center.y, (float)cz);
        }
예제 #14
0
파일: Object3d.cs 프로젝트: tojoevan/BGC-CW
 void Rotate(Matrix3D rotmat)
 {
     for (int c = 0; c < m_lstpoints.Count; c++)
     {
         Point3d p = (Point3d)m_lstpoints[c];
         Point3d p1 = rotmat.Transform(p);
         p.x = p1.x;
         p.y = p1.y;
         p.z = p1.z;
     }
 }
예제 #15
0
        public void Translate( double Xt, double Yt, double Zt )
        {
            // Create 3D translation matrix:

            // Declare translation matrix:
            Matrix3D  Tmat  = new Matrix3D ();

            // Initialize translation matrix:
            Tmat.Matrix[0,0]=1;  Tmat.Matrix[0,1]=0;  Tmat.Matrix[0,2]=0;  Tmat.Matrix[0,3]=0;
            Tmat.Matrix[1,0]=0;  Tmat.Matrix[1,1]=1;  Tmat.Matrix[1,2]=0;  Tmat.Matrix[1,3]=0;
            Tmat.Matrix[2,0]=0;  Tmat.Matrix[2,1]=0;  Tmat.Matrix[2,2]=1;  Tmat.Matrix[2,3]=0;
            Tmat.Matrix[3,0]=Xt; Tmat.Matrix[3,1]=Yt; Tmat.Matrix[3,2]=Zt; Tmat.Matrix[3,3]=1;

            // Merge matrix with master matrix:
            MergeMatrix ( Tmat );
        }
예제 #16
0
 public Camera()
 {
     viewmat = new Matrix3D();
     m_scalex = 22;
     m_scaley = 22;
 }
예제 #17
0
        /// <summary>
        /// This functiuon positions the base at the location 'intersect'
        /// The idir is the direction that was used to intersect
        /// </summary>
        /// <param name="intersect"></param>
        /// <param name="idir"></param>
        /// <param name="inorm"></param>
        public void PositionBottom(ISectData dat)
        {
            // the bottom could be a tip or base
            // need to orient the bottom and position it.
            Point3d center;

            // for a base support, just slide it around
            if (m_subtype == eSubType.eBase)
            {
                center = Centroid(); // get the centroid of the selected portion of the object
                MinMax mm   = CalcMinMaxRange(s1i, s4i);
                float  dist = (float)((mm.m_max - mm.m_min) / 2);
                Translate(
                    (float)(dat.intersect.x - center.x),
                    (float)(dat.intersect.y - center.y),
                    (float)(dat.intersect.z - center.z + dist));
            }
            else if (m_subtype == eSubType.eIntra)  // bottom tip
            {
                // for a base tip, find the angle and angle it in
                Vector3d isectnorm = new Vector3d();
                //save the polygon intersection normal
                isectnorm.x = dat.poly.m_normal.x;
                isectnorm.y = dat.poly.m_normal.y;
                isectnorm.z = dat.poly.m_normal.z;
                isectnorm.Normalize();

                if (isectnorm.z < 0)
                {
                    isectnorm.z *= -1.0f;
                }
                // limit the z down to 45 degrees
                if (isectnorm.z < .75)
                {
                    isectnorm.z = .75f;
                }

                // re-genrate the points on the bottom of the foot
                ReGenSegmentPoints(mSC.htrad, mSC.cdivs, s1i, 0, true); // bottom of foot is the tip radius
                Matrix3D tMat = new Matrix3D();
                Vector3d vup  = new Vector3d(0, 1, 0);
                Vector3d dir  = new Vector3d(isectnorm.x, isectnorm.y, isectnorm.z);
                dir.Normalize();


                //direction should be upward at this point.
                //create a matrix transform
                tMat.LookAt(dir, vup);
                //transform the si1-s2i points to look at the vector
                TransformRange(tMat, s1i, s2i);
                //move the range of points to be touching the intersection point
                STranslateRange(dat.intersect.x, dat.intersect.y, dat.intersect.z, s1i, s2i);

                //now, get the center of s4i to s5i
                Point3d cnt = CalcCentroid(s2i, s4i);
                //translate to 0,0,0
                STranslateRange(-cnt.x, -cnt.y, -cnt.z, s2i, s4i);
                //reset the points,
                ReGenSegmentPoints(mSC.hbrad, mSC.cdivs, s2i, 0, false); // top of foot
                ReGenSegmentPoints(mSC.hbrad, mSC.cdivs, s3i, 0, false); // top of foot
                Point3d newp = new Point3d();
                newp.x = dat.intersect.x + (isectnorm.x * 2);
                newp.y = dat.intersect.y + (isectnorm.y * 2);
                newp.z = dat.intersect.z + (isectnorm.z * 2);
                STranslateRange(newp.x, newp.y, newp.z, s2i, s4i);

                Update();
            }
            //Update();
        }