0
\$\begingroup\$

In my android NDK OpenGL C++ project, I have a render method which executes every frame on draw event so this is the algorithm:

void Engine::render() {
    deltaTime = GetCurrentTime() - lastFrame;
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    update();
    renderDepthMaps();
    renderMeshes();
    if (skybox != nullptr)
        shaders.drawSkyBox(skybox, camera, width, height);
    lastFrame = GetCurrentTime();
}

first I calculate the delta time between the last frame and the current frame, then I update all transformation and view matrices from input then render the scene so the game loop depends on the android draw frames, I have an object which moves over a terrain and a third person camera moves with it and rotates around it, so after the object moves for some distance it begins to flicker forward and backward, the update function for the object is:

double& delta = engine.getDeltaTime();
GLfloat velocity = delta * movementSpeed;
glm::vec3 t(glm::vec3(0, 0, 1) * velocity * 3.0f);
matrix = glm::translate(matrix, t);
glm::vec3 f(matrix[2][0], matrix[2][1], matrix[2][2]);
f = -glm::normalize(f) * velocity * 3.0f;
camera->translate(f);

If it is an interpolation issue I don't know how to make interpolation with using translate matrix to its forward vector.

\$\endgroup\$

2 Answers 2

0
\$\begingroup\$

Try this:

F = glm:vec3(f[0], f[1], f[2] + velocity);

I am suggesting not to do normalization in code as down the graphics pipeline your transformed vertices will be normalized.

\$\endgroup\$
-1
\$\begingroup\$

the problem was in the shader precision once I set it to high it solve the problem

\$\endgroup\$
2
  • \$\begingroup\$ Hey, thanks for coming back to answer your question and mark it as accepted, I'm sure this will help future users! \$\endgroup\$
    – Vaillancourt
    Oct 16, 2017 at 12:06
  • 1
    \$\begingroup\$ it takes me 7 days to find the solution :( so I hope it may help any person \$\endgroup\$ Oct 16, 2017 at 12:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .