paintGL(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslated(0.0, 0.0, -10.0); glRotated(xRot / 16.0, 1.0, 0.0, 0.0); glRotated(yRot / 16.0, 0.0, 1.0, 0.0); glRotated(zRot / 16.0, 0.0, 0.0, 1.0); glCallList(object); glutSolidTeapot (1);}
glBegin(GL_QUADS);glVertex3f(0, 0, 0);glVertex3f(10, 0, 0);glVertex3f(10, 10, 0);glVertex3f(0, 10, 0);glEnd();
{ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslated(0.0, 0.0, -10.0); glRotated(xRot / 16.0, 1.0, 0.0, 0.0); glRotated(yRot / 16.0, 0.0, 1.0, 0.0); glRotated(zRot / 16.0, 0.0, 0.0, 1.0); //glCallList(object); glEnable(GL_DEPTH_TEST); //qglColor(trolltechGreen); qglColor(Qt::white); //glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); gluQuadricDrawStyle(quadratic, GLU_FILL); gluQuadricNormals(quadratic, GLU_SMOOTH); glTranslatef(0.0f,0.0f,0.0f); // Центр цилиндра gluCylinder(quadratic,0.05f,0.05f,0.9f,32,5); // Рисуем наш цилиндр/* //glTranslated(0.0, 0.0, 0.7); qglColor(Qt::black); gluSphere(quadratic,0.1f,32,32); // Рисуем сферу*///******************* рисуем оси координат ****************** glBegin(GL_LINES); glColor3f(0.0, 0.0, 1.0); //ось Х glVertex3d(0.0, 0.0, 0.0); glVertex3d(0.25, 0.0, 0.0); glColor3f(0.0, 1.0, 0.0); //ось Y glVertex3d(0.0, 0.0, 0.0); glVertex3d(0.0, 0.25, 0.0); glColor3f(1.0, 0.0, 0.0); //ось Y glVertex3d(0.0, 0.0, 0.0); glVertex3d(0.0, 0.0, 0.25); glEnd();//************************************************************}
for(int i=0; i<10; i++){ for(int k=0; k<10; k++){ glBegin(GL_QUADS); glVertex3d(0.0, 0.0, 0.0); glVertex3d(2*k, 0.0, 0.0); glVertex3d(2*k, 2*i, 0.0); glVertex3d(0.0, 2*i, 0.0); glEnd(); }}
void DrawPlaneOGL( const float center[3], float sizeU, float sizeV, float resolutionU, float resolutionV ){ ...}
float center[3] = {-5, -5, 0};drPlane (center, 5, 5, 10, 10);//***************************************void VMMutomo::drPlane (float center[3], float sizeU, float sizeV, float longU, float longV){ glBegin(GL_QUADS); for(int u = 0; u < longU; u++){ for(int v = 0; v < longV; v++){ glVertex3d(center[0] + sizeV*v, center[1] + sizeU*u, center[2] + 0.0); glVertex3d(center[0] + sizeV*(v+1), center[1] + sizeU*u, center[2] + 0.0); glVertex3d(center[0] + sizeV*(v+1), center[1] + sizeU*(u+1), center[2] + 0.0); glVertex3d(center[0] + sizeV*v, center[1] + sizeU*(u+1), center[2] + 0.0); } } glEnd();}
struct Vec3D {// avoid constructor void xyz( float _x = 0.0f, float _y = 0.0f, float _z = 0.0f ) { x = _x; y = _y; z = _z; } Vec3D & operator += ( const Vec3D & t ) { ... } Vec3D & operator *= ( float t ) { ... } ... friend Vec3D operator + ( const Vec3D & t1, const Vec3D & t2 ) { .. } friend Vec3D operator - ( const Vec3D & t1, const Vec3D & t2 ) { .. } ...// data float x, y, z;};
float center[3] = {0, 0, 0}; drPlane (center, 50, 50, 10, 10);void VMMutomo::drPlane (float center[3], float sizePU, float sizePV, float numU, float numV){ float sRectU = sizePU/numU; float sRectV = sizePV/numV; float centSpaceU = sizePU/2; float centSpaceV = sizePV/2; center[0] -= centSpaceU; center[1] -= centSpaceV; glBegin(GL_QUADS); for(int v = 0; v < numV; v++){ for(int u = 0; u < numU; u++){ glVertex3d(center[0] + sRectU*u, center[1] + sRectV*v, center[2] + 0.0); glVertex3d(center[0] + sRectU*(u+1), center[1] + sRectV*v, center[2] + 0.0); glVertex3d(center[0] + sRectU*(u+1), center[1] + sRectV*(v+1), center[2] + 0.0); glVertex3d(center[0] + sRectU*u, center[1] + sRectV*(v+1), center[2] + 0.0); } } glEnd();}
x = center[0] + cos(angle) * radius;z = center[2] + sin(angle) * radius;
angle = float (u) / numU * PI * 2 - PI / 2;