i’ve efficiently been in a position to attract a dice utilizing openGL and SDL2. To me the subsequent pure step could be so as to add some fundamental ahead/backward motion to the digital camera. I did so with this code right here:
// SDL Window init and GLSL setup ^^
vec3 cameraPos = {0.0f, 0.0f, 3.0f};
vec3 cameraTarget = {0.0f, 0.0f, 0.0f};
vec3 cameraFront = {0.0f, 0.0f, -1.0f};
whereas(!give up){
vec3 cameraDirection;
glm_vec3_sub(cameraTarget, cameraPos, cameraDirection);
glm_normalize(cameraDirection);
vec3 up = {0.0f, 1.0f, 0.0f};
vec3 cameraRight;
glm_cross(cameraDirection, up, cameraRight);
glm_normalize(cameraRight);
vec3 cameraUp;
glm_cross(cameraRight, cameraDirection, cameraUp);
vec3 cameraFrontPlusPos;
glm_vec3_add(cameraFront, cameraPos, cameraFrontPlusPos);
float cameraSpeed = 0.05f;
whereas (SDL_PollEvent(&e)) {
if (e.kind == SDL_QUIT) {
give up = true;
}
else if (e.kind == SDL_KEYDOWN) {
change (e.key.keysym.sym) {
case SDLK_w:
{
vec3 scaledFront;
glm_vec3_scale(cameraFront, cameraSpeed, scaledFront);
glm_vec3_add(cameraPos, scaledFront, cameraPos);
}
break;
case SDLK_s:
{
vec3 scaledFront;
glm_vec3_scale(cameraFront, cameraSpeed, scaledFront);
glm_vec3_sub(cameraPos, scaledFront, cameraPos);
}
break;
case SDLK_a:
{
vec3 proper;
glm_vec3_cross(cameraFront, cameraUp, proper);
glm_normalize(proper);
glm_vec3_scale(proper, cameraSpeed, proper);
glm_vec3_sub(cameraPos, proper, cameraPos);
}
break;
case SDLK_d:
{
vec3 proper;
glm_vec3_cross(cameraFront, cameraUp, proper);
glm_normalize(proper);
glm_vec3_scale(proper, cameraSpeed, proper);
glm_vec3_add(cameraPos, proper, cameraPos);
}
break;
}
}
}
// Dice Rendering code down right here
}
as a result of i’m scripting this in c i’m not utilizing glm however i’m utilizing cglm that’s supplied by this github web page: https://github.com/recp/cglm.
The issue that i’m having is that when i transfer left and proper the digital camera appears to be jumpy and never easy like when i transfer ahead and backwards.
I’ve tried introducing a deltaTime variable that will get multiplied to my cameraSpeed, however that didn’t appear to have achieved something. I then tried including a delay to the sport loop through the use of SDL_Delay(10) and that made the jittery factor worse. I additionally tried altering the Swap interval from 0 to 1 to -1 and 0 was the smoothest and 1 and -1 the place actually jittery.