checking if entity is in camera's field of view

Posted By: shades04

checking if entity is in camera's field of view - 11/15/07 08:07

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!
Posted By: flits

Re: checking if entity is in camera's field of vie - 11/15/07 10:15

you could use vec_to_screen(my.x,camera); instead of all in this code

manaul:
http://www.conitec.net/beta/avec_to_screen.htm
Posted By: Fenriswolf

Re: checking if entity is in camera's field of vie - 11/15/07 13:19

Hi,

you can also use the clipped flag.
Posted By: tindust

Re: checking if entity is in camera's field of vie - 11/15/07 23:33

Search the forum. It's been discussed ...

here is one thread

cheers
Posted By: Ottawa

Re: checking if entity is in camera's field of vie - 11/16/07 00:06

Hi!

Are you redefining your var in the while loop?


var d[3]; and others
while ().....
Posted By: shades04

Re: checking if entity is in camera's field of vie - 11/16/07 05:19

Ah, so simple! Thanks!

And.. sorry about that; I did search -- I guess I just didn't have the right terms in there.
© 2023 lite-C Forums