View Full Version : Easy Flyby
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!!!
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
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...
:( :( :(
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 );
glFrustum( -width/height, width/height, -1, 1, 1, 8000 );
glMatrixMode( GL_MODELVIEW );
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 );
05-13-2004, 11:08 AM
nice.. almost there...
how can i find the roll, yaw, pitch ?
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
05-13-2004, 11:18 AM
Yeah! Its very easy indeed.
But HOW can i calculated then???
thank you guys!
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
05-13-2004, 11:44 AM
nice.. almost there...
by the way, do you know how to center the mouse in java?
sorry, no i don't. i think it's through the IUIComponent class, but not sure...
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.