本文整理汇总了C++中ogre::Camera::getCameraToViewportRay方法的典型用法代码示例。如果您正苦于以下问题:C++ Camera::getCameraToViewportRay方法的具体用法?C++ Camera::getCameraToViewportRay怎么用?C++ Camera::getCameraToViewportRay使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::Camera
的用法示例。
在下文中一共展示了Camera::getCameraToViewportRay方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RaycastPickScreen
bool Renderer::RaycastPickScreen(const Vec2& screenPosition, float depth, Camera* camera,
RendererRaycastResult& result)
{
// Set up the ray query object
Ogre::Camera* ogreCamera = camera->GetOgreCamera();
Ogre::Ray ray = ogreCamera->getCameraToViewportRay(screenPosition.x, screenPosition.y);
mRaySceneQuery->setRay(ray);
mRaySceneQuery->setQueryMask(~UNIVERSE_OBJECT);
// Execute the ray query
Ogre::RaySceneQueryResult& rayQuery = mRaySceneQuery->execute();
for (auto i = rayQuery.begin(); i != rayQuery.end(); ++i)
{
Ogre::Entity* entity = dynamic_cast<Ogre::Entity*>((*i).movable);
if (entity && (*i).distance > 0.0f)
{
result.hit = true;
result.entity = entity;
result.position = Position::FromCameraSpace(camera, ray.getPoint((*i).distance));
result.normal = Vec3::zero;
return true;
}
}
// At this point - the ray didn't hit anything of interest
result.hit = false;
result.entity = nullptr;
result.position = Position::FromCameraSpace(camera, ray.getPoint(depth));
result.normal = Vec3::zero;
return false;
}
示例2: rayTest
bool gkMouseSensor::rayTest(void)
{
// cannot test no movable data,
if (m_type == MOUSE_MOUSE_OVER && (m_object->getType() == GK_OBJECT || m_object->getType() == GK_SKELETON))
return false;
GK_ASSERT(m_object);
gkCamera* cam = m_object->getOwner()->getMainCamera();
Ogre::Camera* oc = cam->getCamera();
gkMouse* mse = gkWindowSystem::getSingleton().getMouse();
gkScalar ncx = mse->position.x / mse->winsize.x;
gkScalar ncy = mse->position.y / mse->winsize.y;
Ogre::Ray dest;
oc->getCameraToViewportRay(ncx, ncy, &dest);
if (m_rayQuery == 0)
{
Ogre::SceneManager* mgr = m_object->getOwner()->getManager();
m_rayQuery = mgr->createRayQuery(dest);
}
else m_rayQuery->setRay(dest);
// do the test
Ogre::RaySceneQueryResult& res = m_rayQuery->execute();
bool result = false;
for (Ogre::RaySceneQueryResult::iterator it = res.begin(); it != res.end(); ++it)
{
Ogre::RaySceneQueryResultEntry ent = (*it);
if (ent.movable == oc)
continue;
if (ent.movable)
{
if (m_type == MOUSE_MOUSE_OVER)
{
if (ent.movable == m_object->getMovable())
{
result = true;
break;
}
}
else
{
result = true;
break;
}
}
}
return result;
}
示例3: onSelectActorAtClickpoint
void ProjectManager::onSelectActorAtClickpoint(float mouseX,
float mouseY)
{
assert(QThread::currentThread() == thread());
QOCamera* cameraNode = getCameraWithName("cam1");
if(!cameraNode)
{
qWarning("ProjectManager.onSelectActorAtClickpoint: Can't determine an actor to select "
"without a corresponding CameraNode.");
return;
}
Ogre::Camera* camera = cameraNode->camera();
if(!camera)
{
qWarning("ProjectManager.onSelectActorAtClickpoint: Can't determine an actor to select "
"without a corresponding ogre camera.");
return;
}
Ogre::Ray mouseRay = camera->getCameraToViewportRay(mouseX, mouseY);
Scene* current = mScenarioManager.getCurrentScene();
QSharedPointer<Actor> hitActor = current->raycast(mouseRay.getOrigin(),
mouseRay.getDirection()).actor.toStrongRef();
if(hitActor)
{
onActorChangeSelected(hitActor->getName(),
!hitActor->getSceneNode()->getShowBoundingBox());
}
}
示例4: OnMouseLeftDown
//-----------------------------------------------------------------------------------------
void CPGInstanceManager::OnMouseLeftDown (CViewportEditor *viewport, Ogre::Vector2 point, unsigned int buttons)
{
Ogre::Camera *cam = viewport->getCameraEditor()->getCamera();
Ogre::Viewport *vp = static_cast<Ogre::Viewport*>(viewport->getHandle());
float width = vp->getActualWidth();
float height = vp->getActualHeight();
Ogre::Ray mRay = cam->getCameraToViewportRay(point.x / width, point.y / height);
Ogre::Vector3 vPos;
if(viewport->GetHitPosition(mRay, vPos))
{
float yaw = (mMaxYaw->get() - mMinYaw->get()) * Ogre::Math::UnitRandom() + mMinYaw->get();
float scale = (mMaxScale->get() - mMinScale->get()) * Ogre::Math::UnitRandom() + mMinScale->get();
int index = addInstance(vPos, scale, yaw);
OgitorsUndoManager::getSingletonPtr()->BeginCollection("Add Instance");
_createChildEditor(index , vPos, scale, yaw);
OgitorsUndoManager::getSingletonPtr()->AddUndo(OGRE_NEW AddInstanceUndo(mObjectID->get(), index));
OgitorsUndoManager::getSingletonPtr()->EndCollection(true);
}
}
示例5: catch
std::vector<Unite *> RTSState::getUnitesInRectangleUnderCamera(const Rectangle<float> &rectangle) const
{
Ogre::PlaneBoundedVolume vol;
Ogre::Camera *camera = m_gameEngine->cameraManager()->camera();
Ogre::Ray topLeft = camera->getCameraToViewportRay(rectangle.left, rectangle.top);
Ogre::Ray topRight = camera->getCameraToViewportRay(rectangle.left + rectangle.width, rectangle.top);
Ogre::Ray bottomLeft = camera->getCameraToViewportRay(rectangle.left, rectangle.top + rectangle.height);
Ogre::Ray bottomRight = camera->getCameraToViewportRay(rectangle.left + rectangle.width, rectangle.top + rectangle.height);
vol.planes.push_back(Ogre::Plane(topLeft.getPoint(1), topRight.getPoint(1), bottomRight.getPoint(1))); // front plane
vol.planes.push_back(Ogre::Plane(topLeft.getOrigin(), topLeft.getPoint(100), topRight.getPoint(100))); // top plane
vol.planes.push_back(Ogre::Plane(topLeft.getOrigin(), bottomLeft.getPoint(100), topLeft.getPoint(100))); // left plane
vol.planes.push_back(Ogre::Plane(bottomLeft.getOrigin(), bottomRight.getPoint(100), bottomLeft.getPoint(100))); // bottom plane
vol.planes.push_back(Ogre::Plane(topRight.getOrigin(), topRight.getPoint(100), bottomRight.getPoint(100))); // right plane
Ogre::PlaneBoundedVolumeList volList;
volList.push_back(vol);
EngineManager *mng = m_gameEngine->getManager();
Ogre::PlaneBoundedVolumeListSceneQuery *query = mng->getGraphic()->getSceneManager()->createPlaneBoundedVolumeQuery(volList);
Ogre::SceneQueryResult result = query->execute();
std::vector<Unite *> foundUnits;
std::for_each(result.movables.begin(), result.movables.end(), [&foundUnits](Ogre::MovableObject * obj)
{
try
{
WorldObject *worldObj = Ogre::any_cast<WorldObject *>(obj->getUserObjectBindings().getUserAny());
Unite *unite = dynamic_cast<Unite *>(worldObj);
foundUnits.push_back(unite);
}
catch (...)
{
}
});
return foundUnits;
}
示例6:
Ogre::Vector3& PhysicsManager::getMouseWorldPosition(float x, float y){
Ogre::Camera* cam = _sceneManager->getCamera("PlayState");
Ogre::Ray ray = cam->getCameraToViewportRay(x, y);
Ogre::Vector3 position;
OgreBulletCollisions::CollisionClosestRayResultCallback cQuery = OgreBulletCollisions::CollisionClosestRayResultCallback(ray, _world, 10000);
_world->launchRay(cQuery);
if (cQuery.doesCollide()) {
position = cQuery.getCollisionPoint();
}
return position;
}
示例7:
bool
ZWorkspaceController::onMouseMove(const OIS::MouseEvent &evt)
{
if(_workspace->getToolsetController()->isCursorMode())
{
//Get voxel position.
//Just pass in the 3d position of where the user clicked. This is predefined to be a certain distance into the screen.
Ogre::Camera* cam = _workspace->getCinematicController()->getCinematicManager()->getRootCam();
Ogre::Real x, y;
x = evt.state.X.abs / _windowWidth;
y = evt.state.Y.abs / _windowHeight;
Ogre::Ray rayTo;
Ogre::Vector3 position;
Ogre::Real searchDistance = 64.0f;
rayTo = cam->getCameraToViewportRay(x, y);
//Shift modifies cursor to be constraint to a plane.
if(_modifierState & OIS::Keyboard::Shift)
{
Ogre::Plane constraintPlane;
bool hit = _workspace->getToolsetController()->getConstraintPlane(rayTo, constraintPlane);
if(hit)
_workspace->getWorldController()->getCursor3dPosition(rayTo, position, constraintPlane);
else
_workspace->getWorldController()->getCursor3dPosition(rayTo, position, searchDistance);
}
else
{
_workspace->getWorldController()->getCursor3dPosition(rayTo, position, searchDistance);
}
_workspace->getToolsetController()->onCursorPosition3d(position);
_workspace->getCinematicController()->onDisableOneFrame();
}
return true;
}
示例8: camera_get_camera_to_viewport_ray
//Ogre::Camera::getCameraToViewportRay(float, float, Ogre::Ray*) const
void camera_get_camera_to_viewport_ray(CameraHandle handle, coiReal screenx, coiReal screeny, RayHandle result)
{
Ogre::Camera* camera = static_cast<Ogre::Camera*>(handle);
Ogre::Ray* ray = static_cast<Ogre::Ray*>(result);
camera->getCameraToViewportRay(screenx, screeny, ray);
}