public void AutoSet()
        {
            Collider col = GetComponent <Collider>();

            if (col)
            {
                Type type = col.GetType();
                if (type == typeof(SphereCollider))
                {
                    Shape = BoundingType.Circle;
                    GetComponent <SphereCollider>().getOBBB(ref m_BBBuilder);
                }
                else if (type == typeof(CapsuleCollider))
                {
                    Shape = BoundingType.Circle;
                    GetComponent <CapsuleCollider>().getOBBB(ref m_BBBuilder);
                }
                else if (type == typeof(BoxCollider))
                {
                    GetComponent <BoxCollider>().getOBBB(ref m_BBBuilder);
                    if (Math.Abs(m_BBBuilder.degreeY) < 0.1f)
                    {
                        Shape = BoundingType.AABox;
                    }
                    else
                    {
                        Shape = BoundingType.OBB;
                    }
                }
            }
            UpdateValues();
        }
Example #2
0
 public BoundBox(Rectangle rect, int leftOffset, BoundingType type)
 {
     Group = "";
     Rect = rect;
     LeftOffset = leftOffset;
     BoundType = type;
 }
Example #3
0
        public void CreateBoundingBoxForModel()
        {
            // Initialize minimum and maximum corners of the bounding box to max and min values
            Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
            Vector3 max = new Vector3(float.MinValue, float.MinValue, float.MinValue);

            // For each mesh of the model
            foreach (ModelMesh mesh in _gameObject.Model.Meshes)
            {
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    // Vertex buffer parameters
                    int vertexStride     = meshPart.VertexBuffer.VertexDeclaration.VertexStride;
                    int vertexBufferSize = meshPart.NumVertices * vertexStride;

                    // Get vertex data as float
                    float[] vertexData = new float[vertexBufferSize / sizeof(float)];
                    meshPart.VertexBuffer.GetData <float>(vertexData);

                    // Iterate through vertices (possibly) growing bounding box, all calculations are done in world space
                    for (int i = 0; i < vertexBufferSize / sizeof(float); i += vertexStride / sizeof(float))
                    {
                        Vector3 transformedPosition = Vector3.Transform(new Vector3(vertexData[i], vertexData[i + 1], vertexData[i + 2]), _gameObject.TransformationMatrix);

                        min = Vector3.Min(min, transformedPosition);
                        max = Vector3.Max(max, transformedPosition);
                    }
                }
            }

            // Create and return the model bounding box
            this.BoxCollider = new BoundingBox(min, max);
            this.BType       = BoundingType.Box;
        }
Example #4
0
        public static BoundingVolume ReadBoundingVolume(this NetIncomingMessage message)
        {
            BoundingType type = (BoundingType)message.ReadByte();
            Vector3      center;

            message.ReadVector3(out center);
            switch (type)
            {
            case BoundingType.AABB:
                Vector3 aabbExtents;
                message.ReadVector3(out aabbExtents);
                return(new BoundingBox(center, aabbExtents));

            case BoundingType.Sphere:
                return(new BoundingSphere(center, message.ReadFloat()));

            case BoundingType.OBB:
                Vector3 xAxis, yAxis, zAxis, obbExtents;
                message.ReadVector3(out xAxis);
                message.ReadVector3(out yAxis);
                message.ReadVector3(out zAxis);
                message.ReadVector3(out obbExtents);
                return(new OrientedBoundingBox(center, xAxis, yAxis, zAxis, obbExtents));

            default:
                return(null);
            }
        }
Example #5
0
 public new void Init()
 {
     InView        = BoundingType.Outside;
     Dir           = LandDefs.Direction.Unknown;
     Closest       = new Vector2(-1, -1);
     BlockCoord    = new Vector2();
     StaticObjects = new List <PhysicsObj>();
     Buildings     = new List <BuildingObj>();
 }
Example #6
0
        public static BoundingSphere ReadBoundingSphere(this NetIncomingMessage message)
        {
            BoundingType type = (BoundingType)message.ReadByte();
            Vector3      center;

            message.ReadVector3(out center);
            float radius = message.ReadFloat();

            return(new BoundingSphere(center, radius));
        }
Example #7
0
        public static BoundingBox ReadBoundingBox(this NetIncomingMessage message)
        {
            BoundingType type = (BoundingType)message.ReadByte();
            Vector3      center;
            Vector3      extents;

            message.ReadVector3(out center);
            message.ReadVector3(out extents);
            return(new BoundingBox(center, extents));
        }
Example #8
0
        public static OrientedBoundingBox ReadOrientedBoundingBox(this NetIncomingMessage message)
        {
            BoundingType type = (BoundingType)message.ReadByte();
            Vector3      center, xAxis, yAxis, zAxis, extents;

            message.ReadVector3(out center);
            message.ReadVector3(out xAxis);
            message.ReadVector3(out yAxis);
            message.ReadVector3(out zAxis);
            message.ReadVector3(out extents);

            return(new OrientedBoundingBox(center, xAxis, yAxis, zAxis, extents));
        }
Example #9
0
        public static void ReadBoundingSphere(this NetIncomingMessage message, BoundingSphere existing)
        {
            BoundingType type = (BoundingType)message.ReadByte();
            Vector3      center;

            message.ReadVector3(out center);
            float radius = message.ReadFloat();

            if (existing != null)
            {
                existing.Set(center, radius);
            }
        }
Example #10
0
        public static void ReadBoundingBox(this NetIncomingMessage message, BoundingBox existing)
        {
            BoundingType type = (BoundingType)message.ReadByte();
            Vector3      center;
            Vector3      extents;

            message.ReadVector3(out center);
            message.ReadVector3(out extents);
            if (existing != null)
            {
                existing.Set(center, extents);
            }
        }
    private bool GreaterThan(Transform check, BoundingType bounds)
    {
        switch (bounds)
        {
        case BoundingType.Horizontal:
            switch (colliderBounds)
            {
            case ColliderBoundsToUse.None:
                return(check.position.x > transform.position.x);

                break;

            case ColliderBoundsToUse.Right:
                return(check.position.x > transform.position.x + boxCollider.bounds.extents.x);

                break;

            case ColliderBoundsToUse.Left:
                return(check.position.x > transform.position.x - boxCollider.bounds.extents.x);

                break;
            }
            break;

        case BoundingType.Vertical:
            switch (colliderBounds)
            {
            case ColliderBoundsToUse.None:
                return(check.position.y > transform.position.y);

                break;

            case ColliderBoundsToUse.Right:
                return(check.position.y > transform.position.y + boxCollider.bounds.extents.y);

                break;

            case ColliderBoundsToUse.Left:
                return(check.position.y > transform.position.y - boxCollider.bounds.extents.y);

                break;
            }
            break;
        }
        return(false);
    }
Example #12
0
        public Model(Game game, BasicCamera cam)
            : base(game)
        {
            Right     = Vector3.Right;
            Direction = Vector3.Forward;
            Scale     = Vector3.One;
            Rotation  = Vector3.Zero;
            Camera    = cam;

            Up            = Vector3.Up;
            AmbientColor  = Color.White;
            DiffuseColor  = Color.White;
            SpecularColor = Color.Black;
            EmissiveColor = Color.Black;
            SpecularPower = 100;
            FillMode      = FillMode.Solid;
            CullMode      = CullMode.CullCounterClockwiseFace;
            BoundingType  = BoundingType.Box;
        }
Example #13
0
        public static Urho.Physics.ShapeType ToUrhoShapeType(this BoundingType boundingType)
        {
            switch (boundingType)
            {
            case BoundingType.Box:
                return(ShapeType.Box);

            case BoundingType.ConvexHull:
                return(ShapeType.Convexhull);

            case BoundingType.Cylinder:
                return(ShapeType.Cylinder);

            case BoundingType.Sphere:
                return(ShapeType.Sphere);
            }

            return(ShapeType.Box);
        }
Example #14
0
        public void CreateComplexBoundingSphereForModel()
        {
            List <BoundingSphere> collider = new List <BoundingSphere>();

            if (_gameObject.Model == null)
            {
                return;
            }

            if (_gameObject.IsAnimated)
            {
                Matrix[] boneTransforms = new Matrix[_gameObject.Model.Bones.Count];
                _gameObject.Model.CopyAbsoluteBoneTransformsTo(boneTransforms);

                foreach (ModelMesh mesh in _gameObject.Model.Meshes)
                {
                    BoundingSphere sphere = mesh.BoundingSphere;
                    sphere = sphere.Transform(boneTransforms[mesh.ParentBone.Index]);
                    sphere = sphere.Transform(_gameObject.TransformationMatrix);
                    collider.Add(sphere);
                }
            }
            else
            {
                foreach (ModelMesh mesh in _gameObject.Model.Meshes)
                {
                    BoundingSphere sphere = mesh.BoundingSphere;
                    sphere = sphere.Transform(_gameObject.TransformationMatrix);
                    collider.Add(sphere);
                }
            }

            //boundingSphere.Center = this.TransformationMatrix.Translation;
            //this.Scale = this.TransformationMatrix.Scale;
            //float maxScale = new float[] {this.Scale.X, this.Scale.Y, this.Scale.Z}.Max();
            //boundingSphere.Radius *= maxScale;

            this.SphereColliders = collider;
            this.BType           = BoundingType.Complex;
        }
Example #15
0
        public void CreateSingleBoundingSphereForModel()
        {
            BoundingSphere boundingSphere = new BoundingSphere();

            if (_gameObject.Model == null)
            {
                return;
            }

            if (_gameObject.IsAnimated)
            {
                Matrix[] boneTransforms = new Matrix[_gameObject.Model.Bones.Count];
                _gameObject.Model.CopyAbsoluteBoneTransformsTo(boneTransforms);

                foreach (ModelMesh mesh in _gameObject.Model.Meshes)
                {
                    boundingSphere = BoundingSphere.CreateMerged(boundingSphere, mesh.BoundingSphere);
                    boundingSphere.Transform(boneTransforms[mesh.ParentBone.Index]);
                }
            }
            else
            {
                foreach (ModelMesh mesh in _gameObject.Model.Meshes)
                {
                    boundingSphere = BoundingSphere.CreateMerged(boundingSphere, mesh.BoundingSphere);
                }
            }

            //boundingSphere.Center = this.TransformationMatrix.Translation;
            //this.Scale = this.TransformationMatrix.Scale;
            //float maxScale = new float[] {this.Scale.X, this.Scale.Y, this.Scale.Z}.Max();
            //boundingSphere.Radius *= maxScale;
            boundingSphere = boundingSphere.Transform(_gameObject.TransformationMatrix);

            this.SphereCollider = boundingSphere;
            this.BType          = BoundingType.Sphere;
        }
Example #16
0
 public void SetType(BoundingType type)
 {
     BoundType = type;
 }