Camera rotate about y-axis
5 posters
Camera rotate about y-axis
I've searched the forums and tutorials and cannot find a definitive answer on how to rotate the camera about the y-axis. I've tried _SIO2camera->_SIO2transform->rot->y and re-binding the matrix with sio2TransformBindMatrix(), but that has no effect. I've read on the forums to use sio2Lookat(), however I'm not quite sure how to use it to get the desired y rotation.
Any help would be appreciated. I'm still new to the SDK, but it's pretty sweet and I'm getting the hang of it. I just need a little more help from the experts.
Any help would be appreciated. I'm still new to the SDK, but it's pretty sweet and I'm getting the hang of it. I just need a little more help from the experts.
CadetCrusher- Posts : 21
Join date : 2009-10-07
Re: Camera rotate about y-axis
Here is an example below using sio2LookAt() in tutorial03 for a top-down view based on Z axis (UP).
- Code:
void templateRender( void )
{
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
vec3 eyes_point;
eyes_point.x = 0.0f;
eyes_point.y = -25.0f;
eyes_point.z = 0.0f;
vec3 center_reference_point;
center_reference_point.x = 0.0f;
center_reference_point.y = -24.0f;
center_reference_point.z = 0.0f;
vec3 direction_up_vector;
direction_up_vector.x = 0.0f;
direction_up_vector.y = 0.0f;
direction_up_vector.z = 1.0f;
SIO2camera *_SIO2camera = ( SIO2camera * )sio2ResourceGet( sio2->_SIO2resource,
SIO2_CAMERA,
"camera/Camera" );
if( _SIO2camera )
{
sio2Perspective( _SIO2camera->fov,
sio2->_SIO2window->scl->x / sio2->_SIO2window->scl->y,
_SIO2camera->cstart,
_SIO2camera->cend );
sio2WindowEnterLandscape3D();
{
sio2LookAt(&eyes_point, ¢er_reference_point, &direction_up_vector);
//sio2CameraRender( _SIO2camera );
// Render all solid object inside our
// main SIO2resource handle (in this
// case just a cube but...)
sio2ResourceRender( sio2->_SIO2resource,
sio2->_SIO2window,
_SIO2camera,
SIO2_RENDER_SOLID_OBJECT );
}
sio2WindowLeaveLandscape3D();
}
sio2ResetState();
}
Francescu- Posts : 136
Join date : 2009-03-18
Re: Camera rotate about y-axis
Thanks for that. Although, I'm not quite sure how to use sio2LookAt() to rotate the camera on the y-axis. Isn't there a straight forward way of doing it like in sio2TransformRotateZ()?
Anyway here's what I've tried with sio2LookAt()
But this does not work. I'm still new to 3d programming, so forgive me if I'm making some noobish mistakes.
Anyway here's what I've tried with sio2LookAt()
- Code:
vec3 center;
center.x = _SIO2camera->_SIO2transform->loc->x + sin(angle);
center.z = _SIO2camera->_SIO2transform->loc->z - cos(angle);
center.x = _SIO2camera->_SIO2transform->loc->y;
vec3 up;
up.x = 0.0f;
up.y = 1.0f;
up.z = 0.0f;
sio2LookAt(_SIO2camera->_SIO2transform->loc, ¢er, &up);
But this does not work. I'm still new to 3d programming, so forgive me if I'm making some noobish mistakes.
CadetCrusher- Posts : 21
Join date : 2009-10-07
Re: Camera rotate about y-axis
sio2LookAt work the same as gluLookAt and can be used like this:
sio2LookAt( vec3 <location in world space>, vec3 <target location in world space>, vec3 <normalized up vector>);
sio2LookAt( vec3 <location in world space>, vec3 <target location in world space>, vec3 <normalized up vector>);
Re: Camera rotate about y-axis
I guess I'm confused because I don't want to point the camera a a specific object or point, I just want to rotate the camera on its y-axis. I've done it with plain objects using object->_SIO2transform->rot->y successfully. So, when you say "vec3 <target location in world space>", I don't really know what that should be because I don't have any particular place I want the camera to look at. I'm trying to get the same effect as an airplane "roll". I've tried writing my own rotateY() function using sio2TransformRotateZ() as a template, but it only succeeds in making the camera "orbit" the y-axis, but not actually rotating it (camera does not "roll").
Thanks!
Thanks!
CadetCrusher- Posts : 21
Join date : 2009-10-07
Re: Camera rotate about y-axis
One of the tutorials (I think its tutorial04) has a camera move function in it... I spent some time butchering it and was able to get camera rotation working with that... I must have got rid of it though as I can't find the specific code.... but effectively you can use the SIO2transform function, just experiment with the values a bit....
Krypt- Posts : 15
Join date : 2009-09-21
Re: Camera rotate about y-axis
My coordinate system is:
Y-axis inside,z-axis under, x-axis left or right.
my camera need to roate Y-Axis, like airplane "roll".In the forum,I read a lot about the Y-axis rotation of articles,
I used the following method :
I need camera around its own Y axis rotation,my camera need to roate Y-Axis, like airplane "roll",I need to how to do? thank you very much!
Y-axis inside,z-axis under, x-axis left or right.
my camera need to roate Y-Axis, like airplane "roll".In the forum,I read a lot about the Y-axis rotation of articles,
I used the following method :
- Code:
angle_y+=1.0f;
vec3 eyes_point;
eyes_point.x =Myobject->_SIO2transform->loc->x-cosf(angle_y*0.0174532925f)*8.0f;
eyes_point.y = Myobject->_SIO2transform->loc->y;
eyes_point.z = Myobject->_SIO2transform->loc- >z+sinf(angle_y*0.0174532925f)*8.0f;
vec3 center_reference_point;
center_reference_point.x = Myobject->_SIO2transform->loc->x;
center_reference_point.y = Myobject->_SIO2transform->loc->y;
center_reference_point.z = Myobject->_SIO2transform->loc->z;
vec3 direction_up_vector;
direction_up_vector.x = 0.0f;
direction_up_vector.y = 0.0f;
direction_up_vector.z = 1.0f;
sio2LookAt(&eyes_point, ¢er_reference_point, &direction_up_vector);
I need camera around its own Y axis rotation,my camera need to roate Y-Axis, like airplane "roll",I need to how to do? thank you very much!
LuisLee- Posts : 85
Join date : 2009-04-26
Age : 37
Re: Camera rotate about y-axis
I ended up using glRotateF(), it works pretty well but make sure you "smooth" your angles to you don't jump in large steps (this makes the screen look jerky when rolling). Try something like this:
That should work, it did for me.
- Code:
glPushMatrix();
glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
/* remember that the angle here is the total angle to rotate from zero
(in contrast to sio2TransformRotateZ() where the angle is the amount to rotate relative to the current rotation
*/
// render your camera here. ex: sio2CameraRender(_SIO2camera); or similar
glPopMatrix();
That should work, it did for me.
CadetCrusher- Posts : 21
Join date : 2009-10-07
Re: Camera rotate about y-axis
CadetCrusher wrote:I ended up using glRotateF(), it works pretty well but make sure you "smooth" your angles to you don't jump in large steps (this makes the screen look jerky when rolling). Try something like this:
- Code:
glPushMatrix();
glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
/* remember that the angle here is the total angle to rotate from zero
(in contrast to sio2TransformRotateZ() where the angle is the amount to rotate relative to the current rotation
*/
// render your camera here. ex: sio2CameraRender(_SIO2camera); or similar
glPopMatrix();
That should work, it did for me.
thank you very much!
LuisLee- Posts : 85
Join date : 2009-04-26
Age : 37
Similar topics
» Can't rotate the Camera straight up or down
» How to rotate a object without changing the axis by SIO2?
» Rotating the Camera Around the Y-Axis
» Camera Rotate Y
» Rotate the camera instead of the object...
» How to rotate a object without changing the axis by SIO2?
» Rotating the Camera Around the Y-Axis
» Camera Rotate Y
» Rotate the camera instead of the object...
Permissions in this forum:
You cannot reply to topics in this forum