Skip to main content
gamedev.net
🔒 Locked

3D Math

Started by VoodooCHld Oct 10, 2000 at 6:56 PM 3 replies 250+ views
Original Post
VoodooCHld
VoodooCHld
ok ok ok. here is a fairly trivial ? but i am stumped. i have a multiple "actionable" objects in my world, doors, elevators, chest.... well i need a way of determining which object is in front of me, or would it be more reasonable to see what object is closest to me ? just wondering how others do it. voodoochld Code makes the world go round...
Code makes the world go round...
acw83
acw83
Clip the object against the view frustrum, then you know whether it is in fron of you or not.
WitchLord
WitchLord
Or just shoot a ray out in the direction of the camera and "use" the object that the ray hits first.

- WitchLord
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
VoodooCHld
VoodooCHld
I like the idea of shooting a ray, but how ? i am not familiar with that concept, if you could help, would appreciate it much. Right now i have implemented a routine, to search thru the "Actionable" objects, and find the one that is closest, and if it is within a certain distance, i act on it. Does this sound reasonable ?

thanks much

Code makes the world go round...
Code makes the world go round...
WitchLord
WitchLord
If you are not interested in accuracy, which is reasonable for most games, what you are doing should be just fine. You just need to add a test to make sure the object is actually in front of the camera/player. It would be really confusing if when trying to use an object in front of you, you instead open the door behind you just because it was closer.

The idea of the ray is that you draw a line from the camera''s position in the direction it is looking. And then you go through each object to see if they intersect the line. The object that intersects the line closest to the camera is the one that is hit first by the ray. Of course, objects that are too far away don''t need to do any intersection test. With this way you get an exact object picking method, so that the object that is under the player''s reticle is the one that is used. It does require a lot more coding though, so if you don''t need it I would stick with what you''ve already got.

- WitchLord
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.