예제 #1
0
void Arcball::cursorCallback( GLFWwindow *window, double x, double y ){
    if( mouseEvent == 0 )
        return;
    else if( mouseEvent == 1 ) {
        /* Start of trackball, remember the first position */
        prevPos     = toScreenCoord( x, y );
        mouseEvent  = 2;
        return;
    }
    
    /* Tracking the subsequent */
    currPos  = toScreenCoord( x, y );
    
    /* Calculate the angle in radians, and clamp it between 0 and 90 degrees */
    angle    = acos( std::min(1.0f, glm::dot(prevPos, currPos) ));
    
    /* Cross product to get the rotation axis, but it's still in camera coordinate */
    camAxis  = glm::cross( prevPos, currPos );
}
예제 #2
0
/**
* Check whether we clicked in the window
*/
void Arcball::mouseButtonCallbackImpl(GLFWwindow * window, int button, int action, int mods)
{
	processMouse(button, action);

	double x, y;
	glfwGetCursorPos(window, &x, &y);

	m_clicked = m_mouse[GLFW_MOUSE_BUTTON_LEFT];

	if(m_clicked){
		m_prevPos = toScreenCoord(x, y);
	} else {
		m_dragging = false;
		m_prevTrans = m_currTrans;
	}
}
예제 #3
0
/*
* Check if the mouse moved in the window
*/
void Arcball::cursorCallbackImpl(GLFWwindow *window, double x, double y)
{
	if (m_clicked) {
		m_dragging = true;

		m_currPos = toScreenCoord(x, y);

		/* Calculate the angle in radians, and clamp it between 0 and pi/2 */
		m_angle = acos(std::min(1.f, glm::dot(m_prevPos, m_currPos)));

		//if angle really small then m_camAxis will be close to zero and may cause issue where model disappears from screen
		if (m_angle > 0.01f ) {
			/* Cross product to get the rotation axis in camera coordinate */
			m_camAxis = glm::cross(m_prevPos, m_currPos);
		}
	} //else do nothing - mouse just moves over viewport
}