PDA

View Full Version : Easy Flyby



Gelero
05-13-2004, 08:42 AM
Hi there... I'm almost giving up... :(

Can you help me to write a camera movement in a 3d space? I got my context ok, but i really can't make the whole yaw, pitch, cos's and sin's thing getting in the work...

And it will by totally unbeliaveble, if I can control the camera's rotation via mouse... Like 1st person engines...

I have been trying this for months and no success at all

Can somebody share some code??!?! I've made a lot of searchs through the forum, but no good.

Please, please.. Save me!!!
:( (

brcain
05-13-2004, 09:10 AM
This may be more of a heavy-handed solution than you are looking for but ...

You could try looking at the source for Producer::Camera that's used by OpenSceneGraph. Once you download the source ... look at .../Producer/include/Producer/Camera and .../Producer/src/Camera.cpp.

For OpenSceneGraph go to http://openscenegraph.sourceforge.net.

For Producer go to http://www.andesengineering.com/Producer/index.html

Gelero
05-13-2004, 09:18 AM
no man... I guess you are just making way more dificult.

just, i dont know, throw some pseudo code here...
:( :( :(

05-13-2004, 10:50 AM
void FirstPersonView( vec3 camera, float yaw, float pitch, float roll )
{

// 90 degree field of view in y
// near_z = 1 far_z = 8000
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glFrustum( -width/height, width/height, -1, 1, 1, 8000 );

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glRotatef( -roll, 0, 0, 1 ); // around forward
glRotatef( -pitch, 1, 0, 0 ); // around right
glRotatef( -yaw, 0, 1, 0 ); // around up
glTranslatef( -camera.x, -camera.y, -camera.z );

}

Gelero
05-13-2004, 11:08 AM
nice.. almost there...

how can i find the roll, yaw, pitch ?

05-13-2004, 11:12 AM
just keep track of them for the player...

player looks left-right, then change yaw

player looks up-down, then change pitch

player looks leans left-right, then change roll

easy! :)

Gelero
05-13-2004, 11:18 AM
Yeah! Its very easy indeed.

But HOW can i calculated then???
:D

thank you guys!

05-13-2004, 11:30 AM
if player moves mouse in xy

player.yaw -= mouse_x - old_mouse_x

player.pitch -= mouse_y - old_mouse_y

then warp mouse xy back to center of screen

Gelero
05-13-2004, 11:44 AM
nice.. almost there...

by the way, do you know how to center the mouse in java?

05-13-2004, 12:42 PM
sorry, no i don't. i think it's through the IUIComponent class, but not sure...