Ejemplo n.º 1
0
        /// <summary>
        /// Copies part of skeleton to other skeleton, both positions are inclusive
        /// </summary>
        public void CopyTo(MyGridSkeleton target, Vector3I fromGridPosition, Vector3I toGridPosition)
        {
            Vector3I baseBonePos = fromGridPosition * BoneDensity;
            Vector3I max = (toGridPosition - fromGridPosition + Vector3I.One) * BoneDensity;
            Vector3I boneOffset;
            for (boneOffset.X = 0; boneOffset.X <= max.X; boneOffset.X++)
            {
                for (boneOffset.Y = 0; boneOffset.Y <= max.Y; boneOffset.Y++)
                {
                    for (boneOffset.Z = 0; boneOffset.Z <= max.Z; boneOffset.Z++)
                    {
                        Vector3I bonePos = baseBonePos + boneOffset;

                        Vector3 bone;
                        if (Bones.TryGetValue(bonePos, out bone))
                        {
                            target.Bones[bonePos] = bone;
                        }
                        else
                        {
                            target.Bones.Remove(bonePos);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Copies part of skeleton to other skeleton, both positions are inclusive
        /// </summary>
        public void CopyTo(MyGridSkeleton target, Vector3I fromGridPosition, Vector3I toGridPosition)
        {
            Vector3I baseBonePos = fromGridPosition * BoneDensity;
            Vector3I max         = (toGridPosition - fromGridPosition + Vector3I.One) * BoneDensity;
            Vector3I boneOffset;

            for (boneOffset.X = 0; boneOffset.X <= max.X; boneOffset.X++)
            {
                for (boneOffset.Y = 0; boneOffset.Y <= max.Y; boneOffset.Y++)
                {
                    for (boneOffset.Z = 0; boneOffset.Z <= max.Z; boneOffset.Z++)
                    {
                        Vector3I bonePos = baseBonePos + boneOffset;

                        Vector3 bone;
                        if (Bones.TryGetValue(bonePos, out bone))
                        {
                            target.Bones[bonePos] = bone;
                        }
                        else
                        {
                            target.Bones.Remove(bonePos);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
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));
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
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));
                        }

            }
        }
Ejemplo n.º 5
0
        public void SendDirtyBones(Vector3I minBone, Vector3I maxBone, MyGridSkeleton skeleton)
        {
            if (Sync.IsServer)
            {
                m_boneByteList.Clear();
                skeleton.SerializePart(minBone, maxBone, Entity.GridSize, m_boneByteList);

                if (m_boneByteList.Count > 0)
                {
                    var msg = new BonesMsg();
                    msg.GridEntityId = Entity.EntityId;
                    msg.MinBone = minBone;
                    msg.MaxBone = maxBone;
                    msg.Bones = m_boneByteList;

                    Sync.Layer.SendMessageToAll(ref msg);
                }
            }
        }