Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
4 registered members (AndrewAMD, Quad, soulman3, Ayumi), 675 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 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 | chip programmers | 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