void mouseMotionCallback(GLFWwindow* window, double x, double y) { if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED) { scene->camera()->mouseMotionEvent(x, y); } }
void SceneDeserializer::deserialize(const QJsonObject &source, std::shared_ptr<BaseScene> scene) { QJsonObjectWrapper cameraObjWrapper = QJsonObjectWrapper(source[KEY_CAMERA].toObject()); QVector3D eyeVec = cameraObjWrapper.getVector3D(KEY_CAMERA_EYE); QVector3D centerVec = cameraObjWrapper.getVector3D(KEY_CAMERA_CENTER); QVector3D upVec = cameraObjWrapper.getVector3D(KEY_CAMERA_UP); QJsonArray values = source[KEY_OBJECTS].toArray(); for (QJsonValue const& value : values) { QJsonObjectWrapper nodeObjWrapper = value.toObject(); QString nodeClass = nodeObjWrapper.getString(KEY_CLASS); ILoadableNode* node; if (nodeClass == COLOREDCUBE) { node = new ColoredCube(scene.get()); } else if (nodeClass == SHADEDCUBE) { node = new ShadedCube(scene.get()); } else if (nodeClass == COLOREDTETRAHEDRON) { node = new ColoredTetrahedron(scene.get()); } else { assert(!"Undefined node class"); } node->load(nodeObjWrapper); } scene->camera().lookAt(eyeVec, centerVec, upVec); }
void reshape(GLFWwindow* /*window*/, int width, int height) { if (width > 0 && height > 0) { scene->camera()->setViewportSize(width, height); glViewport(0, 0, (GLint)width, (GLint)height); } }
void setScene(std::shared_ptr<Scene>& _scene) { { std::lock_guard<std::mutex> lock(m_sceneMutex); m_scene = _scene; } auto& camera = m_scene->camera(); m_view->setCameraType(camera.type); switch (camera.type) { case CameraType::perspective: m_view->setVanishingPoint(camera.vanishingPoint.x, camera.vanishingPoint.y); if (camera.fovStops) { m_view->setFieldOfViewStops(camera.fovStops); } else { m_view->setFieldOfView(camera.fieldOfView); } break; case CameraType::isometric: m_view->setObliqueAxis(camera.obliqueAxis.x, camera.obliqueAxis.y); break; case CameraType::flat: break; } if (m_scene->useScenePosition) { glm::dvec2 projPos = m_view->getMapProjection().LonLatToMeters(m_scene->startPosition); m_view->setPosition(projPos.x, projPos.y); m_view->setZoom(m_scene->startZoom); } m_inputHandler->setView(m_view); m_tileManager->setDataSources(_scene->dataSources()); m_tileWorker->setScene(_scene); setPixelScale(m_view->pixelScale()); bool animated = m_scene->animated() == Scene::animate::yes; if (m_scene->animated() == Scene::animate::none) { for (const auto& style : m_scene->styles()) { animated |= style->isAnimated(); } } if (animated != isContinuousRendering()) { setContinuousRendering(animated); } }
void mouseButtonCallback(GLFWwindow* window, int button, int action, int /*mods*/) { if (button != GLFW_MOUSE_BUTTON_LEFT) { return; } if (action == GLFW_PRESS) { double cursorX, cursorY; glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwGetCursorPos(window, &cursorX, &cursorY); scene->camera()->mouseButtonEvent(cursorX, cursorY); } else { glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); } }
void key(GLFWwindow* /*window*/, int key, int /*s*/, int action, int /*mods*/) { scene->camera()->keyEvent(key, action); if (action == GLFW_RELEASE) { switch (key) { case GLFW_KEY_L: //scene->toggleLightAnimation(); break; case GLFW_KEY_K: //scene->toggleLightDirection(); break; case GLFW_KEY_O: s_bWireframe = !s_bWireframe; glPolygonMode(GL_FRONT_AND_BACK, s_bWireframe ? GL_LINE : GL_FILL); std::cout << "Wireframe: " << s_bWireframe << std::endl; break; default: break; } } }
void mouseScrollCallback(GLFWwindow* /*window*/, double x, double y) { scene->camera()->mouseScrollEvent(x, y); }