MCPcopy Create free account
hub / github.com/arrayfire/forge / cursorHandler

Method cursorHandler

src/backend/opengl/glfw/window.cpp:286–338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

284}
285
286void Widget::cursorHandler(const float pXPos, const float pYPos)
287{
288 static const float SPEED = 0.005f;
289
290 float deltaX = mLastXPos - pXPos;
291 float deltaY = mLastYPos - pYPos;
292
293 const glm::mat4 viewMat = getCellViewMatrix(pXPos, pYPos);
294
295 if (mButton == GLFW_MOUSE_BUTTON_LEFT) {
296 // Translate
297 glm::mat4 vMat = translate(viewMat, glm::vec3(-deltaX, deltaY, 0.0f) * SPEED);
298
299 setCellViewMatrix(pXPos, pYPos, vMat);
300
301 } else if (mButton == GLFW_MOUSE_BUTTON_LEFT + 10 * GLFW_MOD_ALT ||
302 mButton == GLFW_MOUSE_BUTTON_LEFT + 10 * GLFW_MOD_CONTROL) {
303 // Zoom
304 if(deltaY != 0.0f) {
305 if(deltaY < 0.0f) {
306 deltaY = 1.0f / (-deltaY);
307 }
308 glm::mat4 vMat = scale(viewMat, glm::vec3(pow(deltaY, SPEED)));
309
310 setCellViewMatrix(pXPos, pYPos, vMat);
311 }
312 } else if (mButton == GLFW_MOUSE_BUTTON_RIGHT) {
313 const glm::mat4 orientationMat = getCellOrientationMatrix(pXPos, pYPos);
314
315 // Rotation
316 int width, height;
317 glfwGetWindowSize(mWindow, &width, &height);
318
319 if (mLastXPos != pXPos || mLastYPos != pYPos) {
320 glm::vec3 op1 = trackballPoint(mLastXPos, mLastYPos, float(width), float(height));
321 glm::vec3 op2 = trackballPoint(pXPos, pYPos, float(width), float(height));
322
323 float angle = std::acos(std::min(1.0f, glm::dot(op1, op2)));
324
325 glm::vec3 axisInCamCoord = glm::cross(op1, op2);
326
327 glm::mat3 camera2object = glm::inverse(glm::mat3(viewMat));
328 glm::vec3 axisInObjCoord = camera2object * axisInCamCoord;
329
330 glm::mat4 oMat = glm::rotate(orientationMat, glm::degrees(angle), axisInObjCoord);
331
332 setCellOrientationMatrix(pXPos, pYPos, oMat);
333 }
334 }
335
336 mLastXPos = pXPos;
337 mLastYPos = pYPos;
338}
339
340void Widget::mouseButtonHandler(int pButton, int pAction, int pMods)
341{

Callers 1

WidgetMethod · 0.80

Calls 1

trackballPointFunction · 0.85

Tested by

no test coverage detected