Exemple #1
0
 public void AddVertex(FixVector point, Uvl uvl)
 {
     vertBuffer[pointer++] = -point.x;
     vertBuffer[pointer++] = point.y;
     vertBuffer[pointer++] = point.z;
     vertBuffer[pointer++] = uvl.u;
     vertBuffer[pointer++] = uvl.v;
     vertBuffer[pointer++] = uvl.l;
 }
        /// <summary>
        /// Transfers the gun information from a robot to a Polymodel instance.
        /// </summary>
        /// <param name="robot">The robot to read the guns from.</param>
        private void BuildModelAnimation(Robot robot)
        {
            if (robot.ModelNum == -1)
            {
                return;
            }
            Polymodel        model     = Models[robot.ModelNum];
            List <FixAngles> jointlist = new List <FixAngles>();

            model.NumGuns = robot.NumGuns;
            for (int i = 0; i < Polymodel.MaxGuns; i++)
            {
                model.GunPoints[i]    = robot.GunPoints[i];
                model.GunDirs[i]      = FixVector.FromRawValues(65536, 0, 0);
                model.GunSubmodels[i] = robot.GunSubmodels[i];
            }
            int[,] jointmapping = new int[10, 5];
            for (int m = 0; m < Polymodel.MaxSubmodels; m++)
            {
                for (int f = 0; f < Robot.NumAnimationStates; f++)
                {
                    jointmapping[m, f] = -1;
                }
            }
            int basejoint = 0;

            for (int m = 0; m < Polymodel.MaxGuns + 1; m++)
            {
                for (int f = 0; f < Robot.NumAnimationStates; f++)
                {
                    Robot.JointList robotjointlist = robot.AnimStates[m, f];
                    basejoint = robotjointlist.Offset;
                    for (int j = 0; j < robotjointlist.NumJoints; j++)
                    {
                        JointPos joint = Joints[basejoint];
                        jointmapping[joint.JointNum, f] = basejoint;
                        model.IsAnimated = true;
                        basejoint++;
                    }
                }
            }

            for (int m = 1; m < Polymodel.MaxSubmodels; m++)
            {
                for (int f = 0; f < Robot.NumAnimationStates; f++)
                {
                    int jointnum = jointmapping[m, f];
                    if (jointnum != -1)
                    {
                        JointPos joint = Joints[jointnum];
                        model.AnimationMatrix[m, f].P = joint.Angles.P;
                        model.AnimationMatrix[m, f].B = joint.Angles.B;
                        model.AnimationMatrix[m, f].H = joint.Angles.H;
                    }
                }
            }
        }
        public void TestNormals()
        {
            // Default segment
            var segment = CreateDefaultSegment();

            Assert.AreEqual(new FixVector(1d, 0d, 0d), segment.Sides[0].Normal);
            Assert.AreEqual(new FixVector(0d, -1d, 0d), segment.Sides[1].Normal);
            Assert.AreEqual(new FixVector(-1d, 0d, 0d), segment.Sides[2].Normal);
            Assert.AreEqual(new FixVector(0d, 1d, 0d), segment.Sides[3].Normal);
            Assert.AreEqual(new FixVector(0d, 0d, -1d), segment.Sides[4].Normal);
            Assert.AreEqual(new FixVector(0d, 0d, 1d), segment.Sides[5].Normal);

            // Warped segment
            segment.Vertices[2].X = -30d;
            segment.Vertices[3].X = -30d;

            Assert.AreEqual(TriangulationType.None, segment.GetSide(SegSide.Left).Triangulation);
            Assert.AreEqual(new FixVector(0d, 0d, 1d), segment.GetSide(SegSide.Front).Normal);
            Assert.AreEqual(new FixVector(0d, 0d, -1d), segment.GetSide(SegSide.Back).Normal);
            var expectedNormal = new FixVector(0.7071d, 0d, -0.7071d);

            Assert.AreEqual(expectedNormal.X, segment.GetSide(SegSide.Left).Normal.X, 0.01);
            Assert.AreEqual(expectedNormal.Y, segment.GetSide(SegSide.Left).Normal.Y, 0.01);
            Assert.AreEqual(expectedNormal.Z, segment.GetSide(SegSide.Left).Normal.Z, 0.01);

            // Non-planar sides
            segment.Vertices[6].X = -30d;

            Assert.AreEqual(TriangulationType.Tri013_123, segment.GetSide(SegSide.Left).Triangulation);
            expectedNormal = new FixVector(0.5774, -0.5774, -0.5774);
            Assert.AreEqual(expectedNormal.X, segment.GetSide(SegSide.Left).Normals.Item1.X, 0.01);
            Assert.AreEqual(expectedNormal.Y, segment.GetSide(SegSide.Left).Normals.Item1.Y, 0.01);
            Assert.AreEqual(expectedNormal.Z, segment.GetSide(SegSide.Left).Normals.Item1.Z, 0.01);
            Assert.AreEqual(new FixVector(1, 0, 0), segment.GetSide(SegSide.Left).Normals.Item2);
            expectedNormal = new FixVector(0.8881d, -0.3251d, -0.3251d);
            Assert.AreEqual(expectedNormal.X, segment.GetSide(SegSide.Left).Normal.X, 0.01);
            Assert.AreEqual(expectedNormal.Y, segment.GetSide(SegSide.Left).Normal.Y, 0.01);
            Assert.AreEqual(expectedNormal.Z, segment.GetSide(SegSide.Left).Normal.Z, 0.01);

            segment.Vertices[0].X = 30d;

            Assert.AreEqual(TriangulationType.Tri012_230, segment.GetSide(SegSide.Right).Triangulation);
            expectedNormal = new FixVector(-0.7071d, 0.7071d, 0d);
            Assert.AreEqual(expectedNormal.X, segment.GetSide(SegSide.Right).Normals.Item1.X, 0.01);
            Assert.AreEqual(expectedNormal.Y, segment.GetSide(SegSide.Right).Normals.Item1.Y, 0.01);
            Assert.AreEqual(expectedNormal.Z, segment.GetSide(SegSide.Right).Normals.Item1.Z, 0.01);
            expectedNormal = new FixVector(-0.7071d, 0d, -0.7071d);
            Assert.AreEqual(expectedNormal.X, segment.GetSide(SegSide.Right).Normals.Item2.X, 0.01);
            Assert.AreEqual(expectedNormal.Y, segment.GetSide(SegSide.Right).Normals.Item2.Y, 0.01);
            Assert.AreEqual(expectedNormal.Z, segment.GetSide(SegSide.Right).Normals.Item2.Z, 0.01);
            expectedNormal = new FixVector(-0.8165d, 0.4082d, -0.4082d);
            Assert.AreEqual(expectedNormal.X, segment.GetSide(SegSide.Right).Normal.X, 0.01);
            Assert.AreEqual(expectedNormal.Y, segment.GetSide(SegSide.Right).Normal.Y, 0.01);
            Assert.AreEqual(expectedNormal.Z, segment.GetSide(SegSide.Right).Normal.Z, 0.01);
        }
        /// <summary>
        /// Transfers the gun information from the player ship to a Polymodel instance.
        /// </summary>
        /// <param name="ship">The ship to read the guns from.</param>
        private void BuildModelGunsFromShip(Ship ship)
        {
            Polymodel model = Models[ship.ModelNum];

            model.NumGuns = 8;
            for (int i = 0; i < 8; i++)
            {
                model.GunPoints[i]    = ship.GunPoints[i];
                model.GunDirs[i]      = FixVector.FromRawValues(65536, 0, 0);
                model.GunSubmodels[i] = 0;
            }
        }
Exemple #5
0
        private void BuildModelAnimation(Robot robot)
        {
            //this shouldn't happen?
            if (robot.ModelNum == -1)
            {
                return;
            }
            //If the robot is referring to a base HAM file model, reject it
            if (robot.ModelNum < VHAMFile.NumDescent2Polymodels)
            {
                return;
            }
            Polymodel        model     = Models[robot.ModelNum - VHAMFile.NumDescent2Polymodels];
            List <FixAngles> jointlist = new List <FixAngles>();

            model.NumGuns = robot.NumGuns;
            for (int i = 0; i < Polymodel.MaxGuns; i++)
            {
                model.GunPoints[i]    = robot.GunPoints[i];
                model.GunDirs[i]      = FixVector.FromRawValues(65536, 0, 0);
                model.GunSubmodels[i] = robot.GunSubmodels[i];
            }
            int[,] jointmapping = new int[10, 5];
            for (int m = 0; m < Polymodel.MaxSubmodels; m++)
            {
                for (int f = 0; f < Robot.NumAnimationStates; f++)
                {
                    jointmapping[m, f] = -1;
                }
            }
            int basejoint = 0;

            for (int m = 0; m < Polymodel.MaxGuns + 1; m++)
            {
                for (int f = 0; f < Robot.NumAnimationStates; f++)
                {
                    Robot.JointList robotjointlist = robot.AnimStates[m, f];
                    basejoint = robotjointlist.Offset;
                    for (int j = 0; j < robotjointlist.NumJoints; j++)
                    {
                        JointPos joint = GetJoint(basejoint);
                        jointmapping[joint.JointNum, f] = basejoint;
                        model.IsAnimated = true;
                        basejoint++;
                    }
                }
            }

            for (int m = 1; m < Polymodel.MaxSubmodels; m++)
            {
                for (int f = 0; f < Robot.NumAnimationStates; f++)
                {
                    int jointnum = jointmapping[m, f];
                    if (jointnum != -1)
                    {
                        JointPos joint = GetJoint(jointnum);
                        model.AnimationMatrix[m, f].P = joint.Angles.P;
                        model.AnimationMatrix[m, f].B = joint.Angles.B;
                        model.AnimationMatrix[m, f].H = joint.Angles.H;
                    }
                }
            }
        }