Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / If_In_Screen function

Author
Message
Zokomoko
22
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 15th Feb 2005 23:09 Edited at: 15th Feb 2005 23:19
[DBP]
Since in upgrade 5.7 the commands for object screen x, object screen y, and object in screen, don't seem to work as they should.
Instead, they tell you the object is on the screen when it's actually behind the camera.
I've finally came up with a function that will tell you if a certain object is behind the camera.





The function will return a value of 1 if the object is infront of the camera, and a value of zero if the object is behind the camera.

The function also uses a dummy object, the default object number of the dummt object is 90, but feel free to change it to whatever value you want.

There are two extra functions for distances, that are used in my function, so here they are if anyone's not familiar with them.


EDIT:

here's an example code.

RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 18th Feb 2005 04:01
Zokomo, this is very useful. Might I suggest a shorter method.



However, this method may not work with objects like a person, where the object's center might be between the object's "legs". You would have to offset the object (i.e. Offset Limb 1,0,0,Object Size Y(1)/2,0) so that the object's center is in the torso or somewhere solid.

"Droids don't rip your arms off when they lose." -H. Solo

REALITY II
Zokomoko
22
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 18th Feb 2005 11:55
It doesn't work for me.
When I ran it, it said the object was in front of the camera when it actually was not.

I'm using upgrade 5.7
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 19th Feb 2005 00:39 Edited at: 19th Feb 2005 00:46
Hmmm. Using 5.7 too. It was working so well for me, I programmed an AI to chase evasive balls by 'looking' at the screen instead of the 3d coords. I even tested that code before posting (not something I always do )

Edit: It's a litteral "in front of the camera" check, meaning if the object is in front of the camera's x/y plain, it's considered 'in front of the camera', even if you can't see the object because it's outside of the camera's field of view.

"Droids don't rip your arms off when they lose." -H. Solo

REALITY II
Zokomoko
22
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 19th Feb 2005 03:31
Oh.
I needed to make my function because I put an icon on every object.
and when the camera turned around, the icon should not appear because the object is behind the camera.
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 19th Feb 2005 07:20
I used a retical (sprite) in my program as well. I noticed the same thing, that the sprite would draw regardless if the object was behind or in front of the camera. When the object is just off to the side, it doesn't seem to matter much, neither the object or the sprite gets drawn. I just tried it (for the first time) with text - it works too. I was totally expecting an error for trying to write off of the screen. Give it a try.



"Droids don't rip your arms off when they lose." -H. Solo

REALITY II

Login to post a reply

Server time is: 2024-11-23 16:54:32
Your offset time is: 2024-11-23 16:54:32