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


C# ICollidable.getBoundingBox方法代码示例

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


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

示例1: updateCollisionCellsFor

        public void updateCollisionCellsFor(ICollidable c)
        {
            //first clear the cells the c currently belongs to
            removeFromCollisionGrid(c);

            BoundingBox b = c.getBoundingBox();
            b.Min -= gridOffset;
            b.Max -= gridOffset;
            List<CollisionGridCell> collidablesCells = new List<CollisionGridCell>();
            //get the cell bounds for this
            for (int k = Math.Max(0, (int)Math.Floor(b.Min.Z / cellSize)); k <= Math.Min(grid.GetLength(2) - 1, (int)Math.Ceiling(b.Max.Z / cellSize)); ++k)
                for (int j = Math.Max(0, (int)Math.Floor(b.Min.Y / cellSize)); j <= Math.Min(grid.GetLength(1) - 1, (int)Math.Ceiling(b.Max.Y / cellSize)); ++j)
                    for (int i = Math.Max(0, (int)Math.Floor(b.Min.X / cellSize)); i <= Math.Min(grid.GetLength(0) - 1, (int)Math.Ceiling(b.Max.X / cellSize)); ++i) {
                        grid[i, j, k].elements.Add(c);
                        collidablesCells.Add(grid[i, j, k]);
                    }

            c.setCollisionCells(collidablesCells);
        }
开发者ID:elliottroland,项目名称:Emergence,代码行数:19,代码来源:PhysicsEngine.cs

示例2: getCollidablesToCheck

 private IEnumerable<ICollidable> getCollidablesToCheck(ICollidable c, Vector3 vel)
 {
     BoundingBox bb = c.getBoundingBox();
     Vector3 minA = bb.Min - gridOffset, maxA = bb.Max - gridOffset;
     Vector3 minB = minA + vel, maxB = maxA + vel;
     Dictionary<ICollidable, bool> checkedCols = new Dictionary<ICollidable, bool>();
     for (int k = Math.Max(0, (int)Math.Floor(Math.Min(minA.Z, minB.Z) / cellSize)); k <= Math.Min(grid.GetLength(2) - 1, (int)Math.Ceiling(Math.Max(maxA.Z, maxB.Z) / cellSize)); ++k)
         for (int j = Math.Max(0, (int)Math.Floor(Math.Min(minA.Y, minB.Y) / cellSize)); j <= Math.Min(grid.GetLength(1) - 1, (int)Math.Ceiling(Math.Max(maxA.Y, maxB.Y) / cellSize)); ++j)
             for (int i = Math.Max(0, (int)Math.Floor(Math.Min(minA.X, minB.X) / cellSize)); i <= Math.Min(grid.GetLength(0) - 1, (int)Math.Ceiling(Math.Max(maxA.X, maxB.X) / cellSize)); ++i)
                 foreach(ICollidable col in grid[i,j,k].elements)
                     if (!checkedCols.ContainsKey(col)) {
                         checkedCols.Add(col, true);
                         yield return col;
                     }
 }
开发者ID:elliottroland,项目名称:Emergence,代码行数:15,代码来源:PhysicsEngine.cs

示例3: collides

        public CollisionPackage collides(Vector3 moverRadius, Vector3 basePoint, Vector3 velocity, ICollidable collider)
        {
            float closestCollisionTime = 1;
            Vector3 closestCollisionPoint = Vector3.Zero;

            //make colliderBoundingBox a bounding volume over the movement
            BoundingBox colliderBoundingBox = collider.getBoundingBox();
            Vector3 worldVel = toWorldSpace(moverRadius, velocity);
            if (worldVel.X < 0) colliderBoundingBox.Min.X += worldVel.X;
            else if (worldVel.X > 0) colliderBoundingBox.Max.X += worldVel.X;
            if (worldVel.Y < 0) colliderBoundingBox.Min.Y += worldVel.Y;
            else if (worldVel.Y > 0) colliderBoundingBox.Max.Y += worldVel.Y;
            if (worldVel.Z < 0) colliderBoundingBox.Min.Z += worldVel.Z;
            else if (worldVel.Z > 0) colliderBoundingBox.Max.Z += worldVel.Z;

            List<PickUp> pickedUp = new List<PickUp>();

            List<Vector3> eSpaceVerts = new List<Vector3>();
            bool convertedVerts = false;
            foreach(ICollidable collidable in getCollidablesToCheck(collider, toWorldSpace(moverRadius, velocity)))    {
                if (collidable is Agent)    continue;
                BoundingBox collidableBoundingBox = collidable.getBoundingBox();
                collidableBoundingBox.Min -= boundingBoxPadding;
                collidableBoundingBox.Max += boundingBoxPadding;
                if (!collidableBoundingBox.Intersects(colliderBoundingBox) || collidable == collider) continue;
                if(collidable is Brush) {
                    Brush brush = (Brush)collidable;
                    bool faceCollide = false;
                    foreach (Face face in brush.faces) {
                        if (faceCollide)
                            break;
                        convertedVerts = false;

                        //find the normal of the face's plane in eSpace
                        Microsoft.Xna.Framework.Plane helperPlane = new Microsoft.Xna.Framework.Plane(toESpace(moverRadius, face.plane.first), toESpace(moverRadius, face.plane.second), toESpace(moverRadius, face.plane.third));
                        helperPlane.Normal = -helperPlane.Normal;
                        Vector3 N = helperPlane.Normal;
                        N.Normalize();
                        float D = -helperPlane.D;

                        if (Vector3.Dot(N, Vector3.Normalize(velocity)) >= -0.005)
                            continue;

                        float t0, t1;
                        bool embeddedInPlane = false;
                        if (Vector3.Dot(N, velocity) != 0) {
                            t0 = (-1 - signedDistance(N, basePoint, D)) / Vector3.Dot(N, velocity);
                            t1 = (1 - signedDistance(N, basePoint, D)) / Vector3.Dot(N, velocity);
                            //swap them so that t0 is smallest
                            if (t0 > t1) {
                                float temp = t1;
                                t1 = t0;
                                t0 = temp;
                            }

                            if (t0 < 0 && t1 > 1)
                                face.DiffuseColor = new Vector3(0, 1, 0);

                            if (t0 > 1 || t1 < 0)
                                continue;
                        }
                        else if (Math.Abs(signedDistance(N, basePoint, D)) < 1) {
                            t0 = 0;
                            t1 = 1;
                            embeddedInPlane = true;
                        }
                        else  //in this case we can't collide with this face
                            continue;

                        if (!embeddedInPlane) {
                            //now we find the plane intersection point
                            //Vector3 planeIntersectionPoint = basePoint - N + t0 * velocity;
                            Vector3 planeIntersectionPoint = basePoint - N + t0 * velocity;

                            //project this onto the plane

                            //clamp [t0, t1] to [0,1]
                            if (t0 < 0) t0 = 0;
                            if (t1 < 0) t1 = 0;
                            if (t0 > 1) t0 = 1;
                            if (t1 > 1) t1 = 1;

                            //now we find if this point lies on the face
                            eSpaceVerts.Clear();
                            foreach (Vertex vert in face.vertices)
                                eSpaceVerts.Add(toESpace(moverRadius, vert.position));
                            convertedVerts = true;
                            if (MapEngine.pointOnFace(planeIntersectionPoint, eSpaceVerts, N)) {
                                //float intersectionDistance = t0 * (float)Math.Sqrt(Vector3.Dot(velocity, velocity));
                                if (face.DiffuseColor == new Vector3(1, 1, 1))
                                    face.DiffuseColor = new Vector3(1, 0, 0);
                                if (t0 < closestCollisionTime) {
                                    closestCollisionTime = t0;
                                    closestCollisionPoint = planeIntersectionPoint;
                                    faceCollide = true;
                                    continue;
                                }
                            }
                        }
                        if (!convertedVerts) {
//.........这里部分代码省略.........
开发者ID:elliottroland,项目名称:Emergence,代码行数:101,代码来源:PhysicsEngine.cs


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