void PlotCartesianWidget::mouseMoveEvent(QMouseEvent *event) { int dx = event->x() - lastPos.x(); int dy = event->y() - lastPos.y(); // control+left adjusts the x-scale of the graph if( event->buttons() & Qt::LeftButton && event->modifiers() & Qt::ControlModifier ) { int d = abs(dx) > abs(dy) ? dx : dy; scaleX += float(d) * scaleX * 0.05; scaleX = std::max<float>( scaleX, 0.01 ); scaleX = std::min<float>( scaleX, 50.0 ); updateInputDataLineVAO(); updateViewMatrix(); } // control+right adjusts the x-scale of the graph else if( event->buttons() & Qt::RightButton && event->modifiers() & Qt::ControlModifier ) { int d = abs(dx) > abs(dy) ? dx : dy; scaleY += float(d) * scaleY * 0.05; scaleY = std::max<float>( scaleY, 0.01 ); scaleY = std::min<float>( scaleY, 50.0 ); updateAxisVAO(); updateViewMatrix(); } // left mouse button adjusts the viewing dir else if (event->buttons() & Qt::LeftButton) { float xScalar = 1.0 / float(width()*devicePixelRatio()); float yScalar = 1.0 / float(height()*devicePixelRatio()); float maxScalar = std::max( xScalar, yScalar ); centerX += float(-dx)*maxScalar*2.0*lookZoom; centerY += float( dy)*maxScalar*2.0*lookZoom; updateProjectionMatrix(); updateInputDataLineVAO(); } // right mouse button adjusts the zoom else if (event->buttons() & Qt::RightButton) { // use the dir with the biggest change int d = abs(dx) > abs(dy) ? dx : dy; lookZoom -= float(d) * lookZoom * 0.05; lookZoom = std::max<float>( lookZoom, 0.01f ); lookZoom = std::min<float>( lookZoom, 50.0f ); updateAxisVAO(); updateInputDataLineVAO(); updateProjectionMatrix(); } lastPos = event->pos(); // redraw updateGL(); }
void QGLView::updatePerspectiveAspectRatio() { qreal ratio; int w; int h; if (window() != NULL) { ratio = window()->devicePixelRatio(); } else { ratio = 1.0f; } w = int(ratio * this->width()); h = int(ratio * this->height()); if ((w > 0) && (h > 0)) // avoid division by zero { m_projectionAspectRatio = (float)w/(float)h; } else { m_projectionAspectRatio = 1.0f; } updateProjectionMatrix(); }
void CamtransCamera::setAspectRatio(float a) { // @TODO: [CAMTRANS] Fill this in... m_aspectRatio = a; updateProjectionMatrix(); }
void CamtransCamera::setHeightAngle(float h) { // @TODO: [CAMTRANS] Fill this in... m_heightAngle = h; updateProjectionMatrix(); }
Camera::Camera(const Type& type) : m_type(type) , m_position(Vec3::zero) , m_right(Vec3::xxx) , m_up(Vec3::yyy) , m_front(Vec3::zzz) , m_upFovDegrees(0.0f) , m_aspectRatio(0.0f) , m_rightMin(0.0f) , m_rightMax(0.0f) , m_upMin(0.0f) , m_upMax(0.0f) , m_frontMin(0.0f) , m_frontMax(0.0f) , m_preViewMatrix(Mat4::identity) , m_viewMatrix(Mat4::identity) , m_orthographicProjectionMatrix(Mat4::identity) , m_perspectiveProjectionMatrix(Mat4::identity) , m_viewOrthographicProjectionMatrix(Mat4::identity) , m_viewPerspectiveProjectionMatrix(Mat4::identity) , m_postProjectionMatrix(Mat4::identity) { updateViewMatrix(); updateProjectionMatrix(); updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }
// resize void Camera::ResizeWindow(int w, int h) { this->m_width = w; this->m_height = h; updateProjectionMatrix(); }
void Projector::update() { if(!m_pkCamera) return; updateOrientation(); updateModelViewMatrix(); updateProjectionMatrix(); float16 kViewPrj = m_kModelViewMatrix * m_kProjectionMatrix; float16 kInvViewPrj = inverse(kViewPrj); findFrustumCorners(m_akFrustum, kInvViewPrj); m_uiIntersectionCount = findPlanarIntersections(m_akIntersections, m_akFrustum); if(m_uiIntersectionCount > 0) { m_kRange = findProjectedRange(m_uiIntersectionCount, m_akIntersections, kViewPrj); findProjectedCorners(m_akCorners, m_kRange, kInvViewPrj); updateRangeMatrix(m_kRange); m_bIsVisible = true; } else { m_bIsVisible = false; } }
void CamtransCamera::orientLook(const Vector4 &eye, const Vector4 &look, const Vector4 &up) { // @TODO: [CAMTRANS] Fill this in... m_n = look; m_n = m_n.getNormalized(); m_n *= (-1); m_n.unhomgenize(); REAL uProjection = m_n.dot( up ); m_v.x = up.x - uProjection*m_n.x; m_v.y = up.y - uProjection*m_n.y; m_v.z = up.z - uProjection*m_n.z; m_v = m_v.getNormalized(); m_v.unhomgenize(); m_u = m_v; m_u = m_v.cross(m_n); m_u.unhomgenize(); m_eyePosition = eye; m_lookAt = look; m_up = up; REAL lN = m_lookAt.getMagnitude(); m_lookAt /= lN; m_lookAt.unhomgenize(); m_up = m_v; m_up.unhomgenize(); updateModelViewMatrix(); updateProjectionMatrix(); }
void Camera::perspective(float nFov, float nAspect, float nNear, float nFar) { fov = nFov; aspect = nAspect; near = nNear; far = nFar; projection_type = PERSPECTIVE; updateProjectionMatrix(); }
int windowSizeUpdated(unsigned int newWidth , unsigned int newHeight) { fprintf(stderr,"Window size changed to %u x %u\n",newWidth,newHeight); WIDTH=newWidth; HEIGHT=newHeight; updateProjectionMatrix(); return 1; }
void Camera::ortho(float nWidth, float nHeight, float nNear, float nFar) { ortho_width = nWidth; ortho_height = nHeight; near = nNear; far = nFar; projection_type = ORTHO_CENTER; updateProjectionMatrix(); }
void Camera::orthoBottomLeft(float nWidth, float nHeight, float nNear, float nFar) { ortho_width = nWidth; ortho_height = nHeight; near = nNear; far = nFar; projection_type = ORTHO_BOTTOM_LEFT; updateProjectionMatrix(); }
void CamtransCamera::setClip(float nearPlane, float farPlane) { // @TODO: [CAMTRANS] Fill this in... m_near = nearPlane; m_far = farPlane; updateProjectionMatrix(); }
void Camera::orthoTopLeft(float nWidth, float nHeight, float nNear, float nFar) { ortho_width = nWidth; ortho_height = nHeight; n = nNear; f = nFar; projection_type = ORTHO_TOP_LEFT; updateProjectionMatrix(); }
glm::mat4 Camera::getCameraMatrix(){ if( projectionChanged ){ updateProjectionMatrix(); } if( eyeChanged ){ updateCameraMatrix(); } return camera; }
/* Render::setSize: set size */ void Render::setSize(int w, int h) { if (m_width != w || m_height != h) { if (w > 0) m_width = w; if (h > 0) m_height = h; updateProjectionMatrix(); } }
void RenderingManager::processChangedSettings(const Settings::CategorySettingVector &changed) { for (Settings::CategorySettingVector::const_iterator it = changed.begin(); it != changed.end(); ++it) { if (it->first == "General" && it->second == "field of view") { mFieldOfView = Settings::Manager::getFloat("field of view", "General"); updateProjectionMatrix(); } else if (it->first == "Camera" && it->second == "viewing distance") { mViewDistance = Settings::Manager::getFloat("viewing distance", "Camera"); mStateUpdater->setFogEnd(mViewDistance); updateProjectionMatrix(); } else if (it->first == "General" && (it->second == "texture filtering" || it->second == "anisotropy")) updateTextureFiltering(); } }
Camera::Camera() :fov(60.0f) ,aspect(4.0f/3.0f) ,n(1.0f) ,f(600.0f) ,screen_width(0) ,screen_height(0) ,projection_type(PERSPECTIVE) { updateProjectionMatrix(); }
Camera::Camera(vec3 pos, float horiAngle, float vertAngle, float aspectRatio, float fovy, float viewDistance) : position(pos) { this->verticalAngle = vertAngle; this->horizontalAngle = horiAngle; this->aspect = aspectRatio; this->fovy = fovy; this->viewDistance = viewDistance; updateViewMatrix(); updateProjectionMatrix(); }
OrthographicCamera::OrthographicCamera(float _left, float _right, float _top, float _bottom, float _near, float _far) : Camera(), left(_left), right(_right), top(_top), bottom(_bottom), near(_near), far(_far) { updateProjectionMatrix(); }
void Camera::setFrustum(const float& rightMin, const float& rightMax, const float& upMin, const float& upMax, const float& frontMin, const float& frontMax) { m_rightMin = rightMin; m_rightMax = rightMax; m_upMin = upMin; m_upMax = upMax; m_frontMin = frontMin; m_frontMax = frontMax; updateProjectionMatrix(); updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }
void Camera::setResolution(glm::vec2 resolution) { resX = resolution.x; resY = resolution.y; updateProjectionMatrix(); m_aspectRatio = resX / resY; m_rasterBounds = Bounds2i( glm::vec2 ( -resX / 2.0, -resY / 2.0 ), glm::vec2 ( resX / 2.0, resY / 2.0 ) ); m_area = sensorArea(); }
void SpatialCamera::setFrustum(const float& l, const float& r, const float& b, const float& t, const float& n, const float& f) { m_projectionParameters.l = l; m_projectionParameters.r = r; m_projectionParameters.b = b; m_projectionParameters.t = t; m_projectionParameters.n = n; m_projectionParameters.f = f; updateProjectionMatrix(); updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }
// Reset the camera back to its defaults void Camera::reset() { setPosition(glm::vec3(0.0, 0.0, 0.5)); lookAt(glm::vec3(0.0, 0.0, -1.0), glm::vec3(0.0, 1.0, 0.0)); fieldOfView_ = 45.0f; // frustrum viewing aperture aspectRatio_ = 4.0f / 3.0f; // frustrum view angling nearFieldClip_ = 0.005f; // clip anything closer than this farFieldClip_ = 65536.0f; // clip anything farther than this updateProjectionMatrix(); }
void Camera::set() { updateViewMatrix(); updateProjectionMatrix(); glMatrixMode( GL_MODELVIEW ); glLoadMatrixf( view_matrix.m ); glMatrixMode( GL_PROJECTION ); glLoadMatrixf( projection_matrix.m ); glMatrixMode( GL_MODELVIEW ); }
void setViewOffset (T fullWidth, T fullHeight, T x, T y, T width, T height){ this->fullWidth = fullWidth; this->fullHeight = fullHeight; this->x = x; this->y = y; this->width = width; this->height = height; updateProjectionMatrix(); }
void Camera::setPerspective(float fov, float aspect, float near_plane, float far_plane) { type = PERSPECTIVE; this->fov = fov; this->aspect = aspect; this->near_plane = near_plane; this->far_plane = far_plane; //update projection updateProjectionMatrix(); }
void Camera::setOrthographic(float left, float right, float bottom, float top, float near_plane, float far_plane) { type = ORTHOGRAPHIC; this->left = left; this->right = right; this->bottom = bottom; this->top = top; this->near_plane = near_plane; this->far_plane = far_plane; updateProjectionMatrix(); }
// Reset the camera back to its defaults void Camera::reset() { auto startPos = glm::vec3(0, -1, 0); setPosition(startPos); lookAt(glm::vec3(0, 0, 0), glm::vec3(0, 0, 1)); translate(-startPos); fieldOfView_ = 45.0f; // frustrum viewing aperture aspectRatio_ = 4.0f / 3.0f; // frustrum view angling nearFieldClip_ = 0.005f; // clip anything closer than this farFieldClip_ = 65536.0f; // clip anything farther than this updateProjectionMatrix(); }
void SpatialCamera::setFrustum(const float& upFovRadian, const float& aspectRatio, const float& n, const float& f) { m_upFovRadian = upFovRadian; m_aspectRatio = aspectRatio; m_projectionParameters.n = n; m_projectionParameters.f = f; m_projectionParameters.t = n * tanf(0.5f * upFovRadian); m_projectionParameters.r = aspectRatio * m_projectionParameters.t; m_projectionParameters.b = -m_projectionParameters.t; m_projectionParameters.l = -m_projectionParameters.r; updateProjectionMatrix(); updateViewProjectionMatrix(); updateFrustumPlanesAndPoints(); }