Skip to content

i get camera drift, when setting up fps camera movement #14484

@j0n31

Description

@j0n31

xrel and yrel never returns 0, its 0 when i start the program. when i move the mouse my fps camera moves "normally", but when i stop moving the mouse the camera starts drifting. xrel and yrel returs either 1 or -1 sometimes higher numbers, but rarely.

this happens even when i lift the mouse, or disconnect it(im on a desktop, not a laptop).

this is parts of my code related to mouse movement. not sure if xrel and yrel are floats or not, but making my getters floats makes my camera spinn uncontrollably.

if its relevant i'm running manjaro linux, and i'm using whatever version of sdl3 that is in the manjaro repository as of today.

my getters

int EngineInput::GetMouseXRel(){
//cout << m_relativeMousePos.x << endl;
return m_relativeMousePos.x;
}

int EngineInput::GetMouseYRel(){
return m_relativeMousePos.y;
}

poll event

while(SDL_PollEvent(&m_event)){
if(m_event.type == SDL_EVENT_MOUSE_MOTION){
m_relativeMousePos=glm::vec2(m_event.motion.xrel,m_event.motion.yrel);
}
}

//game logic

xrot = e->Input.GetMouseXRel() * 60; //xrel multiplied by sensitivity, i have messed around with different ways of doing this with no luck.
yrot = e->Input.GetMouseYRel() * 60;
e->Scene.Rotate("Player",glm::vec3(0,-xrot * e->Time.DeltaTime(),0));
e->Scene.Rotate("Player/Camera",glm::vec3(-yrot * e->Time.DeltaTime(),0,0));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions