Checking if an entity is in a box

Blitz3D Forums/Blitz3D Programming/Checking if an entity is in a box

slenkar(Posted 2004) [#1]
I have a builing with one room,the inside of the room is part of the same mesh.

I want to know if another entity like a person enters the house.

I tried setting up a camera like a security camera inside the house and doing 'entityinview'

Unfortunetly it returns a positive result even when there is someone outside the house but right next to it. I checked the camera and it can definetly not see the person through any openings.

It may be because its bounding box can be seen,

Is there a better way of checking if someone enters the house?


Eric(Posted 2004) [#2]
There are probably a bunch of ways to do this, but..Along your lines try the EntityVisible command.

Regards,
Eric


aCiD2(Posted 2004) [#3]
look into deltayaw. If you use a pivot pointing at each possible entrance you can check delta yaw and if its greater than something like -60 and less then 60 then the entity is in basic view.

Iirc entityinview/entityvisible just works by seeing ifyou can pick from one entity to another, like linepicking one entity to another. Sorry i can't remember which one it is though :\


slenkar(Posted 2004) [#4]
entityvisible checks if a pick can be done but entityinview checks if it is in the cameras view. still dont understand why its coming back positive when there is only one entrance and the person is no where near it.


Eric(Posted 2004) [#5]
Well, I'm fairly new to this, but can't you set your levels pickmode as an obscurer?


slenkar(Posted 2004) [#6]
yeah but its already defaulted to that and it still doesnt work.
I tried entityvisible but checking every one of the entities for visibility is VERY slow


RetroBooster(Posted 2004) [#7]
first of all get your bounding boxes right, try making a red cube that is semi transparent to show your bounding box, this will help you see if it's correct. Then if you have a propper box, a simple pure maths way of doing the check is by checking of the players x,y,z is within every boundary (a box has 6 boundaries, you could call em: xstart,xend,ystart etc.) so if the x > xStart and the x < xEnd, the y > yStart etc. then the players current position is in the box.

However the player will no doubt have a radius, to compensate for that you need to expand the box by the radius, like this: if the x > (xStart-radius) and the x < (xEnd+radius), the y > (yStart-radius) etc. then the players current radius is, atleast partialy, inside the bounding box. Hope that helps ya. You really want to shy away from using entityvisible for stuff like that it's a bit slow.


jfk EO-11110(Posted 2004) [#8]
EntityInView only checks if the entity is in the Field of View of the Camera, that means if it is behind the camera or in front of the camera. If it's in Front of it, then it returns true, no matter if it is obscured by other geometry or not.

As RetroBooster said you better use a Coordinate Check (if you really only need to check for Boxes) because EntityVisible is very slow and requires to set pickmodes etc.

I'd suggest to setup an Array for the boxes before you go into the main loop. THe array contains x1,y1,z1 and x2,y2,z2 of all Boxes. To determine these coordnates you need to parse the vertices of the boxes (I assume they are ceated using CreateCube and then hidden with HideEntity - that's how I would do it) you need to use TFormPoint, TFormedX, TFOrmedY and TFormedZ. Those Commands will give you the true world coordinates of VertexX etc. Do something like (only pseudo code)


for j=0 to num_boxes-1
; get entityhandle of a box and determine surface etc.
minX#=100000.0
minY#=100000.0
minZ#=100000.0
maxX#=-100000.0
maxY#=-100000.0
maxZ#=-100000.0
for i=0 to CountVertices(surf)-1
 x#=vertexX(surf,i)
 y#=vertexy(surf,i)
 z#=vertexz(surf,i)
 tformpoint x,y,z,boxhandle,0
 x=tformedx()
 y=tformedy()
 z=tformedz()
 if x#<minX# then 
  minX#=x#
 endif
 ; the same with maxX, miny, maxY...
next
boxarray#(0,j)=minX
boxarray#(1,j)=minY
boxarray#(2,j)=minZ
boxarray#(3,j)=maxX
boxarray#(4,j)=maxY
boxarray#(5,j)=maxZ
next

;and in the game you only need to do this:

for j=0 to num_boxes-1
 x=entityx(enemy)
 y=entityy(enemy)
 z=entityz(enemy)
 if x>=boxarray(0,j) and x<=boxarray(3,j)
  if y>=boxarray(1,j) and y<=boxarray(4,j)
   if z>=boxarray(2,j) and z<=boxarray(5,j)
    print "enemy inside box "+j
   endif
  endif
 endif
next

This is MUCH faster than any Pick-ish command.


ronbravo(Posted 2004) [#9]
I would suggest two things:

1. Find a way to seperate the room as it's own mesh and load it seperatly. Then you could set up collision for the room as it's own seperate entity.

2. Create a pivot point for the room, then setup collision for that pivot point, and increase the pivot points range.


LT(Posted 2004) [#10]
If you want to use the coordinate check method, you need to make sure that the box is aligned to the world, or you need to transform your check point so that it is in the coordinate space of the box.

An alternate, and more powerful, method involves doing point-plane tests with each of the faces in the box. I'd recommend this method if you ever intend on doing more complicated shapes.