• Welcome to Dark Bit Factory & Gravity.
 

Using Pivots In OGL

Started by Clyde, September 21, 2010

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Clyde

I havent forgotten about Jim's ptc / Direct X library. Im toying between the two sides software and hardware.

Now that I've got VC++ Express 2010 installed, I thought I'd try a bit of Open GL for a change, and Im going to try and best explain this problem.

In Blitz3D you'd use a pivot to control a group of entitys; so they rotate / turn at the same ratios, and say for example you wanted them all to slope down. All the children dance the same manner.

What I'd like to know is how to incorparate such a thing.

I've whipped up a bit of psuedo code, if it's helpfull.

void update_cubes( cube_pivot )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
for ( int a=0; a<MAX_CUBES; a++ )
{
  render_flat_shaded_cubes( cube_pivot, flt_pos_x[a], flt_pos_y[a], flt_pos_z[a],1.0f,1.0f,1.0f );
}
}
void render_flat_shaded_cubes( control_pivot, float pos_x, float pos_y, float pos_z, float scale_x, float scale_y, float scale_z )
{
glLoadIdentity();

// set positions.
glTranslatef( pos_x, pos_y, pos_z );     

//glRotatef ( angle_x,1.0f,0.60f,0.80f); 
glBegin(GL_QUADS);      // Draw A Quad
 
  glColor3f(0.5f,0.5f,1.0f);
  // 1st side
  glVertex3f( -scale_x,-scale_y,-scale_z );// 0,1)
  glVertex3f( -scale_x, scale_y,-scale_z );//, 0,0)
  glVertex3f(  scale_x, scale_y,-scale_z );//, 1,0)
  glVertex3f(  scale_x,-scale_y,-scale_z );//, 1,1)
 
  glColor3f(0.25f,0.5f,1.0f);
 
  // 2nd side
  glVertex3f(-scale_x,-scale_y,  scale_z);    // Top Left
  glVertex3f(-scale_x, scale_y,  scale_z);    // Top Right
  glVertex3f(-scale_x, scale_y, -scale_z);    // Bottom Right
  glVertex3f(-scale_x,-scale_y, -scale_z);    // Bottom Left
 
  glColor3f(0.5f,1.0f,0.5f);
  // 3rd side.
  glVertex3f( scale_x,-scale_y, scale_z);    // Top Left
  glVertex3f( scale_x, scale_y, scale_z);    // Top Right
  glVertex3f(-scale_x, scale_y, scale_z);    // Bottom Right
  glVertex3f(-scale_x,-scale_y, scale_z);    // Bottom Left
  glColor3f(1.0f,0.5f,0.0f);
  // 4th side.
  glVertex3f( scale_x,-scale_y, -scale_z);    // Top Left
  glVertex3f( scale_x, scale_y, -scale_z);    // Top Right
  glVertex3f( scale_x, scale_y,  scale_z);    // Bottom Right
  glVertex3f( scale_x,-scale_y,  scale_z);    // Bottom Left

  glColor3f(0.25f,0.5f,.20f);
  // 5th side.
  glVertex3f( -scale_x, scale_y, -scale_z);    // Top Left
  glVertex3f( -scale_x, scale_y,  scale_z);    // Top Right
  glVertex3f(  scale_x, scale_y,  scale_z);    // Bottom Right
  glVertex3f(  scale_x, scale_y, -scale_z);    // Bottom Left
 
  glColor3f(0.25f,1.0f,.10f);
  // 6th side.
  glVertex3f( -scale_x, -scale_y,  scale_z);    // Top Left
  glVertex3f( -scale_x, -scale_y, -scale_z);    // Top Right
  glVertex3f(  scale_x, -scale_y, -scale_z);    // Bottom Right
  glVertex3f(  scale_x, -scale_y,  scale_z);    // Bottom Left
glEnd();
}


Cheers all!
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Jim

OpenGL doesn't have any high level scene graph stuff built in so you have to manage it yourself.
If you've set up the view matrix, then you can switch to the model matrix
glMatrixMode(GL_MODELVIEW);
then for each 'pivot' you can set up the translation and rotation as you are doing above
glLoadIdentity();
glTranslate(x,y,z);
...set the rotation here, as you've seen glRotate doesn't work how you want it to. maybe this will work
glRotate(tilt, 1,0,0);
glRotate(turn, 0,1,0);
glRotate(roll, 0,0,1);
...draw the model

Which is pretty much exactly what you were doing. :)
Jim
Challenge Trophies Won:

Clyde

Thanks Jim.

Im trying to get them to all rotate together at once. as if there's a middle invisible object that they are stuck to, when that moves they are relative.

i've attached my 1st go with ogl for a very long time.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Jim

Nice. So, is it working how you want, or do you want it to do something else?

Jim
Challenge Trophies Won:

Clyde

Here's an example written in blitz3D. wether it's possible in open gl I don't know.

thanks.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

zawran

Neither OpenGL nor DirectX will handle something like that for you. They are just graphical APIs, not complete coding languages. So you will have to setup some kind of system (type/struct). Probably have entities which describes each object, then have them relate to a pivot entity. Then when your system manipulates the pivots, have your system manipulate all entities that are related to the pivot you changed.

The only way around making all the control code yourself, is to use a coding language which has these things built into it, like Blitz3D, or use an "engine" of sorts, like Unity/Leadwerks/Torque/Ogre, which is controlable from c++.

Clyde

#6
not sure at all how to go about that.
perhaps one day someone might have done such a thing.

thankyou for the response and info dude.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Derold

I'm new here and to openGL, however I ran across a couple of resources you might be interested in.
This has to do with Matrices:
http://www.arcsynthesis.org/gltut/Positioning/Tut06%20Fun%20with%20Matrices.html

and openGL in general:
http://www.arcsynthesis.org/gltut/index.html

the gl push and pop commands can be very handy as well. :)

relsoft

I'm downloading the B3D binary but it would take a while.

Meanwhile you can do some pseudoIK by simple push/pop combo.

ie:

Let's say you are making some sort of 4-tentacled being:


//Parent

//1st tentacle
Push matrix
for each segment
{
      Translate
      Rotate
}
Pop Matrix

// second tentacle
Push matrix
for each segment
{
      Translate
      Rotate
}
Pop Matrix



And so on...
   
Challenge Trophies Won: