Exemplo n.º 1
0
		static M2 TransformM2(M2Model model, IEnumerable<int> indicies, MapDoodadDefinition mddf)
		{
			var currentM2 = new M2();
			currentM2.Vertices.Clear();
			currentM2.Indices.Clear();

			var posX = (mddf.Position.X - TerrainConstants.CenterPoint) * -1;
			var posY = (mddf.Position.Y - TerrainConstants.CenterPoint) * -1;
			var origin = new Vector3(posX, posY, mddf.Position.Z);

			// Create the scale matrix used in the following loop.
			Matrix scaleMatrix;
			Matrix.CreateScale(mddf.Scale, out scaleMatrix);

			// Creation the rotations
			var rotateZ = Matrix.CreateRotationZ(MathHelper.ToRadians(mddf.OrientationB + 180));
			var rotateY = Matrix.CreateRotationY(MathHelper.ToRadians(mddf.OrientationA));
			var rotateX = Matrix.CreateRotationX(MathHelper.ToRadians(mddf.OrientationC));

			var worldMatrix = Matrix.Multiply(scaleMatrix, rotateZ);
			worldMatrix = Matrix.Multiply(worldMatrix, rotateX);
			worldMatrix = Matrix.Multiply(worldMatrix, rotateY);

			for (var i = 0; i < model.BoundingVertices.Length; i++)
			{
				var position = model.BoundingVertices[i];
				var normal = model.BoundingNormals[i];

				// Scale and Rotate
				Vector3 rotatedPosition;
				Vector3.Transform(ref position, ref worldMatrix, out rotatedPosition);

				Vector3 rotatedNormal;
				Vector3.Transform(ref normal, ref worldMatrix, out rotatedNormal);
				rotatedNormal.Normalize();

				// Translate
				Vector3 finalVector;
				Vector3.Add(ref rotatedPosition, ref origin, out finalVector);

				currentM2.Vertices.Add(finalVector);
			}

			currentM2.Indices.AddRange(indicies);
			return currentM2;
		}
Exemplo n.º 2
0
		private static M2 TransformWMOM2(M2Model model, IEnumerable<int> indicies, DoodadDefinition modd)
		{
			var currentM2 = new M2();

			currentM2.Vertices.Clear();
			currentM2.Indices.Clear();

			var origin = new Vector3(modd.Position.X, modd.Position.Y, modd.Position.Z);

			// Create the scalar
			var scalar = modd.Scale;
			var scaleMatrix = Matrix.CreateScale(scalar);

			// Create the rotations
			var quatX = modd.Rotation.X;
			var quatY = modd.Rotation.Y;
			var quatZ = modd.Rotation.Z;
			var quatW = modd.Rotation.W;

			var rotQuat = new Quaternion(quatX, quatY, quatZ, quatW);
			var rotMatrix = Matrix.CreateFromQuaternion(rotQuat);

			var compositeMatrix = Matrix.Multiply(scaleMatrix, rotMatrix);

			for (var i = 0; i < model.BoundingVertices.Length; i++)
			{
				// Scale and transform
				var basePosVector = model.BoundingVertices[i];
				var baseNormVector = model.BoundingNormals[i];
				//PositionUtil.TransformToXNACoordSystem(ref vertex.Position);

				// Scale
				//Vector3 scaledVector;
				//Vector3.Transform(ref vector, ref scaleMatrix, out scaledVector);

				// Rotate
				Vector3 rotatedPosVector;
				Vector3.Transform(ref basePosVector, ref compositeMatrix, out rotatedPosVector);

				Vector3 rotatedNormVector;
				Vector3.Transform(ref baseNormVector, ref compositeMatrix, out rotatedNormVector);
				rotatedNormVector.Normalize();

				// Translate
				Vector3 finalPosVector;
				Vector3.Add(ref rotatedPosVector, ref origin, out finalPosVector);

				currentM2.Vertices.Add(finalPosVector);
			}

			currentM2.Indices.AddRange(indicies);
			return currentM2;
		}