Raydium 3D Game Engine

Official forum for everything about Raydium, ManiaDrive, MeMak, ...
It is currently Sun Apr 28, 2024 4:43 am

All times are UTC




Post new topic Reply to topic  [ 51 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
 Post subject: Skysphere
PostPosted: Fri Sep 30, 2005 5:53 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Instead of the usual skybox i'm working on a sphere sky with procedural colors. In that way the colors of the sky can change dynamicaly very easy.

1-we locate tha camera according to simulate the position of the sun. (The sun in the sphere will be always at the top, so we have to turn the sphere to simulate other positions)
2- draw an sphere, vertex by vertex centered in 0,0,0 of the camera. So, we'll be INSIDE the sphere.
3- the normals will point to the center, in that way it will be visible from the center of the sphere.
4- the color of the vertex will be equal at the sun light in the higest point (y=1) and the color will be variyng just the inverse of the sun light in the bottom (-1). Just a gradient from the top to the bottom.
5-This should be done first of all 3d drawing.
6-after drawing this "sky" we will erase ONLY the zbuffer(or at least not the color buffer). So we can use opengl as usual but the just rendered image will be our dynamic backgroud.

Fast and easy, isn't?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 8:47 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
Must be tested, for sure. As said before, just have a look to sky.c since there's probably some interesting code in that file (centered box, z-buffer code, ...). Another good idea may be to mix this "gradient sphere" to an alpha blended skybox with clouds (only), providing the best of the two worlds... no ?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 01, 2005 7:10 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
hmmm, how do you see to use X layers of spheres of different sizes?. The internal spheres should be transparent or semitransparent and could have textures like different kind of clouds, satellites, contellations, etc
This could give interesting dynamic clouds (using 2 or more layers of clouds)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 01, 2005 8:06 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
When correctly transformed, a "textured" skybox will render almost the same as a skysphere, for only 12 triangles. Gradients will be very hard to transform in realtime (so a sphere is a good idea, IMHO), but for clouds (texture), It's just fine. But hey, just try ;)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 11:22 am 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
You know a rapid way to obtain the rotation angles of the current camera?
I have tried with raydium_camera_get_vectors but i'm not sure what i'm getting(i have read the .h )


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 11:44 am 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
Are you sure to want this information (camera angles) ? Since MODELVIEW matrix is ready (done by camera call), just draw you sphere/box/whatever, it will be correctly transformed. You may want to apply a supplementary rotation, using glMatrixPush, glRotate*, glMatrixPop, for example.

It may be a good idea to start looking at OpenGL matrix system ;)

The real answer is no, there's no "good" method to get back rotation from MODELVIEW matrix (and there's so many different ways to set camera rotation that we can't just store this into variables). raydium_camera_get_vectors() will try to, but is far from being exact (only works for 2 axis), and its result is only used for approximative spatial sound setting.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 12:28 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
i have seen the matrix in opengl years ago.. and i'm such confused now as before.
Usually i program opengl with try/error system ;P Really my problem is the algebra... and i don't have intention to learn that now.

I'll keep trying. I'm closer. :D


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 12:35 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
Ok :)
A little fix about my previous post : "glMatrixPush, glRotate*, draw, glMatrixPop", sure :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 1:09 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
nice, it works.
But now the spheres looks quite dark...
I have turned off the lights and fogs(like in the sky box) but the sphere doesn't looks properly.
Ideas?
Maybe if i change the normals to the interior of the sphere...
you know how to inverse a normal in the usual function glNormal3f(x, y , z);


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 1:32 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
glNormal3f(-x, -y , -z); :)
For darkness (like sky.c), try:
Code:
raydium_texture_current_set_name("texture.tga");
raydium_rendering_internal_prepare_texture_render(raydium_texture_current_main);
glColor4fv(raydium_background_color);

... before drawing your sphere. If you're not using a texture, use
Code:
raydium_rendering_internal_restore_render_state()
glColor4fv(raydium_background_color);

Or something like that. The idea is simple: clear any previous texture-unit setting (done by another texture).

Might helps.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 2:33 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
do you see something wrong in this function?
Code:
void raydium_atmosphere_create_sphere(GLfloat x, GLfloat y, GLfloat z,int detail)
{   
   int i, j;   
   //keeping safe the current matrix
   glPushMatrix();
   glLoadIdentity();   
   
   glDisable(GL_LIGHTING);
   glDisable(GL_FOG);
   raydium_rendering_internal_restore_render_state() ;
   glColor4fv(raydium_background_color);
   glDepthMask(GL_FALSE);
   
   //making the sphere
    for(i = 0; i <= detail; i++)
   {
      double lat0    =   M_PI * (-0.5 + (double) (i - 1) / (double)detail);
      double z0       =   sin(lat0);
      double zr0      =   cos(lat0);          
      double lat1      =   M_PI * (-0.5 + (double) i / (double)detail);
      double z1      =   sin(lat1);
      double zr1      =   cos(lat1);
       
      //we create a pair of vertex, that will be used to make QUADs
      glBegin(GL_QUAD_STRIP);
      for(j = 0; j <= detail; j++)
      {   
         double lng = 2 * M_PI * (double) (j - 1) / (double)detail;
         double xx = cos(lng);
         double yy = sin(lng);
         //vertex 1
         glColor4f(1,1,1,1);
         glNormal3f(-xx * zr0, -yy * zr0, -z0);
         glVertex3f(-xx * zr0, -yy * zr0, -z0);
         //vertex2
         glColor4f(1,1,0,1);
         glNormal3f(xx * zr1, yy * zr1, z1);
         glVertex3f(xx * zr1, yy * zr1, z1);
         
      }
        glEnd();
   }
   //making the sphere is always in tha same place that the camera
   //i'd like to do this internally, w/o pass the x,y,z in the params
   //of the function.
   glTranslatef(x,y,z);
   
   //restoring previus states
   if(raydium_light_enabled_tag) glEnable(GL_LIGHTING);
   if(raydium_fog_enabled_tag) glEnable(GL_FOG);
   glDepthMask(GL_TRUE);
   glPopMatrix();
}

The efect of an sky-sphere is right but still the color is quite dark(but no black)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 3:02 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
Good, but a few things :
- function name is strange. (raydium_sky_sphere_render ?)

- About matrix usage.
Code:
glPushMatrix();
glLoadIdentity();
drawing
glTranslate();
glPopMatrix();

... means that you clear matrix (so your sphere is always rendered as identity), render, and then transform matrix with glTranslate ! That's wrong, since OpenGL is a state machine, you should transform and then render. No rotation is done either.

- You're using quads, it's slow ! If you want to draw more than 10 or 20 polygon, use triangles and only triangles.

Can you post a capture of the result ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 7:49 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
the old method to draw trhe sphere was wrong...
i'm recoding whole.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 9:29 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
How tough ! ;)

PS: After re-reading code, there's another very small thing: avoid "int foo=bar;", since it's not C89 (again). Use "int foo; ...; foor=bar;".


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 10:30 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
New function recoded:
Code:
//internal
void raydium_sky_sphere_render(GLfloat x, GLfloat y, GLfloat z,int detail)
{   
   int i, j;
   GLfloat currentradious,z1,z2,ang1;
   GLfloat p[detail+1][detail+1][3];
   
   //keeping safe the current matrix
   glPushMatrix();   
   angle1+=0.2;
   angle2+=0.02;
   glDisable(GL_LIGHTING);
   glDisable(GL_FOG);
   raydium_rendering_internal_prepare_texture_render(raydium_texture_current_main);
   raydium_rendering_internal_restore_render_state() ;
   glColor4fv(raydium_background_color);
   glDepthMask(GL_FALSE);
   
   //MAKING THE SPHERE
   
   //getting the points of the sphere, but no drawing
   for(i=0;i<=detail;i++)
   {
      //getting the radious for each section of the sphere
      currentradious      =   raydium_trigo_sin(180*((float)i/(float)detail));
      //getting the heights for each section of the sphere
      z1               =   raydium_trigo_cos(180*((float)i/(float)detail));      
      for(j=0;j<=detail;j++)
      {
         ang1   =   360*((float)j/(float)detail);
         p[i][j][0]   =   currentradious * raydium_trigo_cos(ang1);
         p[i][j][1]   =   currentradious * raydium_trigo_sin(ang1);
         p[i][j][2]   =   z1;
      }
   }
   //now drawing with the obtained values
   glTranslatef(x,y,z);
   glRotatef(angle2,0,0,1);
   glRotatef(angle1,1,0,0);
   for(i=0;i<detail;i++)
   {
      for(j=0;j<detail;j++)
      {
         //z1=0.5+p[i][j][2]/(float)2;
         //z2=0.5+p[i+1][j][2]/(float)2;
         z1=1-(float)i/detail;
         z2=1-(float)(i+1)/detail;
         glBegin(GL_TRIANGLES);
         //glColor4f(1,0,0,1);
         glColor3f(z1,z1,z1);
         glVertex3f(p[i][j][0],p[i][j][1],p[i][j][2]);
         //glColor4f(0,1,0,1);
         glColor4f(z1,z1,z1,1);
         glVertex3f(p[i][j+1][0],p[i][j+1][1],p[i][j+1][2]);
         //glColor4f(1,0,1,1);
         glColor4f(z2,z2,z2,1);
         glVertex3f(p[i+1][j][0],p[i+1][j][1],p[i+1][j][2]);
         //glColor4f(1,0,0,1);
         glColor4f(z2,z2,z2,1);
         glVertex3f(p[i+1][j][0],p[i+1][j][1],p[i+1][j][2]);
         //glColor4f(0,1,0,1);
         glColor4f(z2,z2,z2,1);
         glVertex3f(p[i+1][j+1][0],p[i+1][j+1][1],p[i+1][j+1][2]);
         //glColor4f(1,0,1,1);
         glColor4f(z1,z1,z1,1);
         glVertex3f(p[i][j+1][0],p[i][j+1][1],p[i][j+1][2]);
         glEnd();
      }
   }

   //restoring previus states
   if(raydium_light_enabled_tag) glEnable(GL_LIGHTING);
   if(raydium_fog_enabled_tag) glEnable(GL_FOG);
   glDepthMask(GL_TRUE);
   glPopMatrix();
}

It works but the color of the sphere is a gradient from black to ¿¿¿blue??? when should be black->white
The error persist in test6.c train.c explo.c and explo2.c(my own test).

Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 51 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 204 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group