use of dt
This commit is contained in:
parent
5b53048505
commit
378398193c
4 changed files with 16 additions and 13 deletions
|
@ -4,6 +4,6 @@
|
|||
#include <GL4D/gl4dummies.h>
|
||||
|
||||
// Récupère un delta-temps
|
||||
double get_dt(void);
|
||||
double get_dt(double *, GLboolean);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -60,13 +60,11 @@ static void draw(void) {
|
|||
glClearColor(0, 0, 0, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
static Uint32 t0 = -1;
|
||||
GLfloat t, d;
|
||||
if ((int)t0 == -1) {
|
||||
t0 = SDL_GetTicks();
|
||||
static double t0 = -1;
|
||||
if (t0 == -1) {
|
||||
t0 = gl4dGetElapsedTime();
|
||||
}
|
||||
t = (GLfloat)(SDL_GetTicks() - t0) / 1000.f;
|
||||
d = -1.1f + .25f * t;
|
||||
GLfloat dt = .25f * (GLfloat)get_dt(&t0, GL_FALSE) - 1.1f;
|
||||
|
||||
GLfloat ratio = (GLfloat)_dims[0] / (GLfloat)_dims[1];
|
||||
gl4duBindMatrix(matrix_proj);
|
||||
|
@ -76,7 +74,7 @@ static void draw(void) {
|
|||
gl4duBindMatrix(matrix_modview);
|
||||
gl4duLoadIdentityf();
|
||||
|
||||
gl4duTranslatef(0.f, d, -2.f);
|
||||
gl4duTranslatef(0.f, dt, -2.f);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, _texId);
|
||||
gl4duScalef(1, 0.3f, 1);
|
||||
|
|
|
@ -40,6 +40,9 @@ static void init(void) {
|
|||
}
|
||||
|
||||
static void draw(void) {
|
||||
static double t0 = 0;
|
||||
double dt = get_dt(&t0, GL_TRUE);
|
||||
|
||||
glClearColor(0.2f, 0.2f, 0.8f, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glUseProgram(_pId);
|
||||
|
@ -47,6 +50,7 @@ static void draw(void) {
|
|||
const GLfloat couleur_plan[] = {0.3f, 0.3f, 0.3f, 1},
|
||||
couleur_heros[] = {1, 1, 0, 1};
|
||||
GLint couleur_loc = glGetUniformLocation(_pId, "couleur");
|
||||
static double deplacement = 0;
|
||||
|
||||
const GLfloat lumpos[] = {1, 2, 3, 1};
|
||||
GLint lum_loc = glGetUniformLocation(_pId, "lumpos");
|
||||
|
@ -78,6 +82,6 @@ static void draw(void) {
|
|||
gl4duSendMatrices();
|
||||
glUniform4fv(couleur_loc, 1, couleur_heros);
|
||||
gl4dgDraw(_herosId);
|
||||
|
||||
deplacement += 0.4 * M_PI * dt;
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#include "../includes/utils.h"
|
||||
|
||||
double get_dt(void) {
|
||||
static double t0 = 0.0f;
|
||||
double t = gl4dGetElapsedTime(), dt = (t - t0) / 1000.0;
|
||||
t0 = t;
|
||||
double get_dt(double *t0, GLboolean override_t0) {
|
||||
double t = gl4dGetElapsedTime(), dt = (t - *t0) / 1000.0;
|
||||
if (override_t0) {
|
||||
*t0 = t;
|
||||
}
|
||||
|
||||
return dt;
|
||||
}
|
||||
|
|
Reference in a new issue