« first day  last day (14 days later) » 

12:00 AM
to the window; it should only be true if the user's cursor is in the window
 
if you ask: IsLeftButtonMousePressed(), then there is an objective answer
but what if the user cursor is in the window but it is not moving
?
 
that's what i'm trying to solve
i don't know how i can disable it; but i've analysed the situation and found that the code is more consistent if I removed the boolean variables and simply read and returned values like you have
 
sure
 
although, one has to ask themselves whether having a class to do it is necessary; sometimes we gotta deviate from the OO to save ourselves some time
 
sure, OO is not the answer for everything
but doing it properly will save you time later
 
12:03 AM
true, it's only a matter of getting the best of both worlds
 
about your moving mouse...
if you want to do something when the mouse is moving and other thing when it is not moving, I think you will need a timer or something
if the mouse position is has not moved for some time, then it is not moving
 
i'll think about it, but it requires time
i've analysed the situation and mousewheel and mouse moves aren't continuous when the booleans are removed
 
you will only get mouse move events when the mouse is moved
 
indeed
 
and mouse wheel events when the wheel is moved; mouse click events when the buttons are pressed or released, etc.
otherwise you would get flooded with useless redundant events
you were probably saving the mouse events in global variables, and then in every turn of the main loop you were checking them
 
12:11 AM
if i declare two private variables in my Application class, called pMousePosition and pMouseWheel, then if I pass them as a pointer to two other variables in InputHandler, then I could change their values without having another class interfering with its affairs
 
yes, you could do that, but then, it would be as useful but easier to understand if these variables were directly into the InputHandler class
just add a InputHandler::GetMousePosition() and a InputHandler::GetMouseWheel() and call them every loop
 
they could, but that means i have to have extra parameters in most of my functions
that can work
 
passing around pointers to private variables is not usually the best idea
 
i already have those functions
 
you could simply do:
while (true)
{
    m_inputHandler->HandleEvents();
    m_mousePos = m_inputHandler->GetMOusePosition();
    //all the other stuff
}
in your main loop
 
12:15 AM
well, inputHandler is already in the main loop
 
there are many ways to do it...
while (true)
{
    m_inputHandler->HandleEvents(&m_mousePos);
    //all the other stuff
}
but InputHandler should keep a pointer to m_mousePos. That way lies madness.
 
well, InputHandler is a singleton; it can't be instantiated
Application is also a singleton
 
well, it doesn't matter too much... Application will get to the InputHandler instance anyway
 InputHandler::Instance().HandleEvents(&m_mousePos);
or whatever
 
so you suggest having a function inside inputHandler that handles such events?
rather than it be in application?
 
this function would only do SDL_PollEvent() the switch and assign to m_mousePos
the actual work would be done by the main loop upon returning of this function
 
12:28 AM
thta's what i was thinking; if i put things under pollevent then they don't loop forever
 
right, it will consume the pending events and return when there is no more
and the main loop will run with the updated mouse position
 
one of the reasons i created a mouseMove criteria within my class is to prevent my camera from moving when the left button is only pressed
i want the camera to rotate only when the mouse is moving AND the left button is pressed; but i did an if condition along those lines but it still won't give.
 
you can check if the mouse moves between succesive iterations simply by comparing the position
    Position oldPos = m_mousePos;
    InputHandler::Instance().HandleEvents(&m_mousePos);
    if (oldPos != m_mousePos)
        //it has moved!
you can even implement a minimum distance threshold, or get the time elapsed and compute the mouse velocity
 
what about getters instead?

pCurrentCursorPosX = InputHandler::instance()->getMousePosition().x
 
yeah, since InputHandler is a singleton, you do not need the m_mousePos anywhere
the thing is that probably you do not want to couple too many classes with it
 
12:38 AM
i just want it practical for reuse anywhere in the program; but i want to have a central location to manage key bindings too
 
InputHandler can easily do keybinding and return actions instead of keys, or something
 
there are various ways of doing it; keybindings can be its own class or container
 
sure, you can keep INputHandler just for input
and do the keybinding translation later
 
I still get that continuous zooming, which is annoying
i've removed the booleans
 
what do you mean with continuous zooming?
 
12:45 AM
imagine a model on your window. if you were to zoom out then you would scroll down. now imagine that even when you're not scrolling down the camera is still zooming out from the model
 
ah, that's probably because you are using the position of the wheel as if it were an offset
since the wheel always a relative axis, you can solve it easily
 
how?
 
just do:
pMouseWheel.x = 0;
pMouseWheel.y = 0;
 
where?
 
after applying the zoom
 
12:48 AM
sure
 
so the next iteration there will be no extra zoom, unless the wheel is moved again
additionally you should change your case to:
    case SDL_MOUSEWHEEL:
        pMouseWheel.x += event.wheel.x;
        pMouseWheel.y += event.wheel.y;
or else if you get consecutive SDL_MOUSEWHEEL events you will lose all but one
 
i thought we didn't want the booleans? ;-)
 
ops!
fixed
 
that's what I do under my onMouseWheelScroll(SDL_event &event) function
i like separating code with functions, so i don't have to worry about what happens under SDL_PollEvent(..)
 
in your original question you say =, now I'm sayng +=
 
12:52 AM
ok, and now I have pMouseWheel set to that
 
you accumulate the wheel events... and when you use the value, you set it to 0
you consume the events
 
well, i've done

pMouseWheel.x = 0
pMouseWheel.y = 0
after the zoom function, but it still does the continuous zooming
 
but what is the condition to do the zooming?
 
there is no condition, it's just in a function on its own
 
and what does it do, exactly?
 
12:59 AM
pCamera.zoom(float y) takes just one parameter, and it needs the value from the vertical scrolling of the mousewheel. Because we get the value from the mousewheel in the inputHandle() function through getMouseWheelScroll() there's no need to check for a condition because the only way for the camera zoom to work is for it to receive the aforesaid variable which can only be obtained through the aforesaid function
 
I see... it doesn't matter if you do pMouseWheel.y = 0 because the next loop you do pMouseWheel.y = getMouseWheelScroll(), don't you?
 
exactly, pMouseWheel = getMouseWheelScroll() happens at the top of the function and zoom occurs towards the end
 
the problem is that the wheel value is kept in two places at the same time: Application::pMouseWheel and InputHandler::pMouseWheel
 
true
 
you have to set the vale in InputHandler to 0
you can do it this way:
instead of getMouseWheelScroll() write:
int consumeMouseWheelScroll()
{
    int res = pMouseWheel;
    pMouseWheel = 0;
    return res;
}
or you can do it this way:
int prevMouseWheel = pMouseWheel.y;
pMouseWheel.y = InputHandler.getMouseWheelScroll();
pCamera.zoom(pMouseWheel.y - prevMouseWheel)
the idea is that if the mouse wheel is not moved, then zoom() should be called with 0, or not at all
I'm assuming that zoom(0) is a no-op, isn't it?
 
1:07 AM
correct
your solution worked
 
cool!
 
also, i only want rotate and pan functions of the camera to only be executed if the mouse is moved AND the left button is pressed
i looked into the concept of bitmasks in SDL, but i don't know how i can integrate them with my inputhandling class
 
ah!
note that the SDL_MouseMotionEvent structure has both absolute and relative values
you may prefer to use xrel,yrel instead of x,y
 
what's the difference?
 
x, y are the coordinates of the cursor in the window
xrel, yrel are the offset from the last reported mouse event
 
1:15 AM
so it would be x2 - x1 sorta?
 
yes, that's it
wheel events are always relative, because the wheel has no actual position
 
indeed
 
you can use the absolute x,y values and the same trick as with prevMouseWheel to compute the moved distance
 
at least my camera works like it would on glfw now :-)
still, i'd prefer to only rotate and pan when a mouse is clicked and is moved
 
you can check the clicked buttons with SDL_MouseButtonEvent
SDL_MOUSEBUTTONDOWN and SDL_MOUSEBUTTONUP, no need to fiddle with bitmasks, IIRC
in this case, a boolean variable is in order
that is, a boolean variable per mouse button
 
1:22 AM
i have, and i even had an if statement like

that's how i implemented it; for both up and down
but because i don't have a isMouseMoved() boolean function, i don' t know how i can check
 
instead of that, do:
at the beginning of the loop, befor handleIput():
int prevMousePosition = pMousePosition;
and then, when you pan the camera do it by:
(pMousePosition.x - prevMousePosition.x, pMousePosition.y - prevMousePosition.y)
so if the mouse is not moved, they will be (0,0), and if they are moved little, they will be small numbers
 
that's what I do, I got a variable called deltaX and deltaY which gets the change in mouse position
 
so? what's missing?
 
it's a panning even if the mouse hasn't moved
the camera rotates even when the mouse hasn't moved
it's understandable why; coz the condition is if the mouse left button is pushed
 
but if deltaX and deltaY are both 0, even if the left button is pressed, it shouldn't pan, should it?
 
1:27 AM
not really; deltaX and deltaY are set to 0 before the functions are called
besides, i don't want it to pan when a button is pressed just
i need to ensure that it pans/rotates if a mouse button is pressed AND the mouse moves
 
but a boolean for the movement is not the solution
if the mouse moves just 1 pixel, the boolean will be true, and you will have a lot of pan, while the user expects a very small one
you have to make the pan proportional to the delta value, so that if the delta is 0, there is no pan
 
yeh, a boolean is absolute by nature
 
thus the boolean is not needed
 
i don't have a boolean; but yeh it needs to be proportional somehow
 
maybe your algorithm for the pan is wrong and it is moving the camera even when the input is 0...
 
1:32 AM
not really; i've tested the camera with another API and it works fine.
 
well... there are only two possibilities:
1. you are calling camera.pan() with non-zero arguments
2. you are calling camera.pan() with zero arguments, but it pans anyway
 
hmm
maybe
if we employed the same nulling behaviour into the inputhandling class, it might resolve the problem
 
possibly
 
it somewhat works, but then it knocks out the y-axis, so i can't do rotation along that
 
well, that is beyond the original question...
i'm going to take some sleep...
 
1:44 AM
ok, thanks for your help!
 
you're welcome!
bye!
 
bye!
 

« first day  last day (14 days later) »