Example #1
0
 public v3f cross(v3f b)
 {
     v3f res;
       res.x = y * b.z - z * b.y;
       res.y = z * b.x - x * b.z;
       res.z = x * b.y - y * b.x;
       return res;
 }
Example #2
0
        public v3f rotateAbout(v3f axis, float rotationRad)
        {
            v3f res = new v3f();
              v3f uvw = axis.norm();
              //http://www.mines.edu/~gmurray/ArbitraryAxisRotation/ArbitraryAxisRotation.htm
              float u = uvw.x;
              float v = uvw.y;
              float w = uvw.z;
              float SIN = (float)Math.Sin(rotationRad);
              float COS = (float)Math.Cos(rotationRad);
              float u2 = u * u;
              float v2 = v * v;
              float w2 = w * w;
              float ux = u * x;
              float vy = v * y;
              float wz = w * z;
              float dot = ux + vy + wz;
              // x=u(ux+vy+wz)+(x(v*v+w*w)+u(-vy-wz))cos(theta)+mag(uvw)(vz-wy)sin(theta)
              res.x = u * dot + COS * (x * (v2 + w2) + u * (-vy - wz)) + uvw.mag() * (v * z - w * y) * SIN;
              res.y = v * dot + COS * (y * (u2 + w2) + v * (-ux - wz)) + uvw.mag() * (w * x - u * z) * SIN;
              res.z = w * dot + COS * (z * (u2 + v2) + w * (-ux - vy)) + uvw.mag() * (u * y - v * x) * SIN;

              return res;
        }
Example #3
0
            public void Pan(v3f v)
            {
                v3f lookat = new v3f();
                lookat.z = -(float)Math.Sin(pitch / 180.0 * Math.PI);
                float horiz = (float)Math.Cos(pitch / 180.0 * Math.PI);
                lookat.x = horiz * (float)Math.Sin(yaw / 180.0 * Math.PI);
                lookat.y = horiz * (float)Math.Cos(yaw / 180.0 * Math.PI);

                v3f forward = lookat;
                v3f left = up.cross(forward).norm();
                v3f T = (forward * v.x + left*v.y + up.norm()*v.z);

                location = location + T;
            }
Example #4
0
            public override void ApplyProjection()
            {
                v3f lookat = new v3f();
                lookat.z = -(float)Math.Sin(pitch / 180.0 * Math.PI);
                float horiz = (float)Math.Cos(pitch / 180.0 * Math.PI);
                lookat.x = horiz*(float)Math.Sin(yaw / 180.0 * Math.PI);
                lookat.y = horiz*(float)Math.Cos(yaw / 180.0 * Math.PI);

                lookat = lookat + location;

                Glu.gluPerspective(45.0, aspect, .01, 1000);
                Glu.gluLookAt(location.x, location.y, location.z, lookat.x, lookat.y, lookat.z, up.x, up.y, up.z);
            }
Example #5
0
            float pitch, yaw; // both in degrees

            #endregion Fields

            #region Constructors

            public GLCameraFree(WorldTransform wt)
            {
                location = new v3f(-5.0f, -5, 5);
                up = new v3f(0, 0, 1);
                pitch = 30;
                yaw = 30;
                UpdateWithWorldTransform(wt);
            }
Example #6
0
 public void Pitch(float rotDegrees)
 {
     v3f v = up.cross(centerRel);
     v3f cv = centerRel - eyeRel;
     centerRel = cv.rotateAbout(v, rotDegrees / 180.0f * (float)Math.PI);
 }
Example #7
0
            public void MoveToPointAndHeading(PointF point, double rotRadians)
            {
                v3f vPoint = new v3f(point.X, point.Y, 1.0f);
                v3f forward = new v3f((float)Math.Cos(rotRadians), (float)Math.Sin(rotRadians), 0);

                float cDist = (float)Math.Sqrt(centerRel.x * centerRel.x + centerRel.y * centerRel.y);
                float cZ = centerRel.z;

                float eDist = (float)Math.Sqrt(eyeRel.x * eyeRel.x + eyeRel.y * eyeRel.y);
                float eZ = eyeRel.z;

                center = vPoint + forward * cDist;
                center.z = cZ;
                eye = vPoint - forward * eDist;
                eye.z = eZ;
            }
Example #8
0
 public GLCameraChase(WorldTransform wt)
 {
     eye = eyeRel;
     center = centerRel;
     up = new v3f(0, 0, 1);
     UpdateWithWorldTransform(wt);
 }