Мне нужно нацелить камеру так чтобы смотреть на объект сбоку (см. рис. в приложении). Как это сделать? Вот мой код для первого рисунка. | Код | #include <glaux.h> #include <GL/glut.h> #include <gl.h> #include <glu.h> #include <math.h> #include <windows.h> #include <ctime> #include <stdlib.h>
#pragma comment (lib, "glaux.lib") #pragma comment (lib, "opengl32.lib") #pragma comment (lib, "glu32.lib") #pragma comment (lib, "glut32.lib")
#define radius 0.5
double x, y;
void DrawBall() { glPushMatrix(); glTranslated(x,y,0); glColor3d(1,0,0); glutSolidSphere(radius, 100, 100); glPopMatrix(); }
void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); DrawBall(); glutSwapBuffers(); glFlush(); }
void resize(int width,int height) { glViewport(0,0,width,height); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho(-5,5, -5,5, 2,12); gluLookAt( 0,0,5, 0,0,0, 0,1,0 ); glMatrixMode( GL_MODELVIEW ); }
int main(int argc, char* argv[]) { glutInitWindowPosition(50, 10); glutInitWindowSize(400, 400); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutCreateWindow("Testbed"); glutDisplayFunc(display); glutReshapeFunc(resize);
glEnable(GL_ALPHA_TEST); glEnable(GL_DEPTH_TEST); glEnable(GL_COLOR_MATERIAL); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glutMainLoop(); return 0; }
|
Присоединённый файл ( Кол-во скачиваний: 12 )
pic.png 103,93 Kb
|