|
Rhaven Marx
Registered User
Join date: 15 Apr 2006
Posts: 6
|
07-01-2006 10:50
I'm a tad over my head here in math, and was wondering if one of you could help me out. What I'm looking for is a formula to find out if a person is within a certain field of view.
In other words, I want to know if a particular vector is within, say, a 45 degree arc in front of an AV who is in mouselook mode.
Thanks for your help!
|
|
Aodhan McDunnough
Gearhead
Join date: 29 Mar 2006
Posts: 1,518
|
07-01-2006 12:30
This is not actual script code. Translate and make conversions accordingly.
AvatarVec (avatar's forward looking vector) = <1,0,0> * llGetRot()
TargetVec (vector drawn from Avatar to Target, from scanner data)
normalize AvatarVec (extra precaution) and TargetVec
AvatarVecNorm = llVecNorm(AvatarVec) TargetVecNorm = llVecNorm(TargetVec)
DotProduct = AvatarVecNorm * TargetVecNorm
Since both vectors have been normalized, the cosine of the angle = DotProduct
So you are looking for ArcCosine of DotProduct <= 22.5 degrees (half the defined viewing arc)
The above can be compressed into less lines but I unrolled it for clarity.
|