hey thanx!
i’ve been trying to do something like that.
no success so far. anyways i’ll look thru again and again and again…
in any case, i thought of posting some of the code. in case anyone finds the pblm, plz let me know.
i think the pblm is somewhere in the Push/Pop matrix area or the order in which i’m giving the translation and rotation. but i just can’t figure out a soln. my code is given below, not very detailed though. any help’ll b appreciated. thanx!
Sea::Sea( QWidget* parent, const char* name )
: QGLWidget( parent, name )
{
xRot = yRot = zRot = 0.0; // default object rotation
xTrans = 0.0; yTrans = 1.0; zTrans = -10.0; // default object translation
scale = 1.0; // default object scale
}
void Sea :: paintGL()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
GLfloat ship1distx = 1.5 etc...
fnCallList(subList, xRot, yRot, zRot, sub1distx, sub1disty, sub1distz, scale/2.0);
fnCallList(subList, xRot, yRot, zRot, sub2distx, sub2disty, sub2distz, scale/2.0);
fnCallList(seaList, xRot, yRot, zRot, 0.0, 0.0, 0.0, scale);
fnCallList(shipList, xRot, yRot, zRot, ship1distx, ship1disty, ship1distz, scale/2.0);
fnCallList(shipList, xRot, yRot, zRot, ship2distx, ship2disty, ship2distz, scale/2.0);
glPopMatrix();
glFlush();
}
void Sea::initializeGL()
{
qglClearColor(QColor::QColor(204,204,210));
glClearDepth(1.0);
glEnable(GL_DEPTH_TEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
glEnable(GL_NORMALIZE);
subList = glGenLists(1);
glNewList(subList, GL_COMPILE);
makeSub();
glEndList();
seaList = glGenLists(1);
glNewList(seaList, GL_COMPILE);
makeSea();
glEndList();
shipList = glGenLists(1);
glNewList(shipList, GL_COMPILE);
makeShip();
glEndList();
}
void Sea::resizeGL( int w, int h )
{
glViewport( 0, 0, (GLint)w, (GLint)h );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
if(h==0) h = 1;
float aspect = (float)w/(float)h;
gluPerspective(45.0, aspect, 3.0, 15.0);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
void Sea::fnCallList(GLuint list, GLfloat xRot, GLfloat yRot, GLfloat zRot, GLfloat distx, GLfloat disty, GLfloat distz, GLfloat scale)
{
glLoadIdentity();
gluLookAt(0.0,2.0,-3.0,0.0,0.0,-15.0,0.0,1.0,0.0);
glTranslatef(xTrans, yTrans, zTrans);
glPushMatrix();
glScalef(scale, scale,scale);
glRotatef( xRot, 1.0, 0.0, 0.0 );
glRotatef( yRot, 0.0, 1.0, 0.0 );
glRotatef( zRot, 0.0, 0.0, 1.0 );
glCallList(list);
glPopMatrix();
glTranslatef(distx, disty, distz);
glPopMatrix();
}
[This message has been edited by just_started (edited 07-31-2003).]