PDA

loudking
01-03-2006, 01:12 AM
Hey, I am using Edward Angel's famous book - "Interactive Computer Graphics: A Top-Down Approach with OpenGL", and encounters a problem in Chapter 9 - "Hierarcical Modeling"

The problem is that in "dynamic.c", Angel uses a new presentation of tree structure. It was Ok to use "glLoadIndentity" and "MultiMatrix", but when I want to move the camara away from the torso, the torso doesn't become smaller. It seems as if the torso just moves together with the camera.

Does anybody know the reason?

RigidBody
01-03-2006, 01:41 AM
are you using orthogonal projection? if you want objects to become smaller with bigger distance, you have to use glFrustum or gluPerspective.

loudking
01-03-2006, 02:48 AM
Originally posted by RigidBody:
are you using orthogonal projection? if you want objects to become smaller with bigger distance, you have to use glFrustum or gluPerspective.Well, Angel was using glOrtho, but I have replaced it with glFrustum. Still, moving the camera cannot change the torso size ......

RigidBody
01-03-2006, 02:57 AM
can you post some code?

loudking
01-03-2006, 03:17 AM
source code is here
http://rapidshare.de/files/10311480/torso.c.html web page (http://rapidshare.de/files/10311480/torso.c.html)

some useful code is following:
/* tree node definination */
typedef struct treenode
{
GLfloat m[16];
void (*f)();
struct treenode *sibling;
struct treenode *child;
}treenode;

/* torso node */
treenode torso_node, head_node, lua_node, rua_node, lll_node, rll_node,lla_node, rla_node, rul_node, lul_node;

void traverse(treenode* root)
{
if(root==NULL) return;
glPushMatrix();
glMultMatrixf(root->m);
root->f();
if(root->child!=NULL) traverse(root->child);
glPopMatrix();
if(root->sibling!=NULL) traverse(root->sibling);

}

void torso()
{
glPushMatrix();
glRotatef(-90.0, 1.0, 0.0, 0.0);
glPopMatrix();
}

{
glPushMatrix();
gluSphere(h,1.0,10,10);
glPopMatrix();
}

void
display(void)
{

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);

gluLookAt(x,y,z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

traverse(&torso_node);

glutSwapBuffers();
}

void myInit(void)
{/* set up tree structure */

glRotatef(theta[0], 0.0, 1.0, 0.0);
glGetFloatv(GL_MODELVIEW_MATRIX,torso_node.m);
torso_node.f = torso;
torso_node.sibling = NULL;

glRotatef(theta[1], 1.0, 0.0, 0.0);
glRotatef(theta[2], 0.0, 1.0, 0.0);