ofRectangle ofMatrixStack::getCurrentViewport() const{ ofRectangle tmpCurrentViewport = currentViewport; if (isVFlipped()){ tmpCurrentViewport.y = getRenderSurfaceHeight() - (tmpCurrentViewport.y + tmpCurrentViewport.height); } if(!doesHWOrientation() && (orientation==OF_ORIENTATION_90_LEFT || orientation==OF_ORIENTATION_90_RIGHT)){ swap(tmpCurrentViewport.width,tmpCurrentViewport.height); swap(tmpCurrentViewport.x,tmpCurrentViewport.y); } return tmpCurrentViewport; }
ofRectangle ofMatrixStack::getCurrentViewport(){ ofRectangle currentViewport = this->currentViewport; if (isVFlipped()){ currentViewport.y = getRenderSurfaceHeight() - (currentViewport.y + currentViewport.height); } if(!doesHWOrientation() && (orientation==OF_ORIENTATION_90_LEFT || orientation==OF_ORIENTATION_90_RIGHT)){ swap(currentViewport.width,currentViewport.height); swap(currentViewport.x,currentViewport.y); } return currentViewport; }
void ofMatrixStack::viewport(float x, float y, float width, float height, bool vflip){ if(!doesHWOrientation() && (orientation==OF_ORIENTATION_90_LEFT || orientation==OF_ORIENTATION_90_RIGHT)){ swap(width,height); swap(x,y); } if(width == 0 || height == 0){ width = getRenderSurfaceWidth(); height = getRenderSurfaceHeight(); } if (vflip){ y = getRenderSurfaceHeight() - (y + height); } currentViewport.set(x,y,width,height); }
void ofMatrixStack::setOrientation(ofOrientation _orientation, bool vFlip){ vFlipped = vFlip; orientation = _orientation; if(vFlip){ handedness = OF_LEFT_HANDED; }else{ handedness = OF_RIGHT_HANDED; } orientationMatrix = glm::mat4(1.0); bool vFlipMatrix = customMatrixNeedsFlip(); if(vFlipMatrix) orientationMatrix = glm::scale(orientationMatrix, glm::vec3(1.f,-1.f,1.f)); if(!doesHWOrientation()){ switch(orientation) { case OF_ORIENTATION_180: orientationMatrix = glm::rotate(orientationMatrix, glm::pi<float>(), glm::vec3{0.f, 0.f, 1.f}); break; case OF_ORIENTATION_90_RIGHT: orientationMatrix = glm::rotate(orientationMatrix, glm::half_pi<float>(), glm::vec3{0.f, 0.f, 1.f}); break; case OF_ORIENTATION_90_LEFT: orientationMatrix = glm::rotate(orientationMatrix, -glm::half_pi<float>(), glm::vec3{0.f, 0.f, 1.f}); break; case OF_ORIENTATION_DEFAULT: default: break; } } orientationMatrixInverse = glm::inverse(orientationMatrix); orientedProjectionMatrix = orientationMatrix * projectionMatrix; modelViewProjectionMatrix = orientedProjectionMatrix * modelViewMatrix; }
void ofMatrixStack::setOrientation(ofOrientation _orientation, bool vFlip){ vFlipped = vFlip; orientation = _orientation; if(vFlip){ handedness = OF_LEFT_HANDED; }else{ handedness = OF_RIGHT_HANDED; } orientationMatrix.makeIdentityMatrix(); bool vFlipMatrix = customMatrixNeedsFlip(); if(vFlipMatrix) orientationMatrix.scale(1,-1,1); if(!doesHWOrientation()){ switch(orientation) { case OF_ORIENTATION_180: orientationMatrix.rotate(180,0,0,1); break; case OF_ORIENTATION_90_RIGHT: orientationMatrix.rotate(90,0,0,1); break; case OF_ORIENTATION_90_LEFT: orientationMatrix.rotate(-90,0,0,1); break; case OF_ORIENTATION_DEFAULT: default: break; } } orientationMatrixInverse = orientationMatrix.getInverse(); orientedProjectionMatrix = projectionMatrix * orientationMatrix; modelViewProjectionMatrix = modelViewMatrix * orientedProjectionMatrix; }