예제 #1
0
 public Vertex(Point xiPosition, Vector xiNormal, Color xiColor, int xiTexCoordX, int xiTexCoordY)
 {
     mPosition = xiPosition;
       mNormal = xiNormal;
       mColor = xiColor;
       mTexCoordX = xiTexCoordX;
       mTexCoordY = xiTexCoordY;
 }
예제 #2
0
        public void testDecomposition()
        {
            Matrix t = Matrix.Translation(9, 10, 11);
              Vector rotAxis = new Vector(1, 2, 3).Normalise();
              // == [0.26726, 0.5345, 0.801]
              Matrix r = Matrix.Rotation(1.5, rotAxis);
              Matrix s = Matrix.ScalingMatrix(3, 3, 3);

              Matrix m = s*r*t;

              Vector scale;
              Vector rotationAxis;
              double rotationAngle;
              Vector translation;
              m.Decompose(out translation, out rotationAxis, out rotationAngle, out scale);

              Assert.AreEqual(new Vector(9, 10, 11), translation);
              Assert.AreEqual(rotAxis, rotationAxis * -1); // TODO need to fix rotation inverse
              Assert.That(1.5, AlmostEqualTo(rotationAngle));
              Assert.AreEqual(new Vector(3,3,3), scale);

              testDecompositionRoundTrip(m);
        }
예제 #3
0
        // a 2d move request, which will be turned into 3d camera
        // movement, in a manner dependent on
        private void MoveCamera(Vector xiMove)
        {
            if (MovementMode == eMovementMode.InspectMode)
              {
            //turn movement requests into rotation about origin

              }

              if (LightingMode == eLightingMode.Headlight)
              {
            //light moves with camera
            mLight.Move(xiMove);
              }
              mCamera.Move(xiMove);
        }
예제 #4
0
 public double Dot(Vector xiOther)
 {
     return mElements[0] * xiOther.mElements[0]
        + mElements[1] * xiOther.mElements[1]
        + mElements[2] * xiOther.mElements[2];
 }
예제 #5
0
        /// <summary>
        /// TODO: document this method...
        /// 
        /// Not 100% sure what this does -- it came from the GLTK code.
        /// I think it keeps the rotations the same but makes them more 'normalised'?
        /// </summary>
        public Matrix Orthogonalise()
        {
            Vector lColumn1 = new Vector(this[1, 0], this[1, 1], this[1, 2]);
              Vector lColumn2 = new Vector(this[2, 0], this[2, 1], this[2, 2]);

              Vector lNewColumn0 = (lColumn1 ^ lColumn2).Normalise();
              Vector lNewColumn1 = lColumn1.Normalise();
              Vector lNewColumn2 = (lNewColumn0 ^ lColumn1).Normalise();

              return new Matrix(
            lNewColumn0.x, lNewColumn0.y, lNewColumn0.z, 0,
            lNewColumn1.x, lNewColumn1.y, lNewColumn1.z, 0,
            lNewColumn2.x, lNewColumn2.y, lNewColumn2.z, 0,
            this[3, 0], this[3, 1], this[3, 2], this[3, 3]);
        }
예제 #6
0
        /// <summary>
        /// If possible, decomposes this matrix into S*R*T
        /// for a translation T, a rotation R and a scaling S.
        ///
        /// The rotation is represented as an angle in radians about an axis.
        ///
        /// http://graphcomp.com/info/specs/sgi/vrml/spec/part1/concepts.html#CoordinateSystems
        /// http://graphcomp.com/info/specs/sgi/vrml/spec/part1/nodesRef.html#Transform
        /// </summary>
        public void Decompose(out Vector translation, out Vector rotationAxis, out double rotationAngle, out Vector scale)
        {
            translation = new Vector(this[3, 0], this[3, 1], this[3, 2]);

              var M11 = this[0, 0];
              var M12 = this[0, 1];
              var M13 = this[0, 2];
              var M14 = this[0, 3];
              var M21 = this[1, 0];
              var M22 = this[1, 1];
              var M23 = this[1, 2];
              var M24 = this[1, 3];
              var M31 = this[2, 0];
              var M32 = this[2, 1];
              var M33 = this[2, 2];
              var M34 = this[2, 3];
              var M41 = this[3, 0];
              var M42 = this[3, 1];
              var M43 = this[3, 2];

              float xs = (Math.Sign(M11 * M12 * M13 * M14) < 0) ? -1f : 1f;
              float ys = (Math.Sign(M21 * M22 * M23 * M24) < 0) ? -1f : 1f;
              float zs = (Math.Sign(M31 * M32 * M33 * M34) < 0) ? -1f : 1f;

              var scaleX = xs * (float)Math.Sqrt(M11 * M11 + M12 * M12 + M13 * M13);
              var scaleY = ys * (float)Math.Sqrt(M21 * M21 + M22 * M22 + M23 * M23);
              var scaleZ = zs * (float)Math.Sqrt(M31 * M31 + M32 * M32 + M33 * M33);
              scale = new Vector(scaleX,scaleY,scaleZ);

              if (scaleX == 0.0 || scaleY == 0.0 || scaleZ == 0.0)
              {
            rotationAngle = 0;
            rotationAxis = new Vector(1, 0, 0);
            return;
              }

              Matrix m1 = new Matrix(M11 / scaleX, M12 / scaleX, M13 / scaleX, 0,
                             M21 / scaleY, M22 / scaleY, M23 / scaleY, 0,
                             M31 / scaleZ, M32 / scaleZ, M33 / scaleZ, 0,
                             0, 0, 0, 1);

              var rotation = Quaternion.CreateFromRotationMatrix(m1);

              rotation.ToAxisAngle(out rotationAxis, out rotationAngle);
        }
예제 #7
0
 public static Matrix Translation(Vector xiVector)
 {
     return Translation(xiVector.x, xiVector.y, xiVector.z);
 }
예제 #8
0
        public static Matrix Rotation(double xiAngle, Vector xiAxis)
        {
            if (xiAxis.Length == 0)
              {
            throw new Exception("Cannot have axis of zero length");
              }

              double t = 1 - Math.Cos(xiAngle);
              double s = Math.Sin(xiAngle);
              double c = Math.Cos(xiAngle);
              double x = xiAxis.x / xiAxis.Length;
              double y = xiAxis.y / xiAxis.Length;
              double z = xiAxis.z / xiAxis.Length;

              return new Matrix(
            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);
        }
예제 #9
0
        public void LookAt(Point xiTarget, Vector xiUp)
        {
            Vector lV1 = (Position - xiTarget).Normalise();
              Vector lV2 = xiUp.Normalise();

              Vector lV3 = lV2 ^ lV1;
              lV2 = lV1 ^ lV3;

              mTransform = new Matrix(
            lV3.x, lV3.y, lV3.z, 0,
            lV2.x, lV2.y, lV2.z, 0,
            lV1.x, lV1.y, lV1.z, 0,
            mTransform[3, 0], mTransform[3, 1], mTransform[3, 2], mTransform[3, 3]);

              Reorthogonalise();
        }
예제 #10
0
        public void RotateAboutWorldOrigin(double xiAngle, Vector xiAxis)
        {
            mTransform = mTransform * Matrix.Rotation(xiAngle, xiAxis);

              Reorthogonalise();
        }
예제 #11
0
 //rotates about the Entity's current origin.
 public void Rotate(double xiAngle, Vector xiAxis)
 {
     Point lStart = Position;
       Position = Point.Origin;
       RotateAboutWorldOrigin(xiAngle, xiAxis);
       Position = lStart;
 }
예제 #12
0
        public void Move(Vector xiVector)
        {
            mTransform = mTransform * Matrix.Translation(xiVector);

              Reorthogonalise();
        }
예제 #13
0
 public Vertex(Point xiPosition, Vector xiNormal, Color xiColor)
 {
     mPosition = xiPosition;
       mNormal = xiNormal;
       mColor = xiColor;
 }