Gamestudio Links
Zorro Links
Newest Posts
WFO Training with parallel cores Zorro64
by Martin_HH. 02/24/26 19:51
Zorro version 3.0 prerelease!
by TipmyPip. 02/24/26 17:09
ZorroGPT
by TipmyPip. 02/23/26 21:52
Camera always moves upwards?
by clonman. 02/21/26 09:29
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 02/19/26 13:22
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
5 registered members (Martin_HH, TipmyPip, AndrewAMD, Grant, USER0328), 5,287 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
alx, ApprenticeInMuc, PatrickH90, USER0328, Sfrdragon
19199 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
checking if entity is in camera's field of view #167497
11/15/07 08:07
11/15/07 08:07
Joined: Sep 2007
Posts: 2
S
shades04 Offline OP
Guest
shades04  Offline OP
Guest
S

Joined: Sep 2007
Posts: 2
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!

Re: checking if entity is in camera's field of vie [Re: shades04] #167498
11/15/07 10:15
11/15/07 10:15
Joined: Jul 2007
Posts: 959
nl
F
flits Offline
User
flits  Offline
User
F

Joined: Jul 2007
Posts: 959
nl
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


"empty"
Re: checking if entity is in camera's field of vie [Re: flits] #167499
11/15/07 13:19
11/15/07 13:19
Joined: Jan 2007
Posts: 221
F
Fenriswolf Offline
Member
Fenriswolf  Offline
Member
F

Joined: Jan 2007
Posts: 221
Hi,

you can also use the clipped flag.

Re: checking if entity is in camera's field of vie [Re: Fenriswolf] #167500
11/15/07 23:33
11/15/07 23:33
Joined: Aug 2005
Posts: 312
Sweden
tindust Offline
Senior Member
tindust  Offline
Senior Member

Joined: Aug 2005
Posts: 312
Sweden
Search the forum. It's been discussed ...

here is one thread

cheers

Re: checking if entity is in camera's field of vie [Re: tindust] #167501
11/16/07 00:06
11/16/07 00:06
Joined: Apr 2006
Posts: 737
Ottawa, Canada
O
Ottawa Offline
User
Ottawa  Offline
User
O

Joined: Apr 2006
Posts: 737
Ottawa, Canada
Hi!

Are you redefining your var in the while loop?


var d[3]; and others
while ().....

Re: checking if entity is in camera's field of vie [Re: Ottawa] #167502
11/16/07 05:19
11/16/07 05:19
Joined: Sep 2007
Posts: 2
S
shades04 Offline OP
Guest
shades04  Offline OP
Guest
S

Joined: Sep 2007
Posts: 2
Ah, so simple! Thanks!

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


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1