当前位置: 首页>>代码示例>>C#>>正文


C# BoundingBox.Transform方法代码示例

本文整理汇总了C#中BoundingBox.Transform方法的典型用法代码示例。如果您正苦于以下问题:C# BoundingBox.Transform方法的具体用法?C# BoundingBox.Transform怎么用?C# BoundingBox.Transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BoundingBox的用法示例。


在下文中一共展示了BoundingBox.Transform方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: M2RenderInstance

 public M2RenderInstance(int uuid, Vector3 position, Vector3 rotation, Vector3 scale, M2BatchRenderer renderer)
 {
     mScale = scale;
     mPosition = position;
     mRotation = rotation;
     NumReferences = 1;
     Uuid = uuid;
     BoundingBox = renderer.BoundingBox;
     mOrigBoundingBox = BoundingBox;
     mInstanceMatrix = Matrix.RotationYawPitchRoll(MathUtil.DegreesToRadians(rotation.Y),
         MathUtil.DegreesToRadians(rotation.X), MathUtil.DegreesToRadians(rotation.Z)) * Matrix.Scaling(scale) * Matrix.Translation(position);
     BoundingBox = BoundingBox.Transform(ref mInstanceMatrix);
     Matrix.Invert(ref mInstanceMatrix, out InverseMatrix);
 }
开发者ID:Linrasis,项目名称:WoWEditor,代码行数:14,代码来源:M2RenderInstance.cs

示例2: WmoInstance

        public WmoInstance(int uuid, Vector3 position, Vector3 rotation, WmoRootRender model)
        {
            Uuid = uuid;
            BoundingBox = model.BoundingBox;
            mInstanceMatrix = Matrix.RotationYawPitchRoll(MathUtil.DegreesToRadians(rotation.Y),
                                  MathUtil.DegreesToRadians(rotation.X), MathUtil.DegreesToRadians(rotation.Z)) * Matrix.Translation(position);

            BoundingBox = BoundingBox.Transform(ref mInstanceMatrix);
            GroupBoxes = new BoundingBox[model.Groups.Count];
            for(var i = 0; i < GroupBoxes.Length; ++i)
            {
                var group = model.Groups[i];
                GroupBoxes[i] = group.BoundingBox.Transform(ref mInstanceMatrix);
            }

            mInstanceMatrix = Matrix.Transpose(mInstanceMatrix);
        }
开发者ID:Linrasis,项目名称:WoWEditor,代码行数:17,代码来源:WmoInstance.cs

示例3: AddInstance

        /// <summary>
        /// Adds instance of the given model. Local matrix specified might be changed internally for renderer (must be used for removing instances).
        /// </summary>
        /// <param name="subtypeId"></param>
        /// <param name="localMatrix">Local transformation matrix. Changed to internal matrix.</param>
        /// <param name="colorMaskHsv"></param>
        public int AddInstance(
            MyStringHash subtypeId, 
            ModelId modelId,
            int localId,
            ref Matrix localMatrix, 
            BoundingBox localAabb, 
            MyInstanceFlagsEnum instanceFlags, 
            float maxViewDistance,
            Vector4 colorMaskHsv = default(Vector4))
        {
            MyModelInstanceData builderInstanceData;
            if (!m_instanceParts.TryGetValue(modelId, out builderInstanceData))
            {
                builderInstanceData = new MyModelInstanceData(subtypeId, instanceFlags, maxViewDistance, localAabb);
                m_instanceParts.Add(modelId, builderInstanceData);
            }

            MySectorInstanceData newInstance = new MySectorInstanceData()
            {
                LocalId = localId,
                InstanceData = new MyInstanceData()
                {
                ColorMaskHSV = new VRageMath.PackedVector.HalfVector4(colorMaskHsv),
                LocalMatrix = localMatrix
                }
            };
            int sectorInstanceId = builderInstanceData.AddInstanceData(ref newInstance);

            // Matrix has been changed due to packing.
            localMatrix = builderInstanceData.InstanceData[sectorInstanceId].InstanceData.LocalMatrix;
            Debug.Assert(builderInstanceData.InstanceData[sectorInstanceId].InstanceData.LocalMatrix == localMatrix, "Bad matrix");

            m_AABB = m_AABB.Include(localAabb.Transform(localMatrix));
            m_sectorItemCount++;
            m_invalidateAABB = true;

            return sectorInstanceId;
        }
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:44,代码来源:MyEnvironmentSector.cs

示例4: MirrorGizmoSpace


//.........这里部分代码省略.........
                case Common.ObjectBuilders.Definitions.MySymmetryAxisEnum.MinusHalfZ:
                    targetSpace.m_localMatrixAdd = Matrix.CreateRotationZ(MathHelper.PiOver2) * sourceSpace.m_localMatrixAdd;
                    break;

                default:
                    targetSpace.m_localMatrixAdd = sourceSpace.m_localMatrixAdd;
                    break;
            }

            if (!string.IsNullOrEmpty(sourceSpace.m_blockDefinition.MirroringBlock))
            {
                targetSpace.m_blockDefinition = MyDefinitionManager.Static.GetCubeBlockDefinition(new MyDefinitionId(typeof(MyObjectBuilder_CubeBlock), sourceSpace.m_blockDefinition.MirroringBlock));
            }
            else
                targetSpace.m_blockDefinition = sourceSpace.m_blockDefinition;

            // Correct mirroring of objects with center offset
            // if (blockMirrorOption == Common.ObjectBuilders.Definitions.MySymmetryAxisEnum.None)
            if (cubeBlockDefinition.SymmetryX == MySymmetryAxisEnum.None && cubeBlockDefinition.SymmetryY == MySymmetryAxisEnum.None && cubeBlockDefinition.SymmetryZ == MySymmetryAxisEnum.None)
            {
                Vector3 min = sourceSpace.m_min * cubeGrid.GridSize - new Vector3(cubeGrid.GridSize / 2);
                Vector3 max = sourceSpace.m_max * cubeGrid.GridSize + new Vector3(cubeGrid.GridSize / 2);

                BoundingBox box = new BoundingBox(min, max);

                //Mirroring algorithm
                // 1. Find vector from closest source box side to mirror (vector A)
                // 2. Find vector from source box pos to opposite side (vector B)
                // 3. Correct mirrored position is source box pos + A - B

                if (box.Size.X > 1 * cubeGrid.GridSize || box.Size.Y > 1 * cubeGrid.GridSize || box.Size.Z > 1 * cubeGrid.GridSize)
                {
                    //align to mirror
                    BoundingBox worldAABB = box.Transform((Matrix)cubeGrid.WorldMatrix);
                    //VRageRender.MyRenderProxy.DebugDrawAABB(worldAABB, Vector3.One, 1, 1, false);

                    Vector3 sourceCenterFloatLocal = sourceSpace.m_localMatrixAdd.Translation * cubeGrid.GridSize;
                    Vector3 sourceCenterWorld = Vector3.Transform(sourceCenterFloatLocal, cubeGrid.WorldMatrix);
                    //VRageRender.MyRenderProxy.DebugDrawSphere(sourceCenterWorld, 0.5f, Vector3.One, 1, false, false);

                    Vector3I localToMirror = mirrorPosition - new Vector3I(sourceSpace.m_localMatrixAdd.Translation);
                    Vector3 floatLocalToMirror = localToMirror * cubeGrid.GridSize;
                    if (isOdd)
                    {
                        floatLocalToMirror.X -= cubeGrid.GridSize / 2;
                        floatLocalToMirror.Y -= cubeGrid.GridSize / 2;
                        floatLocalToMirror.Z += cubeGrid.GridSize / 2;
                    }


                    Vector3 fullFloatLocalToMirror = floatLocalToMirror;
                    Vector3 alignedFloatLocalToMirror = Vector3.Clamp(sourceCenterFloatLocal + floatLocalToMirror, box.Min, box.Max) - sourceCenterFloatLocal;
                    Vector3 alignedFloatLocalToBoxEnd = Vector3.Clamp(sourceCenterFloatLocal + floatLocalToMirror * 100, box.Min, box.Max) - sourceCenterFloatLocal;
                    Vector3 oppositeFromMirror = Vector3.Clamp(sourceCenterFloatLocal - floatLocalToMirror * 100, box.Min, box.Max) - sourceCenterFloatLocal;


                    if (mirrorPlane == MySymmetrySettingModeEnum.XPlane || mirrorPlane == MySymmetrySettingModeEnum.XPlaneOdd)
                    {
                        oppositeFromMirror.Y = 0;
                        oppositeFromMirror.Z = 0;
                        alignedFloatLocalToMirror.Y = 0;
                        alignedFloatLocalToMirror.Z = 0;
                        fullFloatLocalToMirror.Y = 0;
                        fullFloatLocalToMirror.Z = 0;
                        alignedFloatLocalToBoxEnd.Y = 0;
                        alignedFloatLocalToBoxEnd.Z = 0;
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:67,代码来源:MyCubeBuilderGizmo.cs

示例5: AddMountForShape

 private HkdBreakableShape AddMountForShape(HkdBreakableShape shape, Matrix transform, ref BoundingBox blockBB)
 {
     Vector4 min;
     Vector4 max;
     shape.GetShape().GetLocalAABB(0.01f, out min, out max);//.Transform(CubeGrid.PositionComp.WorldMatrix);
     var bb = new BoundingBox(new Vector3(min), new Vector3(max));
     bb = bb.Transform(transform);
     bb.Min /= CubeGrid.GridSize; //normalize for mount point
     bb.Max /= CubeGrid.GridSize;
     
     bb.Inflate(0.04f);//add tolerance (fracture shapes are smaller than block)
     bb.Min += blockBB.HalfExtents;
     bb.Max += blockBB.HalfExtents;
     
     if (blockBB.Contains(bb) == ContainmentType.Intersects)
     {
         bb.Inflate(-0.04f);
         foreach (var directionEnum in Base6Directions.EnumDirections)
         {
             int dirEnum = (int)directionEnum;
             Vector3 direction = Base6Directions.Directions[dirEnum];
             Vector3 absDir = Vector3.Abs(direction);
             var mp = new MyCubeBlockDefinition.MountPoint();
             mp.Start = bb.Min;
             mp.End = bb.Max;
             var start = mp.Start * absDir / (blockBB.HalfExtents * 2) - absDir * 0.04f;
             var end = mp.End * absDir / (blockBB.HalfExtents * 2) + absDir * 0.04f;
             bool add = false;
             bool one = false;
             if (start.Max() < 1 && end.Max() > 1 && direction.Max() > 0)
             {
                 add = true;
                 one = true;
             }
             else if (start.Min() < 0 && end.Max() > 0 && direction.Min() < 0)
             {
                 add = true;
             }
             if (!add)
             {
                 continue;
             }
             mp.Start -= mp.Start * absDir - absDir * 0.04f;
             mp.End -= mp.End * absDir + absDir * 0.04f;
             if (one)
             {
                 mp.Start += absDir * blockBB.HalfExtents * 2;
                 mp.End += absDir * blockBB.HalfExtents * 2;
             }
             mp.Start -= blockBB.HalfExtents - Vector3.One / 2;
             mp.End -= blockBB.HalfExtents - Vector3.One / 2;
             mp.Normal = new Vector3I(direction);
             MountPoints.Add(mp);
         }
     }
     return shape;
 }
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:57,代码来源:MyFracturedBlock.cs

示例6: CreateMountPoints

        private void CreateMountPoints()
        {
            ProfilerShort.Begin("FB.CreateMountPoints");
            if (MyFakes.FRACTURED_BLOCK_AABB_MOUNT_POINTS)
            {
                MountPoints = new List<MyCubeBlockDefinition.MountPoint>();
                var blockBB = BoundingBox.CreateInvalid();
                for (int i = 0; i < OriginalBlocks.Count; i++)
                {
                    var b = OriginalBlocks[i];
                    Matrix m;
                    Orientations[i].GetMatrix(out m);
                    var size = new Vector3(MyDefinitionManager.Static.GetCubeBlockDefinition(b).Size);
                    var bb = new BoundingBox(-size / 2, size / 2);
                    blockBB = blockBB.Include(bb.Transform(m));
                }
                var he = blockBB.HalfExtents;
                blockBB.Min += he;
                blockBB.Max += he;

                Shape.GetChildren(m_children);
                foreach (var child in m_children)
                {
                    var shape = child.Shape;
                    shape = AddMountForShape(shape, child.GetTransform(), ref blockBB);
                }
                if (m_children.Count == 0)
                    AddMountForShape(Shape, Matrix.Identity, ref blockBB);
                m_children.Clear();
            }
            else
            {
                MountPoints = MyCubeBuilder.AutogenerateMountpoints(new HkShape[] { Shape.GetShape() }, CubeGrid.GridSize);
            }
            ProfilerShort.End();
        }
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:36,代码来源:MyFracturedBlock.cs

示例7: AddInstance

        /// <summary>
        /// Adds instance of the given model and returns its internal id which can be used for removing the instance. Local matrix specified will be changed to internal packed matrix.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="localMatrix">Local transformation matrix. Changed to internal matrix.</param>
        /// <param name="colorMaskHsv"></param>
        public uint AddInstance(ModelId model, ref Matrix localMatrix, BoundingBox localAabb, Vector4 colorMaskHsv = default(Vector4))
        {
            MyModelInstanceData builderInstanceData;
            if (!m_instanceParts.TryGetValue(model, out builderInstanceData))
            {
                builderInstanceData = new MyModelInstanceData(m_instanceFlags, m_maxViewDistance);
                builderInstanceData.Model = model;
                m_instanceParts.Add(model, builderInstanceData);
            }

            uint instanceId = m_idCounter++;

            var instanceData = new MyCubeInstanceData()
            {
                ColorMaskHSV = colorMaskHsv,
                EnableSkinning = false,
                LocalMatrix = localMatrix
            };
            instanceData.SetColorMaskHSV(colorMaskHsv);

            builderInstanceData.InstanceData.Add(instanceId, instanceData);
            // Matrix has been changed due to packing.
            localMatrix = builderInstanceData.InstanceData[instanceId].LocalMatrix;

            m_AABB = m_AABB.Include(localAabb.Transform(localMatrix));

            return instanceId;
        }
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:34,代码来源:MyGridPartsRenderData.cs

示例8: FindConnectionsToWorld

        private void FindConnectionsToWorld(HashSet<MySlimBlock> blocks)
        {
            if (m_grid.Physics != null && m_grid.Physics.LinearVelocity.LengthSquared() > 0) //jn: TODO nicer
                return;
            int counter = 0;
            ProfilerShort.Begin("FindConnectionsToWorld");
            var q = Quaternion.Identity;
            foreach (var b in blocks)
            {
                var geometryBox = b.FatBlock.GetGeometryLocalBox();
                Vector3 halfExtents = geometryBox.Size / 2;

                Vector3D pos;
                b.ComputeScaledCenter(out pos);
                pos += geometryBox.Center;
                pos = Vector3D.Transform(pos, m_grid.WorldMatrix);

                Matrix blockMatrix;
                b.Orientation.GetMatrix(out blockMatrix);
                q = Quaternion.CreateFromRotationMatrix(blockMatrix * m_grid.WorldMatrix.GetOrientation());

                Sandbox.Engine.Physics.MyPhysics.GetPenetrationsBox(ref halfExtents, ref pos, ref q, m_penetrations, Sandbox.Engine.Physics.MyPhysics.CollideWithStaticLayer);
                counter++;
                bool isStatic = false;
                foreach (var p in m_penetrations)
                {
                    if (p == null)
                        continue;
                    var e = p.UserObject as Sandbox.Engine.Physics.MyPhysicsBody;
                    if (e != null && e.Entity != null && e.Entity is MyVoxelMap)
                    {
                        isStatic = true;
                        break;
                    }
                }

                m_penetrations.Clear();
                if (isStatic && !BlocksConnectedToWorld.Contains(b.Position))
                {
                    isStatic = false;
                    m_blocksShapes[b.Position].GetChildren(m_shapeInfosList2);
                    for (int i = 0; i < m_shapeInfosList2.Count; i++)
                    {
                        var child = m_shapeInfosList2[i];
                        if (child.Shape.GetChildrenCount() > 0)
                        {
                            child.Shape.GetChildren(m_shapeInfosList2);
                            continue;
                        }
                        Vector4 min;
                        Vector4 max;
                        child.Shape.GetShape().GetLocalAABB(0.01f, out min, out max);//.Transform(CubeGrid.PositionComp.WorldMatrix);
                        BoundingBox bb = new BoundingBox(new Vector3(min), new Vector3(max));
                        bb = bb.Translate(b.Position * m_grid.GridSize);
                        var bbd = bb.Transform(m_grid.WorldMatrix);
                        halfExtents = bbd.HalfExtents;
                        pos = bbd.Center;
                        Sandbox.Engine.Physics.MyPhysics.GetPenetrationsBox(ref halfExtents, ref pos, ref q, m_penetrations, Sandbox.Engine.Physics.MyPhysics.CollideWithStaticLayer);
                        counter++;
                        foreach (var p in m_penetrations)
                        {
                            if (p == null)
                                continue;
                            var e = p.UserObject as Sandbox.Engine.Physics.MyPhysicsBody;
                            if (e != null && e.Entity != null && e.Entity is MyVoxelMap)
                            {
                                isStatic = true;
                                child.Shape.SetFlagRecursively(HkdBreakableShape.Flags.IS_FIXED);
                                break;
                            }
                        }
                        m_penetrations.Clear();
                    }
                    m_shapeInfosList2.Clear();
                    if (isStatic)
                        BlocksConnectedToWorld.Add(b.Position);
                }
            }
            ProfilerShort.End(counter);
        }
开发者ID:avivbeeri,项目名称:SpaceEngineers,代码行数:80,代码来源:MyGridShape.cs

示例9: Update

        internal void Update(TransformComponent transformComponent, ref Matrix worldMatrix)
        {
            if (!Enabled || model == null)
                return;

            // Check if scaling is negative
            var up = Vector3.Cross(worldMatrix.Right, worldMatrix.Forward);
            bool isScalingNegative = Vector3.Dot(worldMatrix.Up, up) < 0.0f;

            // Make sure skeleton is up to date
            CheckSkeleton();
            if (skeleton != null)
            {
                // Update model view hierarchy node matrices
                skeleton.NodeTransformations[0].LocalMatrix = worldMatrix;
                skeleton.NodeTransformations[0].IsScalingNegative = isScalingNegative;
                skeleton.UpdateMatrices();
            }

            // Update the bounding sphere / bounding box in world space
            BoundingSphere = BoundingSphere.Empty;
            BoundingBox = BoundingBox.Empty;
            bool modelHasBoundingBox = false;

            for (int meshIndex = 0; meshIndex < Model.Meshes.Count; meshIndex++)
            {
                var mesh = Model.Meshes[meshIndex];
                var meshInfo = meshInfos[meshIndex];
                meshInfo.BoundingSphere = BoundingSphere.Empty;
                meshInfo.BoundingBox = BoundingBox.Empty;

                if (mesh.Skinning != null && skeleton != null)
                {
                    bool meshHasBoundingBox = false;
                    var bones = mesh.Skinning.Bones;

                    // For skinned meshes, bounding box is union of the bounding boxes of the unskinned mesh, transformed by each affecting bone.
                    for (int boneIndex = 0; boneIndex < bones.Length; boneIndex++)
                    {
                        var nodeIndex = bones[boneIndex].NodeIndex;
                        Matrix.Multiply(ref bones[boneIndex].LinkToMeshMatrix, ref skeleton.NodeTransformations[nodeIndex].WorldMatrix, out meshInfos[meshIndex].BlendMatrices[boneIndex]);

                        BoundingBox skinnedBoundingBox;
                        BoundingBox.Transform(ref mesh.BoundingBox, ref meshInfos[meshIndex].BlendMatrices[boneIndex], out skinnedBoundingBox);
                        BoundingSphere skinnedBoundingSphere;
                        BoundingSphere.Transform(ref mesh.BoundingSphere, ref meshInfos[meshIndex].BlendMatrices[boneIndex], out skinnedBoundingSphere);

                        if (meshHasBoundingBox)
                        {
                            BoundingBox.Merge(ref meshInfo.BoundingBox, ref skinnedBoundingBox, out meshInfo.BoundingBox);
                            BoundingSphere.Merge(ref meshInfo.BoundingSphere, ref skinnedBoundingSphere, out meshInfo.BoundingSphere);
                        }
                        else
                        {
                            meshHasBoundingBox = true;
                            meshInfo.BoundingSphere = skinnedBoundingSphere;
                            meshInfo.BoundingBox = skinnedBoundingBox;
                        }
                    }
                }
                else
                {
                    // If there is a skeleton, use the corresponding node's transform. Otherwise, fall back to the model transform.
                    var transform = skeleton != null ? skeleton.NodeTransformations[mesh.NodeIndex].WorldMatrix : worldMatrix;
                    BoundingBox.Transform(ref mesh.BoundingBox, ref transform, out meshInfo.BoundingBox);
                    BoundingSphere.Transform(ref mesh.BoundingSphere, ref transform, out meshInfo.BoundingSphere);
                }

                if (modelHasBoundingBox)
                {
                    BoundingBox.Merge(ref BoundingBox, ref meshInfo.BoundingBox, out BoundingBox);
                    BoundingSphere.Merge(ref BoundingSphere, ref meshInfo.BoundingSphere, out BoundingSphere);
                }
                else
                {
                    BoundingBox = meshInfo.BoundingBox;
                    BoundingSphere = meshInfo.BoundingSphere;
                    modelHasBoundingBox = true;
                }
            }
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:81,代码来源:ModelComponent.cs

示例10: IntersectStorage

        /**
         * Intersect the storage
         * 
         * @param box WorldSpace bounding box to intersect with the storage.
         */
        public ContainmentType IntersectStorage(ref BoundingBox box, bool lazy = true)
        {
            box.Transform(PositionComp.WorldMatrixInvScaled);

            box.Translate(SizeInMetresHalf + StorageMin);

            return Storage.Intersect(ref box, lazy);
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:13,代码来源:MyVoxelBase.cs

示例11: IsInVoxels

        public static bool IsInVoxels(MySlimBlock block,bool checkForPhysics = true)
        {
            if (block.CubeGrid.Physics == null && checkForPhysics)
               return false;

            if (MyPerGameSettings.Destruction && block.CubeGrid.GridSizeEnum == Common.ObjectBuilders.MyCubeSize.Large)
                return block.CubeGrid.Physics.Shape.BlocksConnectedToWorld.Contains(block.Position);

            var min = (Vector3)block.Min;
            var max = (Vector3)block.Max;
            min -= 0.5f;
            max += 0.5f;
            var gridSize = block.CubeGrid.GridSize;
            min *= gridSize;
            max *= gridSize;
            BoundingBox localAabb = new BoundingBox(min, max);

            var worldMat = block.CubeGrid.WorldMatrix;

            var worldAabb = (BoundingBoxD)localAabb.Transform(worldMat);

            List<MyEntity> entities = new List<MyEntity>(); // Fine for test
            MyGamePruningStructure.GetAllEntitiesInBox(ref worldAabb, entities);
            MyVoxelBase overlappedVoxelMap = null;
            foreach (var entity in entities)
            {
                var voxelMap = entity as MyVoxelBase;
                if (voxelMap != null)
                {
                    if (voxelMap.DoOverlapSphereTest(localAabb.Size.AbsMax() / 2.0f, worldAabb.Center))
                    {
                        overlappedVoxelMap = voxelMap;
                        break;
                    }
                }
            }

            float penetrationRatio = 0.0f;
            if (overlappedVoxelMap != null)
            {
                float unused;
                var penetrationAmountNormalized = overlappedVoxelMap.GetVoxelContentInBoundingBox_Obsolete(worldAabb, out unused);
                var penetrationVolume = penetrationAmountNormalized * MyVoxelConstants.VOXEL_VOLUME_IN_METERS;
                penetrationRatio = penetrationVolume / (float)worldAabb.Volume;
            }

            return penetrationRatio > 0.125f;
        }
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:48,代码来源:MyCubeGrid.Static.cs

示例12: AddInstance

        /// <summary>
        /// Adds instance of the given model. Local matrix specified might be changed internally for renderer (must be used for removing instances).
        /// </summary>
        /// <param name="subtypeId"></param>
        /// <param name="localMatrix">Local transformation matrix. Changed to internal matrix.</param>
        /// <param name="colorMaskHsv"></param>
        public int AddInstance(
            MyStringHash subtypeId, 
            ModelId modelId,
            int localId,
            ref Matrix localMatrix, 
            BoundingBox localAabb, 
            MyInstanceFlagsEnum instanceFlags, 
            float maxViewDistance,
            Vector4 colorMaskHsv = default(Vector4),
            Vector2I uvOffset = default(Vector2I))
        {
            MyModelInstanceData builderInstanceData;

            using (m_instancePartsLock.AcquireExclusiveUsing())
            {
                if (!m_instanceParts.TryGetValue(modelId, out builderInstanceData))
                {
                    builderInstanceData = new MyModelInstanceData(subtypeId, instanceFlags, maxViewDistance, localAabb);
                    m_instanceParts.Add(modelId, builderInstanceData);
                }
            }


            uvOffset = new Vector2I(MyUtils.GetRandomInt(2), MyUtils.GetRandomInt(2));
            Color green = Color.Green;
            Vector3 hsv = green.ColorToHSVDX11();
            hsv.Y = MyUtils.GetRandomFloat(0.0f, 1.0f);
            colorMaskHsv = new Vector4(hsv, 0);

            MySectorInstanceData newInstance = new MySectorInstanceData()
            {
                LocalId = localId,
                InstanceData = new MyInstanceData()
                {
                    ColorMaskHSV = new VRageMath.PackedVector.HalfVector4(colorMaskHsv),
                    LocalMatrix = localMatrix,
                    UVOffset = new VRageMath.PackedVector.HalfVector2(uvOffset)
                }
            };
            int sectorInstanceId = builderInstanceData.AddInstanceData(ref newInstance);

            // Matrix has been changed due to packing.
            localMatrix = builderInstanceData.InstanceData[sectorInstanceId].InstanceData.LocalMatrix;
            Debug.Assert(builderInstanceData.InstanceData[sectorInstanceId].InstanceData.LocalMatrix == localMatrix, "Bad matrix");

            m_AABB = m_AABB.Include(localAabb.Transform(localMatrix));
            m_sectorItemCount++;
            m_invalidateAABB = true;

            return sectorInstanceId;
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:57,代码来源:MyEnvironmentSector.cs

示例13: CreateMountPoints

        private void CreateMountPoints()
        {
            ProfilerShort.Begin("FractureComponent.CreateMountPoints");

            Debug.Assert(m_tmpChildren.Count == 0);

            if (MyFakes.FRACTURED_BLOCK_AABB_MOUNT_POINTS)
            {
                MountPoints = new List<MyCubeBlockDefinition.MountPoint>();

                var blockDef = Block.BlockDefinition;
                Matrix m;
                Block.Orientation.GetMatrix(out m);
                var size = new Vector3(blockDef.Size);
                var bb = new BoundingBox(-size / 2, size / 2);
                var blockBB = bb.Transform(m);

                var he = blockBB.HalfExtents;
                blockBB.Min += he;
                blockBB.Max += he;

                Shape.GetChildren(m_tmpChildren);
                if (m_tmpChildren.Count > 0)
                {
                    foreach (var child in m_tmpChildren)
                    {
                        var shape = child.Shape;
                        shape = AddMountForShape(shape, m, ref blockBB, Block.CubeGrid.GridSize, MountPoints);
                    }
                }
                else
                {
                    AddMountForShape(Shape, m, ref blockBB, Block.CubeGrid.GridSize, MountPoints);
                }

                m_tmpChildren.Clear();
            }
            else
            {
                MountPoints = MyCubeBuilder.AutogenerateMountpoints(new HkShape[] { Shape.GetShape() }, Block.CubeGrid.GridSize);
            }
            ProfilerShort.End();
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:43,代码来源:MyFractureComponentCubeBlock.cs


注:本文中的BoundingBox.Transform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。