From 2463c19868be5e060bb8c0cf897d89397a6d88be Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Tue, 12 Jun 2012 18:27:31 +0100 Subject: [PATCH] c3camera: matrix contains the eye position Moved stuff around and added the translation to eye coordinates to the matrix. Signed-off-by: Michel Pollet --- examples/shared/libc3/src/c3camera.c | 52 +++++---------------------- examples/shared/libc3/src/c3camera.h | 7 +--- examples/shared/libc3/src/c3context.c | 2 +- 3 files changed, 10 insertions(+), 51 deletions(-) diff --git a/examples/shared/libc3/src/c3camera.c b/examples/shared/libc3/src/c3camera.c index be3070d..f4eef0f 100644 --- a/examples/shared/libc3/src/c3camera.c +++ b/examples/shared/libc3/src/c3camera.c @@ -317,38 +317,14 @@ c3cam_update_matrix( { c3cam_update(c); - c->mtx = c3mat4_vec4( + c3mat4 m1 = translation3D(c3vec3_minus(c->eye)); + c3mat4 m2 = c3mat4_vec4( c3vec4f(c->side.n[VX], c->up.n[VX], c->forward.n[VX], 0.0), c3vec4f(c->side.n[VY], c->up.n[VY], c->forward.n[VY], 0.0), c3vec4f(c->side.n[VZ], c->up.n[VZ], c->forward.n[VZ], 0.0), c3vec4f(0.0, 0.0, 0.0, 1.0)); + c->mtx = c3mat4_mul(&m1, &m2); } -#if 0 -void -c3cam_load_to_openGL(c3cam_p c) -{ - c3mat4 m; - - make_mtx(); - - glMatrixMode( GL_MODELVIEW ); - glLoadIdentity(); - glMultMatrixf( (c3f*) &mtx[0][0]); - glTranslatef( -eye[VX], -eye[VY], -eye[VZ] ); -} - -void -c3cam_load_to_openGL_noident(c3cam_p c) -{ - c3mat4 m; - - make_mtx(); - - glMatrixMode( GL_MODELVIEW ); - glMultMatrixf( (c3f*) &mtx[0][0]); - glTranslatef( -eye[VX], -eye[VY], -eye[VZ] ); -} -#endif void c3cam_reset( @@ -364,11 +340,12 @@ c3cam_reset( c3cam_update(c); } -c3cam_t +c3cam_p c3cam_new() { - c3cam_t c; - c3cam_reset(&c); + c3cam_p c = malloc(sizeof(*c)); + memset(c, 0, sizeof(*c)); + c3cam_reset(c); return c; } @@ -376,6 +353,7 @@ void c3cam_init( c3cam_p c) { + memset(c, 0, sizeof(*c)); c3cam_reset(c); } @@ -395,17 +373,3 @@ c3cam_update( c->up = c3vec3_normalize(c->up); c->side = c3vec3_normalize(c->side); } - -# if 0 -void -c3cam_dump(c3cam_p c, FILE *output) const -{ - fprintf( output, "Viewmodel: \n" ); - eye.print( output, " eye" ); - lookat.print( output, " lookat" ); - up.print( output, " up" ); - side.print( output, " side" ); - forward.print(output, " forward"); - mtx.print( output, " mtx" ); -} -#endif diff --git a/examples/shared/libc3/src/c3camera.h b/examples/shared/libc3/src/c3camera.h index 1a719db..5f47af7 100644 --- a/examples/shared/libc3/src/c3camera.h +++ b/examples/shared/libc3/src/c3camera.h @@ -220,7 +220,7 @@ c3cam_reset( /******************************* c3cam_t() ************/ /* Constructor */ -c3cam_t +c3cam_p c3cam_new(); void @@ -232,9 +232,4 @@ c3cam_init( void c3cam_update( c3cam_p c); -/******************************* dump() *******************/ -/* Prints the contents of this class to a file, typically */ -/* stdin or stderr */ -//void c3cam_dump(FILE *output); - #endif /* __C3VIEW_H___ */ diff --git a/examples/shared/libc3/src/c3context.c b/examples/shared/libc3/src/c3context.c index 79508e6..8a85c93 100644 --- a/examples/shared/libc3/src/c3context.c +++ b/examples/shared/libc3/src/c3context.c @@ -44,9 +44,9 @@ c3context_init( c3context_view_t v = { .type = C3_CONTEXT_VIEW_EYE, .size = c3vec2f(w, h), - .cam = c3cam_new(), .dirty = 1, }; + c3cam_init(&v.cam); c3context_view_array_add(&c->views, v); c->root = c3object_new(NULL); c->root->context = c; -- 2.39.5