FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Camera rotate about y-axis

5 posters

Go down

Camera rotate about y-axis Empty Camera rotate about y-axis

Post  CadetCrusher Thu Oct 15, 2009 12:35 am

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. Very Happy

CadetCrusher

Posts : 21
Join date : 2009-10-07

Back to top Go down

Camera rotate about y-axis Empty Re: Camera rotate about y-axis

Post  Francescu Thu Oct 15, 2009 1:23 am

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, &center_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

Back to top Go down

Camera rotate about y-axis Empty Re: Camera rotate about y-axis

Post  CadetCrusher Thu Oct 15, 2009 3:31 pm

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()

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, &center, &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

Back to top Go down

Camera rotate about y-axis Empty Re: Camera rotate about y-axis

Post  sio2interactive Thu Oct 15, 2009 3:41 pm

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>);
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 44
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Camera rotate about y-axis Empty Re: Camera rotate about y-axis

Post  CadetCrusher Thu Oct 15, 2009 4:00 pm

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!

CadetCrusher

Posts : 21
Join date : 2009-10-07

Back to top Go down

Camera rotate about y-axis Empty Re: Camera rotate about y-axis

Post  Krypt Fri Oct 16, 2009 6:09 am

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

Back to top Go down

Camera rotate about y-axis Empty Re: Camera rotate about y-axis

Post  LuisLee Mon Oct 19, 2009 9:41 pm

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 :
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, &center_reference_point, &direction_up_vector);
but it Around the Y-axis rotation.
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! Very Happy

LuisLee

Posts : 85
Join date : 2009-04-26
Age : 36

Back to top Go down

Camera rotate about y-axis Empty Re: Camera rotate about y-axis

Post  CadetCrusher Tue Oct 20, 2009 11:20 pm

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.

CadetCrusher

Posts : 21
Join date : 2009-10-07

Back to top Go down

Camera rotate about y-axis Empty Re: Camera rotate about y-axis

Post  LuisLee Wed Oct 21, 2009 12:47 am

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! Very Happy

LuisLee

Posts : 85
Join date : 2009-04-26
Age : 36

Back to top Go down

Camera rotate about y-axis Empty Re: Camera rotate about y-axis

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum