Entity within BOX

Blitz3D Forums/Blitz3D Programming/Entity within BOX

Naughty Alien(Posted 2007) [#1]
..I saw this a while in code archives and I simply cant find it again...it was function that basically returning you true/false if entity(pivot, camera, object, whatever) is inside/outside specified box mesh...anyone have this code maybe??


Matty(Posted 2007) [#2]
Is it this one:
http://blitzbasic.com/codearcs/codearcs.php?code=414


Naughty Alien(Posted 2007) [#3]
..this could be useful, but it wasnt Swift's code..I have this one downloaded already...there was another very simple example and quite fast..I need it for some kind of portal thingy im working on..


Stevie G(Posted 2007) [#4]
I just knocked this up .... any use ..

Global PIVOT = CreatePivot()


Function INSIDEbox( Entity , x#, y#, z#, Sx#, Sy#, Sz# )

	PositionEntity PIVOT, x, y, z

	TFormPoint 0,0,0,Entity, PIVOT
	
	Return (  Abs( TFormedX() ) < Sx And Abs( TFormedY() ) < Sy And Abs( TFormedZ() ) < Sz
	
End Function



Naughty Alien(Posted 2007) [#5]
..mm..thats interesting Stevie..anyway, I found it..its something like Swifty code..boxes used as a zones for checking portals will be nice to precalculate after level mesh loading..anyway here it is..I hope someone else will find it useful..

;Inside check
;this will check to see if a specified 3d position is within another
;entity.

;This code uses the box code from Rob Cummings so he deserves some of the
;credit too =).

;if you use the code please give me (EdzUp) and Rob Cummings credit for
;the code :)

Function InsideCheck( Ent, x#, y#, z# )
Local tx#, ty#, tz# ;Top Left
Local tx2#, ty2#, tz2# ;Top Right
Local bx#, by#, bz# ;Bottom Left
Local bx2#, by2#, bz2# ;Bottom Right
Local Top#, Bottom# ;absolute highest and lowest

Local VX#, VY#, VZ# ;Vertex coords

Local Inside=0 ;this will be 0 if its not inside

;We really need to check to see if the player is within the entity
If Ent=0 Return 0

For i=0 To CountSurfaces( Ent )-1
s = GetSurface( Ent, 1 )
For v=0 To CountVertices( s )-1
TFormPoint VertexX(s,v),VertexY(s,v),VertexZ(s,v),ent,0

VX# = TFormedX#()
VY# = TFormedY#()
VZ# = TFormedZ#()

;now we need to check to see if its in a better
;position that any of our other vertex coords.
If vy#>Top# Then Top# = vy#
If vy#<Bottom# Then Bottom# = vy#
;vx
If vx#<tx# Then tx#=vx#
If vx#<bx# Then bx#=vx#
If vx#>tx2# Then tx2#=vx#
If vx#>bx2# Then bx2#=vx#

;vy
If vy#>ty# Then ty#=vy#
If vy#>ty2# Then ty2#=vy#
If vy#<by# Then by#=vy#
If vy#<by2# Then by2#=vy#

;vz
If vz#<tz# Then tz#=vz#
If vz#<bz# Then bz#=vz#
If vz#>tz2# Then tz2#=vz#
If vz#>bz2# Then bz2#=vz#
Next
Next

;now we need to see if the point is within the entity
ok=0
If bx#<=x# And tx#<=x# Then ok=ok+1
If bx2#>x# And tx2#>x# Then ok=ok+1
If bz#<z# And tz#<z# Then ok=ok+1
If bz2#>=z# And tz2#>=z Then ok=ok+1
If top#>=y# And bottom#<y# Then ok=ok+1

If ok=5 Then Return 1 Else Return 0 ;0 if point not inside entity
End Function