PDA

View Full Version : 3d modelling_silly questions_plz help



chign
05-12-2010, 01:43 PM
well, i am new to 3d modelling and i have a little problem in understanting some basic things..

lets say we have this simple code..


#include <glut.h>

void display()
{
glColor3f(0,0,1);
glClearColor(1,1,1,0);

glClear(GL_COLOR_BUFFER_BIT);

glutWireCube(40);

glFlush();
}

int main(int argc, char **argv)
{
glutInit(&amp;argc,argv);
glutInitWindowPosition(50,50);
glutInitWindowSize(800,600);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutCreateWindow("A cube wireframe");

glMatrixMode(GL_PROJECTION);
glOrtho(-80,80,-60,60,0,100);

glMatrixMode(GL_MODELVIEW);
gluLookAt(-30,-30,40,0,0,0,0,1,0);

glutDisplayFunc(display);
glutMainLoop();

return 0;
}




questions:
1.
glMatrixMode(GL_PROJECTION);
glOrtho(-80,80,-60,60,0,100);

what i do here is setting the "dimensions" of the screen??

2.
glMatrixMode(GL_MODELVIEW);
gluLookAt(-30,-30,40,0,0,0,0,1,0);


what i do here is "placing my camera" and determine from where i see the model..?? i have understood each of the arguments, so plz do not explain me this.. i have trouble in getting the general idea..

3.
glutWireCube(40);

whats the center of the cube..?? the center of the window?? the arguments of gluLookAt??
can i define the center??

thanks for your time..

ZbuffeR
05-12-2010, 02:36 PM
questions:
1.
glMatrixMode(GL_PROJECTION);
glOrtho(-80,80,-60,60,0,100);

what i do here is setting the "dimensions" of the screen??

Here :
glutInitWindowSize(800,600);

And glOrtho merely defines a rectangular box, and everything created within this box will be visible :
http://www.opengl.org/sdk/docs/man/xhtml/glOrtho.xml



2.
glMatrixMode(GL_MODELVIEW);
gluLookAt(-30,-30,40,0,0,0,0,1,0);


what i do here is "placing my camera" and determine from where i see the model..?? i have understood each of the arguments, so plz do not explain me this.. i have trouble in getting the general idea..

So you have read this :
http://www.opengl.org/sdk/docs/man/xhtml/gluLookAt.xml
"gluLookAt creates a viewing matrix derived from an eye point, a reference point indicating the center of the scene, and an UP vector."
This is explains well the general idea for me, can you be more precise about what you did not understood ?



3.
glutWireCube(40);

whats the center of the cube..?? the center of the window?? the arguments of gluLookAt??
can i define the center??
The center is the current modelview coordinate 0,0,0 : so if you want the change that, you can apply glTranslate, or any other modification, to the GL_MODELVIEW matrix.

chign
05-13-2010, 02:22 AM
ok got that.. what i want to do now is draw 2 consecutive cubes.. specifically in 2d modelling i have this..


glBegin(GL_POLYGON);//sxediasmos poligonoy
glVertex2i(b1,b2+a2);
glVertex2i(b1,b2);
glVertex2i(b1+a1,b2);
glVertex2i(b1+a1,b2+a2);
glEnd(); in a loop
for example one rectangle :
(b1,b2) , (b1+a1,b2), (b1+a1,b2+a2), (b1,b2+a2)
then the next one attached to it [b1=b1+a1] and so on..

imagine reding an array n*n and when i see the char "2" draw a rectangle... this is working..

when i am trying with 3d modelling i have some problems.. each cubes overlap the next one..
the only thing i change is replace the gl_polygon with draw cube..

both codes are below... (the 2d modelling runs and performs the task i want to)
2d:

void display()
{
int i,j;
GLsizei temp1,temp2=-50,cnt1,cnt2;
glClearColor(1,1,1,0);
glClear(GL_COLOR_BUFFER_BIT);
cnt1=(2*xwmax/AR_STIL);
cnt2=(2*ywmax/(AR_GRAM+1));
for (i=AR_GRAM;i>=0;i--) {//gia na sxediastei opws to vlepoume stin pista
temp1=-50;
for (j=0;j<AR_STIL;j++) {
if (x[i][j]=='*') {
glColor3f(1,0,0);
drawpolygon(cnt1,cnt2,temp1,temp2);
}
temp1=temp1+cnt1;
}
temp2=temp2+cnt2;
}
glFlush();
}

and in 3d:

void drawcube(int a1,int a2, int b1, int b2) {//a->cnt, b->temp

glColor3f(1,0,0);
glPushMatrix();
glTranslatef( (GLfloat) b1+a1/2, (GLfloat) b2+a2/2, 0);
glScalef(2.0,1.0,1.0);
if (a1<a2)
glutSolidCube(a1);
else
glutSolidCube(a2);
glColor3f(1,0,1);
if (a1<a2)
glutWireCube(a1);
else
glutWireCube(a1);
glPopMatrix();
}
display func is the same..

sorry i confised you.. i want help in changing my 2d to 3d.. thanks..