eventDragStart being called only single time ?

This topic contains 2 replies, has 2 voices, and was last updated by  Fname 1 year, 1 month ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #54864

    Fname
    Member

    Hello,

    I’ve got an application where I need to drag the background grid within the x axis using mouse/touch interactions.
    I’m using this code to do that:

    void MyApp::eventDragStart(int buttonIdx, pvr::PointerLocation loc)
    {
       glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
       glClear(GL_COLOR_BUFFER_BIT);
    
       shaderManager.use(shaderProgramGrid);
       // here I'm updating the appropriate matrices
       // in order to multiply them with projection and send to a vertex shader
    	
       projectionModel = projection * this->getMyTransformMatrix();	
    
       glUniformMatrix4fv(mvpLoc, 1, GL_FALSE, glm::value_ptr(projectionModel));
       glDraw…
    }

    it works with errors but the thing is that the rendering is kinda single discrete – it only moves the grid by a single eventDragStart function call – but it needs to be called every time mouse moved or touch moved.
    From the inline docs about eventDragStart.

    \description This event will be fired after a movement of more than a few pixels is detected with a button down.

    It says like it will behave like a mouse move or touch move but the result is different.
    What am I mis uderstooding here ?
    Why the callback function isn’t being called every time mouse or touch moved ?
    How to drag things smoothly ?

    #54869

    Shaun
    Member

    Hi Fname,

    As you point out the function eventDragStart is fired when a user holds a mouse button down and moves the mouse cursor. However this function is only called when the event is detected and will not continue to be called ‘during’ the drag event.

    I would like to propose an alternate solution to dragging smoothly, you can use the function getPointingDeviceState().isDragging() to check if the mouse is being dragged (this can be polled in your update loop for example), you could then use getPointerAbsolutePosition() or getPointerNormalisedPosition to retrieve the cursors current position either in pixels or normalised device co-ordinates and then use this information to update your objects position / view matrix etc.

    Take a look at the example code below:

    Result MyApp::renderFrame() //This function is called every frame
    {
    if (getPointingDeviceState().isDragging()) //Poll pointer state
        {
            loc = getPointerAbsolutePosition(); //Get cursor position in pixels
            //Update objects position 
            devObj->uiRenderer.getDefaultTitle()->setAnchor(pvr::ui::Anchor::Center, -1.f, 1.f);
            devObj->uiRenderer.getDefaultTitle()->setPixelOffset(loc.x, -loc.y);
            devObj->uiRenderer.getDefaultTitle()->commitUpdates();
        }
    //Draw
    ……..
    }

    Currently there is a bug in the framework where moving the window will invalidate the position returned by the function getPointerAbsolutePosition() and we are currently working to resolve this.

    Hope this helps.
    Shaun

    #54874

    Fname
    Member

    Hi Shaun,

    yeah, that worked out.

    thanks !

Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.