Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,397 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
How to check if player is in sight of camera? #365345
03/25/11 16:02
03/25/11 16:02
Joined: Aug 2007
Posts: 74
Mahdi Offline OP
Junior Member
Mahdi  Offline OP
Junior Member

Joined: Aug 2007
Posts: 74
Hi,

I have a player and a static camera.

I want to check if camera can see the player.

Any way to do this?


I don't care!
Re: How to check if player is in sight of camera? [Re: Mahdi] #365346
03/25/11 16:07
03/25/11 16:07
Joined: Aug 2009
Posts: 1,438
Spain
painkiller Offline
Serious User
painkiller  Offline
Serious User

Joined: Aug 2009
Posts: 1,438
Spain
This is one way

Code:
if(vec_to_screen(player, camera)!=NULL)




3D Gamestudio A8 Pro
AMD FX 8350 4.00 Ghz
16GB RAM
Gigabyte GeForce GTX 960 4GB
Re: How to check if player is in sight of camera? [Re: painkiller] #365349
03/25/11 17:28
03/25/11 17:28
Joined: Aug 2007
Posts: 74
Mahdi Offline OP
Junior Member
Mahdi  Offline OP
Junior Member

Joined: Aug 2007
Posts: 74
Wow, thank you. I didn't know such a function already exists.


I don't care!
Re: How to check if player is in sight of camera? [Re: Mahdi] #365351
03/25/11 17:41
03/25/11 17:41
Joined: Aug 2009
Posts: 1,438
Spain
painkiller Offline
Serious User
painkiller  Offline
Serious User

Joined: Aug 2009
Posts: 1,438
Spain
huh I had an error there, it's player.x, not player


3D Gamestudio A8 Pro
AMD FX 8350 4.00 Ghz
16GB RAM
Gigabyte GeForce GTX 960 4GB
Re: How to check if player is in sight of camera? [Re: painkiller] #365353
03/25/11 18:13
03/25/11 18:13
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
It is camera.x as well instead of camera...


Always learn from history, to be sure you make the same mistakes again...
Re: How to check if player is in sight of camera? [Re: Uhrwerk] #365354
03/25/11 18:31
03/25/11 18:31
Joined: Aug 2009
Posts: 1,438
Spain
painkiller Offline
Serious User
painkiller  Offline
Serious User

Joined: Aug 2009
Posts: 1,438
Spain
haha yes,I'm too blind today...


3D Gamestudio A8 Pro
AMD FX 8350 4.00 Ghz
16GB RAM
Gigabyte GeForce GTX 960 4GB
Re: How to check if player is in sight of camera? [Re: painkiller] #365598
03/27/11 18:21
03/27/11 18:21
Joined: Aug 2007
Posts: 74
Mahdi Offline OP
Junior Member
Mahdi  Offline OP
Junior Member

Joined: Aug 2007
Posts: 74
It seems to be a bug with the vec_to_screen function.

Before anything else I say about the bug: You shouldn't use Player directly in the argument and also the Camera should not have a ".X" (I mean: camera.x).

this is the difinition:

vec_set(temp,player.x);
if (vec_to_screen(temp,camera) != NULL)
{
//Codes
}

there is no problem till here ok?

The buggy thing is here:

The problem I have is something strange.

Code:
if (my.flag1==on )
{
vec_set(temp,player.x);
if(vec_to_screen(temp, cam_sta)!=NULL)
{
//my codes
}

//if (vec_to_screen(temp, another_cam)!=NULL)
//{
//
//}
}



The problem is: this function I wrote should work without any problem. But it does not.

I accidentally noticed that the function works as I want only when an empty if clause like this, is used:

Code:
if (vec_to_screen(temp, another_cam)!=NULL)
{
//Nothing here. just emptiness!
}



When I comment the above if clause, the function doesn't work as I want.

Why this happens? I mean this is just an If statement and it does not apply any effects. But why it affects my function when I comment it?


Last edited by Mahdi; 03/27/11 18:42.

I don't care!
Re: How to check if player is in sight of camera? [Re: Mahdi] #365601
03/27/11 18:33
03/27/11 18:33
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
Why not use the CLIPPED eflag?

if (!(my.eflags&CLIPPED))

Re: How to check if player is in sight of camera? [Re: Mahdi] #365602
03/27/11 18:36
03/27/11 18:36
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
You're right about the second argument. A view is expected there, not a vector. My bad. Sorry about this. The if clause will modify your temp vector. I don't know if this helps. Post the rest of your code and please describe what "not working" means to you...

EDIT: You can use the CLIPPED flag as widi suggested, but this is not very precise. An object might not be visible on the screen but be clippped anyways.


Always learn from history, to be sure you make the same mistakes again...
Re: How to check if player is in sight of camera? [Re: Uhrwerk] #365607
03/27/11 20:06
03/27/11 20:06
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
if you're using more than one view use vec_for_screen, otherwise just use the CLIPPED flag
i've never had issues with an entity being visible but not having it's clipped flag set
(you can also use view_check() though i'd stick with one of the other methods, see here for a similar thread)

Page 1 of 2 1 2

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