Camera::Camera(cv::Mat proj){ //Set projection matrix setProjectionMatrix(proj); //Calculate and store origin m_origin = this->calcOrigin(); }
void SceneView::setProjectionMatrixAsFrustum(double left, double right, double bottom, double top, double zNear, double zFar) { setProjectionMatrix(osg::Matrixd::frustum(left, right, bottom, top, zNear, zFar)); }
void Renderer::init(GLSLProgram & shader) { setProjectionMatrix(30,1, 1, -100, projection); shader.use(); shader.setUniformMatrix4fv("projectionMatrix", projection); shader.unuse(); }
void Renderer::resizeGlScene(int width, int height){ if (height == 0) height = 1; winWidth = width; winHeight = height; glViewport(0, 0, width, height); // Reset The Current Viewport setProjectionMatrix(); }
void QSGRenderer::setProjectionMatrixToRect(const QRectF &rect) { QMatrix4x4 matrix; matrix.ortho(rect.x(), rect.x() + rect.width(), rect.y() + rect.height(), rect.y(), qreal(0.01), -1); setProjectionMatrix(matrix); }
void CRender::orthoSet(float xres, float yres) { float xhalf, yhalf; setProjectionMatrix(); pushMatrix(); xhalf = (xres==-1) ? (this->m_Width)*0.5 : xres*0.5; yhalf = (yres==-1) ? (this->m_Height)*0.5 : yres*0.5; glViewport(0, 0, m_Width, m_Height); glOrtho(-xhalf, xhalf, -yhalf, yhalf, m_OrthoNear, m_OrthoFar); setModelMatrix(); }
/** * @brief Sets the projection matrix as a perspective matrix. * * Creates a perspective matrix with the given parameters and sets as the projection matrix. * @param fy Vertical field of view angle * @param in_aspect_ratio Ratio of width to the height of the viewport * @param in_near_plane Near plane * @param in_far_plane Far plane * @return The created perspective matrix. */ Eigen::Matrix4f setPerspectiveMatrix (float fy, float in_aspect_ratio, float in_near_plane,float in_far_plane) { fovy = fy; aspect_ratio = in_aspect_ratio; near_plane = in_near_plane; far_plane = in_far_plane; Eigen::Matrix4f proj = createPerspectiveMatrix(fovy, aspect_ratio, near_plane, far_plane); setProjectionMatrix(proj); use_perspective = true; return proj; }
Minimap::Minimap(const Common::UString &map, int northAxis, float mapPt1X, float mapPt1Y, float mapPt2X, float mapPt2Y, float worldPt1X, float worldPt1Y, float worldPt2X, float worldPt2Y) : _mapQuad("lbl_map" + map, 0, 0, 512, 256), _northAxis(northAxis), _mapPt1X(mapPt1X), _mapPt1Y(mapPt1Y), _mapPt2X(mapPt2X), _mapPt2Y(mapPt2Y), _worldPt1X(worldPt1X), _worldPt1Y(worldPt1Y), _worldPt2X(worldPt2X), _worldPt2Y(worldPt2Y) { add(&_mapQuad); glm::mat4 projection(glm::ortho(0.0f, 120.0f, 0.0f, 120.0f, -1.0f, 1.0f)); setProjectionMatrix(projection); }
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"); }
void Painter::restoreSavedState() { m_oldStateIndex--; setResolution(m_olderStates[m_oldStateIndex].resolution); setProjectionMatrix(m_olderStates[m_oldStateIndex].projectionMatrix); setTextureMatrix(m_olderStates[m_oldStateIndex].textureMatrix); setColor(m_olderStates[m_oldStateIndex].color); setOpacity(m_olderStates[m_oldStateIndex].opacity); setCompositionMode(m_olderStates[m_oldStateIndex].compositionMode); setClipRect(m_olderStates[m_oldStateIndex].clipRect); setShaderProgram(m_olderStates[m_oldStateIndex].shaderProgram); setTexture(m_olderStates[m_oldStateIndex].texture); setAlphaWriting(m_olderStates[m_oldStateIndex].alphaWriting); }
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); }
void GFXD3D9Device::setClipRect( const RectI &inRect ) { // We transform the incoming rect by the view // matrix first, so that it can be used to pan // and scale the clip rect. // // This is currently used to take tiled screenshots. Point3F pos( inRect.point.x, inRect.point.y, 0.0f ); Point3F extent( inRect.extent.x, inRect.extent.y, 0.0f ); getViewMatrix().mulP( pos ); getViewMatrix().mulV( extent ); RectI rect( pos.x, pos.y, extent.x, extent.y ); // Clip the rect against the renderable size. Point2I size = mCurrentRT->getSize(); RectI maxRect(Point2I(0,0), size); rect.intersect(maxRect); mClipRect = rect; F32 l = F32( mClipRect.point.x ); F32 r = F32( mClipRect.point.x + mClipRect.extent.x ); F32 b = F32( mClipRect.point.y + mClipRect.extent.y ); F32 t = F32( mClipRect.point.y ); // Set up projection matrix, static Point4F pt; pt.set(2.0f / (r - l), 0.0f, 0.0f, 0.0f); mTempMatrix.setColumn(0, pt); pt.set(0.0f, 2.0f/(t - b), 0.0f, 0.0f); mTempMatrix.setColumn(1, pt); pt.set(0.0f, 0.0f, 1.0f, 0.0f); mTempMatrix.setColumn(2, pt); pt.set((l+r)/(l-r), (t+b)/(b-t), 1.0f, 1.0f); mTempMatrix.setColumn(3, pt); setProjectionMatrix( mTempMatrix ); // Set up world/view matrix mTempMatrix.identity(); setWorldMatrix( mTempMatrix ); setViewport( mClipRect ); }
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 Camera::setShape(float _viewAngle, float _aspect, float _near, float _far) { if(_viewAngle >180.0) { _viewAngle=180.0; } ; if(_near<CAMERANEARLIMIT) { _near=CAMERANEARLIMIT; } m_FOV = _viewAngle; // viewangle in degrees - must be < 180 m_aspect = _aspect; m_nearPlane = _near; m_farPlane = _far; setProjectionMatrix(); }
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 ShaderProgram::drawQuadInternal(SkRect& geometry, GLint textureId, float opacity, GLint program, GLint projectionMatrixHandle, GLint texSampler, GLenum textureTarget, GLint position, GLint alpha, GLint texFilter, GLint contrast) { glUseProgram(program); if (!geometry.isEmpty()) setProjectionMatrix(geometry, projectionMatrixHandle); else { TransformationMatrix matrix; // Map x,y from (0,1) to (-1, 1) matrix.scale3d(2, 2, 1); matrix.translate3d(-0.5, -0.5, 0); GLfloat projectionMatrix[16]; GLUtils::toGLMatrix(projectionMatrix, matrix); glUniformMatrix4fv(projectionMatrixHandle, 1, GL_FALSE, projectionMatrix); } glActiveTexture(GL_TEXTURE0); glUniform1i(texSampler, 0); glBindTexture(textureTarget, textureId); glTexParameteri(textureTarget, GL_TEXTURE_MIN_FILTER, texFilter); glTexParameteri(textureTarget, GL_TEXTURE_MAG_FILTER, texFilter); glTexParameteri(textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glBindBuffer(GL_ARRAY_BUFFER, m_textureBuffer[0]); glEnableVertexAttribArray(position); glVertexAttribPointer(position, 2, GL_FLOAT, GL_FALSE, 0, 0); glUniform1f(alpha, opacity); if (contrast != -1) glUniform1f(contrast, m_contrast); setBlendingState(opacity < 1.0); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); }
void Camera::setShape(Real _viewAngle, Real _aspect, Real _near, Real _far ) noexcept { // load projection matrix and camera values if(_viewAngle >180.0) { _viewAngle=180.0; } NGL_ASSERT(_far>_near); NGL_ASSERT(_near>CAMERANEARLIMIT); if(_near<CAMERANEARLIMIT) { _near=CAMERANEARLIMIT; } m_fov = _viewAngle; // viewangle in degrees - must be < 180 m_aspect = _aspect; m_zNear = _near; m_zFar = _far; setProjectionMatrix(); //calculateFrustum(); }
HelpScreen::HelpScreen(void) : Level(LEVEL_MENU, UserInterface()) { int windowWidth = GameApp::getInstance()->getWindowWidth(); int windowHeight = GameApp::getInstance()->getWindowHeight(); setProjectionMatrix(Matrix4::Perspective(1.0f, -100.0f, 1280.0f / 720.0f, 45.0f)); setCameraMatrix(Matrix4::Translation(Vector3(0, 0, 0))); Texture *bgTexture = Texture::getOrCreate("InstructionsBg", "resources/images/HeXcape Instructions.png"); ImageItem *background = new ImageItem(Vector2(), 0, Vector2((float) (windowWidth), (float) (windowHeight)), bgTexture); userInterface->addItem(background, "BackgroundHelp"); // Create the menu buttons ButtonItem *backButton = new ButtonItem(Vector2(900, 840), 0, Vector2(800, 120), "MenuButton", "resources/images/MenuButton.png", "resources/images/MenuButtonHov.png", "resources/images/MenuButtonPress.png", "resources/images/MenuButtonPress.png"); // Draw some text over the buttons background TextItem *backText = new TextItem(Vector2(1020, 860), 0, "Back To Menu", 72); backText->setFont("resources/fonts/Neuropol.ttf"); actionAfterFade = 0; // Set the ambience music Music *music = Music::getOrCreate("resources/audio/Doors.mp3", "MenuMusic"); userInterface->addItem(backButton, "ZBackButton"); userInterface->addItem(backText, "ZBackText"); }
// 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); }
WindowPaintData::WindowPaintData(const WindowPaintData &other) : PaintData() , quads(other.quads) , shader(other.shader) , d(new WindowPaintDataPrivate()) { setXScale(other.xScale()); setYScale(other.yScale()); setZScale(other.zScale()); translate(other.translation()); setRotationOrigin(other.rotationOrigin()); setRotationAxis(other.rotationAxis()); setRotationAngle(other.rotationAngle()); setOpacity(other.opacity()); setSaturation(other.saturation()); setBrightness(other.brightness()); setScreen(other.screen()); setCrossFadeProgress(other.crossFadeProgress()); setProjectionMatrix(other.projectionMatrix()); setModelViewMatrix(other.modelViewMatrix()); d->screenProjectionMatrix = other.d->screenProjectionMatrix; }
void GFXD3D9Device::setClipRect( const RectI &inRect ) { // Clip the rect against the renderable size. Point2I size = mCurrentRT->getSize(); RectI maxRect(Point2I(0,0), size); RectI rect = inRect; rect.intersect(maxRect); mClipRect = rect; F32 l = F32( mClipRect.point.x ); F32 r = F32( mClipRect.point.x + mClipRect.extent.x ); F32 b = F32( mClipRect.point.y + mClipRect.extent.y ); F32 t = F32( mClipRect.point.y ); // Set up projection matrix, static Point4F pt; pt.set(2.0f / (r - l), 0.0f, 0.0f, 0.0f); mTempMatrix.setColumn(0, pt); pt.set(0.0f, 2.0f/(t - b), 0.0f, 0.0f); mTempMatrix.setColumn(1, pt); pt.set(0.0f, 0.0f, 1.0f, 0.0f); mTempMatrix.setColumn(2, pt); pt.set((l+r)/(l-r), (t+b)/(b-t), 1.0f, 1.0f); mTempMatrix.setColumn(3, pt); setProjectionMatrix( mTempMatrix ); // Set up world/view matrix mTempMatrix.identity(); setViewMatrix( mTempMatrix ); setWorldMatrix( mTempMatrix ); setViewport( mClipRect ); }
void SceneView::setProjectionMatrixAsPerspective(double fovy,double aspectRatio, double zNear, double zFar) { setProjectionMatrix(osg::Matrixd::perspective(fovy,aspectRatio, zNear, zFar)); }
void MHCamera::makePerspective(float ratio, Degree fov) { setProjectionMatrix(Matrix::Perspective(ratio, Radian(fov), 1.0f, _viewDistance)); }
void MSRenderer::updateState() { setProjectionMatrix(); configureVideoBackground(); }
void calcuatetransformationMatrix( Camera eye, glm::vec2 resolution, float front, float back) { /*glm::vec4 normal = glm::vec4(glm::normalize(glm::vec3(center - eye.position)),0); glm::vec4 Y = glm::normalize(glm::vec4(eye.up,0) - glm::dot(glm::vec4(eye.up,0),normal ) * normal); glm::vec4 X = glm::cross(Y, normal);*/ /*glm::vec3 Z = glm::normalize(glm::vec3(center - eye.position)); glm::vec3 Y = glm::normalize(eye.up - glm::dot(eye.up, Z) * Z); glm::vec3 X = glm::cross(Y, Z); glm::mat4 m; // Look At trans_matrix.x.x = X.x; trans_matrix.y.x = X.y; trans_matrix.z.x = X.z; trans_matrix.w.x = -1 * eye.position.x; trans_matrix.x.y = Y.x; trans_matrix.y.y = Y.y; trans_matrix.z.y = Y.z; trans_matrix.w.y = -1 * eye.position.y; trans_matrix.x.z = Z.x; trans_matrix.y.z = Z.y; trans_matrix.z.z = Z.z; trans_matrix.w.z = -1 * eye.position.z; trans_matrix.x.w = 0; trans_matrix.y.w = 0; trans_matrix.z.w = 0; trans_matrix.w.w = 1; //Perspective ViewPort Transform glm::vec2 w_start; glm::vec2 w_end; cudaMat4 viewport_trans; viewport_trans.x = glm::vec4(2.0f * view_plane / far / resolution.x, 0,0,0); viewport_trans.y = glm::vec4(0, 2.0f * view_plane / far / resolution.y,0,0); viewport_trans.z = glm::vec4((2.0f * glm::dot(X,Z) - (w_end.x + w_start.x)) / ((w_end.x - w_start.x)*far), (2.0f * glm::dot(Y,Z) - (w_end.y + w_start.y)) / ((w_end.x - w_start.x)*far), 1.0f / far, 0); viewport_trans.w = glm::vec4(0,0,0,1); trans_Matrix = multiplyMV(view_port_trans, trans_Matrix);*/ glm::vec3 Z = -1.0f * eye.view; glm::vec3 Y = glm::normalize(eye.up - glm::dot(eye.up, Z) * Z); glm::vec3 X = glm::normalize(glm::cross(1.0f * Y, Z)); //Look At glm::mat4 lookatMatrix; /*lookatMatrix[0][0] = X.x; lookatMatrix[0][1] = X.y; lookatMatrix[0][2] = X.z; lookatMatrix[0][3] = -1 * eye.position.x; lookatMatrix[1][0] = Y.x; lookatMatrix[1][1] = Y.y; lookatMatrix[ 1][2] = Y.z; lookatMatrix[1][3] = -1 * eye.position.y; lookatMatrix[2][0] = Z.x; lookatMatrix[2][1] = Z.y; lookatMatrix[2][2] = Z.z; lookatMatrix[2][3] = -1 * eye.position.z; lookatMatrix[3][0] = 0; lookatMatrix[3][1] = 0; lookatMatrix[3][2] = 0; lookatMatrix[3][3] = 1;*/ lookatMatrix[0][0] = X.x; lookatMatrix[0][1] = Y.x; lookatMatrix[0][2] = Z.x; lookatMatrix[0][3] = 0; lookatMatrix[1][0] = X.y; lookatMatrix[1][1] = Y.y; lookatMatrix[1][2] = Z.y; lookatMatrix[1][3] = 0; lookatMatrix[2][0] = X.z; lookatMatrix[2][1] = Y.z; lookatMatrix[2][2] = Z.z; lookatMatrix[2][3] = 0; lookatMatrix[3][0] = 0; lookatMatrix[3][1] = 0; lookatMatrix[3][2] = 0; lookatMatrix[3][3] = 1; glm::vec4 newtranslation = lookatMatrix * glm::vec4(-1.0f * eye.position,1); lookatMatrix[3] = newtranslation; float aspectRatio = resolution.x / resolution.y; float inverseTanFov = 1.0f / tan((eye.fov * PI/ 180.0f)); glm::mat4 viewTrans; /* viewTrans[0][0] = inverseTanFov / aspectRatio; viewTrans[0][1] = 0; viewTrans[0][2] = 0; viewTrans[0][3] = 0; viewTrans[1][0] = 0; viewTrans[1][1] = inverseTanFov; viewTrans[1][2] = 0; viewTrans[1][3] = 0; viewTrans[2][0] = 0; viewTrans[2][1] = 0; viewTrans[2][2] = (front + back)/(front - back); viewTrans[2][3] = 2 * front * back / (front - back); viewTrans[3][0] = 0; viewTrans[3][1] = 0; viewTrans[3][2] = -1; viewTrans[3][3] = 0;*/ viewTrans[0][0] = inverseTanFov / aspectRatio; viewTrans[0][1] = 0; viewTrans[0][2] = 0; viewTrans[0][3] = 0; viewTrans[1][0] = 0; viewTrans[1][1] = inverseTanFov; viewTrans[1][2] = 0; viewTrans[1][3] = 0; viewTrans[2][0] = 0; viewTrans[2][1] = 0; viewTrans[2][2] = (front + back)/(front - back); viewTrans[2][3] = -1; viewTrans[3][0] = 0; viewTrans[3][1] = 0; viewTrans[3][2] = 2 * front * back / (front - back); viewTrans[3][3] = 0; setProjectionMatrix(viewTrans); setViewMatrix(lookatMatrix); //return viewTrans * lookatMatrix; //return glm::mat4(1.0); //Look At //return lookatMatrix; }
Frustum(const Mat4f &projmat) { setProjectionMatrix(projmat); }
void SharedProgramState::setOrthoProjectionMatrix(float width, float height) { setProjectionMatrix(ortho(0.f, width, 0.f, height)); }
void SceneView::setProjectionMatrixAsOrtho2D(double left, double right, double bottom, double top) { setProjectionMatrix(osg::Matrixd::ortho2D(left, right, bottom, top)); }
void MHCamera::makeCenterOrtho(float x, float y, float width, float height) { setProjectionMatrix(Matrix::CenterOrtho(width, height, Vector2(x, y), 1.0, _viewDistance)); }