OpenGL Object Hierarchy
Describes how to use OpenGL's matrix stack to attain an object hierarchy.
[/td][td]
[/td][td]
[/td][/tr][tr][td]Fig. 1a - Object Hierarchy[/td][td]1b - GL model[/td][td]1c - GL light model[/td][/tr][/table] Note the relationships between objects: Leg is pelvis child and pelvis is bust's child, forearm is arm's child and arm is shoulder's child, shoulder is bust's child too, and so on. So, if we move bust for example, legs and arms move too. This is an object hierarchy. Every piece of the robot is modeled into a function and stored in a display list so we'll have: void struct_part_name(void) { glNewList(part_name,GL_COMPILE); .../* GL Commands to model */ glEndList(); }void struct_left_arm(void) { glNewList(left_arm,GL_COMPILE); // Shoulder glTranslatef(1.1,0.25,0.0); glScalef(0.5,0.5,0.5); glColor3ub(128,128,128); glutSolidSphere(0.5,20,20); // Arm glTranslatef(0.0,-1.10,0.0); glScalef(0.5,1.5,0.5); glColor3ub(255,255,255); glutSolidCube(1.0); glEndList(); }... #include <gl/glut.h> ... void DrawRobot() { glPushMatrix(); /* all objects are bust's son that is if we move bust all other parts move too */ /*-------------------- DRAW HEAD AND BUST -----------------------*/ glPushMatrix(); /* Draw head */ /* Draw bust */ glPopMatrix(); | [attachment=3301:head&bust.jpg] |
/*---------------- DRAW RIGHT ARM AND FOREARM --------------*/ glPushMatrix(); glPushMatrix(); /* Draw Right arm */ glPopMatrix(); glPushMatrix(); /* forearm is arm's child */ /* Draw Forearm */ glPopMatrix(); glPopMatrix(); | [attachment=3302:arm&forearm.jpg] |
/*-------------- DRAW LEFT ARM AND FOREARM -----------------*/ glPushMatrix(); glPushMatrix(); /* Draw Left arm */ glPopMatrix(); glPushMatrix(); /* forearm is arm's child */ /* Draw Forearm */ glPopMatrix(); glPopMatrix(); | [attachment=3303:arm&forearml.jpg] |
/*------------------ DRAW PELVIS AND LEGS ----------------*/ glPushMatrix(); /* another glPushMatrix because if we move pelvis the legs move too... (legs are pelvis' son) */ glPushMatrix(); /* Draw pelvis */ glPopMatrix(); glPushMatrix(); glPushMatrix(); /* Draw Right thigh */ glPopMatrix(); glPushMatrix(); /* leg is thigh's child */ /* Draw Leg */ glPopMatrix(); glPopMatrix(); glPushMatrix(); glPushMatrix(); /* Draw Left thigh */ glPopMatrix(); glPushMatrix(); /* leg is thigh's child */ /* Draw Leg */ glPopMatrix(); glPopMatrix(); glPopMatrix(); glPopMatrix(); } | [attachment=3304:pelvis&legs.jpg] |
void DrawRobot(void) { /*-------------BUST AND HEAD--------------*/ glPushMatrix(); glRotatef(bust_angle_y,0,1,0); glRotatef(bust_angle_x,1,0,0); glPushMatrix(); glCallList(bust); glCallList(head); glPopMatrix(); /*--------RIGHT ARM AND FOREARM---------*/ glPushMatrix(); glTranslatef(0,0.25,0); glRotatef(right_arm_angle,1,0,0); glTranslatef(0,-0.25,0); glPushMatrix(); glCallList(right_arm); glPopMatrix(); glPushMatrix(); glTranslatef(1.25,-0.7,0); glRotatef(right_forearm_angle,1,0,0); glTranslatef(-1.25,0.7,0); glCallList(right_forearm); glPopMatrix(); glPopMatrix(); /*---------LEFT ARM AND FOREARM---------*/ glPushMatrix(); glTranslatef(0,0.25,0); glRotatef(left_arm_angle,1,0,0); glTranslatef(0,-0.25,0); glPushMatrix(); glCallList(left_arm); glPopMatrix(); glPushMatrix(); glTranslatef(1.25,-0.7,0); glRotatef(left_forearm_angle,1,0,0); glTranslatef(-1.25,0.7,0); glCallList(left_forearm); glPopMatrix(); glPopMatrix();| '1' & 'Q' '2' & 'W' '3' & 'E' '4' & 'R' '5' & 'T' '6' & 'Y' '7' & 'U' '8' & 'I' KEY ARROWS PGUP & PGDOWN 'V' 'B' 'N' 'M' | right arm control right forearm control left arm control left forearm control left thigh control left leg control right thigh control right thigh control rotate model light control camera control |
Related Tutorials
Procedural Generation of 2D Tile Maps in Games
The article explains how to build a procedural 2D cave map generator using cellular automata. It covers map representat…
Localizing A Game Into French — Which Variant Should You Choose?
So, you’re making an awesome indie game, and now you’re thinking about localizing it into French? Great idea! There ar…
How Long Does It Take To Localize An Indie Game?
So you’re planning on localizing your indie game, but you’re not sure how much time to schedule in. While the timing o…
Creating game videos: best practices and pitfalls to avoid
Game video production: practical tips on how to create a game trailer or teaser that you can be proud of. Give your aud…
Adopting CI/CD: How Midwinter Entertainment iterates at speed with the help of IMS
Game development was once like one long sprint: a huge effort until you reached the finish line — at which point you co…
GameDev.net
5 Things to Consider When Making a Video to Promote Your App or Game
How can you show an app or game in your video in a way that attracts new users? Let’s take a look at what to go by when…
Discussion
More from Arturo Montieri
Comparing Shadow Mapping Techniques with Shadow Explorer
New Incentives and a Whole New Platform From The Intel AppUp developer program
The final installment in this series on Intel's AppUp program details additional incentives and opportunities for devel…
The Game Maker
This book excerpt contains the first chapter of the book that introduces beginning game developers to the Game Maker pr…

Discussion