Rotate according to time not number of frames in the crate example
Previously the crate example incremented the angle of rotation of the cube every frame so depending on the framerate the cube might rotate too fast to see. This just changes it to calculate the rotation based on the elapsed time using a GTimer. The rate that frames are drawn is unaffected. Reviewed-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
parent
8325ca00b8
commit
dedee399d6
@ -13,11 +13,6 @@ typedef struct _Data
|
|||||||
CoglTexture *texture;
|
CoglTexture *texture;
|
||||||
CoglPipeline *crate_pipeline;
|
CoglPipeline *crate_pipeline;
|
||||||
|
|
||||||
/* The cube continually rotates around each axis. */
|
|
||||||
float rotate_x;
|
|
||||||
float rotate_y;
|
|
||||||
float rotate_z;
|
|
||||||
|
|
||||||
CoglPangoFontMap *pango_font_map;
|
CoglPangoFontMap *pango_font_map;
|
||||||
PangoContext *pango_context;
|
PangoContext *pango_context;
|
||||||
PangoFontDescription *pango_font_desc;
|
PangoFontDescription *pango_font_desc;
|
||||||
@ -26,6 +21,8 @@ typedef struct _Data
|
|||||||
int hello_label_width;
|
int hello_label_width;
|
||||||
int hello_label_height;
|
int hello_label_height;
|
||||||
|
|
||||||
|
GTimer *timer;
|
||||||
|
|
||||||
} Data;
|
} Data;
|
||||||
|
|
||||||
/* A static identity matrix initialized for convenience. */
|
/* A static identity matrix initialized for convenience. */
|
||||||
@ -97,6 +94,8 @@ CoglVertexP3T2 vertices[] =
|
|||||||
static void
|
static void
|
||||||
paint (Data *data)
|
paint (Data *data)
|
||||||
{
|
{
|
||||||
|
float rotation;
|
||||||
|
|
||||||
cogl_clear (&black, COGL_BUFFER_BIT_COLOR|COGL_BUFFER_BIT_DEPTH);
|
cogl_clear (&black, COGL_BUFFER_BIT_COLOR|COGL_BUFFER_BIT_DEPTH);
|
||||||
|
|
||||||
cogl_push_matrix ();
|
cogl_push_matrix ();
|
||||||
@ -105,6 +104,11 @@ paint (Data *data)
|
|||||||
|
|
||||||
cogl_scale (75, 75, 75);
|
cogl_scale (75, 75, 75);
|
||||||
|
|
||||||
|
/* Update the rotation based on the time the application has been
|
||||||
|
running so that we get a linear animation regardless of the frame
|
||||||
|
rate */
|
||||||
|
rotation = g_timer_elapsed (data->timer, NULL) * 60.0f;
|
||||||
|
|
||||||
/* Rotate the cube separately around each axis.
|
/* Rotate the cube separately around each axis.
|
||||||
*
|
*
|
||||||
* Note: Cogl matrix manipulation follows the same rules as for
|
* Note: Cogl matrix manipulation follows the same rules as for
|
||||||
@ -114,9 +118,9 @@ paint (Data *data)
|
|||||||
* we want it to be a rotation around the origin, before it is
|
* we want it to be a rotation around the origin, before it is
|
||||||
* scaled and translated.
|
* scaled and translated.
|
||||||
*/
|
*/
|
||||||
cogl_rotate (data->rotate_x++, 0, 0, 1);
|
cogl_rotate (rotation, 0, 0, 1);
|
||||||
cogl_rotate (data->rotate_y++, 0, 1, 0);
|
cogl_rotate (rotation, 0, 1, 0);
|
||||||
cogl_rotate (data->rotate_z++, 1, 0, 0);
|
cogl_rotate (rotation, 1, 0, 0);
|
||||||
|
|
||||||
/* Whenever you draw something with Cogl using geometry defined by
|
/* Whenever you draw something with Cogl using geometry defined by
|
||||||
* one of cogl_rectangle, cogl_polygon, cogl_path or
|
* one of cogl_rectangle, cogl_polygon, cogl_path or
|
||||||
@ -175,6 +179,8 @@ main (int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.timer = g_timer_new ();
|
||||||
|
|
||||||
cogl_onscreen_show (onscreen);
|
cogl_onscreen_show (onscreen);
|
||||||
|
|
||||||
cogl_push_framebuffer (fb);
|
cogl_push_framebuffer (fb);
|
||||||
|
Loading…
Reference in New Issue
Block a user