本文整理汇总了C++中ogre::Ray::getDirection方法的典型用法代码示例。如果您正苦于以下问题:C++ Ray::getDirection方法的具体用法?C++ Ray::getDirection怎么用?C++ Ray::getDirection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::Ray
的用法示例。
在下文中一共展示了Ray::getDirection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: Camera_GetWindowToViewportRay
VOID CEngineInterface::Camera_GetWindowToViewportRay(INT nX, INT nY, fRay& fRay)
{
Ogre::Ray ray = m_pFairySystem->getWindowToViewportRay(nX, nY);
fVector3 fGFX = fVector3(ray.getOrigin().x, ray.getOrigin().y, ray.getOrigin().z);
Axis_Trans(AX_GFX, fGFX, AX_GAME, fRay.mOrigin);
fRay.mDirection = fVector3(ray.getDirection().x, ray.getDirection().y, ray.getDirection().z);
}
示例3: publishOCSRayRequest
void Selection3DDisplayCustom::raycastRequest(bool, int x, int y)
{
float win_width = render_panel_->width();
float win_height = render_panel_->height();
//then send a raycast straight out from the camera at the mouse's position
Ogre::Ray mouseRay = this->render_panel_->getCamera()->getCameraToViewportRay((float)x/win_width, (float)y/win_height);
// send ray data to other instances of OCS
publishOCSRayRequest(RAYCAST_SELECTION, mouseRay.getOrigin(), mouseRay.getDirection());
// send ray data to onboard
publishRayRequest(mouseRay.getOrigin(), mouseRay.getDirection());
}
示例4: OnDragMove
//----------------------------------------------------------------------------------------
bool ObjectsViewWidget::OnDragMove(Ogre::Viewport *vp, unsigned int modifier, Ogre::Vector2& position)
{
if(mDragData.ObjectType == "")
return false;
if(!mDragData.Object)
return true;
Ogre::Ray mouseRay;
mouseRay = vp->getCamera()->getCameraToViewportRay(position.x, position.y);
Ogre::Vector3 vPos;
mDragData.Object->getProperties()->getValue("position", vPos);
bool hitfound = false;
if(modifier & Ogitors::DragDropShiftModifier)
{
hitfound = OgitorsRoot::getSingletonPtr()->GetViewport()->GetHitPosition(mouseRay, vPos, mDragData.Object->getName());
}
if(!hitfound)
{
if(vPos.x == 999999 && vPos.y == 999999 && vPos.z == 999999)
vPos = mouseRay.getOrigin() + (mouseRay.getDirection() * 40.0f);
else
vPos = OgitorsRoot::getSingletonPtr()->GetGizmoIntersectCameraPlane(mDragData.Object, mouseRay);
}
mDragData.Object->getProperties()->setValue("position", vPos);
return true;
}
示例5: pos
gkCam2ViewportRay::gkCam2ViewportRay(gkScalar x, gkScalar y, gkScalar rayLength)
{
gkScene* pScene = gkEngine::getSingleton().getActiveScene();
GK_ASSERT(pScene);
gkCamera* pCamera = pScene->getMainCamera();
GK_ASSERT(pCamera);
gkVector2 pos(x, y);
gkWindow* pWindow = pScene->getDisplayWindow();
if (pWindow == 0)
pWindow = gkWindowSystem::getSingleton().getMainWindow();
GK_ASSERT(pWindow);
gkScalar width = pWindow->getWidth();
gkScalar height = pWindow->getHeight();
GK_ASSERT(width && height);
Ogre::Ray ray = pCamera->getCamera()->getCameraToViewportRay(pos.x / width, pos.y / height);
gkVector3 p0 = ray.getOrigin();
gkVector3 p1 = p0 + ray.getDirection() * rayLength;
setOrigin(p0);
setDirection(p1 - p0);
}
示例6: injectMousePress
void OrientationControlet::injectMousePress(int _absx, int _absy, MyGUI::MouseButton _id)
{
if( _id == MyGUI::MouseButton::Left ){
string name = Game::getSingleton().pickMovableObject( _absx,_absy );
if( name == mName ){
mPick = true;
mMouseX = _absx;
mMouseY = _absy;
InputFilter::getSingleton().setCapture();
/*判断开始时候,控制球是在球的正面还是背面
*/
Game& game = Game::getSingleton();
int sx = game.getScreenWidth();
int sy = game.getScreenHeight();
Ogre::Ray B = game.getCamera()->getCameraToViewportRay(
(Ogre::Real)_absx/(Ogre::Real)sx,
(Ogre::Real)_absy/(Ogre::Real)sy
);
Ogre::Matrix3 m3 = mNode->getLocalAxes();
Ogre::Vector3 axis = m3.GetColumn(2);
if( axis.dotProduct(B.getDirection())>0 )
mNearFar = false;
else
mNearFar = true;
}
}
}
示例7: shootingMouvements
void InputListener::shootingMouvements(const Ogre::FrameEvent& evt)
{
if (this->_Game->getGun(this->_Game->getNextTeam()->getChoseGun()).getAfterEffect() == true)
{
if (this->_Game->getGun(this->_Game->getNextTeam()->getChoseGun()).afterEffect(evt.timeSinceLastFrame) == true)
{
this->changeTurn();
}
else
{
this->_Game->doDamageToWorms(this->_Game->
getGun(this->_Game->getNextTeam()->getChoseGun()).getExplosion(), this->_Game->
getGun(this->_Game->getNextTeam()->getChoseGun()).getScale() / 20);
}
}
else if (!this->_WormsApp->getSceneManager()->getScene("PlayScene")->getGame()
->getGun(this->_Game->getNextTeam()->getChoseGun()).getIsFree())
this->_Game->getGun(this->_Game->getNextTeam()->getChoseGun()).move(evt.timeSinceLastFrame, this->_CollisionMgr, this->_Game->getTeam());
if (this->_Mouse->getMouseState().buttonDown(OIS::MB_Left))
{
if (this->_Game->getTeleportActivated())
{
Ogre::Vector2 pos = this->_WormsApp->getUIManager()->teleportPressed();
pos.x = pos.x / this->_currentScene->getViewPort()->getActualWidth();
pos.y = pos.y / this->_currentScene->getViewPort()->getActualHeight();
Ogre::Ray ray = this->_currentScene->getCamera()->getCameraToViewportRay(pos.x, pos.y);
Ogre::Vector3 newRay= ray.getOrigin() + (ray.getDirection() * 3);
newRay.z = 0;
_current->getNode()->setPosition(newRay);
}
}
}
示例8: collides
bool gkRayTest::collides(const Ogre::Ray& ray)
{
gkVector3 from = ray.getOrigin();
gkVector3 to = ray.getOrigin() + ray.getDirection();
gkRayTestFilter test;
return gkRayTest::collides(from, to,test);
}
示例9: getBodyUnderCursorUsingBullet
// -------------------------------------------------------------------------
void OgreBulletListener::button1Pressed()
{
// small unique impulse under cursor.
Ogre::Vector3 pickPos;
Ogre::Ray rayTo;
OgreBulletDynamics::RigidBody * body =
getBodyUnderCursorUsingBullet(pickPos, rayTo);
//getBodyUnderCursorUsingOgre(pickPos, rayTo);
if (body)
{
if (!(body->isStaticObject()
|| body->isKinematicObject()
))
{
body->enableActiveState ();
const Ogre::Vector3 relPos (pickPos - body->getCenterOfMassPosition());
const Ogre::Vector3 impulse (rayTo.getDirection ());
body->applyImpulse (impulse * mImpulseForce, relPos);
}
getDebugLines();
mDebugRayLine->addLine (rayTo.getOrigin(), pickPos);
mDebugRayLine->draw();
}
}
示例10: 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());
}
}
示例11: world_ray
std::pair<bool, Real>
doPicking(const Ogre::Ray& localRay, const CollisionModel& collisionModel, CullingMode cullingMode)
{
// Convert our ray to Opcode ray
IceMaths::Ray world_ray(
IceMaths::Point(localRay.getOrigin().x, localRay.getOrigin().y, localRay.getOrigin().z),
IceMaths::Point(localRay.getDirection().x, localRay.getDirection().y, localRay.getDirection().z));
// Be aware we store triangle as ccw in collision mode, and Opcode treat it as cw,
// so need to inverse cull mode here.
Opcode::CullMode cullMode;
switch (cullingMode)
{
default:
case CULL_NONE:
cullMode = Opcode::CULLMODE_NONE;
break;
case CULL_CLOCKWISE:
cullMode = Opcode::CULLMODE_CCW;
break;
case CULL_ANTICLOCKWISE:
cullMode = Opcode::CULLMODE_CW;
break;
}
// Cull mode callback for Opcode
struct Local
{
static Opcode::CullMode cullModeCallback(udword triangle_index, void* user_data)
{
return (Opcode::CullMode) (int) user_data;
}
};
std::pair<bool, Real> ret;
// Do picking
Opcode::CollisionFace picked_face;
ret.first = Opcode::Picking(picked_face,
world_ray, collisionModel.getOpcodeModel(), 0,
0, FLT_MAX,
world_ray.mOrig,
&Local::cullModeCallback, (void*) (int) cullMode);
ret.second = ret.first ? picked_face.mDistance : 0;
return ret;
}
示例12: transformRay
Ogre::Ray OgreMesh::transformRay(Ogre::Node *node, const Ogre::Ray &ray) {
return ray;
const Ogre::Vector3 &position = node->_getDerivedPosition();
const Ogre::Quaternion &orient = node->_getDerivedOrientation();
const Ogre::Vector3 &scale = node->_getDerivedScale();
Ogre::Vector3 newStart = (orient.Inverse() * (ray.getOrigin() - position)) / scale;
Ogre::Vector3 newDirection = orient.Inverse() * ray.getDirection();
return Ogre::Ray(newStart, newDirection);
}
示例13: injectMouseMoved
bool Panel::injectMouseMoved(const Ogre::Ray& ray)
{
Ogre::Matrix4 transform;
transform.makeTransform(mNode->getPosition(), mNode->getScale(), mNode->getOrientation());
Ogre::AxisAlignedBox aabb = mScreenRenderable->getBoundingBox();
aabb.transform(transform);
pair<bool, Ogre::Real> result = Ogre::Math::intersects(ray, aabb);
if (result.first == false)
{
unOverAllElements();
return false;
}
Ogre::Vector3 a,b,c,d;
Ogre::Vector2 halfSize = (mSize/100) * 0.5f;
a = transform * Ogre::Vector3(-halfSize.x,-halfSize.y,0);
b = transform * Ogre::Vector3( halfSize.x,-halfSize.y,0);
c = transform * Ogre::Vector3(-halfSize.x, halfSize.y,0);
d = transform * Ogre::Vector3( halfSize.x, halfSize.y,0);
result = Ogre::Math::intersects(ray, c, b, a);
if (result.first == false)
result = Ogre::Math::intersects(ray, c, d, b);
if (result.first == false)
{
unOverAllElements();
return false;
}
if (result.second > mDistanceFromPanelToInteractWith)
{
unOverAllElements();
return false;
}
Ogre::Vector3 hitPos = (ray.getOrigin() + (ray.getDirection() * result.second));
Ogre::Vector3 localPos = transform.inverse() * hitPos;
localPos.x += halfSize.x;
localPos.y -= halfSize.y;
localPos.x *= 100;
localPos.y *= 100;
// Cursor clip
localPos.x = Ogre::Math::Clamp<Ogre::Real>(localPos.x, 0, mSize.x - 10);
localPos.y = Ogre::Math::Clamp<Ogre::Real>(-localPos.y, 0, mSize.y - 18);
mInternalMousePos = Ogre::Vector2(localPos.x, localPos.y);
mMousePointer->position(mInternalMousePos);
// Let's actualize the "over" for each elements
for (size_t i=0; i < mPanelElements.size(); i++)
mPanelElements[i]->isOver(mInternalMousePos);
return true;
}
示例14: _onDrag
void CameraDragMove::_onDrag(const Point& pt)
{
if (!mTerrainHitInfo.hitted)
return;
Ogre::Ray ray = getSceneManipulator()->getWindowToViewportRay(pt);
if (!ray.getDirection().y)
return;
Ogre::Vector3 newPosition;
// 对正交投影和透视投影分开处理
if (getSceneManipulator()->getCamera()->getProjectionType() == Ogre::PT_ORTHOGRAPHIC)
{
Real offsetx = mRay.getOrigin().x - ray.getOrigin().x;
Real offsetz = mRay.getOrigin().z - ray.getOrigin().z;
newPosition.x = getSceneManipulator()->getCamera()->getRealPosition().x + offsetx;
newPosition.y = getSceneManipulator()->getCamera()->getRealPosition().y;
newPosition.z = getSceneManipulator()->getCamera()->getRealPosition().z + offsetz;
}
else
{
Real length = (mTerrainHitInfo.position.y - mTerrainHitInfo.hitPosition.y) / ray.getDirection().y;
newPosition = mTerrainHitInfo.hitPosition + ray.getDirection() * length;
if (getSceneManipulator()->getCameraHeightLocked())
{
newPosition.y +=
getTerrainData()->getHeightAt(newPosition.x, newPosition.z) -
getTerrainData()->getHeightAt(mTerrainHitInfo.position.x, mTerrainHitInfo.position.z);
}
}
getSceneManipulator()->setCameraPosition(newPosition);
}
示例15: mouseMoved
// -------------------------------------------------------------------------
void OgreBulletListener::mouseMoved()
{
mGuiListener->setMousePosition(mInputListener->getAbsMouseX (), mInputListener->getAbsMouseY ());
if (mPickConstraint)
{
// dragging
//add a point to point constraint for picking
Ogre::Ray rayTo = mCamera->getCameraToViewportRay (mInputListener->getAbsMouseX(), mInputListener->getAbsMouseY());
//move the constraint pivot
OgreBulletDynamics::PointToPointConstraint * p2p = static_cast <OgreBulletDynamics::PointToPointConstraint *>(mPickConstraint);
//keep it at the same picking distance
const Ogre::Vector3 eyePos(mCamera->getDerivedPosition());
//Ogre::Vector3 dir = rayTo.getDirection () - eyePos;
//dir.normalise();
//dir *= mOldPickingDist;
Ogre::Vector3 dir = rayTo.getDirection () * mOldPickingDist;
dir.normalise();
const Ogre::Vector3 newPos (eyePos + dir);
p2p->setPivotB (newPos);
setDebugText ("Dragging");
getDebugLines();
mDebugRayLine->addLine (mPickedBody->getWorldPosition (), newPos);
mDebugRayLine->draw();
mGuiListener->showMouse();
}
if (mGuiListener->getGui()->injectMouse(mInputListener->getAbsMouseX ()*mWindow->getWidth(),
mInputListener->getAbsMouseY ()*mWindow->getHeight(), mInputListener->getButton0Pressed()))
{
mGuiListener->hideMouse();
}
else
{
mGuiListener->showMouse();
}
if (mInputListener->getButton2Pressed())
{
mCameraRotX = Degree(-mInputListener->getRelMouseX () * 0.13);
mCameraRotY = Degree(-mInputListener->getRelMouseY () * 0.13);
}
}