// Moves the camera position void Camera::move(float tick) { pos += (destination-pos) * tick; if( (destination-pos).magnitude() < 0.05f ) in_action = false; setViewMatrix(); }
void Camera::rotate(float dx, float dy) { float roty = 1.5f * dx / mWidth; float rotx = 1.5f * dy / mHeight; float phi = rotx; float theta = roty; QVector3D cameraW = (mLookAtPosition - mCameraPosition).normalized(); QVector3D cameraU = QVector3D::crossProduct(cameraW, mUpVector).normalized(); QQuaternion q = (QQuaternion(theta, QVector3D(0.0, 1.0, 0.0)) * QQuaternion(phi, cameraU)).normalized(); QMatrix4x4 rotMat = QMatrix4x4(); rotMat.rotate(q); QVector3D tmp = mCameraPosition - mLookAtPosition; QVector4D myPoint = QVector4D(tmp, 1.0); QVector4D myVector = QVector4D(mUpVector); QVector4D newPos = rotMat * myPoint; QVector4D tmp1 = rotMat * myVector; // Hacky fix for some degeneracy newPos.setY(-newPos.y()); tmp1.setY(-tmp1.y()); mCameraPosition = QVector3D(newPos) + mLookAtPosition; mUpVector = QVector3D(tmp1).normalized(); setViewMatrix(mCameraPosition, mLookAtPosition, mUpVector); }
CCamera::CCamera() { d_LastTime = glfwGetTime(); m_viewMatrix = new glm::mat4(1); m_projectionMatrix = new glm::mat4(1); // Intrinsische Kameraparameter definieren stcpi_intrinsic.f_fieldOfView = 27.6380615; stcpi_intrinsic.f_aspect = 1.7777; stcpi_intrinsic.f_near = 0.1; stcpi_intrinsic.f_far = 100; setProjectionPerspMatrix(); stcmp_update.f_verticalAngle = 0.0f; stcmp_update.f_horizontalAngle = 3.1454f; stcmp_update.f_rotationSpeed = CAM_ROTATION_SPEED; stcmp_update.f_moveSpeed = CAM_MOVE_SPEED; stcv_update.v_eyePosition = glm::vec3(CAM_POS_X,CAM_POS_Y,CAM_POS_Z); stcv_update.v_eyeLookAt = glm::vec3(CAM_LOOK_AT_X,CAM_LOOK_AT_Y,CAM_LOOK_AT_Z); stcv_update.v_eyeUp = glm::vec3(CAM_UP_X,CAM_UP_Y,CAM_UP_Z); setViewMatrix(stcv_update.v_eyePosition, stcv_update.v_eyeLookAt, stcv_update.v_eyeUp); //setViewMatrix(glm::vec3(6.8,-5.9,4.9), glm::vec3(0,0,0), glm::vec3(-0.3,0.3,0.9)); }
void Camera::slide(float _du, float _dv, float _dn) { m_eye[0] = m_eye.x() + (_du * m_u.x() + _dv * m_v.x() + _dn * m_n.x()); m_eye[1] = m_eye.y() + (_du * m_u.y() + _dv * m_v.y() + _dn * m_n.y()); m_eye[2] = m_eye.z() + (_du * m_u.z() + _dv * m_v.z() + _dn * m_n.z()); setViewMatrix(); }
//---------------------------------------------------------------------------------------------------------------------- void PathCamera::update() noexcept { Vec3 ept=m_eyePath.getPointOnCurve(m_eyeCurvePoint); Vec3 lpt=m_lookPath.getPointOnCurve(m_lookCurvePoint); std::cout <<ept<<lpt<<std::endl; m_eye.set(ept); m_look.set(lpt); m_n=m_eye-m_look; m_u.set(m_up.cross(m_n)); m_v.set(m_n.cross(m_u)); m_u.normalize(); m_v.normalize(); m_n.normalize(); setViewMatrix(); m_eyeCurvePoint+=m_step; if(m_eyeCurvePoint>1.0) { m_eyeCurvePoint=0.0; } m_lookCurvePoint+=m_step; if(m_lookCurvePoint>1.0) { m_lookCurvePoint=0.0; } }
//---------------------------------------------------------------------------------------------------------------------- void Camera::slide( Real _du, Real _dv, Real _dn ) noexcept { // slide eye by amount du * u + dv * v + dn * n; m_eye.m_x += _du * m_u.m_x + _dv * m_v.m_x + _dn * m_n.m_x; m_eye.m_y += _du * m_u.m_y + _dv * m_v.m_y + _dn * m_n.m_y; m_eye.m_z += _du * m_u.m_z + _dv * m_v.m_z + _dn * m_n.m_z; setViewMatrix(); }
//---------------------------------------------------------------------------------------------------------------------- void Camera::move( Real _dx, Real _dy, Real _dz ) noexcept { // simply add the translation to the current eye point m_eye.m_x += _dx; m_eye.m_y += _dy; m_eye.m_z += _dz; setViewMatrix(); }
void ArcShaderProgram::run(ArcCanvas &canvas, ArcMatrix view) { glUseProgram(mProgram); ExitOnGLError("ERROR: Could not use the shader program"); setViewMatrix(view); canvas.draw(); glUseProgram(0); }
void TerosCam::setcampos (double x, double y, double z) { m_camx = x; m_camy = y; m_camz = z; m_position.set(m_camx, m_camy, m_camz, 1.0f); setViewMatrix(); }
//----------------------------------------------------------------------------- // Description: Overloadable update function // Parameters: // Returns: True if the application wants to continue, false otherwise // Notes: This implementation updates the modelview matrix //----------------------------------------------------------------------------- bool FWGCMCamApplication::onUpdate() { if(FWGCMApplication::onUpdate() == false) return false; mCamera.update(); setViewMatrix(mCamera.getMatrix()); return true; }
// Looks at a given point void Camera::lookat(vector3f target) { target = target - pos; theta = getAngle(vector3f(-1, 0, 0), target); if( target.z > 0 ) theta = -theta; phi = -getAngle(vector3f(0, 1, 0), target); setViewMatrix(); }
void GFXGLDevice::setClipRect( const RectI &inRect ) { AssertFatal(mCurrentRT.isValid(), "GFXGLDevice::setClipRect - must have a render target set to do any rendering operations!"); // Clip the rect against the renderable size. Point2I size = mCurrentRT->getSize(); RectI maxRect(Point2I(0,0), size); mClip = inRect; mClip.intersect(maxRect); // Create projection matrix. See http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/ortho.html const F32 left = mClip.point.x; const F32 right = mClip.point.x + mClip.extent.x; const F32 bottom = mClip.extent.y; const F32 top = 0.0f; const F32 nearPlane = 0.0f; const F32 farPlane = 1.0f; const F32 tx = -(right + left)/(right - left); const F32 ty = -(top + bottom)/(top - bottom); const F32 tz = -(farPlane + nearPlane)/(farPlane - nearPlane); static Point4F pt; pt.set(2.0f / (right - left), 0.0f, 0.0f, 0.0f); mProjectionMatrix.setColumn(0, pt); pt.set(0.0f, 2.0f/(top - bottom), 0.0f, 0.0f); mProjectionMatrix.setColumn(1, pt); pt.set(0.0f, 0.0f, -2.0f/(farPlane - nearPlane), 0.0f); mProjectionMatrix.setColumn(2, pt); pt.set(tx, ty, tz, 1.0f); mProjectionMatrix.setColumn(3, pt); // Translate projection matrix. static MatrixF translate(true); pt.set(0.0f, -mClip.point.y, 0.0f, 1.0f); translate.setColumn(3, pt); mProjectionMatrix *= translate; setMatrix(GFXMatrixProjection, mProjectionMatrix); MatrixF mTempMatrix(true); setViewMatrix( mTempMatrix ); setWorldMatrix( mTempMatrix ); // Set the viewport to the clip rect RectI viewport(mClip.point.x, mClip.point.y, mClip.extent.x, mClip.extent.y); setViewport(viewport); }
void Camera::zoom(float d) { mRealDiv = mWidth + mHeight; QVector3D dir = (mCameraPosition - mLookAtPosition).normalized(); totalZoom += 9.0 * d / mRealDiv; totalZoom = std::max(totalZoom, 0.1f); QVector3D change2 = mLookAtPosition + dir * totalZoom; mCameraPosition = change2; setViewMatrix(mCameraPosition, mLookAtPosition, mUpVector); }
//---------------------------------------------------------------------------------------------------------------------- void Camera::normalisedPitch(Real _angle ) noexcept { // build a rotation matrix around the y axis Mat4 mat; mat.identity(); mat.rotateX(_angle); //multiply all three local coord vectors by the matrix m_u = m_u * mat; m_v = m_v * mat; m_n = m_n * mat; // reset the modelview matrix setViewMatrix(); }
DisplayTexture::DisplayTexture() { setReferenceFrame(osg::Transform::ABSOLUTE_RF); setRenderOrder(osg::Camera::POST_RENDER); setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); setViewMatrix(osg::Matrix()); setProjectionMatrix(osg::Matrix::ortho2D(0, 1, 0, 1)); getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF); addChild(createFullscreenQuad()); setName("Display"); }
// Changes the cameras rotation. Used for free looking with the mouse. void Camera::lookat(float dx,float dy,float sensitivity,float dt) { theta += dx * sensitivity * dt; phi -= dy * sensitivity * dt; theta = fmod(theta,360); if( phi < -180 ) phi = -179.9999; else if( phi > 0 ) phi = -0.0001; setViewMatrix(); }
// Looks at a given point void Camera::lookat(float x, float y, float z) { vector3f target(x,y,z); target = target - pos; theta = getAngle(vector3f(-1, 0, 0), target); if( target.z > 0 ) theta = -theta; phi = -getAngle(vector3f(0, 1, 0), target); setViewMatrix(); }
//---------------------------------------------------------------------------------------------------------------------- void Camera :: set(const Vec3 &_eye, const Vec3 &_look, const Vec3 &_up ) noexcept { // make U, V, N vectors m_eye=_eye; m_look=_look; m_up=_up; m_n=m_eye-m_look; m_u=m_up.cross(m_n); m_v=m_n.cross(m_u); m_u.normalize(); m_v.normalize(); m_n.normalize(); setViewMatrix(); }
//---------------------------------------------------------------------------------------------------------------------- void Camera::moveLook(Real _dx, Real _dy, Real _dz ) noexcept { m_look.m_x+=_dx; m_look.m_y+=_dy; m_look.m_z+=_dz; m_n=m_eye-m_look; m_u.set(m_up.cross(m_n)); m_v.set(m_n.cross(m_u)); // normalise vectors m_u.normalize(); m_v.normalize(); m_n.normalize(); // pass to OpenGL setViewMatrix(); }
void Camera::init(float ratio) { pos = vector3f(0,0,0); heading = vector3f(0,0,-1); up = vector3f(0,1,0); right = vector3f(1,0,0); destination = vector3f(0,0,0); theta = 90; phi = -90; speed = 1.0f; in_action = false; setViewMatrix(); setProjectionMatrix(ratio); }
// Replacement Camera Functions for hnadling movenet though mouse // TODO: Clean up most of the above code void Camera::translate(float dx, float dy) { QVector3D cameraW = (mLookAtPosition - mCameraPosition).normalized(); QVector3D cameraU = QVector3D::crossProduct(mUpVector, cameraW).normalized(); QVector3D changel = mLookAtPosition + mUpVector * (10.0 * dy / mWidth) + cameraU * (10.0 * dx / mHeight); QVector3D changec = mCameraPosition + mUpVector * (10.0 * dy / mWidth) + cameraU * (10.0 * dx / mHeight); mCameraPosition = changec; mLookAtPosition = changel; setViewMatrix(mCameraPosition, mLookAtPosition, mUpVector); }
void Camera::set(const openvdb::Vec3f &_eye, const openvdb::Vec3f &_look, const openvdb::Vec3f &_up) { m_eye=openvdb::Vec4s(_eye.x(),_eye.y(),_eye.z(),0.0); m_look=openvdb::Vec4s(_look.x(),_look.y(),_look.z(),0.0); m_up=openvdb::Vec4s(_up.x(),_up.y(),_up.z(),0.0); m_n=m_eye-m_look; openvdb::Vec3f u3,v3; u3 = m_up.getVec3().cross(m_n.getVec3()); m_u=openvdb::Vec4f(u3.x(),u3.y(),u3.z(),0.0f); v3 = m_n.getVec3().cross(m_u.getVec3()); m_v=openvdb::Vec4f(v3.x(),v3.y(),v3.z(),0.0f); m_u.normalize(); m_v.normalize(); m_n.normalize(); setViewMatrix(); }
bool Drawable::init() { static const GLfloat I[] = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; if (program_.create() && addShaders() && program_.link()) { setProjectionMatrix(I); setViewMatrix(I); setModelMatrix(I); return true; } return false; }
void TerosCam::basisreset () { cambasisx [0] = 1; cambasisx [1] = 0; cambasisx [2] = 0; cambasisy [0] = 0; cambasisy [1] = 1; cambasisy [2] = 0; cambasisz [0] = 0; cambasisz [1] = 0; cambasisz [2] = 1; setViewMatrix(); }
void Camera::setEye(openvdb::Vec4f _e) { m_eye=_e; m_n=m_eye-m_look; openvdb::Vec3f u3,v3; u3 = m_up.getVec3().cross(m_n.getVec3()); m_u=openvdb::Vec4f(u3.x(),u3.y(),u3.z(),0.0f); v3 = m_n.getVec3().cross(m_u.getVec3()); m_v=openvdb::Vec4f(v3.x(),v3.y(),v3.z(),0.0f); m_u.normalize(); m_v.normalize(); m_n.normalize(); setViewMatrix(); }
void RenderTargetD3D9::setRenderState( const RenderState & rs) { //矩阵状态 setWorldMatrix( rs.m_mtxWorld); setViewMatrix(rs.m_mtxView); setProjectionMatrix( rs.m_mtxProjection); //背面拣选 setCullingMode(rs.m_cullingMode); //光照参数 setLightingEnabled(rs.m_bLightingEnabled); //深度检测 setDepthBufferCheckEnabled(rs.m_bDepthCheckEnabled); setDepthBufferFunction(rs.m_DepthBufferFunction); setDepthBufferWriteEnabled(rs.m_bDepthWriteEnabled); }
//---------------------------------------------------------------------------------------------------------------------- void PathCamera::updateLooped() noexcept { Vec3 ept=m_eyePath.getPointOnCurve(m_eyeCurvePoint); Vec3 lpt=m_lookPath.getPointOnCurve(m_lookCurvePoint); m_eye.set(ept); m_look.set(lpt); m_n=m_eye-m_look; m_u=m_up.cross(m_n); m_v=m_n.cross(m_u); m_u.normalize(); m_v.normalize(); m_n.normalize(); setViewMatrix(); if(m_dir==CAMFWD) { m_eyeCurvePoint+=m_step; if(m_eyeCurvePoint>=1.0) { m_dir=CAMBWD; } m_lookCurvePoint+=m_step; if(m_lookCurvePoint>=1.0) { m_dir=CAMBWD; } } // end if fwd else { m_eyeCurvePoint-=m_step; if(m_eyeCurvePoint<=m_step) { m_dir=CAMFWD; } m_lookCurvePoint-=m_step; if(m_lookCurvePoint<=m_step) { m_dir=CAMFWD; } }// end else }
void Camera::moveLook(float _dx, float _dy, float _dz) { m_look[0] = m_look.x() + _dx; m_look[1] = m_look.y() + _dy; m_look[2] = m_look.z() + _dz; m_n=m_eye-m_look; openvdb::Vec3f u3,v3; u3 = m_up.getVec3().cross(m_n.getVec3()); m_u=openvdb::Vec4f(u3.x(),u3.y(),u3.z(),0.0f); v3 = m_n.getVec3().cross(m_u.getVec3()); m_v=openvdb::Vec4f(v3.x(),v3.y(),v3.z(),0.0f); m_u.normalize(); m_v.normalize(); m_n.normalize(); setViewMatrix(); }
// Intercept cull visitor and adjust traversal mask to skip triton drawable void PlanarReflection::accept(osg::NodeVisitor& nv) { osgUtil::CullVisitor * cv = dynamic_cast< osgUtil::CullVisitor* >( &nv ); if( cv ) { // Update view and projection matrices from main camera osg::Matrix view = _sceneCamera->getViewMatrix(); osg::Matrix projection = _sceneCamera->getProjectionMatrix(); setViewMatrix( view ); setProjectionMatrix( projection ); // Triton Shader expects matrix that takes world coords with origin translated to camera position view.setTrans( 0, 0, 0 ); _textureProjectionMatrix->set( view * projection * osg::Matrix::translate( 1,1,1 ) * osg::Matrix::scale( 0.5, 0.5, 0.5 ) ); } Camera::accept( nv ); }
Camera::Camera(QVector3D position, QVector3D center, float width, float height, float fovy, float zNear, float zFar) { m_world.lookAt(position, center, LocalUp); mWidth = width; mHeight = height; mFOVy = fovy; mZNear = zNear; mZFar = zFar; mCameraPosition = position; mLookAtPosition = center; mUpVector = QVector3D(0,1,0); setModelMatrix(QVector3D(1,0,0),0,QVector3D(0,0,0),QVector3D(1,1,1)); setProjectionMatrix(mWidth, mHeight); setViewMatrix(mCameraPosition, mLookAtPosition, mUpVector); totalZoom = position.distanceToPoint(center); }