コード例 #1
0
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();
    }
}
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;
}
コード例 #3
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;
}
コード例 #4
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);
 }
コード例 #5
0
ファイル: Ground.cpp プロジェクト: agruzdev/OgreNature
//-------------------------------------------------------
std::pair<bool, Ogre::Vector3> Ground::GetIntersectionLocalSpace(const Ogre::Ray & ray) const
{
    if (ray.intersects(mGlobalBoundingBox).first)
    {
        float intersection = -1.0f;
        for (const auto & region : mEntities)
        {
            auto hit = ray.intersects(region->getBoundingBox());
            if (hit.first)
            {
                auto meshHit = GetVertexIntersection(ray, region->getMesh()->getSubMesh(0));
                if (meshHit.first && (intersection < 0.0f || meshHit.second < intersection))
                {
                    intersection = meshHit.second;
                }
            }
        }
        if (intersection >= 0.0f)
        {
            return std::make_pair(true, ray.getPoint(intersection));
        }
    }
    return std::make_pair(false, Ogre::Vector3::ZERO);
}
コード例 #6
0
bool XYOrbitViewController::intersectGroundPlane( Ogre::Ray mouse_ray, Ogre::Vector3 &intersection_3d )
{
  //convert rays into reference frame
  mouse_ray.setOrigin( target_scene_node_->convertWorldToLocalPosition( mouse_ray.getOrigin() ) );
  mouse_ray.setDirection( target_scene_node_->convertWorldToLocalOrientation( Ogre::Quaternion::IDENTITY ) * mouse_ray.getDirection() );

  Ogre::Plane ground_plane( Ogre::Vector3::UNIT_Z, 0 );

  std::pair<bool, Ogre::Real> intersection = mouse_ray.intersects(ground_plane);
  if (!intersection.first)
  {
    return false;
  }

  intersection_3d = mouse_ray.getPoint(intersection.second);
  return true;
}
コード例 #7
0
Vector3 TransformInventoryUtil::getOriginPositionPlane()
{
	Camera* player_camera = GameFramework::getSingletonPtr()->camera;
	Plane far_plane = player_camera->getFrustumPlane(1);

	float x_percent = 0.5; //((float)x / player_camera->getViewport()->getActualWidth());
	float y_percent = 0.5; //((float)y / player_camera->getViewport()->getActualHeight());

	Ogre::Ray ray = player_camera->getCameraToViewportRay(x_percent, y_percent);

	std::pair<bool, Real> result = ray.intersects(far_plane);

	if (result.first)
	{
		Vector3 origin_plane =  /*ray.getOrigin() + ray.getDirection() * 1000*/ray.getPoint(result.second * 0.9);
		return origin_plane;
	}

	return Vector3::ZERO;
}
コード例 #8
0
void ClientGame::UpdateTileUnderCursor(Ogre::Ray aRay)
{
    Ogre::Real radius = mTiles[0]->GetPosition().length();
    Ogre::Sphere sphere(Ogre::Vector3::ZERO, radius);
    std::pair<bool, Ogre::Real> res = aRay.intersects(sphere);
    if (res.first)
    {
        Ogre::Vector3 position(aRay.getPoint(res.second));
        mTileUnderCursor = mTileUnderCursor->GetTileAtPosition(position);
        if (mSelectionMarker->getParent())
        {
            mSelectionMarker->getParent()->removeChild(mSelectionMarker);
        }

        if (mTileUnderCursor->GetTile())
        {
            mTileUnderCursor->GetTile()->GetNode().addChild(mSelectionMarker);
        }

    }
    mSelectionMarker->setVisible(res.first);
}
コード例 #9
0
ファイル: HeadsUpDisplay.cpp プロジェクト: eblock12/stuff
void HeadsUpDisplay::tick(Ogre::Real timeDelta)
{
    // window dimensions may have changed
    Application &app = Application::getSingleton();
    Ogre::Real windowWidth = (Ogre::Real)app.getWindowWidth();
    Ogre::Real windowHeight = (Ogre::Real)app.getWindowHeight();

    // get mouse cursor and update absolute position from relative change
    OIS::Mouse *mouse = app.getMouse();
    if (mouse != nullptr)
    {
        OIS::MouseState mouseState = mouse->getMouseState();
        m_cursorX += mouseState.X.rel;
        m_cursorY += mouseState.Y.rel;
        m_cursorX = Math::clamp(m_cursorX, 0, windowWidth);
        m_cursorY = Math::clamp(m_cursorY, 0, windowHeight);

        // normalize cursor position and size from 0 to 1
        Ogre::Real cursorX = m_cursorX / windowWidth;
        Ogre::Real cursorY = m_cursorY / windowHeight;
        m_cursorContainer->setPosition(cursorX, cursorY);
        m_cursorContainer->setWidth(CURSOR_WIDTH / windowWidth);
        m_cursorContainer->setHeight(CURSOR_HEIGHT / windowHeight);
        m_cursorContainer->show();

        // project cursor ray into scene and get query results
        if (!m_mouseLeftLastDown && mouseState.buttonDown(OIS::MouseButtonID::MB_Left))
        {
            Ogre::Ray mouseRay;
            getCamera()->getCameraToViewportRay(cursorX, cursorY, &mouseRay);
            m_rayQuery->setRay(mouseRay);
            m_objectFound = false;
            m_rayQuery->execute(this);

            if (!m_objectFound && (m_currentSelection != nullptr))
            {
                // user selected nothing so clear current selection
                m_currentSelection->onDeselect();
            }
        }

        if ((m_currentSelection != nullptr) && !m_mouseRightLastDown && mouseState.buttonDown(OIS::MouseButtonID::MB_Right))
        {
            Ogre::Ray mouseRay;
            getCamera()->getCameraToViewportRay(cursorX, cursorY, &mouseRay);
            Ogre::Plane plane(Ogre::Vector3(0, 1, 0), Ogre::Vector3::ZERO);
            auto intersectResult = mouseRay.intersects(plane);
            if (intersectResult.first)
            {
                Ogre::Vector3 destination = mouseRay.getPoint(intersectResult.second);
                m_currentSelection->onMoveOrder(destination);
            }
        }
        
        m_mouseLeftLastDown = mouseState.buttonDown(OIS::MouseButtonID::MB_Left);
        m_mouseRightLastDown = mouseState.buttonDown(OIS::MouseButtonID::MB_Right);
    }
    else
    {
        m_cursorContainer->hide();
    }
}
コード例 #10
0
std::pair<bool, Real>
rayCollide(const Ogre::Ray& ray,
           Ogre::MovableObject* movable,
           bool accurate,
           CullingMode cullingMode,
           bool allowAnimable)
{
    // Get local space axis aligned bounding box
    const Ogre::AxisAlignedBox& aabb = movable->getBoundingBox();

    // Matrix4 to transform local space to world space
    const Ogre::Matrix4& localToWorld = movable->_getParentNodeFullTransform();

    // Matrix4 to transform world space to local space
    Ogre::Matrix4 worldToLocal = localToWorld.inverse();

    // Matrix3 to transform world space normal to local space
    Ogre::Matrix3 worldToLocalN;
    worldToLocal.extract3x3Matrix(worldToLocalN);

    // Convert world space ray to local space ray
    // Note:
    //      By preserving the scale between world space and local space of the
    //      direction, we don't need to recalculate the distance later.
    Ogre::Ray localRay;
    localRay.setOrigin(worldToLocal * ray.getOrigin());
    localRay.setDirection(worldToLocalN * ray.getDirection());

    // Intersect with axis aligned bounding box, but because we transformed
    // ray to local space of the bounding box, so this test just like test
    // with oriented bounding box.
    std::pair<bool, Real> ret = localRay.intersects(aabb);

    // Do accurate test if hitted bounding box and user required.
    if (ret.first && accurate)
    {
        if (movable->getMovableType() == Ogre::EntityFactory::FACTORY_TYPE_NAME ||
            allowAnimable && movable->getMovableType() == Ogre::AutoAnimationEntityFactory::FACTORY_TYPE_NAME)
        {
            Ogre::Entity* entity = static_cast<Ogre::Entity*>(movable);
            if (!entity->_isAnimated())
            {
                // Static entity

                // Get the entity mesh
                const Ogre::MeshPtr& mesh = entity->getMesh();

                // Get the collision mode
                CollisionModelPtr collisionModel = CollisionModelManager::getSingleton().getCollisionModel(mesh);

                ret = doPicking(localRay, *collisionModel, cullingMode);
            }
            else if (allowAnimable)
            {
                // Animation entity

                bool addedSoftwareAnimation = false;
                if (entity->getSoftwareAnimationRequests() <= 0)
                {
                    entity->addSoftwareAnimationRequest(false);
                    entity->_updateAnimation();
                    addedSoftwareAnimation = true;
                }

                CollisionModel collisionModel;
                collisionModel.addEntity(entity);
                collisionModel.build(true);

                ret = doPicking(localRay, collisionModel, cullingMode);

                if (addedSoftwareAnimation)
                {
                    entity->removeSoftwareAnimationRequest(false);
                }
            }
        }
    }

    return ret;
}
コード例 #11
0
ファイル: lagom_player_base.cpp プロジェクト: jaschmid/Lagom
bool LagomPlayerBase::CheckHover(const Ogre::Ray& ray)
{
	return ray.intersects( Ogre::Sphere(getIntFactory().ConstructionOffset, getIntFactory().ConstructingTriggerSize) ).first;
}