Using my own camera

View previous topic View next topic Go down

Using my own camera

Post  Cobbler on Mon Feb 09, 2009 9:33 pm

I'm using my own camera code so I'm setting up the modelview- and projection-stacks myself.

To render I need a SIO2 Camera so I set one up like this:
Code:
sio2->_SIO2camera = sio2CameraInit("GameCamera");

And then to render the resources:
Code:
sio2CameraUpdateFrustum( sio2->_SIO2camera );
sio2ResourceCull( sio2->_SIO2resource, sio2->_SIO2camera );
sio2ResourceRender( sio2->_SIO2resource, sio2->_SIO2window,   sio2->_SIO2camera, SIO2_RENDER_SOLID_OBJECT | SIO2_RENDER_CLIPPED_OBJECT );

Now, I created a scene in Blender with just the monkey head, no materials, didn't change any settings. It looks like every other face is backface-culled (kind of like when the vertex winding is messed up when stripping for instance). I'm thinking it must be the data but I just thought I'd get some advice here before I start debugging... Smile

Cobbler

Posts : 15
Join date : 2009-02-01

View user profile

Back to top Go down

Re: Using my own camera

Post  sw on Mon Feb 09, 2009 11:39 pm

sio2CameraSetPerspective ???

and do NOT set your camera look at {0 , 0 ,0 }
avatar
sw

Posts : 73
Join date : 2008-10-12

View user profile

Back to top Go down

Re: Using my own camera

Post  Cobbler on Mon Feb 09, 2009 11:44 pm

I'm setting up the modelview- AND projection-stacks with my own code. All my debug drawing works just fine.

My projection matrix is different than the SIO2 projection matrix but that shouldn't give me the issue I'm seeing.

Cobbler

Posts : 15
Join date : 2009-02-01

View user profile

Back to top Go down

glFrustum

Post  freakTheMighty on Thu Mar 05, 2009 11:43 pm

I am just begin to explore SIO2, seeing if it makes sense for my project. I am wondering if it is possible to design portions of the game in blender and others outside? As the first poster seems to have alluded to, I think that I would like to use an opengl camera not defined by a blender camera. Is this possible?

Thank you.

freakTheMighty

Posts : 12
Join date : 2009-03-05

View user profile

Back to top Go down

Re: Using my own camera

Post  sio2interactive on Fri Mar 06, 2009 12:22 am

Absolutely the culling system is based on the reconstruction of frustum planes, simply render your camera, then use a dummy camera to store the current frustum.

Code:


// Render your camera

// Use a dummy camera to hold the frustum data
sio2CameraUpdateFrustum( sio2->_SIO2camera );
      
// Cull the objects in the resource base on that frustum
sio2ResourceCull( sio2->_SIO2resource, sio2->_SIO2camera );

// Render the objects   
sio2ResourceRender( sio2->_SIO2resource, sio2->_SIO2window, sio2->_SIO2camera, SIO2_RENDER_SOLID_OBJECT | SIO2_RENDER_ALPHA_OBJECT );


If you need to use other SIO2 features that are based on the SIO2camera data (in example the billboards), just fill in the data manually from your camera data and that's it 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

Re: Using my own camera

Post  meteors on Fri Mar 06, 2009 6:08 am

"do NOT set your camera look at {0 , 0 ,0 }"


Why?


-j
avatar
meteors

Posts : 241
Join date : 2008-11-08
Location : Sunny Florida

View user profile

Back to top Go down

adding glfrustumf to tutorial2

Post  freakTheMighty on Sun Mar 22, 2009 4:06 pm

I am trying to alter Tutorial2 to use a projection matrix defined by glfrustumf. I've added these lines per Mr. SIO2's instruction. What i've done causes the program to break when it reaches SIO2's getprojectionmatrix method. This is the function where it breaks. This makes me think that there is no projection matrix to get.

First: Does anyone know what I'm doing wrong?
Second: How do I position and orient an opengl camera relative to an SIO2 scene?

Code:

         //Set the OpenGL projection matrix
         glMatrixMode(GL_PROJECTION);
         glFrustumf(-.5,.5,-.5,.5,.01,1000);
         //glViewport(0, 0, 320, 240);
         
         // Use a dummy camera to hold the frustum data
         sio2CameraUpdateFrustum( sio2->_SIO2camera );
         
         // Cull the objects in the resource base on that frustum
         //sio2ResourceCull( sio2->_SIO2resource, sio2->_SIO2camera );
         // Render our camera.
         sio2CameraRender( _SIO2camera );

I'm hoping to get a hold of working with projection matrices and the SIO2 structure.

Thanks for the help,
Jesse

freakTheMighty

Posts : 12
Join date : 2009-03-05

View user profile

Back to top Go down

Re: Using my own camera

Post  sio2interactive on Sun Mar 22, 2009 4:27 pm

Put back the matrix mode to GL_MODELVIEW before sio2CameraUpdateFrustum

_________________
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

MODEL_VIEW

Post  freakTheMighty on Sun Mar 22, 2009 4:31 pm

Thanks for the response. Setting it back to model_view doesn't fix the problem. The code breaks at the same point.

freakTheMighty

Posts : 12
Join date : 2009-03-05

View user profile

Back to top Go down

Re: Using my own camera

Post  sio2interactive on Sun Mar 22, 2009 4:42 pm

Have you initialize SIO2?

_________________
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

building on Tut2

Post  freakTheMighty on Sun Mar 22, 2009 4:50 pm

I am working from tutorial2 so where in tutorial2 is the sio2 object initialized? I don't see it in template.mm

freakTheMighty

Posts : 12
Join date : 2009-03-05

View user profile

Back to top Go down

Re: Using my own camera

Post  freebird373 on Sun Mar 22, 2009 8:42 pm

I used this in template.m in tutorial 15 to use my own camera.
I just ignored sio2->_SIO2camera. I guess you could initialize it to zero.

Code:
void templateRender( void )
{
   glMatrixMode( GL_MODELVIEW );
   glLoadIdentity();

   glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );

/*
   if( !sio2->_SIO2camera )
   {
   SIO2camera *_SIO2camera = ( SIO2camera * )sio2ResourceGet( sio2->_SIO2resource, SIO2_CAMERA, "camera/Camera" );
   if( !_SIO2camera )
   { return; }

   sio2->_SIO2camera = _SIO2camera;
      
   sio2CameraSetPerspective( _SIO2camera, sio2->_SIO2window );
   }
*/   
   
   // Setup Camera Manually
   glMatrixMode( GL_PROJECTION );
   glLoadIdentity();
   
   glFrustumf( -0.0005705f, 0.0005705f, -0.000761f,  0.000761f, 0.1f, 10000.0f );
   cam_lookAt(8.904, -23.491, 10.53, 0, 0, 0, 0.0f, 0.0f, -1.0f);
   
   glMatrixMode( GL_MODELVIEW );

   // sio2WindowEnterLandscape3D();
   
   
   {
      // Use a static time step for the physic simulation.
      sio2PhysicRender( sio2->_SIO2physic, 1.0f / 60.0f, 0 );         
   
      // sio2CameraRender( sio2->_SIO2camera );

      //sio2CameraUpdateListener( (SIO2camera*) sio2ResourceGet( sio2->_SIO2resource,
       //                                         SIO2_CAMERA,
       //                                            "camera/Camera" ) );

      // We have an ambient sound that is streaming from
      // memory, this command will automatically update
      // the stream and swap the buffer. Toggle the "UseAlpha"
      // button in the Map Image panel withing blender to
      // activate it. However when using double buffer the
      // soundbuffer cannot be indepently shared among
      // sound source. Since the sound buffer will be
      // dynamically updated on a global scale, it is impossible
      // to have an independent playback on a sound source
      // basis. Use it with care... my suggestion is that the
      // ambient music should be streamed and all other
      // sound FX should be directly pushed into memory.
                           
      sio2ResourceRender( sio2->_SIO2resource,
                     sio2->_SIO2window,
                     sio2->_SIO2camera,
                     SIO2_RENDER_SOLID_OBJECT | SIO2_UPDATE_SOUND_STREAM );

   }
   
   //sio2WindowLeaveLandscape3D();
}

freebird373

Posts : 10
Join date : 2008-11-21

View user profile

Back to top Go down

cam look at function

Post  freakTheMighty on Sun Mar 22, 2009 9:57 pm

Thanks for the help. Would you mind showing me your camlookat function?

freakTheMighty

Posts : 12
Join date : 2009-03-05

View user profile

Back to top Go down

Re: Using my own camera

Post  sio2interactive on Sun Mar 22, 2009 11:01 pm

Its probably the same as sio2LookAt 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

Re: Using my own camera

Post  Jawdy on Mon Mar 23, 2009 3:19 am

meteors wrote:"do NOT set your camera look at {0 , 0 ,0 }"


Why?


-j
I tried this and searched around - you can't look directly up or down the Z axis. I would think it is something to do with the translation/rotation matrices, but without delving _too_ deep, I can't answer for sure. If you're going to lock the axis to look straight down (i.e. 2D) then look for the details on this forum about setting 2D mode.
I did what someone else suggested - locked it to the X or Y axis, as I'm not using physics but still want 3D objects in a 2D plane.
avatar
Jawdy

Posts : 65
Join date : 2009-03-17
Location : UK

View user profile http://www.gaslightgames.co.uk

Back to top Go down

Re: Using my own camera

Post  freebird373 on Mon Mar 23, 2009 4:20 pm

Yeah, it is pretty much the same as sio2LookAt, but it is an all in one function (other than opengl and math calls).
Based on the mesa 3d lib version.

/
Code:
/ ====================================================================================== //
// // Adapted from the gluLookAt Mesa Graphics lib ( http://www.mesa3d.org) and the Oolong3d engine.
// ====================================================================================== //
void cam_lookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx, GLfloat centery, GLfloat centerz, GLfloat upx, GLfloat upy, GLfloat upz) {
      GLfloat m[16];
      float fmult, magf;
      GLfloat z1, z2, z3, y1, y2, y3, x1, x2, x3;
      
      z1 = eyex - centerx;
      z2 = eyey - centery;
      z3 = eyez - centerz;
      magf = sqrtf( z1 * z1 + z2 * z2 + z3 * z3);
      if ( magf != 0 ) {
         fmult = ( 1.0f / magf);
      } else {
         fmult = 0;
      }
      z1 *= fmult;
      z2 *= fmult;
      z3 *= fmult;
       
      x1 = upy * z3 - upz * z2;
      x2 = -upx * z3 + upz * z1;
      x3 = upx * z2 - upy * z1;
      y1 = z2 * x3 - z3 * x2;
      y2 = -z1 * x3 + z3 * x1;
      y3 = z1 * x2 - z2 * x1;
   
      magf = sqrtf(  x1 * x1 + x2 * x2 + x3 * x3);
      if ( magf != 0 ) {
         fmult = (1.0f / magf);
      } else {
         fmult = 0;
      }

      x1 *= fmult;
      x2 *= fmult;
      x3 *= fmult;

      magf = sqrtf( y1 * y1 + y2 * y2 + y3 * y3 );
      if ( magf != 0 ) {
         fmult = ( 1.0f / magf);
      } else {
         fmult = 0;
      }
      y1 *= fmult;
      y2 *= fmult;
      y3 *= fmult;
   
      m[0] = x1;
      m[4] = x2;
      m[8] = x3;
      
      m[1] = y1;
      m[5] = y2;
      m[9] = y3;
      
      m[2] = z1;
      m[6] = z2;
      m[10] = z3;
      
      m[12] = m[13] = m[14] = m[3] = m[7] = m[11] = 0.0f;
      
      m[15] = 1.0f;

      glMultMatrixf( m );
      glTranslatef(-eyex, -eyey, -eyez);
   
} // cam_lookAt



freebird373

Posts : 10
Join date : 2008-11-21

View user profile

Back to top Go down

working!

Post  freakTheMighty on Mon Mar 23, 2009 5:27 pm

Thanks so much, I got it working. I am curious what I was doing wrong with the SIO2 code, maybe that will become more obvious when I am more familiar.

freakTheMighty

Posts : 12
Join date : 2009-03-05

View user profile

Back to top Go down

Re: Using my own camera

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