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(); }
public BoundBox(Rectangle rect, int leftOffset, BoundingType type) { Group = ""; Rect = rect; LeftOffset = leftOffset; BoundType = type; }
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; }
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); } }
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>(); }
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)); }
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)); }
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)); }
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); } }
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); }
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; }
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); }
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; }
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; }
public void SetType(BoundingType type) { BoundType = type; }