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


C# BEPUutilities.BoundingBox类代码示例

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


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

示例1: GetOverlaps

		public void GetOverlaps( Vector3 gridPosition, BoundingBox boundingBox, ref QuickList<Int3> overlaps )
		{
			Vector3.Subtract( ref boundingBox.Min, ref gridPosition, out boundingBox.Min );
			Vector3.Subtract( ref boundingBox.Max, ref gridPosition, out boundingBox.Max );
			var inverseWidth = 1f / CellWidth;
			var min = new Int3
			{
				X = Math.Max( 0, (uint)( boundingBox.Min.X * inverseWidth ) ),
				Y = Math.Max( 0, (uint)( boundingBox.Min.Y * inverseWidth ) ),
				Z = Math.Max( 0, (uint)( boundingBox.Min.Z * inverseWidth ) )
			};
			var max = new Int3
			{
				X = Math.Min( VoxelSector.ZVOXELBLOCSIZE_X - 1, (uint)( boundingBox.Max.X * inverseWidth ) ),
				Y = Math.Min( VoxelSector.ZVOXELBLOCSIZE_Y - 1, (uint)( boundingBox.Max.Y * inverseWidth ) ),
				Z = Math.Min( VoxelSector.ZVOXELBLOCSIZE_Z - 1, (uint)( boundingBox.Max.Z * inverseWidth ) )
			};

			for( uint i = min.X; i <= max.X; ++i )
			{
				for( uint j = min.Y; j <= max.Y; ++j )
				{
					for( uint k = min.Z; k <= max.Z; ++k )
					{
						uint offset = i * VoxelSector.ZVOXELBLOCSIZE_Y + j + k * VoxelSector.ZVOXELBLOCSIZE_X * VoxelSector.ZVOXELBLOCSIZE_Y;
						if( Cells[offset] != VoxelShape.Empty )
						{
							overlaps.Add( new Int3 { X = i, Y = j, Z = k } );
						}
					}
				}
			}
		}
开发者ID:d3x0r,项目名称:Voxelarium,代码行数:33,代码来源:BEPU.VoxelBlob.cs

示例2: HassSolidEntity

 public bool HassSolidEntity(Location min, Location max)
 {
     // TODO: Better alg!
     BoundingBox bb = new BoundingBox(min.ToBVector(), max.ToBVector());
     List<BroadPhaseEntry> entries = new List<BroadPhaseEntry>();
     PhysicsWorld.BroadPhase.QueryAccelerator.GetEntries(bb, entries);
     if (entries.Count == 0)
     {
         return false;
     }
     Location center = (max + min) * 0.5;
     Location rel = max - min;
     BoxShape box = new BoxShape((double)rel.X, (double)rel.Y, (double)rel.Z);
     RigidTransform start = new RigidTransform(center.ToBVector(), Quaternion.Identity);
     Vector3 sweep = new Vector3(0, 0, 0.01f);
     RayHit rh;
     foreach (BroadPhaseEntry entry in entries)
     {
         if (entry is EntityCollidable && Collision.ShouldCollide(entry) &&
             entry.CollisionRules.Group != CollisionUtil.Player &&
             entry.ConvexCast(box, ref start, ref sweep, out rh))
         {
             return true;
         }
     }
     return false;
 }
开发者ID:Morphan1,项目名称:Voxalia,代码行数:27,代码来源:RegionPhysics.cs

示例3: GetBoundingBox

		public void GetBoundingBox( ref Vector3 position, out BoundingBox boundingBox )
		{
			var size = new Vector3( CellWidth * VoxelSector.ZVOXELBLOCSIZE_X
								, CellWidth * VoxelSector.ZVOXELBLOCSIZE_Y
								, CellWidth * VoxelSector.ZVOXELBLOCSIZE_Z );
			boundingBox.Min = position;
			Vector3.Add( ref size, ref position, out boundingBox.Max );
		}
开发者ID:d3x0r,项目名称:Voxelarium,代码行数:8,代码来源:BEPU.VoxelBlob.cs

示例4: GetBoundingBox

 /// <summary>
 /// Gets the bounding box of an element in the data.
 /// </summary>
 /// <param name="triangleIndex">Index of the triangle in the data.</param>
 /// <param name="boundingBox">Bounding box of the triangle.</param>
 public void GetBoundingBox(int triangleIndex, out BoundingBox boundingBox)
 {
     Vector3 v1, v2, v3;
     GetTriangle(triangleIndex, out v1, out v2, out v3);
     Vector3.Min(ref v1, ref v2, out boundingBox.Min);
     Vector3.Min(ref boundingBox.Min, ref v3, out boundingBox.Min);
     Vector3.Max(ref v1, ref v2, out boundingBox.Max);
     Vector3.Max(ref boundingBox.Max, ref v3, out boundingBox.Max);
 }
开发者ID:EugenyN,项目名称:BEPUphysicsMG,代码行数:14,代码来源:MeshBoundingBoxTreeData.cs

示例5: Intersects

        /// <summary>
        /// Determines if a bounding box intersects another bounding box.
        /// </summary>
        /// <param name="boundingBox">Bounding box to test against.</param>
        /// <returns>Whether the bounding boxes intersected.</returns>
        public bool Intersects(BoundingBox boundingBox)
        {
            if (boundingBox.Min.X > Max.X || boundingBox.Min.Y > Max.Y || boundingBox.Min.Z > Max.Z)
                return false;
            if (Min.X > boundingBox.Max.X || Min.Y > boundingBox.Max.Y || Min.Z > boundingBox.Max.Z)
                return false;
            return true;

        }
开发者ID:d3x0r,项目名称:Voxelarium,代码行数:14,代码来源:BoundingBox.cs

示例6: MobileChunkCollidable

 public MobileChunkCollidable(MobileChunkShape shape)
 {
     ChunkShape = shape;
     base.Shape = ChunkShape;
     Vector3 max = new Vector3(shape.ChunkSize.X, shape.ChunkSize.Y, shape.ChunkSize.Z);
     boundingBox = new BoundingBox(-max, max);
     Events = new ContactEventManager<EntityCollidable>();
     LocalPosition = -shape.Center;
 }
开发者ID:Morphan1,项目名称:Voxalia,代码行数:9,代码来源:MobileChunkCollidable.cs

示例7: FullChunkObject

 public FullChunkObject(Vector3 pos, BlockInternal[] blocks)
 {
     ChunkShape = new FullChunkShape(blocks);
     base.Shape = ChunkShape;
     Position = pos;
     boundingBox = new BoundingBox(Position, Position + new Vector3(30, 30, 30));
     Events = new ContactEventManager<FullChunkObject>(this);
     Material.Bounciness = 0.75f;
 }
开发者ID:Morphan1,项目名称:Voxalia,代码行数:9,代码来源:FullChunkObject.cs

示例8: GetOverlaps

 /// <summary>
 /// Gets the triangles whose bounding boxes are overlapped by the query.
 /// </summary>
 /// <param name="boundingBox">Shape to query against the tree.</param>
 /// <param name="outputOverlappedElements">Indices of triangles in the index buffer with bounding boxes which are overlapped by the query.</param>
 /// <returns>Whether or not any elements were overlapped.</returns>
 public bool GetOverlaps(BoundingBox boundingBox, IList<int> outputOverlappedElements)
 {
     if (root != null)
     {
         bool intersects;
         root.BoundingBox.Intersects(ref boundingBox, out intersects);
         if (intersects)
             root.GetOverlaps(ref boundingBox, outputOverlappedElements);
     }
     return outputOverlappedElements.Count > 0;
 }
开发者ID:karrtmomil,项目名称:coms437_assignment2,代码行数:17,代码来源:MeshBoundingBoxTree.cs

示例9: GetBoundingBox

 /// <summary>
 /// Gets the bounding box of the shape given a transform.
 /// </summary>
 /// <param name="shapeTransform">Transform to use.</param>
 /// <param name="boundingBox">Bounding box of the transformed shape.</param>
 public override void GetBoundingBox(ref RigidTransform shapeTransform, out BoundingBox boundingBox)
 {
     #if !WINDOWS
     boundingBox = new BoundingBox();
     #endif
     boundingBox.Min.X = shapeTransform.Position.X - collisionMargin;
     boundingBox.Min.Y = shapeTransform.Position.Y - collisionMargin;
     boundingBox.Min.Z = shapeTransform.Position.Z - collisionMargin;
     boundingBox.Max.X = shapeTransform.Position.X + collisionMargin;
     boundingBox.Max.Y = shapeTransform.Position.Y + collisionMargin;
     boundingBox.Max.Z = shapeTransform.Position.Z + collisionMargin;
 }
开发者ID:karrtmomil,项目名称:coms437_assignment2,代码行数:17,代码来源:SphereShape.cs

示例10: LotsOfBoxesTestDemo

        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public LotsOfBoxesTestDemo(DemosGame game)
            : base(game)
        {
            var ground = new Box(new Vector3(0, -.5f, 0), 200, 1, 200);
            Space.Add(ground);



            var spawnVolume = new BoundingBox
                {
                    Min = new Vector3(-25, 2, -25),
                    Max = new Vector3(25, 102, 25)
                };

            var span = spawnVolume.Max - spawnVolume.Min;

            NarrowPhaseHelper.Factories.BoxBox.EnsureCount(30000);

            var random = new Random(5);
            for (int i = 0; i < 5000; ++i)
            {
                Vector3 position;
                position.X = spawnVolume.Min.X + (float)random.NextDouble() * span.X;
                position.Y = spawnVolume.Min.Y + (float)random.NextDouble() * span.Y;
                position.Z = spawnVolume.Min.Z + (float)random.NextDouble() * span.Z;

                var entity = new Box(position, 2, 2, 2, 10);
                Space.Add(entity);
            }

            for (int i = 0; i < 100; ++i)
            {
                Space.Update();
            }

            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime;
            
            var start = Stopwatch.GetTimestamp();
            for (int i = 0; i < 200; ++i)
            {
                Space.Update();
            }
            var end = Stopwatch.GetTimestamp();
            var time = (end - start) / (double)Stopwatch.Frequency;

            Console.WriteLine("Time: {0}", time);
 
            game.Camera.Position = new Vector3(-10, 10, 10);
            game.Camera.Yaw((float)Math.PI / -4f);
            game.Camera.Pitch((float)Math.PI / 9f);
        }
开发者ID:Anomalous-Software,项目名称:BEPUPhysics,代码行数:55,代码来源:LotsOfBoxesTestDemo.cs

示例11: GetBoundingBox

        /// <summary>
        /// Gets the bounding box of the shape given a transform.
        /// </summary>
        /// <param name="shapeTransform">Transform to use.</param>
        /// <param name="boundingBox">Bounding box of the transformed shape.</param>
        public override void GetBoundingBox(ref RigidTransform shapeTransform, out BoundingBox boundingBox)
        {
            #if !WINDOWS
            boundingBox = new BoundingBox();
            #endif
            Matrix3x3 o;
            Matrix3x3.CreateFromQuaternion(ref shapeTransform.Orientation, out o);
            //Sample the local directions from the orientation matrix, implicitly transposed.

            Vector3 right;
            var direction = new Vector3(o.M11, o.M21, o.M31);
            GetLocalExtremePointWithoutMargin(ref direction, out right);

            Vector3 left;
            direction = new Vector3(-o.M11, -o.M21, -o.M31);
            GetLocalExtremePointWithoutMargin(ref direction, out left);

            Vector3 up;
            direction = new Vector3(o.M12, o.M22, o.M32);
            GetLocalExtremePointWithoutMargin(ref direction, out up);

            Vector3 down;
            direction = new Vector3(-o.M12, -o.M22, -o.M32);
            GetLocalExtremePointWithoutMargin(ref direction, out down);

            Vector3 backward;
            direction = new Vector3(o.M13, o.M23, o.M33);
            GetLocalExtremePointWithoutMargin(ref direction, out backward);

            Vector3 forward;
            direction = new Vector3(-o.M13, -o.M23, -o.M33);
            GetLocalExtremePointWithoutMargin(ref direction, out forward);

            //Rather than transforming each axis independently (and doing three times as many operations as required), just get the 6 required values directly.
            Vector3 positive, negative;
            TransformLocalExtremePoints(ref right, ref up, ref backward, ref o, out positive);
            TransformLocalExtremePoints(ref left, ref down, ref forward, ref o, out negative);

            //The positive and negative vectors represent the X, Y and Z coordinates of the extreme points in world space along the world space axes.
            boundingBox.Max.X = shapeTransform.Position.X + positive.X + collisionMargin;
            boundingBox.Max.Y = shapeTransform.Position.Y + positive.Y + collisionMargin;
            boundingBox.Max.Z = shapeTransform.Position.Z + positive.Z + collisionMargin;

            boundingBox.Min.X = shapeTransform.Position.X + negative.X - collisionMargin;
            boundingBox.Min.Y = shapeTransform.Position.Y + negative.Y - collisionMargin;
            boundingBox.Min.Z = shapeTransform.Position.Z + negative.Z - collisionMargin;
        }
开发者ID:karrtmomil,项目名称:coms437_assignment2,代码行数:52,代码来源:ConvexShape.cs

示例12: DrawBoundingBox

		static void DrawBoundingBox( Display render, BoundingBox bb )
		{
			///Box box = e as Box;
			// = e.CollisionInformation.BoundingBox;
			//Vector3 corner = Matrix.TransformNormal( Vector3.One, e.WorldTransform );
			Vector3[] corners = new Vector3[8];
			//Vector3 half_size = new Vector3( box.HalfWidth, box.HalfHeight, box.HalfLength );
			corners[0] = bb.Min;
			corners[6] = bb.Max;
			corners[1] = corners[0];
			corners[1].X = corners[6].X;
			corners[2] = corners[0];
			corners[2].X = corners[6].X;
			corners[2].Y = corners[6].Y;
			corners[3] = corners[0];
			corners[3].Y = corners[6].Y;

			corners[4] = corners[0];
			corners[4].Z = corners[6].Z;

			corners[5] = corners[0];
			corners[5].X = corners[6].X;
			corners[5].Z = corners[6].Z;
			corners[7] = corners[0];
			corners[7].Y = corners[6].Y;
			corners[7].Z = corners[6].Z;
			Vector3 white = Vector3.One;
			white.Y = 0;
			white.Z = 0;
			drawLine( render, ref corners[0], ref corners[1], ref white, ref white );
			drawLine( render, ref corners[1], ref corners[2], ref white, ref white );
			drawLine( render, ref corners[2], ref corners[3], ref white, ref white );
			drawLine( render, ref corners[3], ref corners[0], ref white, ref white );
			drawLine( render, ref corners[0], ref corners[4], ref white, ref white );
			drawLine( render, ref corners[1], ref corners[5], ref white, ref white );
			drawLine( render, ref corners[2], ref corners[6], ref white, ref white );
			drawLine( render, ref corners[3], ref corners[7], ref white, ref white );
			drawLine( render, ref corners[4], ref corners[5], ref white, ref white );
			drawLine( render, ref corners[5], ref corners[6], ref white, ref white );
			drawLine( render, ref corners[6], ref corners[7], ref white, ref white );
			drawLine( render, ref corners[7], ref corners[4], ref white, ref white );
		}
开发者ID:d3x0r,项目名称:Voxelarium,代码行数:42,代码来源:BEPUDebugDrawer.cs

示例13: ComputeBoundingBox

        ///<summary>
        /// Computes the bounding box of the transformed mesh shape.
        ///</summary>
        ///<param name="transform">Transform to apply to the shape during the bounding box calculation.</param>
        ///<param name="boundingBox">Bounding box containing the transformed mesh shape.</param>
        public void ComputeBoundingBox(ref AffineTransform transform, out BoundingBox boundingBox)
        {
            #if !WINDOWS
            boundingBox = new BoundingBox();
            #endif
            float minX = float.MaxValue;
            float minY = float.MaxValue;
            float minZ = float.MaxValue;

            float maxX = -float.MaxValue;
            float maxY = -float.MaxValue;
            float maxZ = -float.MaxValue;
            for (int i = 0; i < triangleMesh.Data.vertices.Length; i++)
            {
                System.Numerics.Vector3 vertex;
                triangleMesh.Data.GetVertexPosition(i, out vertex);
                Matrix3x3.Transform(ref vertex, ref transform.LinearTransform, out vertex);
                if (vertex.X < minX)
                    minX = vertex.X;
                if (vertex.X > maxX)
                    maxX = vertex.X;

                if (vertex.Y < minY)
                    minY = vertex.Y;
                if (vertex.Y > maxY)
                    maxY = vertex.Y;

                if (vertex.Z < minZ)
                    minZ = vertex.Z;
                if (vertex.Z > maxZ)
                    maxZ = vertex.Z;
            }
            boundingBox.Min.X = transform.Translation.X + minX;
            boundingBox.Min.Y = transform.Translation.Y + minY;
            boundingBox.Min.Z = transform.Translation.Z + minZ;

            boundingBox.Max.X = transform.Translation.X + maxX;
            boundingBox.Max.Y = transform.Translation.Y + maxY;
            boundingBox.Max.Z = transform.Translation.Z + maxZ;
        }
开发者ID:Raverenx,项目名称:GameEngine,代码行数:45,代码来源:InstancedMeshShape.cs

示例14: GetEntries

        public void GetEntries(BoundingBox boundingShape, IList<BroadPhaseEntry> overlaps)
        {
            //Compute the min and max of the bounding box.
            //Loop through the cells and select bounding boxes which overlap the x axis.

            Int2 min, max;
            Grid2DSortAndSweep.ComputeCell(ref boundingShape.Min, out min);
            Grid2DSortAndSweep.ComputeCell(ref boundingShape.Max, out max);
            for (int i = min.Y; i <= max.Y; i++)
            {
                for (int j = min.Z; j <= max.Z; j++)
                {
                    //Grab the cell that we are currently in.
                    Int2 cellIndex;
                    cellIndex.Y = i;
                    cellIndex.Z = j;
                    GridCell2D cell;
                    if (owner.cellSet.TryGetCell(ref cellIndex, out cell))
                    {

                        //To fully accelerate this, the entries list would need to contain both min and max interval markers.
                        //Since it only contains the sorted min intervals, we can't just start at a point in the middle of the list.
                        //Consider some giant bounding box that spans the entire list.
                        for (int k = 0; k < cell.entries.Count
                            && cell.entries.Elements[k].item.boundingBox.Min.X <= boundingShape.Max.X; k++) //TODO: Try additional x axis pruning? A bit of optimization potential due to overlap with AABB test.
                        {
                            bool intersects;
                            var item = cell.entries.Elements[k].item;
                            boundingShape.Intersects(ref item.boundingBox, out intersects);
                            if (intersects && !overlaps.Contains(item))
                            {
                                overlaps.Add(item);
                            }
                        }
                    }
                }
            }
        }
开发者ID:Raverenx,项目名称:GameEngine,代码行数:38,代码来源:Grid2DSortAndSweepQueryAccelerator.cs

示例15: GetBoundingBox

        /// <summary>
        /// Computes a bounding box for the shape given the specified transform.
        /// </summary>
        /// <param name="transform">Transform to apply to the shape to compute the bounding box.</param>
        /// <param name="boundingBox">Bounding box for the shape given the transform.</param>
        public override void GetBoundingBox(ref RigidTransform transform, out BoundingBox boundingBox)
        {
            RigidTransform combinedTransform;
            RigidTransform.Transform(ref shapes.Elements[0].LocalTransform, ref transform, out combinedTransform);
            shapes.Elements[0].Shape.GetBoundingBox(ref combinedTransform, out boundingBox);

            for (int i = 0; i < shapes.Count; i++)
            {
                RigidTransform.Transform(ref shapes.Elements[i].LocalTransform, ref transform, out combinedTransform);
                BoundingBox childBoundingBox;
                shapes.Elements[i].Shape.GetBoundingBox(ref combinedTransform, out childBoundingBox);
                BoundingBox.CreateMerged(ref boundingBox, ref childBoundingBox, out boundingBox);
            }
        }
开发者ID:karrtmomil,项目名称:coms437_assignment2,代码行数:19,代码来源:CompoundShape.cs


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