当前位置: 首页>>代码示例>>C++>>正文


C++ ogre::Ray类代码示例

本文整理汇总了C++中ogre::Ray的典型用法代码示例。如果您正苦于以下问题:C++ Ray类的具体用法?C++ Ray怎么用?C++ Ray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Ray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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);
    }
  }
}
开发者ID:vladydan,项目名称:Indie-Worms-3D,代码行数:33,代码来源:InputListener.cpp

示例2: 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;
}
开发者ID:EternalWind,项目名称:Ogitor-Facade,代码行数:35,代码来源:objectsview.cpp

示例3: 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();	
    }  
}
开发者ID:bb123n4,项目名称:OgreBulletDemos,代码行数:31,代码来源:OgreBulletListener.cpp

示例4: 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());
    }
}
开发者ID:palais-ai,项目名称:palais-sandbox,代码行数:33,代码来源:ProjectManager.cpp

示例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);
}
开发者ID:guozanhua,项目名称:github,代码行数:33,代码来源:gkCam2ViewportRay.cpp

示例6: 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;
}
开发者ID:JamesLinus,项目名称:dawnengine,代码行数:32,代码来源:Renderer.cpp

示例7: updateCameraHeight

void TerrainManager::updateCameraHeight(const Ogre::FrameEvent& evt)
{
  // clamp to terrain
  Ogre::Vector3 camPos = mCamera->getPosition();
  Ogre::Ray ray;
  ray.setOrigin(Ogre::Vector3(camPos.x, mTerrainPos.y + 10000, camPos.z));
  ray.setDirection(Ogre::Vector3::NEGATIVE_UNIT_Y);

  Ogre::TerrainGroup::RayResult rayResult = mTerrainGroup->rayIntersects(ray);
  Ogre::Real distanceAboveTerrain = 50;
  Ogre::Real fallSpeed = 300;
  Ogre::Real newy = camPos.y;
  if (rayResult.hit)
    {
      if (camPos.y > rayResult.position.y + distanceAboveTerrain)
	{
	  mFallVelocity += evt.timeSinceLastFrame * 20;
	  mFallVelocity = std::min(mFallVelocity, fallSpeed);
	  newy = camPos.y - mFallVelocity * evt.timeSinceLastFrame;

	}
      newy = std::max(rayResult.position.y + distanceAboveTerrain, newy);
      mCamera->setPosition(camPos.x, newy, camPos.z);
				
    }
}
开发者ID:lkarydas,项目名称:ogre_object_placement_utility,代码行数:26,代码来源:TerrainManager.cpp

示例8: 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;
}
开发者ID:F34140r,项目名称:visualization-userfriendly,代码行数:29,代码来源:interactive_marker_control.cpp

示例9: 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;
}
开发者ID:F34140r,项目名称:visualization-userfriendly,代码行数:33,代码来源:interactive_marker_control.cpp

示例10: 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;
		}
开发者ID:Ithos,项目名称:TTG,代码行数:27,代码来源:PlayerController.cpp

示例11: 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;
		}
	}
}
开发者ID:JohnCrash,项目名称:iRobot,代码行数:28,代码来源:RigidControlet.cpp

示例12: 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);
}
开发者ID:Ali-il,项目名称:gamekit,代码行数:7,代码来源:gkRayTest.cpp

示例13: ViewportRay

void CombatCamera::ViewportRay(double screen_x, double screen_y, Ogre::Ray& ray) const
{
    double out_origin[3];
    double ray_direction[3];
    ViewportRay(screen_x,  screen_y, out_origin, ray_direction);
    ray.setOrigin(Ogre::Vector3(out_origin[0], out_origin[1], out_origin[2]));
    ray.setDirection(Ogre::Vector3(ray_direction[0], ray_direction[1], ray_direction[2]));
}
开发者ID:Ablu,项目名称:freeorion,代码行数:8,代码来源:CombatCamera.cpp

示例14: 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);
}
开发者ID:LittleForker,项目名称:sirikata,代码行数:9,代码来源:OgreMeshRaytrace.cpp

示例15: 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;
}
开发者ID:Valentin33,项目名称:Gui3D,代码行数:56,代码来源:Gui3DPanel.cpp


注:本文中的ogre::Ray类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。