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.

Preserving a blender camera's up vector.

2 posters

Go down

Preserving a blender camera's up vector. Empty Preserving a blender camera's up vector.

Post  gtmacdonald Sun Dec 14, 2008 10:37 pm

Hi Everyone,

I noticed that the up vector for cameras is hard coded to z-up (as of version 1.3.1). If you roll your Blender camera or point it straight down, you're likely to have issues. So I decided to hack the exporter and loading code. It seems to be working perfectly for me so I thought I'd share:

On line 554 in the exporter, right before the "CLOSE CAMERA" block insert this:

Code:

            #================================
            # UP POSITION
            #================================
            up = ( Blender.Mathutils.Vector( 0.0, 1.0, 0.0, 0.0 ) * obj.matrixWorld )

            buffer = "\tup( %s %s %s )\n" % ( optimize_float( up[0] ),
                                    optimize_float( up[1] ),
                                    optimize_float( up[2] ) )
            f.write( buffer )   

Then load the up vector using this modified function from sio2_camera.cc; note case 6 and the added "up" token.

Code:

unsigned char sio2CameraLoad( char *_root,
                      char *_tok,
                      char *_val )
{
   unsigned int i = 0;
   
   static const unsigned int n_token = 7;
   
   static char *token[ n_token ] = { "pos", "tar", "fov", "cstart", "cend", "iponame", "up" };
   
   
   if( !*_tok )
   {
      char name[ SIO2_MAX_CHAR ] = {""};
      sio2StringScanf( _val, "%s", name );
      sio2->_SIO2camera = sio2CameraInit( name );
      
      return 1;
   }
   
   
   while( i != n_token )
   {
      if( !sio2StringCmp( _tok, token[ i ] ) )
      { break; }
      
      ++i;
   }
   
   
   switch( i )
   {
      case 0:
      {
         sio2StringScanf( _val, "%f%f%f", &sio2->_SIO2camera->pos->x,
                     &sio2->_SIO2camera->pos->y,
                     &sio2->_SIO2camera->pos->z );
         return 1;
      }
         
         
      case 1:
      {
         sio2StringScanf( _val, "%f%f%f", &sio2->_SIO2camera->tar->x,
                     &sio2->_SIO2camera->tar->y,
                     &sio2->_SIO2camera->tar->z );      
         return 1;   
      }
         
      case 2:
      {
         sio2StringScanf( _val, "%f", &sio2->_SIO2camera->fov );
         return 1;      
      }
         
      case 3:
      {
         sio2StringScanf( _val, "%f", &sio2->_SIO2camera->cstart );
         return 1;      
      }
         
      case 4:
      {
         sio2StringScanf( _val, "%f", &sio2->_SIO2camera->cend );
         return 1;      
      }
         
      case 5:
      {
         sio2StringScanf( _val, "%s", sio2->_SIO2camera->iponame );      
         return 1;      
      }
      case 6:
      {
         sio2StringScanf( _val, "%f%f%f", &sio2->_SIO2camera->up->x,
                     &sio2->_SIO2camera->up->y,
                     &sio2->_SIO2camera->up->z );
         return 1;
      }
   }
   
   return 0;
}

-Greg

gtmacdonald

Posts : 9
Join date : 2008-12-11

Back to top Go down

Preserving a blender camera's up vector. Empty Re: Preserving a blender camera's up vector.

Post  sio2interactive Mon Dec 15, 2008 3:33 am

Looking good to me I will add it in 1.3.2... Tks for you contribution!

Cheers,
sio2interactive
sio2interactive

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

http://sio2interactive.com

Back to top Go down

Preserving a blender camera's up vector. Empty Re: Preserving a blender camera's up vector.

Post  sio2interactive Mon Dec 15, 2008 3:43 am

Hummmm actually testing your thing I found that its basically wrong... the vector is not normalized and when looking straight down the Y axis the up vector should be 0.0f, 0.0f, 1.0f, and if the camera Y rotation is 90 the up vector should be 0.0f, 1.0f, 0.0f etc...

Cheers,
sio2interactive
sio2interactive

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

http://sio2interactive.com

Back to top Go down

Preserving a blender camera's up vector. Empty Re: Preserving a blender camera's up vector.

Post  gtmacdonald Mon Dec 15, 2008 4:01 am

Oh, damn. I thought I had tested it enough. If I figure out a fix I'll repost. Sorry about that...

-Greg

gtmacdonald

Posts : 9
Join date : 2008-12-11

Back to top Go down

Preserving a blender camera's up vector. Empty Re: Preserving a blender camera's up vector.

Post  gtmacdonald Mon Dec 15, 2008 5:33 am

I think I needed to normalize and divide by w before. Hopefully this one will work better.

Code:

            #================================
            # UP POSITION
            #================================
            m = obj.matrixWorld.rotationPart()
            m = m.invert()
            m.transpose()
            up = ( Blender.Mathutils.Vector( 0.0, 1.0, 0.0 ) * m )
            up = up.normalize()
            
            buffer = "\tup( %s %s %s )\n" % ( optimize_float( up[0] ),
                                            optimize_float( up[1] ),
                                            optimize_float( up[2] ) )
            
            f.write( buffer )   

-Greg

gtmacdonald

Posts : 9
Join date : 2008-12-11

Back to top Go down

Preserving a blender camera's up vector. Empty Re: Preserving a blender camera's up vector.

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