Пример #1
0
        public void CopyTo(MyGridSkeleton target, MatrixI transformationMatrix, MyCubeGrid targetGrid)
        {
            Vector3I oldPosition, newPosition;
            Vector3  oldBone, newBone;

            // transformationMatrix is in cube coordinates, so change it to bone coords
            MatrixI BoneOriginToGridOrigin = new MatrixI(new Vector3I(1, 1, 1), Base6Directions.Direction.Forward, Base6Directions.Direction.Up);
            MatrixI GridOriginToBoneOrigin = new MatrixI(new Vector3I(-1, -1, -1), Base6Directions.Direction.Forward, Base6Directions.Direction.Up);

            transformationMatrix.Translation = transformationMatrix.Translation * BoneDensity;

            MatrixI tmp;

            MatrixI.Multiply(ref GridOriginToBoneOrigin, ref transformationMatrix, out tmp);
            MatrixI.Multiply(ref tmp, ref BoneOriginToGridOrigin, out transformationMatrix);

            Matrix orientation;

            transformationMatrix.GetBlockOrientation().GetMatrix(out orientation);

            foreach (var bone in Bones)
            {
                oldPosition = bone.Key;
                Vector3I.Transform(ref oldPosition, ref transformationMatrix, out newPosition);
                Vector3 transformedBone = Vector3.Transform(bone.Value, orientation);

                if (target.Bones.TryGetValue(newPosition, out oldBone))
                {
                    newBone = (oldBone + transformedBone) * 0.5f;
                    target.Bones[newPosition] = newBone;
                }
                else
                {
                    target.Bones[newPosition] = transformedBone;
                }

                Vector3I cubePosition = newPosition / BoneDensity;

                for (int i = -1; i <= 1; i++)
                {
                    for (int j = -1; j <= 1; j++)
                    {
                        for (int k = -1; k <= 1; k++)
                        {
                            targetGrid.SetCubeDirty(cubePosition + new Vector3I(i, j, k));
                        }
                    }
                }
            }
        }
Пример #2
0
        public void CopyTo(MyGridSkeleton target, MatrixI transformationMatrix, MyCubeGrid targetGrid)
        {
            Vector3I oldPosition, newPosition;
            Vector3 oldBone, newBone;

            // transformationMatrix is in cube coordinates, so change it to bone coords
            MatrixI BoneOriginToGridOrigin = new MatrixI(new Vector3I(1, 1, 1), Base6Directions.Direction.Forward, Base6Directions.Direction.Up);
            MatrixI GridOriginToBoneOrigin = new MatrixI(new Vector3I(-1, -1, -1), Base6Directions.Direction.Forward, Base6Directions.Direction.Up);

            transformationMatrix.Translation = transformationMatrix.Translation * BoneDensity;

            MatrixI tmp;
            MatrixI.Multiply(ref GridOriginToBoneOrigin, ref transformationMatrix, out tmp);
            MatrixI.Multiply(ref tmp, ref BoneOriginToGridOrigin, out transformationMatrix);

            Matrix orientation;
            transformationMatrix.GetBlockOrientation().GetMatrix(out orientation);

            foreach (var bone in Bones)
            {
                oldPosition = bone.Key;
                Vector3I.Transform(ref oldPosition, ref transformationMatrix, out newPosition);
                Vector3 transformedBone = Vector3.Transform(bone.Value, orientation);

                if (target.Bones.TryGetValue(newPosition, out oldBone))
                {
                    newBone = (oldBone + transformedBone) * 0.5f;
                    target.Bones[newPosition] = newBone;
                }
                else
                {
                    target.Bones[newPosition] = transformedBone;
                }

                Vector3I cubePosition = newPosition / BoneDensity;
  
                for (int i = -1; i <= 1; i++)
                    for (int j = -1; j <= 1; j++)
                        for (int k = -1; k <= 1; k++)
                        {
                            targetGrid.SetCubeDirty(cubePosition + new Vector3I(i, j, k));
                        }

            }
        }