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 / A unit vector to the right of the camera pick vector

Author
Message
aersixb9
16
Years of Service
User Offline
Joined: 29th Nov 2007
Location:
Posted: 13th Dec 2007 20:34
Does anyone know how I can get a unit vector pointed to the right (and also up btw) of the direction that the camera is facing? I'm using the dbPick (or something like that) to get a unit vector in the direction the camera is facing...uh, here's the code



Anyways, I need to add A&D and Q&Z for accelerating left and right and up and down, how do I do this? Thanks.
aersixb9
16
Years of Service
User Offline
Joined: 29th Nov 2007
Location:
Posted: 13th Dec 2007 23:25 Edited at: 13th Dec 2007 23:26
What, nobody knows? Come on, I know you're a bunch of math-heads...does anyone know how to rotate a vector 90 degrees to the right? Around the y-axis? Uh...I can almost do that, I swear. I should have paid more attention in math...can I just use 2D rotations about the y axis??? How would I translate the 2D rotation into my 3 variable vector??? Is there a db function that does this for me??? (Like dbStrafeLeft() or something?) Wait, dbStrafeLeft wouldn't work, I really need a unit vector pointed right...or left...and up...or down...so my acceleration works...anyone?
tparkin
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location:
Posted: 14th Dec 2007 07:06
Hi,

You need to do a cross product of the unit vector you get from picking with the global right vector (1, 0, 0 ). The order matters. (Which one you cross with the other). When you do this properly you will get a resulting normalized vector pointing up, that is perpendicular to both your pick vector and the global right vector that you used.

dbCrossProductVector3() is what you need. Output the components of the resulting vector to see if you had the order right (there are only two options, right crossed with pick or pick crossed with right).

Hope this helps.
aersixb9
16
Years of Service
User Offline
Joined: 29th Nov 2007
Location:
Posted: 14th Dec 2007 19:23
I'm a little confused about how to use dbCrossProductVector3(int, int, int)...is there some kind of data type that holds a vector that I should be using? Why does dbCrossProductVector3(int,int,int) take 3 ints as parameters, and return void??? My current vector is <dbGetPickVectorX(), dbGetPickVectorY(), dbGetPickVectorZ()> and <1,0,0> ... how do I use dbCrossProductVector3 to obtain the cross product of these two vectors???
tparkin
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location:
Posted: 14th Dec 2007 19:42 Edited at: 14th Dec 2007 19:43
When you use dbMakeVector3() or whatever you specify an integer ID for the vector. That is the integer (the ID) that you pass into dbCrossProductVector3()



Now

should be your resulting vector
aersixb9
16
Years of Service
User Offline
Joined: 29th Nov 2007
Location:
Posted: 14th Dec 2007 19:54
It doesn't work...I tried lots of different numbers, but the direction of acceleration is not the correct direction! Also it seems that when the camera is rotated, the acceleration buttons accelerate in different directions with different camera rotations...is the basis of this approach (crossing <1,0,0> with the dbPickVector<> to accelerate right) correct, or did I just implement it wrong???? Here's my code:



Help! I'm so very bad at 3D math. Sorry about that.
aersixb9
16
Years of Service
User Offline
Joined: 29th Nov 2007
Location:
Posted: 14th Dec 2007 20:03
Wait, I fixed it! I juggled the numbers around (they needed some informal juggling...) does anyone want to explain to me why this code works and the previous code does not??? Heh, thanks. I totally don't get this at all...



Thanks, especially for the people who answered both my questions in an apparently accurate manner! You guys are awesome.
tparkin
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location:
Posted: 14th Dec 2007 20:03 Edited at: 14th Dec 2007 20:04
Edit: Removed my post, will update once I review your updated code.
aersixb9
16
Years of Service
User Offline
Joined: 29th Nov 2007
Location:
Posted: 14th Dec 2007 20:05
It's a spaceship! When you press W it accelerates forward, S accelerates backwards, A accelerates to the left, etc...the mouse rotates (just like a FPS!)...and uh, I think you answered my question too! About how you cross pick with right to get up...it's not obvious, I was crossing pick with right and expecting to get right. Thanks!
tparkin
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location:
Posted: 14th Dec 2007 20:09
Yes, you understand it. Crossing right with up gives you foward. Crossing foward with right gives you up. Etc.

This is why your changes to the code worked, for left/right you are crossing global up with pick vector to get the vector you needed.

Glad you got it working.
aersixb9
16
Years of Service
User Offline
Joined: 29th Nov 2007
Location:
Posted: 15th Dec 2007 03:32
Dang. After further testing, it actually doesn't work. I think the problem is this: what if the player is facing in the direction <1,0,0> and we cross that with <1,0,0> to get the up vector...will this produce the up vector? Same with the player facing up <0,1,0> and then crossing that with the up vector <0,1,0> will produce an invalid result??? Is there an error in the technique???
tparkin
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location:
Posted: 15th Dec 2007 05:12
The problem is that you are using static vectors to cross with as you described. I'm still unsure why or how you are using dbPickScreen()

What you need to do is use your Y rotation angle to calculate forward vector in the X-Z plane. You can do this by taking cos() and sin() of your Y rotation angle. In other words, your forward vector in the X-Z plane would be cos( angleY ), 0, sin( angleY )

This way, if you were rotated 60 degrees, your forward vector would be 0.5, 0, 0.86

Now you cross this with your global up vector (0,1,0) to get your actual right vector. Then you can add that resulting right vector to your ships position multiplied by your speed to move to the right. You can also subtract that vector multiplied by your speed to move left.
aersixb9
16
Years of Service
User Offline
Joined: 29th Nov 2007
Location:
Posted: 16th Dec 2007 03:42
I'm using dbPickScreen to get a unit vector in the direction that the camera is facing...

Uh, this is a 6-degrees of freedom game. The camera rotates in two directions currently, yaw (around the y-axis) and pitch (around the x-axis)...

I remember doing this in Direct3D, and I needed to use Quaternions...if that matters here...

"To the right" is a relative term, since the camera could be upside down, making the right actually a left! It could also be at a funny angle, making the "right" any arbitrary direction!

Help!!!
aersixb9
16
Years of Service
User Offline
Joined: 29th Nov 2007
Location:
Posted: 17th Dec 2007 22:34
Also, on a completely related topic, how do I get the forward-facing vector of an Object (from dbLoadObject), after I've rotated the object arbitrarily on all 3 axises?
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 17th Dec 2007 22:46
careful here - I'm no vector guru - but I do know - sometimes directly after an object move/rotate (same for Cam) If you try to poll the "new values" immediately it doesn't always work. Like - if I pitch up - the value might not be correct - so I'll move on a different plane:

Pitch Object Up 1,10
Turn Object Left 1,90
Turn Object Right 1,90

THEN Polling seems to return correct values very time Just something to keep in mind - its intermittant - but you'll know it when you run in to it - and its an easy fix. Moving on all three axis does "seem" to Squash the issue - its weird I know - but I've seen it and fixed stuff with this trick.

Login to post a reply

Server time is: 2024-10-08 18:24:43
Your offset time is: 2024-10-08 18:24:43