GLBasic forum

Main forum => GLBasic - en => Topic started by: planetm on 2007-Aug-05

Title: 3D Navigation - Help Required!
Post by: planetm on 2007-Aug-05
I've just begun using the 3D functions of GLBasic. I've coded a very basic tool which plots a graph in 3D (for anybody that cares, I'm plotting number of neutrons against number of protons against binding energy per nucleon for about 3000 isotopes, produces the 'nuclear valley' shape - this is not relevant to my question though!). I'm amazed just how easy this has been in GLBasic, but now I want to be able to 'fly' around my graph.

My maths ability is pretty good and I have a reasonable grasp of vectors in 2D, but I can't get my head around how to code the movement stuff in 3D. I've searched around some and found references to cross products and the like but this is unfamiliar to me.

Ideally I'd like to 'fly' around the graph using a first person type control method. Something like arrow keys to go forwards/backwards and side to side, plus a mouselook type function. I'm storing the camera position cx,cy,cz and the direction relative to the camera dx,dy,dz and assume there are pretty standard functions used in 3D programming to process these for the type of movement i'm looking for.

Please could somebody point me in the direction of a good tutorial, or even provide some glbasic code for me to incorporate or build upon.

Thanks,

Matt.
Title: 3D Navigation - Help Required!
Post by: Kitty Hello on 2007-Aug-06
Well, you have 2 verctors then. One for the position of the camera, and one for the direction you're looking at.
Then you can call:
X_CAMERA x,y,z,   dx+x, dy+y, dz+y
where x,y,z = position, dx,dy,dz=direction (maybe unified, does not matter)

if you want to rotate in the x,z layer, use:
dx = cos(phi)
dz = -sin(phi)

for rotation around the up-down axis use:

dx = cos(phi) * cos(psi)
dy =                sin(psi)
dz = -sin(phi)*cos(psi)
Title: 3D Navigation - Help Required!
Post by: planetm on 2007-Aug-06
Thanks Gernot. I've still got quite a lot to learn regarding this 3d stuff, but I'm a step closer - I can now move around my graph :)