Browse Source

move the camera with the arrow

master
Droum 3 years ago
parent
commit
7f457ab5f7
3 changed files with 57 additions and 0 deletions
  1. +20
    -0
      camera.cpp
  2. +8
    -0
      camera.h
  3. +29
    -0
      main.cpp

+ 20
- 0
camera.cpp View File

@@ -40,4 +40,24 @@ void Camera::calculateUp()
upVector.x = s.y * v.z - s.z * v.y;
upVector.y = s.z * v.x - s.x * v.z;
upVector.z = s.x * v.y - s.y * v.x;
}

void Camera::setPos(Vec3 newPos)
{
eyePos=newPos;
}

void Camera::setOrient(Vec3 newOri)
{
centerPos=newOri;
}

Vec3 Camera::getPos()
{
return eyePos;
}

Vec3 Camera::getOrient()
{
return centerPos;
}

+ 8
- 0
camera.h View File

@@ -26,5 +26,13 @@ class Camera

/* Compute the current up vector */
void calculateUp();

void setPos(Vec3 newPos);

void setOrient(Vec3 newOrient);

Vec3 getPos();

Vec3 getOrient();
};


+ 29
- 0
main.cpp View File

@@ -62,6 +62,33 @@ void reshape(GLsizei width, GLsizei height) {
gluPerspective(45.0f, aspect, 0.1f, 100.0f);
}

void keyInput(unsigned char key, int x, int y){

}

void specialInput(int key, int x, int y){
Vec3 newPos;
switch(key){
case GLUT_KEY_UP :
newPos = c.getPos();
newPos.y+=0.1;
c.setPos(newPos);break;
case GLUT_KEY_DOWN :
newPos = c.getPos();
newPos.y-=0.1;
c.setPos(newPos);break;
case GLUT_KEY_RIGHT :
newPos = c.getPos();
newPos.x+=0.1;
c.setPos(newPos);break;
case GLUT_KEY_LEFT :
newPos = c.getPos();
newPos.x-=0.1;
c.setPos(newPos);break;
default : break;
}
}

int main(int argc, char** argv)
{
c = Camera();
@@ -76,6 +103,8 @@ int main(int argc, char** argv)
glutInitWindowSize(640, 480);
glutInitWindowPosition(50, 50);
glutCreateWindow("IN55 - Animation rendering");
glutKeyboardFunc(keyInput);
glutSpecialFunc(specialInput);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
initGL();

Loading…
Cancel
Save