// T2.cpp : Defines the entry point for the console application.
//
#include<math.h>
#include <glut.h>
#include <stdio.h>
#include <string.h>
float tx=0.0;
float ty=0.0;
float tz=0.0;
void draw()
{
glColor3f (1.0, 1.0, 0.0);
glutWireCube (3);
//glutSolidCube(.01);
}
void reshape(int w, int h)
{
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
//glOrtho(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
gluPerspective(45,1,0,50);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void mySpecialKey(int key, int x, int y)
{
//GLfloat tx = 0.0, ty = 0.0,tz=0.0;
switch(key)
{
case GLUT_KEY_UP : ty += 0.05; break;
case GLUT_KEY_DOWN : ty -= 0.05; break;
case GLUT_KEY_RIGHT : tx += 0.05; break;
case GLUT_KEY_LEFT : tx -= 0.05; break;
case GLUT_KEY_F1 : tz -= 0.01;break;
case GLUT_KEY_F2 : tz += 0.01;break;
case GLUT_KEY_HOME : glLoadIdentity();
break;
}
//render_1(tx,ty,tz); //no need for this call the system will call it automatcly when calling the follwoing fucntion glutPostRedisplay
glutPostRedisplay();
}
void render_1()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//gluLookAt (0.0+tx,0.0+ty, 0.0+tz, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0);
gluLookAt (tx,ty, tz, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
draw();
glutSwapBuffers();
}
void main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
//window
glutInitWindowPosition(40,40);
glutInitWindowSize(160,160);
glutCreateWindow("lookat 1");
glutReshapeFunc(reshape);
glutDisplayFunc(render_1);
glutSpecialFunc(mySpecialKey);
glutMainLoop();
}
//
#include<math.h>
#include <glut.h>
#include <stdio.h>
#include <string.h>
float tx=0.0;
float ty=0.0;
float tz=0.0;
void draw()
{
glColor3f (1.0, 1.0, 0.0);
glutWireCube (3);
//glutSolidCube(.01);
}
void reshape(int w, int h)
{
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
//glOrtho(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
gluPerspective(45,1,0,50);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void mySpecialKey(int key, int x, int y)
{
//GLfloat tx = 0.0, ty = 0.0,tz=0.0;
switch(key)
{
case GLUT_KEY_UP : ty += 0.05; break;
case GLUT_KEY_DOWN : ty -= 0.05; break;
case GLUT_KEY_RIGHT : tx += 0.05; break;
case GLUT_KEY_LEFT : tx -= 0.05; break;
case GLUT_KEY_F1 : tz -= 0.01;break;
case GLUT_KEY_F2 : tz += 0.01;break;
case GLUT_KEY_HOME : glLoadIdentity();
break;
}
//render_1(tx,ty,tz); //no need for this call the system will call it automatcly when calling the follwoing fucntion glutPostRedisplay
glutPostRedisplay();
}
void render_1()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//gluLookAt (0.0+tx,0.0+ty, 0.0+tz, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0);
gluLookAt (tx,ty, tz, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
draw();
glutSwapBuffers();
}
void main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
//window
glutInitWindowPosition(40,40);
glutInitWindowSize(160,160);
glutCreateWindow("lookat 1");
glutReshapeFunc(reshape);
glutDisplayFunc(render_1);
glutSpecialFunc(mySpecialKey);
glutMainLoop();
}