本文整理汇总了C++中ogre::Ray::getPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ Ray::getPoint方法的具体用法?C++ Ray::getPoint怎么用?C++ Ray::getPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::Ray
的用法示例。
在下文中一共展示了Ray::getPoint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mouseMoveEvent
void OgreWidget::mouseMoveEvent(QMouseEvent * e)
{
if (m_oldPos != InvalidMousePoint)
{
Ogre::Real deltaX = e->pos().x() - m_oldPos.x();
Ogre::Real deltaY = e->pos().y() - m_oldPos.y();
if (m_mouseButtonsPressed.testFlag(Qt::MiddleButton))
{
if(e->modifiers().testFlag(Qt::ControlModifier))
m_camera->zoom(-deltaY);
else if (e->modifiers().testFlag(Qt::ShiftModifier))
m_camera->rotate(deltaX, -deltaY);
else
m_camera->shift(-deltaX, -deltaY);
}
else if (m_mouseButtonsPressed.testFlag(Qt::LeftButton) && !m_selectionManager.isEmpty())
{
if (m_constraintedX && e->modifiers().testFlag(Qt::ShiftModifier))
m_selectionManager.pitch(Ogre::Degree(deltaX));
else if (m_constraintedY && e->modifiers().testFlag(Qt::ShiftModifier))
m_selectionManager.yaw(Ogre::Degree(deltaX));
else if (m_constraintedZ && e->modifiers().testFlag(Qt::ShiftModifier))
m_selectionManager.roll(Ogre::Degree(deltaX));
else
{
Ogre::Plane plane;
if (m_constraintedX)
plane.redefine(Ogre::Vector3(1, 0, 0), m_selectionManager.getPosition());
else if (m_constraintedY)
plane.redefine(Ogre::Vector3(0, 1, 0), m_selectionManager.getPosition());
else if (m_constraintedZ)
plane.redefine(Ogre::Vector3(0, 0, 1), m_selectionManager.getPosition());
Ogre::Ray oldRay = m_camera->getCamera()->getCameraToViewportRay(e->pos().x() / (float)width(), e->pos().y() / (float)height());
Ogre::Ray ray = m_camera->getCamera()->getCameraToViewportRay(m_oldPos.x() / (float)width(), m_oldPos.y() / (float)height());
std::pair<bool, Ogre::Real> oldResult = oldRay.intersects(plane);
std::pair<bool, Ogre::Real> result = ray.intersects(plane);
if (result.first && oldResult.first)
{
Ogre::Vector3 point;
point = oldRay.getPoint(oldResult.second) - ray.getPoint(result.second);
m_selectionManager.translate(point.x, point.y, point.z);
}
}
emit itemMoved();
}
m_oldPos = e->pos();
update();
e->accept();
}
else
{
e->ignore();
}
}
示例2: 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;
}
示例3: mousePressed
bool CPlayerController::mousePressed(const InputListener::CMouseState &mouseState)
{
if(m_avatar){
CEGUI::Vector2f mousePos = CEGUI::System::getSingleton().getDefaultGUIContext().getMouseCursor().getPosition();
Ogre::Ray mouseRay = m_avatar->getScene()->getSceneCamera()->getCameraToViewportRay(mousePos.d_x/float(mouseState.width),mousePos.d_y/float(mouseState.height));
float dist(1300.0f);
Ogre::Vector3 point = mouseRay.getPoint(Ogre::Real(dist));
int i =0;
while((point.y > -295.0 || point.y < -305.0) && i < 20){
dist += 300.0 + point.y;
point = mouseRay.getPoint(Ogre::Real(dist));
i+=1;
}
point.y = -300.0f;
auto it (m_mouseCommands.find(mouseState.button));
if(it != m_mouseCommands.end()){
m_mouseCommands[mouseState.button]->execute
(Common::Input::Action::MOUSE_PRESSED,m_avatar,point);
//return true; //We're not returning true because we want the mouse event to get to the GUI
}
}
return false;
}
示例4: make_pair
std::pair<bool, Ogre::Vector3>
PhysicsSystem::castRay(const Ogre::Vector3 &orig, const Ogre::Vector3 &dir, float len)
{
Ogre::Ray ray = Ogre::Ray(orig, dir);
Ogre::Vector3 to = ray.getPoint(len);
btVector3 btFrom = btVector3(orig.x, orig.y, orig.z);
btVector3 btTo = btVector3(to.x, to.y, to.z);
std::pair<std::string, float> test = mEngine->rayTest(btFrom, btTo);
if (test.first == "") {
return std::make_pair(false, Ogre::Vector3());
}
return std::make_pair(true, ray.getPoint(len * test.second));
}
示例5: intersectSomeYzPlane
bool InteractiveMarkerControl::intersectSomeYzPlane( const Ogre::Ray& mouse_ray,
const Ogre::Vector3& point_on_plane,
const Ogre::Quaternion& plane_orientation,
Ogre::Vector3& intersection_3d,
Ogre::Vector2& intersection_2d,
float& ray_t )
{
Ogre::Vector3 normal = plane_orientation * control_orientation_.xAxis();
Ogre::Vector3 axis_1 = plane_orientation * control_orientation_.yAxis();
Ogre::Vector3 axis_2 = plane_orientation * control_orientation_.zAxis();
Ogre::Plane plane(normal, point_on_plane);
Ogre::Vector2 origin_2d(point_on_plane.dotProduct(axis_1), point_on_plane.dotProduct(axis_2));
std::pair<bool, Ogre::Real> intersection = mouse_ray.intersects(plane);
if (intersection.first)
{
intersection_3d = mouse_ray.getPoint(intersection.second);
intersection_2d = Ogre::Vector2(intersection_3d.dotProduct(axis_1), intersection_3d.dotProduct(axis_2));
intersection_2d -= origin_2d;
ray_t = intersection.second;
return true;
}
ray_t = 0;
return false;
}
示例6: findClosestPoint
/** Find the closest point on target_ray to mouse_ray.
* @returns false if rays are effectively parallel, true otherwise.
*/
bool InteractiveMarkerControl::findClosestPoint( const Ogre::Ray& target_ray,
const Ogre::Ray& mouse_ray,
Ogre::Vector3& closest_point )
{
// Find the closest point on target_ray to any point on mouse_ray.
//
// Math taken from http://paulbourke.net/geometry/lineline3d/
// line P1->P2 is target_ray
// line P3->P4 is mouse_ray
Ogre::Vector3 v13 = target_ray.getOrigin() - mouse_ray.getOrigin();
Ogre::Vector3 v43 = mouse_ray.getDirection();
Ogre::Vector3 v21 = target_ray.getDirection();
double d1343 = v13.dotProduct( v43 );
double d4321 = v43.dotProduct( v21 );
double d1321 = v13.dotProduct( v21 );
double d4343 = v43.dotProduct( v43 );
double d2121 = v21.dotProduct( v21 );
double denom = d2121 * d4343 - d4321 * d4321;
if( fabs( denom ) <= Ogre::Matrix3::EPSILON )
{
return false;
}
double numer = d1343 * d4321 - d1321 * d4343;
double mua = numer / denom;
closest_point = target_ray.getPoint( mua );
return true;
}
示例7: intersectTri
bool OgreMesh::intersectTri(const Ogre::Ray &ray, IntersectResult &rtn, Triangle*itr, bool isplane) {
std::pair<bool, Real> hit = isplane
? Ogre::Math::intersects(ray, Ogre::Plane(itr->v1.coord, itr->v2.coord,itr->v3.coord))
: Ogre::Math::intersects(ray, itr->v1.coord, itr->v2.coord,itr->v3.coord, true, false);
rtn.u = 0;
rtn.v = 0;
if (hit.first && hit.second < rtn.distance) {
rtn.intersected = hit.first;
rtn.distance = hit.second;
Ogre::Vector3 nml=(itr->v1.coord-itr->v2.coord).
crossProduct(itr->v3.coord-itr->v2.coord);
rtn.normal.x=nml.x;
rtn.normal.y=nml.y;
rtn.normal.z=nml.z;
rtn.tri = *itr;
Ogre::Vector3 intersect = ray.getPoint(hit.second) - rtn.tri.v2.coord;
Ogre::Vector3 aVec = (rtn.tri.v1.coord - rtn.tri.v2.coord);
Ogre::Vector3 bVec = (rtn.tri.v3.coord - rtn.tri.v2.coord);
if (aVec.length() > 1.0e-10 && bVec.length() > 1.0e-10) {
rtn.u = rtn.tri.v2.u + (rtn.tri.v1.u - rtn.tri.v2.u)*cos(aVec.angleBetween(intersect).valueRadians())*intersect.length()/aVec.length();
rtn.v = rtn.tri.v2.v + (rtn.tri.v3.v - rtn.tri.v2.v)*cos(bVec.angleBetween(intersect).valueRadians())*intersect.length()/bVec.length();
}
}
return rtn.intersected;
}
示例8: RaycastAABB
/*
* Heuristic method for raycasting using axis-aligned bounding boxes.
*
* The output of this method is the location the ray hit the first bounding box
* belonging to the robot model or an interactive marker, where the bounding
* boxes are sorted in order of the distance to the ray.
*
* This is not very accurate, and is designed to determine if the ray hits a
* point that is "close enough" to some target point. For polygon-level
* raytracing, see the * OGRE Wiki at goo.gl/YLKQEo.
*
* Input:
* ray: The ray to check.
*
* Output:
* hit: The median AABB point the ray hit, if any.
*
* Returns: True if the ray hit anything.
*/
bool VisibilityChecker::RaycastAABB(const Ogre::Ray& ray, Ogre::Vector3* hit) {
if (!ray_scene_query_) {
return false;
}
ray_scene_query_->clearResults();
ray_scene_query_->setRay(ray);
Ogre::RaySceneQueryResult& query_results = ray_scene_query_->execute();
if (query_results.size() <= 0) {
return false;
}
// The query results are ordered by distance along the ray. However, for some
// reason, some of the results have zero distance. We ignore these when
// finding the median.
for (const auto& result : query_results) {
auto name = result.movable->getName();
// TODO: have the visibility checker pass in what we're looking for,
// exactly.
if (result.distance > 0 &&
(name.find("Robot Link") != -1 || name.find("Shape") != -1)) {
*hit = ray.getPoint(result.distance);
return true;
}
}
return false;
}
示例9: _updateProjector
void GodRaysManager::_updateProjector()
{
const Ogre::Vector3& SunPosition = mHydrax->getSunPosition();
const Ogre::Vector3& CameraPosition = mHydrax->getCamera()->getDerivedPosition();
Ogre::Plane WaterPlane = Ogre::Plane(Ogre::Vector3(0, 1, 0), mHydrax->getPosition());
Ogre::Ray SunToCameraRay = Ogre::Ray(SunPosition, CameraPosition - SunPosition);
Ogre::Vector3 WaterProjectionPoint = SunToCameraRay.getPoint(SunToCameraRay.intersects(WaterPlane).second);
Ogre::Vector3 WaterPosition = Ogre::Vector3(WaterProjectionPoint.x, mHydrax->getHeigth(WaterProjectionPoint), WaterProjectionPoint.z);
mProjectorSN->setPosition(WaterProjectionPoint);
mProjectorCamera->setFarClipDistance((WaterProjectionPoint - CameraPosition).length());
mProjectorSN->setDirection(-(WaterProjectionPoint - CameraPosition).normalisedCopy(), Ogre::Node::TS_WORLD);
}
示例10: setQueryMask
/*
*Build Ray Query for getting 3d mouse position
*/
const Ogre::Vector3 MyFrameListener::getMouse3DPoint() {
int x = _mouse->getMouseState().X.abs;
int y = _mouse->getMouseState().Y.abs;
Ogre::Ray ray = this->setRayQuery(x, y);
_rayScnQueryDD->setRay(ray);
_rayScnQueryDD->setSortByDistance(true);
_rayScnQueryDD-> setQueryMask(PLANE_DRAG_DROP);
Ogre::RaySceneQueryResult &result = _rayScnQueryDD->execute();
Ogre::RaySceneQueryResult::iterator it = result.begin();
return ray.getPoint(it->distance);
}
示例11: make_pair
std::pair<bool, Ogre::Vector3> PhysicsSystem::castRay(float mouseX, float mouseY)
{
Ogre::Ray ray = mRender.getCamera()->getCameraToViewportRay(
mouseX,
mouseY);
Ogre::Vector3 from = ray.getOrigin();
Ogre::Vector3 to = ray.getPoint(200); /// \todo make this distance (ray length) configurable
btVector3 _from, _to;
// OGRE to MW coordinates
_from = btVector3(from.x, -from.z, from.y);
_to = btVector3(to.x, -to.z, to.y);
std::pair<std::string, float> result = mEngine->rayTest(_from, _to);
if (result.first == "")
return std::make_pair(false, Ogre::Vector3());
else
{
return std::make_pair(true, ray.getPoint(200*result.second)); /// \todo make this distance (ray length) configurable
}
}
示例12: 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;
}
示例13: testCollision
void AuthoringVisualizationCollisionDetector::testCollision(Ogre::Ray& ray, CollisionResult& result)
{
std::pair<bool, Ogre::Real> intersectionResult(Ogre::Math::intersects(ray, mEntity.getWorldBoundingBox()));
if (intersectionResult.first) {
// raycast success
result.collided = true;
result.position = ray.getPoint(intersectionResult.second);
result.distance = intersectionResult.second;
result.isTransparent = true; //The authoring selector should always be transparent so that we can select things behind it
} else {
// raycast failed
result.collided = false;
}
}
示例14: isIntersectMesh
bool SceneObject::isIntersectMesh(int& _x, int& _y, const Ogre::Ray& _ray, int _texture_width, int _texture_height) const
{
Ogre::Real closest_distance = -1.0f;
Ogre::Vector3 closest_result;
// test for hitting individual triangles on the mesh
bool new_closest_found = false;
int index_found = 0;
for (int i = 0; i < static_cast<int>(mIndexCount); i += 3)
{
// check for a hit against this triangle
std::pair<bool, Ogre::Real> hit = Ogre::Math::intersects(_ray, mVertices[mIndices[i]],
mVertices[mIndices[i+1]], mVertices[mIndices[i+2]], true, false);
// if it was a hit check if its the closest
if (hit.first)
{
if ((closest_distance < 0.0f) ||
(hit.second < closest_distance))
{
// this is the closest so far, save it off
closest_distance = hit.second;
index_found = i;
new_closest_found = true;
}
}
}
if (new_closest_found)
{
closest_result = _ray.getPoint(closest_distance);
// return the result
if (closest_distance >= 0.0f)
{
// raycast success
Ogre::Vector2 point = getCoordByTriangle(closest_result, mVertices[mIndices[index_found]], mVertices[mIndices[index_found+1]], mVertices[mIndices[index_found+2]]);
Ogre::Vector2 point2 = getCoordByRel(point, mTextureCoords[mIndices[index_found]], mTextureCoords[mIndices[index_found+1]], mTextureCoords[mIndices[index_found+2]]);
_x = (int)(point2.x * _texture_width);
_y = (int)(point2.y * _texture_height);
return true;
}
}
// raycast failed
return false;
}
示例15: cameraPreRenderScene
//-----------------------------------------------------------------------
void OrthoCameraGizmo::cameraPreRenderScene (Ogre::Camera *camera)
{
// Adjust the ortho camera gizmo
Ogre::SceneNode* node = mOrthoCameraNodeBox->getParentSceneNode();
if (node)
{
// Reposition according to the actual viewport
Ogre::Ray ray = camera->getCameraToViewportRay(0.9f, 0.1f);
Ogre::Vector3 position = ray.getPoint(80.0f);
//position = camera->getDerivedOrientation().Inverse() * (position - camera->getDerivedPosition()); // Transform from world to local (camera) position
node->setPosition(position);
// Adjust the scale
Ogre::Real scaleFactor = Gizmo::SCALE_NODE_ORTHOZOOM_FACTOR * camera->getOrthoWindowWidth() / camera->getViewport()->getActualWidth();
setScale(scaleFactor);
}
}