本文整理汇总了C++中ogre::Camera::getProjectionMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ Camera::getProjectionMatrix方法的具体用法?C++ Camera::getProjectionMatrix怎么用?C++ Camera::getProjectionMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::Camera
的用法示例。
在下文中一共展示了Camera::getProjectionMatrix方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: notifyMaterialRender
void CameraBlurListener::notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
{
if (pass_id == 999)
{
if(mApp->pGame->pause == false)
{
//acquire the texture flipping attribute in the first frame
if(compositorinstance)
{
mRequiresTextureFlipping = compositorinstance->getRenderTarget("previousscene")->requiresTextureFlipping();
compositorinstance=NULL;
}
// this is the camera you're using
#ifndef ROAD_EDITOR
Ogre::Camera *cam = mApp->mSplitMgr->mCameras.front();
#else
Ogre::Camera *cam = mApp->mCamera;
#endif
// get the pass
Ogre::Pass *pass = mat->getBestTechnique()->getPass(0);
Ogre::GpuProgramParametersSharedPtr params = pass->getFragmentProgramParameters();
const Ogre::RenderTarget::FrameStats& stats = mApp->getWindow()->getStatistics();
float m_lastFPS =stats.lastFPS;
Ogre::Matrix4 projectionMatrix = cam->getProjectionMatrix();
if (mRequiresTextureFlipping)
{
// Because we're not using setProjectionMatrix, this needs to be done here
// Invert transformed y
projectionMatrix[1][0] = -projectionMatrix[1][0];
projectionMatrix[1][1] = -projectionMatrix[1][1];
projectionMatrix[1][2] = -projectionMatrix[1][2];
projectionMatrix[1][3] = -projectionMatrix[1][3];
}
Ogre::Matrix4 iVP = (projectionMatrix * cam->getViewMatrix()).inverse();
if (params->_findNamedConstantDefinition("EPF_ViewProjectionInverseMatrix"))
params->setNamedConstant("EPF_ViewProjectionInverseMatrix", iVP);
if (params->_findNamedConstantDefinition("EPF_PreviousViewProjectionMatrix"))
params->setNamedConstant("EPF_PreviousViewProjectionMatrix", prevviewproj);
if (params->_findNamedConstantDefinition("intensity"))
params->setNamedConstant("intensity", mApp->pSet->motionblurintensity);
float interpolationFactor = m_lastFPS * 0.03f ; //* m_timeScale m_timeScale is a multiplier to control motion blur interactively
Ogre::Quaternion current_orientation = cam->getDerivedOrientation();
Ogre::Vector3 current_position = cam->getDerivedPosition();
Ogre::Quaternion estimatedOrientation = Ogre::Quaternion::Slerp(interpolationFactor, current_orientation, (m_pPreviousOrientation));
Ogre::Vector3 estimatedPosition = (1-interpolationFactor) * current_position + interpolationFactor * (m_pPreviousPosition);
Ogre::Matrix4 prev_viewMatrix = Ogre::Math::makeViewMatrix(estimatedPosition, estimatedOrientation);//.inverse().transpose();
// compute final matrix
prevviewproj = projectionMatrix * prev_viewMatrix;
// update position and orientation for next update time
m_pPreviousOrientation = current_orientation;
m_pPreviousPosition = current_position;
}
}
}
示例2: SetPosition
void Stall::SetPosition(Ogre::Rectangle2D *rect, Ogre::Vector3 pos, float size)
{
Ogre::Camera *camera = CommonDeclarations::GetCamera()->GetOgreCamera();
Ogre::Matrix4 vm = camera->getViewMatrix();
Ogre::Matrix4 pm = camera->getProjectionMatrix();
Ogre::Vector3 vpos = vm*pos;
Ogre::Vector3 ppos = pm*vpos;
rect->setCorners(ppos.x-size, ppos.y+size, ppos.x+size/AspectRatio, ppos.y-size);
}
示例3:
Ogre::Vector2 DemoApp::GetScreenspaceCoords(const Ogre::Vector3& iPoint, const Ogre::Camera& iCamera)
{
Ogre:: Vector3 point = iCamera.getProjectionMatrix() * (iCamera.getViewMatrix() * iPoint);
Ogre::Vector2 screenSpacePoint = Ogre::Vector2::ZERO;
screenSpacePoint.x = (point.x / 2.f) + 0.5f;
screenSpacePoint.y = (point.y / 2.f) + 0.5f;
return screenSpacePoint;
}
示例4: OnUpdate
void TextComponent::OnUpdate(double time_diff) {
if(mRefresh && mFont != "") {
// calculate the text width
mTextWidth = 0;
Ogre::Font* font = dynamic_cast<Ogre::Font*>(Ogre::FontManager::getSingleton().getByName(Utils::ToStdString(mFont)).getPointer());
if(font == nullptr) {
Logger::Get().Warning("Cannot find font: \"" + mFont + "\".");
} else {
std::string str = Utils::ToStdString(mText);
for(Ogre::String::iterator iter = str.begin(); iter < str.end(); ++iter) {
if(*iter == 0x0020) {
mTextWidth += font->getGlyphAspectRatio(0x0030);
} else {
mTextWidth += font->getGlyphAspectRatio(*iter);
}
}
mTextWidth *= mFontSize;
}
mRefresh = false;
}
// set the position
if(DisplayManager::Get()->GetMainCamera() == nullptr) {
Logger::Get().Error("Cannot get main camera for text component: no main camera set. Disabling text component " + mName + ".");
Disable();
return;
}
Ogre::Camera* camera = DisplayManager::Get()->GetMainCamera()->GetCamera();
Ogre::Vector3 screen_pos(camera->getProjectionMatrix() * camera->getViewMatrix() * GetNode()->GetPosition(Node::SCENE));
if(screen_pos.z >= 1) {
// behind or in the camera, hide
mOverlay->hide();
} else {
mOverlay->show();
}
float x = 1.0f - ((-screen_pos.x * 0.5f) + 0.5f); // 0 <= x <= 1 // left := 0,right := 1
float y = ((-screen_pos.y * 0.5f) + 0.5f); // 0 <= y <= 1 // bottom := 0,top := 1
x *= camera->getViewport()->getActualWidth();
y *= camera->getViewport()->getActualHeight();
mPanel->setMetricsMode(Ogre::GMM_PIXELS);
mPanel->setWidth(mTextWidth + 2 * mPadding.x);
mPanel->setHeight(mFontSize + 2 * mPadding.y);
mPanel->setLeft(x - mTextWidth / 2 - mPadding.x);
mPanel->setTop(y - mFontSize / 2 - mPadding.y);
mLabel->setPosition(mPadding.x, mPadding.y);
mLabel->setDimensions(mTextWidth, mFontSize);
}
示例5:
void
MovableTextArea::getWorldTransforms(Ogre::Matrix4 *xform) const
{
Ogre::Camera* camera = Ogre::Root::getSingleton().getAutoCreatedWindow()->getViewport(0)->getCamera();
Ogre::Vector3 p = m_Position;
p.z = p.z + m_AdditionalHeight;
p = camera->getProjectionMatrix() * camera->getViewMatrix() * p;
//p.x = 1 + p.x;
//p.y = -1 + p.y;
// we round aligment to pixel border to reduce blurring
int width = Ogre::OverlayManager::getSingleton().getViewportWidth() / 2;
int height = Ogre::OverlayManager::getSingleton().getViewportHeight() / 2;
p.x = (float)((int)((1 + p.x) * width)) / width;
p.y = (float)((int)((-1 + p.y) * height)) / height;
p.z = 0;
*xform = Ogre::Matrix3::IDENTITY;
xform->setTrans(p);
}
示例6: Axis_Trans
//.........这里部分代码省略.........
{
KLThrow("(AX_GAME->AX_SCREEN) Not support yet!");
}
}
break;
//-----------------------------------------------
case AX_PLAN:
{
if(!pTerrainData) return FALSE;
FLOAT fGfxX = pTerrainData->mPosition.x + (FLOAT)fvSource.x * pTerrainData->mScale.x;
FLOAT fGfxZ = pTerrainData->mPosition.z + (FLOAT)fvSource.z * pTerrainData->mScale.z;
if(AX_GAME==typeTar)
{
//取得相地形高度作为Y坐标(游戏坐标)
fvTarget.y = (pTerrainData->getHeightAtGrid(fvSource.x, fvSource.z)-pTerrainData->mPosition.y)/ pTerrainData->mScale.y;
return TRUE;
}
else if(AX_GFX == typeTar)
{
//取得相地形高度作为Y坐标
fvTarget.x = fGfxX;
fvTarget.z = fGfxZ;
fvTarget.y = pTerrainData->getHeightAtGrid(fvSource.x, fvSource.z);
return TRUE;
}
else if(AX_SCREEN==typeTar)
{
KLThrow("(AX_PLAN->AX_SCREEN) Not support yet!");
}
}
break;
//-----------------------------------------------
case AX_GFX:
{
if(AX_GAME==typeTar || AX_PLAN==typeTar)
{
if(pTerrainData)
{
fvTarget.x = (fvSource.x-pTerrainData->mPosition.x)/pTerrainData->mScale.x;
fvTarget.y = (fvSource.y-pTerrainData->mPosition.y)/pTerrainData->mScale.y;
fvTarget.z = (fvSource.z-pTerrainData->mPosition.z)/pTerrainData->mScale.z;
}
else
{
fvTarget.x = (fvSource.x)/fvScale.x;
fvTarget.y = (fvSource.y)/fvScale.y;
fvTarget.z = (fvSource.z)/fvScale.z;
}
return TRUE;
}
else if(AX_SCREEN==typeTar)
{
//KLThrow("(AX_GFX->AX_SCREEN) Not support yet!");
if(!pTerrainData) return FALSE;
//得到Ogre相机
Ogre::Camera* pOgreCamera = m_pCamera_Current->GetOgreCamera();
if(!pOgreCamera) return FALSE;
if(!(pOgreCamera->isVisible(Ogre::Vector3(fvSource.x, fvSource.y, fvSource.z)))) return FALSE;
// x:[-1w, 1w] z:[-1h, 1h]
Ogre::Vector3 vRet = pOgreCamera->getProjectionMatrix()* pOgreCamera->getViewMatrix() * Ogre::Vector3(fvSource.x, fvSource.y, fvSource.z);
int nWidth = m_pFairySystem->getViewport()->getActualWidth();
int nHeight = m_pFairySystem->getViewport()->getActualHeight();
fvTarget.x = (( vRet.x + 1.0f)*nWidth/2.0f);
fvTarget.y = ((-vRet.y + 1.0f)*nHeight/2.0f);
return TRUE;
}
}
break;
//-----------------------------------------------
case AX_SCREEN:
{
if(!pTerrainData) return FALSE;
Ogre::Vector3 vRenderPos;
BOOL bRet = m_pFairySystem->getTerrainIntersects(Fairy::Point((INT)fvSource.x, fvSource.y), vRenderPos);
if(!bRet) return FALSE;
if(AX_GAME==typeTar || AX_PLAN==typeTar)
{
return Axis_Trans(AX_GFX, fVector3(vRenderPos.x, vRenderPos.y, vRenderPos.z), AX_GAME, fvTarget);
}
else if(AX_GFX==typeTar)
{
fvTarget = fVector3(vRenderPos.x, vRenderPos.y, vRenderPos.z);
return TRUE;
}
}
break;
}
return FALSE;
}
示例7: Update
void EC_OgreMovableTextOverlay::Update()
{
if (!node_ || !visible_ || !placeable_ || renderer_.expired())
return;
if(!node_->isInSceneGraph())
{
overlay_->hide();
return;
}
Ogre::Camera* camera = renderer_.lock()->GetCurrentCamera();
if (!camera)
return;
Ogre::Viewport* viewport = camera->getViewport();
Ogre::Vector3 point = node_->_getDerivedPosition();
// Is the camera facing that point? If not, hide the overlay and return.
Ogre::Plane cameraPlane = Ogre::Plane(Ogre::Vector3(camera->getDerivedOrientation().zAxis()), camera->getDerivedPosition());
if(cameraPlane.getSide(point) != Ogre::Plane::NEGATIVE_SIDE)
{
overlay_->hide();
return;
}
// Hide the overlay if it's too far.
Ogre::Vector3 res = camera->getDerivedPosition() - point;
float distance = sqrt(res.x * res.x + res.y * res.y + res.z * res.z);
if (distance > MAX_VISIBILITY_DISTANCE)
{
overlay_->hide();
return;
}
// Set the alpha channel for the overlay.
if (materialHasAlpha_)
SetAlphaChannelIntensity(distance);
// Derive the 2D screen-space coordinates for node point.
point = camera->getProjectionMatrix() * (camera->getViewMatrix() * point);
// Transform from coordinate space [-1, 1] to [0, 1]
float x = (point.x / 2) + 0.5f;
float y = 1 - ((point.y / 2) + 0.5f);
// Update the position (centering the text)
container_->setPosition(x - (textDim_.x / 2), y);
// Update the dimensions also if the window is resized.
if (windowWidth_ != viewport->getActualWidth() ||
windowHeight_ != viewport->getActualHeight())
{
windowWidth_ = viewport->getActualWidth();
windowHeight_ = viewport->getActualHeight();
textDim_ = GetTextDimensions(text_);
container_->setDimensions(textDim_.x, textDim_.y);
}
///\todo Scale the text and width and height of the container?
// text_element_->setMetricsMode(Ogre::GMM_RELATIVE);
// text_element_->setPosition(textDim_.x, textDim_.y);
// text_element_->setPosition(textDim_.x / 10, 0.01);
// text_element_->setCharHeight(max_x - min_x/*2*0.0175f*///);
overlay_->show();
}