Hi,
I'm trying to check within an action of certain entities, whether they are within the camera's field of view. I have the following action attached to the entities:
action viewable() {
while(1) {
// get vector from camera to object
var d[3];
vec_diff(d, vector(my.x, my.y, my.z), vector(camera.x, camera.y, camera.z));
// get magnitude of this vector
var d_mag = vec_length(d);
// rotate vector to align it with camera's pan angle
var r[3];
vec_set(r,d);
vec_rotate(r,-camera.pan);
vec_normalize(r,1);
// in view if in front and within 45 degree angle
var in_view = ((r[1] > 0) && (abs(r[0]) < abs(r[1])));
// viewable if in view and close enough
var viewable = (in_view && d_mag <= MIN_DIST);
// do some stuff here to use the viewable variable
wait(1);
}
}
So, I think that r[0] should be around 0 when the camera is looking at the object, or if the object is directly behind the camera. However, it's not working. I'm thinking it has something to do with how I'm rotating the vector, but I'm not sure. When the camera rotates, r[0] does go from -1 to 0 to 1, but it's not consistent with the location of the entity.
Does anyone have any ideas?
Thanks!