Small camera fix
This commit is contained in:
parent
f2b6d98d34
commit
3f386f1347
23
camera.h
23
camera.h
|
@ -13,20 +13,39 @@ class Camera
|
|||
/* Camera constructor */
|
||||
Camera()
|
||||
{
|
||||
eyePos = Vec3(0.0f, 0.0f, -20.0f);
|
||||
centerPos = Vec3(0.0f, 0.0f, -10.0f);
|
||||
eyePos = Vec3(0.0f, 0.0f, -1.0f);
|
||||
centerPos = Vec3(0.0f, 0.0f, 0.0f);
|
||||
upVector = Vec3(0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
/* Update the camera to look at the correct position with correct orientation */
|
||||
void updateCamera()
|
||||
{
|
||||
this->calculateUp();
|
||||
gluLookAt(
|
||||
eyePos.x, eyePos.y, eyePos.z,
|
||||
centerPos.x, centerPos.y, centerPos.z,
|
||||
upVector.x, upVector.y, upVector.z
|
||||
);
|
||||
}
|
||||
|
||||
/* Compute the current up vector */
|
||||
void calculateUp()
|
||||
{
|
||||
float l = eyePos.length();
|
||||
Vec3 v = Vec3(eyePos.x/l, eyePos.y/l, eyePos.z/l);
|
||||
Vec3 up = Vec3(0.0f, 1.0f, 0.0f);
|
||||
|
||||
Vec3 s = Vec3(
|
||||
v.y * up.z - v.z * up.y,
|
||||
v.z * up.x - v.x * up.z,
|
||||
v.x * up.y - v.y * up.x
|
||||
);
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
class Light
|
||||
|
|
13
main.cpp
13
main.cpp
|
@ -32,23 +32,26 @@ void display()
|
|||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glRotatef(angle, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
glLoadIdentity();
|
||||
c.updateCamera();
|
||||
glTranslatef(0, -0.5, 1);
|
||||
glRotatef(angle, 0.0f, 1.0f, 0.0f);
|
||||
glScalef(0.05, 0.05, 0.05);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
unsigned int size = m.getVertexList().size();
|
||||
glColor3f(1.0, 0.0, 0.0);
|
||||
for (unsigned int i = 0; i < size; i++)
|
||||
{
|
||||
Vec3 v = m.getVertexList()[i];
|
||||
glColor3f(0.0, 1.0, ((float)i)/size);
|
||||
glVertex3f(v.x, v.y, v.z);
|
||||
}
|
||||
glEnd();
|
||||
glutSwapBuffers();
|
||||
angle += 0.9;
|
||||
angle += 0.2;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
v -0.5 0 -0
|
||||
v 0 0.5 -0
|
||||
v 0.5 0 -0
|
||||
v 1 0 -0
|
||||
v 1 1 -0
|
||||
v 0 1 -0
|
||||
v 0 0 -1
|
||||
v 0 1 -1
|
||||
v 0 1 0
|
||||
f 1 2 3
|
||||
f 4 5 6
|
||||
|
|
Loading…
Reference in a new issue