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.

AppGameKit Classic Chat / Question about direction vectors.

Author
Message
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 20th Jan 2016 22:52
Hello, what's the quickest way to get a direction vector based on the direction the camera is facing?

I could do it with moving a temporary object at the cameras location, but there has to be a more efficient pure maths way to do it?
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Jan 2016 01:48 Edited at: 21st Jan 2016 01:50
Converts an Angle (in degrees) to a 2Dvector and a 2Dvector to and angle. If the Angle is in radians then you need to use the rad functions like sinrad() and cosrad(). The angle must be between 0 and 360
I think you might be looking for a 3D vector though.
Thanks to Phaelax for the vector routines


Sign up for NaGaCreMo!
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 21st Jan 2016 08:26
Yes, I need a 3D vector. Thanks anyway.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 22nd Jan 2016 02:47 Edited at: 22nd Jan 2016 03:05
http://snipd.net/2d-and-3d-vector-normalization-and-angle-calculation-in-c
you need to translate C to basic but it seems pretty straight forward. just remember that the AppGameKit sin/cos functions are based on degrees not radians use sinrad/cosrad for radians

my apologies. i got that the wrong way around. i am buggered if i can find any sort of reasonable example of converting angles to 3D vectors

Sign up for NaGaCreMo!
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 22nd Jan 2016 08:28
Cheers, In the end I used the most simple method I could think of to get it working...



Not ideal, but got the job done! lol
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 22nd Jan 2016 09:44
Quote: "Not ideal, but got the job done! lol"


This is what I love about AppGameKit! If it works man, use it!

You could do the same with a dummy object like an invisible cube. It might be a little more efficient than moving the camera.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 22nd Jan 2016 12:53
Perhaps, but it took less lines of code to use the camera, especially since I'm after the cameras direction vector.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 22nd Jan 2016 15:19
I'm not 100% sure about this, but I think this might be it.

N.x = sin(GetCameraAngleY(1))
N.z = cos(GetCameraAngleY(1))
N.y = -tan(GetCameraAngleX(1))

Based on my notes.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 23rd Jan 2016 16:52
I'll give it a try, cheers!

Login to post a reply

Server time is: 2024-09-29 09:19:15
Your offset time is: 2024-09-29 09:19:15