moving camera with constraint

View previous topic View next topic Go down

moving camera with constraint

Post  andi1492 on Sat Jun 06, 2009 10:39 am

hi. I want to move my camera around my object in a special radius when I'm touch-moving left or right so that the camera always looks to the object.

I made a constraint in blender, but this doesnt work in sio2.

does someone know how to solve my problem?

i tried it with:
Code:
vec2 d;
   d.y = sio2->_SIO2window->touch[ 0 ].x - start.x;
   d.x = start.y - sio2->_SIO2window->touch[ 0 ].y;
   
   if( d.x > 5.0f )
   {
      turnAround = turnAround + 0.002f;
   }
   else if( d.x < -5.0f )
   {
      turnAround = turnAround - 0.002f;
      
   }
cameraLoc->x = sinf(turnAround) * 5.0f;
cameraLoc->y = cosf(turnAround) * 5.0f;
in the function void templateScreenTouchMove( void *_ptr )

but the camera doesnt look to my object.

andi1492

Posts : 4
Join date : 2009-05-04

View user profile

Back to top Go down

Re: moving camera with constraint

Post  oioioi on Sat Jun 06, 2009 12:03 pm

You can use sio2rotate3d() to set the camera position(rotating it around your object) and the set camera->_SIO2transform->dir to object->_SIO2transform->loc. Look at tutorial 9 for more info on how to do this

oioioi

Posts : 136
Join date : 2008-12-02
Location : Norway

View user profile

Back to top Go down

Re: moving camera with constraint

Post  andi1492 on Sat Jun 06, 2009 3:24 pm

i dont get it. i dont use physics...does that matter?

i tried to implement the code from tut09 but it doesn't work.

andi1492

Posts : 4
Join date : 2009-05-04

View user profile

Back to top Go down

Re: moving camera with constraint

Post  Francescu on Sat Jun 06, 2009 3:57 pm

andi1492 wrote:i dont get it. i dont use physics...does that matter?
No it doesn't - does tutorial09 really make use of physics heavily? not really - sure it does but it is mostly ray casting / hitting involved in that example.

If you follow this tutorial closely, it explains how to set-up the camera position from a moving target which is a 3rd person player in that case.

Without posting sample code using tutorial09, it is not possible to diagnose why it is not working.

Sounds like what you want is some kind of Camera Orbiting around a point.
There is an example posted in the forums - this might help you:
http://sio2interactive.forumotion.net/sio2-engine-f3/arcball-camera-up-down-rotation-bug-t405.htm
using this example you can always make the pitch a fixed value if this is what you want.


Last edited by Francescu on Sat Jun 06, 2009 4:25 pm; edited 1 time in total

Francescu

Posts : 136
Join date : 2009-03-18

View user profile

Back to top Go down

Re: moving camera with constraint

Post  oioioi on Sat Jun 06, 2009 4:10 pm

Hmmmm... Try this:
Code:
...
float ROTZ;
...

templateRender()//or what ever function you use for rending the scene
{
   ...
   SIO2object *object = ( SIO2object * )sio2ResourceGet( sio2->_SIO2resource,
                                      SIO2_OBJECT,
                                      "object/cube" );//remember to change it to the right name!
   if( object )
   {
      vec3 tmp_pos;
      //find the pos of the camera, you can test out different values in the second  and third parameters(is that the right word?)
      sio2Rotate3D( object->_SIO2transform->loc, 10.0f, ROTZ, 15.0f, &tmp_pos );
      sio2TransformSetLoc( sio2->_SIO2camera->_SIO2transform, tmp_pos);

      tmp_pos.x = object->_SIO2transform->loc->x;
      tmp_pos.y = object->_SIO2transform->loc->y;
      tmp_pos.z = object->_SIO2transform->loc->z;
            
      // Update the camera direction.
      sio2Vec3Diff( &tmp_pos,
               sio2->_SIO2camera->_SIO2transform->loc,
                sio2->_SIO2camera->_SIO2transform->dir );
            
      / Make sure that our camera direction is properly normalized.
      sio2Normalize( sio2->_SIO2camera->_SIO2transform->dir,
               sio2->_SIO2camera->_SIO2transform->dir );
   }
   sio2CameraRender( sio2->_SIO2camera );

   sio2CameraUpdateFrustum( sio2->_SIO2camera );

   sio2ResourceCull( sio2->_SIO2resource,
              sio2->_SIO2camera );         

   sio2ResourceRender( sio2->_SIO2resource,
               sio2->_SIO2window,
               sio2->_SIO2camera,
               SIO2_RENDER_SOLID_OBJECT );
   ...
}


vec2 start;
void templateScreenTap( void *_ptr, unsigned char _state )
{
   if( _state == SIO2_WINDOW_TAP_DOWN )
   {
      start.x = sio2->_SIO2window->touch[ 0 ].x;
      start.y = sio2->_SIO2window->touch[ 0 ].y;
   }
}


void templateScreenTouchMove( void *_ptr )
{
   if( sio2->_SIO2window->n_touch )
   {
      vec2 d;
      d.y = start.x - sio2->_SIO2window->touch[ 0 ].x;
      d.x = sio2->_SIO2window->touch[ 0 ].y - start.y;
      start.x = sio2->_SIO2window->touch[ 0 ].x;
      start.y = sio2->_SIO2window->touch[ 0 ].y;
      
      if( d.y > 0.1 || d.y < -0.1 )
         ROTZ += -d.y * 0.4f ;
      }
   }
}
I just took some code from some different projects so I'm not sure if it works or if there is any errors in it, just let me know if something is wrong. If you want you could change the touchMove function to the one in tutorial 2 if you think that works better. And one last thing, this doesn't work with multi touch(multi touch requires some modification)

oioioi

Posts : 136
Join date : 2008-12-02
Location : Norway

View user profile

Back to top Go down

Re: moving camera with constraint

Post  andi1492 on Sat Jun 06, 2009 6:12 pm

thanks man !
it works =) yippiie Smile

andi1492

Posts : 4
Join date : 2009-05-04

View user profile

Back to top Go down

Re: moving camera with constraint

Post  Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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