May 11, 2021, 03:02:37 AM

### Author Topic: [bb] InsideCheck by * [ 1+ years ago ]  (Read 723 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] InsideCheck by * [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : InsideCheck
Author : *
Posted : 1+ years ago

Description : The function checks to see if a point is within another point

Code :
Code: BlitzBasic
1. ;Inside check
2. ;this will check to see if a specified 3d position is within another
3. ;entity.
4.
5. ;This code uses the box code from Rob Cummings so he deserves some of the
6. ;credit too =).
7.
8. ;if you use the code please give me (EdzUp) and Rob Cummings credit for
9. ;the code :)
10.
11. Function InsideCheck( Ent, x#, y#, z# )
12.         Local tx#, ty#, tz#                     ;Top Left
13.         Local tx2#, ty2#, tz2#          ;Top Right
14.         Local bx#, by#, bz#                     ;Bottom Left
15.         Local bx2#, by2#, bz2#          ;Bottom Right
16.         Local Top#, Bottom#                     ;absolute highest and lowest
17.
18.         Local VX#, VY#, VZ#                     ;Vertex coords
19.
20.         Local Inside=0                          ;this will be 0 if its not inside
21.
22.         ;We really need to check to see if the player is within the entity
23.         If Ent=0 Return 0
24.
25.         For i=0 To CountSurfaces( Ent )-1
26.                 s = GetSurface( Ent, 1 )
27.                 For v=0 To CountVertices( s )-1
28.             TFormPoint VertexX(s,v),VertexY(s,v),VertexZ(s,v),ent,0
29.
30.                         VX# = TFormedX#()
31.                         VY# = TFormedY#()
32.                         VZ# = TFormedZ#()
33.
34.                         ;now we need to check to see if its in a better
35.                         ;position that any of our other vertex coords.
36.                         If vy#>Top# Then Top# = vy#
37.                         If vy#<Bottom# Then Bottom# = vy#
38.                         ;vx
39.                         If vx#<tx# Then tx#=vx#
40.                         If vx#<bx# Then bx#=vx#
41.                         If vx#>tx2# Then tx2#=vx#
42.                         If vx#>bx2# Then bx2#=vx#
43.
44.                         ;vy
45.                         If vy#>ty# Then ty#=vy#
46.                         If vy#>ty2# Then ty2#=vy#
47.                         If vy#<by# Then by#=vy#
48.                         If vy#<by2# Then by2#=vy#
49.
50.                         ;vz
51.                         If vz#<tz# Then tz#=vz#
52.                         If vz#<bz# Then bz#=vz#
53.                         If vz#>tz2# Then tz2#=vz#
54.                         If vz#>bz2# Then bz2#=vz#
55.                 Next
56.         Next
57.
58.         ;now we need to see if the point is within the entity
59.         ok=0
60.         If bx#<=x# And tx#<=x# Then     ok=ok+1
61.         If bx2#>x# And tx2#>x# Then ok=ok+1
62.         If bz#<z#  And tz#<z#  Then     ok=ok+1
63.         If bz2#>=z# And tz2#>=z Then ok=ok+1
64.         If top#>=y# And bottom#<y# Then ok=ok+1
65.
66.         If ok=5 Then Return 1 Else Return 0     ;0 if point not inside entity
67. End Function