0
\$\begingroup\$

I'm trying to draw "bullets" in my game, but I think something is wrong with velocity computation. Sometimes the "bullets" are going in the right way, but sometimes they won't. The CameraFront is constructed with euler angles. Can you help? Thanks in advance

So this is how I create bullets:

Bullet_tracer makeBulletTracer(v3 cameraFront,v3 startP, v3 endP)
{

    Bullet_tracer result = {};
    
    //assert((gTracersCount + 1) <= MAX_BULLET_TRACERS);
    
    mat4 model = indentity();
    model = scale(model, v3(.5f,.5f,1.5f));
    v3 up = v3(0.0f,1.0f,0.0f);
    v3 right = normalize(cross(cameraFront,up));
    mat4 M = rows3x3(right,up,cameraFront);
    model = model * M;
    model = translate(model, startP + v3(0.0f,3.0f,0.0f));
    result.model = model;
    result.velocity = cameraFront;
    gTracersCount++;
    return result;
}

This is how I draw them:

for (u32 tracerIndex = 0; tracerIndex < gTracersCount; tracerIndex++)
{
    Bullet_tracer *tracer = gameState->tracers + tracerIndex;
    
    v3 p = getTranslationPart(tracer->model);
     v3 offset = (p + tracer->velocity) * input->dtForFrame * 0.01f;
    tracer->model = translate(tracer->model, offset);
    
    passUniformMatrix(opengl.shaderProgram,tracer->model,false,"model");
    glDrawArrays(GL_TRIANGLES, 0, 36);
}
\$\endgroup\$
3
  • \$\begingroup\$ I think you'll need to provide more details, for example, what kind of game is it (3D, 2D, top down, ect)? How's cameraFront build up? And where is the makeBulletTracer used. \$\endgroup\$ – Steven Dec 11 '20 at 7:40
  • \$\begingroup\$ @Steven That is a 3D game. makeBulletTraces called when I press mouse button That is how I construct cameraFront. gameState->cameraFront.x = cos(ToRadians(camera->yaw)) * cos(ToRadians(camera->pitch)); gameState->cameraFront.y = sin(ToRadians(camera->pitch)); gameState->cameraFront.z = sin(ToRadians(camera->yaw)) * cos(ToRadians(camera->pitch)); gameState->cameraFront = normalize(gameState->cameraFront); \$\endgroup\$ – ExTrayEx Dec 11 '20 at 17:06
  • \$\begingroup\$ Thank you, although I've no experience with 3D games, perhaps someone else would. You should put the code of your comment in your question, so it's easier to read. \$\endgroup\$ – Steven Dec 14 '20 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.