paysages: Finally fixed camera transformation !

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@249 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-01-29 14:23:10 +00:00 committed by ThunderK
parent e5365091aa
commit b46d25628a
3 changed files with 12 additions and 12 deletions

View file

@ -189,7 +189,7 @@ void WidgetWanderer::resizeGL(int w, int h)
{
double ratio = (double)h / (double)w;
glViewport(0, 0, (GLint)w, (GLint)h);
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

View file

@ -114,7 +114,7 @@ void cameraValidateDefinition(CameraDefinition* definition, int check_above)
definition->target = v3Add(definition->location, definition->forward);
definition->project = m4Mult(m4NewPerspective(1.57, 1.333333, 1.0, 1000.0), m4NewLookAt(VECTOR_ZERO, definition->forward, definition->up));
definition->project = m4Mult(m4NewPerspective(1.57, 1.333333, 1.0, 1000.0), m4NewLookAt(definition->location, definition->target, definition->up));
definition->unproject = m4Inverse(definition->project);
}
@ -213,25 +213,25 @@ void cameraRotateRoll(CameraDefinition* camera, double value)
Vector3 cameraProject(CameraDefinition* camera, Vector3 point)
{
point = m4Transform(camera->project, v3Sub(point, camera->location));
point.x = (-point.x + 1.0) * 0.5 * (double)render_width;
point = m4Transform(camera->project, point);
point.x = (point.x + 1.0) * 0.5 * (double)render_width;
point.y = (-point.y + 1.0) * 0.5 * (double)render_height;
return point;
}
Vector3 cameraUnproject(CameraDefinition* camera, Vector3 point)
{
point.x = -(point.x / (0.5 * (double)render_width) - 1.0);
point.x = (point.x / (0.5 * (double)render_width) - 1.0);
point.y = -(point.y / (0.5 * (double)render_height) - 1.0);
return v3Add(m4Transform(camera->unproject, point), camera->location);
return m4Transform(camera->unproject, point);
}
void cameraProjectToFragment(CameraDefinition* camera, double x, double y, double z, RenderFragment* result)
{
Vector3 point = {x, y, z};
point = m4Transform(camera->project, v3Sub(point, camera->location));
result->x = lround((-point.x + 1.0) * 0.5 * (double)render_width);
result->y = lround((-point.y + 1.0) * 0.5 * (double)render_height);
point = cameraProject(camera, point);
result->x = lround(point.x);
result->y = lround(point.y);
result->z = point.z;
}

View file

@ -331,14 +331,14 @@ Matrix4 m4NewRotateTripleAxis(Vector3 x, Vector3 y, Vector3 z)
Matrix4 m4NewLookAt(Vector3 eye, Vector3 at, Vector3 up)
{
Vector3 z = v3Normalize(v3Sub(eye, at));
Vector3 z = v3Normalize(v3Sub(at, eye));
Vector3 x = v3Normalize(v3Cross(up, z));
Vector3 y = v3Cross(z, x);
Matrix4 result = m4NewRotateTripleAxis(x, y, v3Neg(z));
Matrix4 result = m4NewRotateTripleAxis(x, y, z);
result.d = eye.x;
result.h = eye.y;
result.l = eye.z;
return result;
return m4Inverse(result);
}
Matrix4 m4NewPerspective(double fov_y, double aspect, double near, double far)