RiiDii, I helped you out a little with rotation and 3D sectors.
You will need to make 1 vector and 4 matrices for it to work.
Untested but it should work.
function in_sector( SourceObj as DWord, TargetObj as DWord, SectArcH as Float, SectArcV as Float, SectRad as Float,FreeVector as dword,FreeMatrix1 as dword,FreeMatrix2 as dword,FreeMatrix3 as dword,FreeMatrix4 as dword)
`Declarations
SectX as Float
SectY as Float
SectZ as Float
SectAng as Float
TargX as Float
TargY as Float
TargZ as Float
Distance as Float
inFlag as Boolean = 0
`Defensive Code
If SourceObj<1 Then ExitFunction inFlag
If Not Object Exist(SourceObj) Then ExitFunction inFlag
If TargetObj<1 Then ExitFunction inFlag
If Not Object Exist(TargetObj) Then ExitFunction inFlag
`Set variables
SectX = Object Position X(SourceObj)
SectY = Object Position Y(SourceObj)
SectZ = Object Position Z(SourceObj)
SectAngX = Object Angle X(SourceObj)
SectAngY = Object Angle Y(SourceObj)
SectAngZ = Object Angle Z(SourceObj)
SectAng = 0
TargX = Object Position X(TargetObj)
TargY = Object Position X(TargetObj)
TargZ = Object Position X(TargetObj)
SectArcH =SectArcH*.5
SectArcV =SectArcV*.5
`Set vector
set vector4 FreeVector,SectX,SectY,SectZ
`Set Matrices
rotate x matrix4 FreeMatrix1,-SectAngX/57.2958
rotate y matrix4 FreeMatrix2,-SectAngY/57.2958
rotate z matrix4 FreeMatrix3,-SectAngZ/57.2958
translate matrix4 FreeMatrix4,TargX-SectX,TargY-SectY,TargZ-SectZ
multiply matrix4 FreeMatrix1,FreeMatrix1,FreeMatrix2
multiply matrix4 FreeMatrix1,FreeMatrix1,FreeMatrix3
add matrix4 FreeMatrix1,FreeMatrix1,FreeMatrix4
transform vector4 FreeVector,FreeVector,FreeMatrix1
TargX=X Vector4(FreeVector)
TargY=Y Vector4(FreeVector)
TargZ=Z Vector4(FreeVector)
SectX = 0
SectY = 0
SectZ = 0
`check for distance
Distance =get_distance( TargX, TargZ, SectX, SectZ )
`Object is outside of sector radius
if Distance > SectRad Then ExitFunction inFlag
`Get the Y-angle of the Target Object relative to the Source Object
angle# = wrapvalue( atanfull( TargX-SectX , TargZ-SectZ ) )
`check angle
if abs( angle# - SectAng ) < SectArcH
inFlag = 1
endif
`Check for angle wrap around (0 becomes 360 etc.)
if SectAng < SectArcH or SectAng > (360 - SectArcH)
if abs( angle# - SectAng ) > 360 - SectArcH
inFlag = 1
endif
endif
if inFlag = 0 Then ExitFunction inFlag
inFlag = 0
`Get the vertical-angle of the Target Object relative to the Source Object
angle# = wrapvalue( atanfull( TargY-SectY , Distance ) )
if angle# < SectArcV or angle# > (360-sectArcV)
inFlag = 1
endif
endfunction inFlag
Function Initialize_Distance_Functions()
Dim initDistance(0)
If initDistance(0) Then ExitFunction
initDistance(0)=1
Global Distance3D = 1
NoValue=Make Vector3(Distance3D)
Global Distance2D = 2
NoValue=Make Vector2(Distance2D)
Endfunction
function get_target_distance(object1,obj2x#,obj2y#,obj2z#)
Initialize_Distance_Functions()
If object1<1 Then Exitfunction 0.0
If Object Exist(object1)=0 Then ExitFunction 0.0
ObjX#=Object Position X(Object1)
ObjY#=Object Position Y(Object1)
ObjZ#=Object Position Z(Object1)
Set Vector3 Distance3D,obj2x#-ObjX#,obj2y#-ObjY#,obj2z#-ObjZ#
distance# = Length Vector3(Distance3D)
endfunction distance#
function get_distance( x1 as float, y1 as float, x2 as float, y2 as float )
Initialize_Distance_Functions()
set vector2 Distance2D, x1-x2, y1-y2
result# = length vector2( Distance2D )
endfunction result#