sio2CameraRender ...why all those operations? :)

View previous topic View next topic Go down

sio2CameraRender ...why all those operations? :)

Post  glDisable on Tue Aug 25, 2009 11:53 am

Hi! I looked in sio2CameraRender months ago and in v 1.4.0 there is a part of code that didn't changed and it "squeezes" my brain. I don't understand why are you doing all that operations when you have all the time that "vec3 v" initialized to ( 0, 0, 1 ) ?
This part of the code:

Code:
   v.x =
   v.y = 0.0f;
   v.z = 1.0f;
   
   _SIO2camera->_SIO2transform->mat[ 0  ] = ( _SIO2camera->_SIO2transform->dir->y * v.z ) - ( _SIO2camera->_SIO2transform->dir->z * v.y );
   _SIO2camera->_SIO2transform->mat[ 4  ] = ( _SIO2camera->_SIO2transform->dir->z * v.x ) - ( _SIO2camera->_SIO2transform->dir->x * v.z );
   _SIO2camera->_SIO2transform->mat[ 8  ] = ( _SIO2camera->_SIO2transform->dir->x * v.y ) - ( _SIO2camera->_SIO2transform->dir->y * v.x );

   _SIO2camera->_SIO2transform->mat[ 1  ] = ( _SIO2camera->_SIO2transform->mat[ 4 ] * _SIO2camera->_SIO2transform->dir->z ) -
                                  ( _SIO2camera->_SIO2transform->mat[ 8 ] * _SIO2camera->_SIO2transform->dir->y );
                                 
   _SIO2camera->_SIO2transform->mat[ 5  ] = ( _SIO2camera->_SIO2transform->mat[ 8 ] * _SIO2camera->_SIO2transform->dir->x ) -
                                  ( _SIO2camera->_SIO2transform->mat[ 0 ] * _SIO2camera->_SIO2transform->dir->z );
                                 
   _SIO2camera->_SIO2transform->mat[ 9  ] = ( _SIO2camera->_SIO2transform->mat[ 0 ] * _SIO2camera->_SIO2transform->dir->y ) -
                                  ( _SIO2camera->_SIO2transform->mat[ 4 ] * _SIO2camera->_SIO2transform->dir->x );

   _SIO2camera->_SIO2transform->mat[ 2  ] = -_SIO2camera->_SIO2transform->dir->x;
   _SIO2camera->_SIO2transform->mat[ 6  ] = -_SIO2camera->_SIO2transform->dir->y;
   _SIO2camera->_SIO2transform->mat[ 10 ] = -_SIO2camera->_SIO2transform->dir->z;

   _SIO2camera->_SIO2transform->mat[ 15 ] = 1.0f;

A lot of terms will dissapear if you do the "0"-s and "1"-s computations from v and remove the redundant terms in these equations.
Also mat[ 8 ] is always zero and mat[ 15 ] = 1.0f is not necessary.
In the end you will have something more simpler:

Code:
   _SIO2camera->_SIO2transform->mat[ 0  ] =  _SIO2camera->_SIO2transform->dir->y
   _SIO2camera->_SIO2transform->mat[ 4  ] = - _SIO2camera->_SIO2transform->dir->x;

   _SIO2camera->_SIO2transform->mat[ 1  ] =  ( _SIO2camera->_SIO2transform->mat[ 4 ] * _SIO2camera->_SIO2transform->dir->z );                                 
   _SIO2camera->_SIO2transform->mat[ 5  ] = - ( _SIO2camera->_SIO2transform->mat[ 0 ] * _SIO2camera->_SIO2transform->dir->z );
                                 
   _SIO2camera->_SIO2transform->mat[ 9  ] = ( _SIO2camera->_SIO2transform->mat[ 0 ] * _SIO2camera->_SIO2transform->dir->y ) -
                                  ( _SIO2camera->_SIO2transform->mat[ 4 ] * _SIO2camera->_SIO2transform->dir->x );

   _SIO2camera->_SIO2transform->mat[ 2  ] = -_SIO2camera->_SIO2transform->dir->x;
   _SIO2camera->_SIO2transform->mat[ 6  ] = -_SIO2camera->_SIO2transform->dir->y;
   _SIO2camera->_SIO2transform->mat[ 10 ] = -_SIO2camera->_SIO2transform->dir->z;

glDisable

Posts : 3
Join date : 2009-03-11

View user profile

Back to top Go down

Re: sio2CameraRender ...why all those operations? :)

Post  sio2interactive on Tue Aug 25, 2009 4:42 pm

Haven't tested it, but it look about right... personally I never use sio2CameraRender and use sio2LookAt... that's probably why I never go back in it to check Wink

_________________
SIO2 Interactive
Free Open Source 3D Game Engine for iPhone and iPod Touch
http://sio2interactive.com
avatar
sio2interactive

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

View user profile http://sio2interactive.com

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