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.

Dark GDK / How to get a Forward Vector?

Author
Message
endre3000
15
Years of Service
User Offline
Joined: 20th May 2009
Location:
Posted: 27th May 2009 01:02
Can someone show me how I might get a "forward vector" from a given 3D object? I would like to use it to then maintain, for example, a camera in line with the object. Thanks
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 27th May 2009 13:36 Edited at: 27th May 2009 13:36
Get the object position, using dbGetObjectPositionX/Y/Z, then use dbMoveObject with a distance of 1, and get the new position. Subtract the old position from the new position and you have the normalized forward vector. You might then want to reposition the object back at its old position.

endre3000
15
Years of Service
User Offline
Joined: 20th May 2009
Location:
Posted: 27th May 2009 22:01
Thanks, pretty creative, wouldn't have thought of that! Odd how GDK has things like dbMoveObject but not something like dbGetForwardVector, considering the previous function would need that vector to do its job.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 28th May 2009 08:59 Edited at: 28th May 2009 09:01
It should be simpler to use the dbObjectAngleX, dbObjectAngleY and dbObjectAngleZ functions to get the direction of the object and use the angles to set up the camera.

I looked up these functions in the documentation since I was pretty sure they exist. I hope they work but I haven't used them yet, because I have an object class which stores always the direction the object is facing (it is needed for my movement functions). That is yet another solution you can try.
endre3000
15
Years of Service
User Offline
Joined: 20th May 2009
Location:
Posted: 28th May 2009 11:43
Yeah... you're right. I guess I could get a normalized vector by taking cos(theta) (eg. dot product) of all angles to get each component. Thanks for the heads up.

It did work as Diggsey suggested though.

BTW, Mireben, do you have any suggestions for my other, somewhat related, more boggling camera problem?
http://forum.thegamecreators.com/?m=forum_view&t=151402&b=22

Login to post a reply

Server time is: 2024-11-25 10:26:54
Your offset time is: 2024-11-25 10:26:54