Parameters:entity - entity handle#
x# - x position of entity's collision box
y# - y position of entity's collision box
z# - z position of entity's collision box
width# - width of entity's collision box
height# - height of entity's collision box
depth# - depth of entity's collision box
Description:Sets the dimensions of an entity's collision box.
See also: EntityRadius, Collisions, EntityType.
| The collision box is defined in terms of the entities local space. For example a default blitz cube extends from -1,-1,-1 to 1,1,1 in x,y,z and thus is of size 2x2x2. Therefore to define a box for this cube you would use Entitybox entity, -1,-1,-1, 2,2,2. That is a box starting at -1,-1,-1 and with a width, height and depth of 2. |
Once you have defined a box for an entity it will follow the entities rotations and movements. It will not however be effected by scaling, and so you will have to adjust the size of the box if you use the EntityScale command to change the size of the entity. However the space the entity resides in should be scaled uniformly. EntityBox will not work as you might expect in non-uniform scaled space. An example of that would be to create a pivot and scale that to 1,2,1 say and then parent your mesh entity to the pivot. This will only work if your entity is not rotated and remains aligned to the world axis because once you rotate it away from 0,0,0 its space becomes "warped" and the box will be unable to stay true to the entities deformation. Scaling the pivot uniformly by 2,2,2 say would be fine. It is worth mentioning that scaling is hierarchical, so it you had another pivot this pivot was parented to and that was not scaled uniformly you would still have problems.
Entitybox is not currently aware of sprite orientation and so will not work as expected with sprites.
Some code for auto defining boxes for meshes...
Const Infinity# = (999.0)^(99999.0), NaN# = (-1.0)^(0.5) Global Mesh_MinX#,Mesh_MinY#,Mesh_MinZ# Global Mesh_MaxX#,Mesh_MaxY#,Mesh_MaxZ# Global Mesh_MagX#,Mesh_MagY#,Mesh_MagZ# ; create a collision box for a mesh entity taking into account entity scale ; (will not work in non-uniform scaled space) Function makecollbox(mesh) Local sx# = EntityScaleX(mesh,1) Local sy# = EntityScaleY(mesh,1) Local sz# = EntityScaleZ(mesh,1) GetMeshExtents(mesh) EntityBox mesh, Mesh_MinX*sx,Mesh_MinY*sy,Mesh_MinZ*sz,Mesh_MagX*sx,Mesh_MagY*sy,Mesh_MagZ*sz End Function ; make a proxy bounding box for a mesh ; (will work in non-uniform scaled space using sphere to poly collisions) Function makeproxybox(mesh,alpha#=0) Local proxy = CreateCube(mesh) EntityAlpha proxy,alpha GetMeshExtents(mesh) FitMesh proxy, Mesh_MinX,Mesh_MinY,Mesh_MinZ, Mesh_MagX,Mesh_MagY,Mesh_MagZ Return proxy End Function ; Find Mesh extents Function GetMeshExtents(Mesh) Local s,surf,surfs,v,verts,x#,y#,z# Local minx# = Infinity Local miny# = Infinity Local minz# = Infinity Local maxx# = -Infinity Local maxy# = -Infinity Local maxz# = -Infinity surfs = CountSurfaces(mesh) For s=1 To surfs surf = GetSurface(mesh,s) verts = CountVertices(surf) For v=0 To verts-1 x = VertexX(surf,v) y = VertexY(surf,v) z = VertexZ(surf,v) If x < minx Then minx = x Else If x > maxx Then maxx = x If y < minx Then miny = y Else If y > maxy Then maxy = y If z < minz Then minz = z Else If z > maxz Then maxz = z Next Next Mesh_MinX = minx Mesh_MinY = miny Mesh_MinZ = minz Mesh_MaxX = maxx Mesh_MaxY = maxy Mesh_MaxZ = maxz Mesh_MagX = maxx-minx Mesh_MagY = maxy-miny Mesh_MagZ = maxz-minz End Function Function EntityScaleX#(entity, globl=False) If globl Then TFormVector 1,0,0,entity,0 Else TFormVector 1,0,0,entity,GetParent(entity) Return Sqr(TFormedX()*TFormedX()+TFormedY()*TFormedY()+TFormedZ()*TFormedZ()) End Function Function EntityScaleY#(entity, globl=False) If globl Then TFormVector 0,1,0,entity,0 Else TFormVector 0,1,0,entity,GetParent(entity) Return Sqr(TFormedX()*TFormedX()+TFormedY()*TFormedY()+TFormedZ()*TFormedZ()) End Function Function EntityScaleZ#(entity, globl=False) If globl Then TFormVector 0,0,1,entity,0 Else TFormVector 0,0,1,entity,GetParent(entity) Return Sqr(TFormedX()*TFormedX()+TFormedY()*TFormedY()+TFormedZ()*TFormedZ()) End Function
BTW. Blitz cleverly keeps tracks of any changes to a mesh and marks a mesh as dirty if it has been changed. When you use Meshwidth() or Meshheight() or Meshdepth() or do a renderworld Blitz only needs to calculate the new bounds once. When it does so it necessarily also calculates the meshes MinX,MinY and MinZ.
So wouldn't it be nice if Blitz provided functions to return a meshes MinX,MinY and MinZ?
Blitz3D Manual Forum
BlitzPlus Equivalent Command