c3camera: matrix contains the eye position
authorMichel Pollet <buserror@gmail.com>
Tue, 12 Jun 2012 17:27:31 +0000 (18:27 +0100)
committerMichel Pollet <buserror@gmail.com>
Tue, 12 Jun 2012 17:27:31 +0000 (18:27 +0100)
Moved stuff around and added the translation to eye coordinates
to the matrix.

Signed-off-by: Michel Pollet <buserror@gmail.com>
examples/shared/libc3/src/c3camera.c
examples/shared/libc3/src/c3camera.h
examples/shared/libc3/src/c3context.c

index be3070d..f4eef0f 100644 (file)
@@ -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
index 1a719db..5f47af7 100644 (file)
@@ -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___ */
index 79508e6..8a85c93 100644 (file)
@@ -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;