コード例 #1
0
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);
    }
  }
}
コード例 #2
0
//----------------------------------------------------------------------------------------
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;
}
コード例 #3
0
// -------------------------------------------------------------------------
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();	
    }  
}
コード例 #4
0
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());
    }
}
コード例 #5
0
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
0
ファイル: Renderer.cpp プロジェクト: JamesLinus/dawnengine
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;
}
コード例 #7
0
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);
				
    }
}
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;
}
/** 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;
}
コード例 #10
0
ファイル: PlayerController.cpp プロジェクト: Ithos/TTG
		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;
		}
コード例 #11
0
ファイル: RigidControlet.cpp プロジェクト: JohnCrash/iRobot
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;
		}
	}
}
コード例 #12
0
ファイル: gkRayTest.cpp プロジェクト: Ali-il/gamekit
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);
}
コード例 #13
0
ファイル: CombatCamera.cpp プロジェクト: Ablu/freeorion
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]));
}
コード例 #14
0
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);
}
コード例 #15
0
ファイル: Gui3DPanel.cpp プロジェクト: Valentin33/Gui3D
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;
}
コード例 #16
0
ファイル: MyFrameListener.cpp プロジェクト: flush/CEDV-2015
/*
 *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);
}
コード例 #17
0
ファイル: GodRaysManager.cpp プロジェクト: xDusk/lostisland04
 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);
 }
コード例 #18
0
ファイル: CollisionTools.cpp プロジェクト: nikki93/ngf
// raycast from a point in to the scene.
// returns success or failure.
// on success the point is returned in the result.
bool CollisionTools::raycastFromPoint(const Vector3 &point,
                                        const Vector3 &normal,
										Vector3 &result,unsigned long &target,float &closest_distance,
										const uint32 queryMask)
{
    // create the ray to test
    static Ogre::Ray ray;
	ray.setOrigin(point);
	ray.setDirection(normal);

	return raycast(ray, result, target, closest_distance, queryMask);
}
コード例 #19
0
bool CollisionTools::raycastFromPoint(const Ogre::Vector3 &point,
                                        const Ogre::Vector3 &normal,
										Ogre::Vector3 &result,int &FaceIndex,Ogre::MovableObject* &target,
										float &closest_distance,
										const Ogre::uint32 queryMask)
{
    // create the ray to test
    static Ogre::Ray ray;
	ray.setOrigin(point);
	ray.setDirection(normal);

	return raycast(ray, result,FaceIndex, target, closest_distance, queryMask);
}
コード例 #20
0
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());
}
コード例 #21
0
// -------------------------------------------------------------------------
void OgreBulletListener::button0Pressed()
{
    // pick a body and try to drag it.
    Ogre::Vector3 pickPos;
    Ogre::Ray rayTo;
    OgreBulletDynamics::RigidBody * body = 
        getBodyUnderCursorUsingBullet(pickPos, rayTo);
        //getBodyUnderCursorUsingOgre(pickPos, rayTo);
    if (body)
    {  
        //other exclusions?
        if (!(body->isStaticObject() 
            //|| body->isKinematicObject()
            ))
        {
            mPickedBody = body;
            mPickedBody->disableDeactivation();		
            const Ogre::Vector3 localPivot (body->getCenterOfMassPivot(pickPos));
            OgreBulletDynamics::PointToPointConstraint *p2p  = 
                new OgreBulletDynamics::PointToPointConstraint(body, localPivot);

            mWorld->addConstraint(p2p);					    

            //save mouse position for dragging
            mOldPickingPos = pickPos;
            const Ogre::Vector3 eyePos(mCamera->getDerivedPosition());
            mOldPickingDist  = (pickPos - eyePos).length();

            //very weak constraint for picking
            p2p->setTau (0.1f);
            mPickConstraint = p2p;


        }
        getDebugLines();
        mDebugRayLine->addLine (rayTo.getOrigin(), pickPos);
        mDebugRayLine->draw();
    }

    if (mGuiListener->getGui()->injectMouse(mInputListener->getAbsMouseX ()*mWindow->getWidth(), 
        mInputListener->getAbsMouseY ()*mWindow->getHeight(), true))
    {
        mGuiListener->hideMouse();
    }
    else
    {
        mGuiListener->showMouse ();
    }
}
コード例 #22
0
// -------------------------------------------------------------------------
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);
    }

}
コード例 #23
0
    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));
    }
コード例 #24
0
ファイル: StandLatas.cpp プロジェクト: jalcolea/shooter
/**
 * Calcula dirección del disparo
 */
Vector3 StandLatas::calculateDirShoot() {

  
  Vector3 dirShoot;
  _rayScnQuery->setSortByDistance(true);
  _rayScnQuery->setQueryMask(COL_STAND|COL_CAN);

    Ogre::Ray ray  = _camera->
                       getCameraToViewportRay(_mousex/float(1024),
                                              _mousey/float(768));
    dirShoot = ray.getDirection();


    std::cout << "Factor de Potencia "<< (_timeLoadingShoot/0.1)   << " tiempo Pulsado " <<_timeLoadingShoot << std::endl;
    return dirShoot*(_timeLoadingShoot/0.05);
}
コード例 #25
0
//-------------------------------------------------------------------------------
bool CEditableMeshEditor::_pickVertex(Ogre::Ray& ray)
{
    Ogre::Real distance = 999999.0f;
    mCurrentVertex = 0;

    Ogre::Vector3 nodePos = mHandle->_getDerivedPosition();
    Ogre::Vector3 vertexPos;

    for(unsigned int i = 0;i < mVertexes.size();i++)
    {
        vertexPos = nodePos + mVertexes[i];
        Ogre::AxisAlignedBox box(vertexPos.x - 0.1f, vertexPos.y - 0.1f, vertexPos.z - 0.1f, vertexPos.x + 0.1f, vertexPos.y + 0.1f, vertexPos.z + 0.1f);
        std::pair<bool, Ogre::Real> result = ray.intersects(box);
        if(result.first && result.second < distance)
        {
            distance = result.second;
            mCurrentVertex = &(mVertexes[i]);
        }
    }
    
    if(distance < 999999.0f)
        return true;

    return false;
}
コード例 #26
0
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;
}
コード例 #27
0
ファイル: visibility.cpp プロジェクト: jstnhuang/autocp
/*
 * 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;
}
コード例 #28
0
ファイル: MousePicker.cpp プロジェクト: amireh/Elementum
  bool
  GenericMousePicker::cast(
    const OIS::MouseEvent &e,
    const CEGUI::Point& mousePos,
    const Ogre::Camera *mCamera,
    Ogre::MovableObject **out,
    Ogre::uint32 mask)
  {
    Ogre::Ray mouseRay =
      mCamera->getCameraToViewportRay(
        mousePos.d_x/float(e.state.width),
        mousePos.d_y/float(e.state.height)
      );

    return cast(mouseRay.getOrigin(), mouseRay.getDirection(), out, mask);
  }
コード例 #29
0
//-----------------------------------------------------------------------
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);
	}
}
コード例 #30
0
void AIRayPathFinderStrategy::CalcLines(Ogre::Ray &line)
{
	Vector3 start;
	Vector3 direction = line.getDirection();
	Ogre::Quaternion quat;
	for (int i=0;i<LinesNumber-1;++i)
	{
		start = LineOrigins[i];			
		quat = start.getRotationTo(direction);

		start = quat*start; //matr.rotateVect(lines[i].start);
		Lines[i].setOrigin(start+line.getOrigin()); //lines[i].start += line.start;
		Lines[i].setDirection(start+direction); //lines[i].end = lines[i].start+v;		
	}

	Lines[LinesNumber-1] = line;
}