void OgreCursor::update()
{
  int x,y, w;
  getPosition(x, y);
  updatePosition(x-7, y-7); //FIXME: ugly hack to compensate offset (-7, -7) from OIS Mouse

  getWheelPos(w);

  deltaWheel += (wheelPos - w);
  int upDown = deltaWheel / wheelPosStep;
  //std::cerr << "upDown=" << upDown << std::endl;

  if (upDown > 0)
  {
    wheelDown += upDown;
    deltaWheel -= upDown * wheelPosStep;
  }
  else if (upDown < 0)
  {
    wheelUp -= upDown;
    deltaWheel -= upDown * wheelPosStep;
  }

  wheelPos = w;

  //update button status
  OIS::MouseState ms = _mouse->getMouseState();
  leftButton = ms.buttonDown(OIS::MB_Left);
  rightButton = ms.buttonDown(OIS::MB_Right);
  wheelButton = ms.buttonDown(OIS::MB_Middle);
}
bool SceneMouse::mousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id)
{
    if (App::sim_state.GetActive() == SimState::PAUSED) { return true; } // Do nothing when paused

    const OIS::MouseState ms = _arg.state;

    if (ms.buttonDown(OIS::MB_Middle))
    {
        if (gEnv->cameraManager && gEnv->cameraManager->getCurrentBehavior() == CameraManager::CAMERA_BEHAVIOR_VEHICLE)
        {
            Beam* truck = m_sim_controller->GetBeamFactory()->getCurrentTruck();

            if (truck)
            {
                lastMouseY = ms.Y.abs;
                lastMouseX = ms.X.abs;
                Ray mouseRay = getMouseRay();

                Real nearest_camera_distance = std::numeric_limits<float>::max();
                Real nearest_ray_distance = std::numeric_limits<float>::max();
                int nearest_node_index = -1;

                for (int i = 0; i < truck->free_node; i++)
                {
                    std::pair<bool, Real> pair = mouseRay.intersects(Sphere(truck->nodes[i].AbsPosition, 0.25f));
                    if (pair.first)
                    {
                        Real ray_distance = mouseRay.getDirection().crossProduct(truck->nodes[i].AbsPosition - mouseRay.getOrigin()).length();
                        if (ray_distance < nearest_ray_distance || (ray_distance == nearest_ray_distance && pair.second < nearest_camera_distance))
                        {
                            nearest_camera_distance = pair.second;
                            nearest_ray_distance = ray_distance;
                            nearest_node_index = i;
                        }
                    }
                }
                if (truck->m_custom_camera_node != nearest_node_index)
                {
                    truck->m_custom_camera_node = nearest_node_index;
                    truck->calculateAveragePosition();
                    gEnv->cameraManager->NotifyContextChange();
                }
            }
        }
    }

    if (gEnv->cameraManager)
    {
        gEnv->cameraManager->mousePressed(_arg, _id);
    }

    return true;
}
bool CameraBehaviorVehicleSpline::mouseMoved(const CameraManager::CameraContext &ctx, const OIS::MouseEvent& _arg)
{
	const OIS::MouseState ms = _arg.state;

	if ( RoR::Application::GetInputEngine()->isKeyDown(OIS::KC_LCONTROL) && ms.buttonDown(OIS::MB_Right) )
	{
		Real splinePosDiff = ms.X.rel * std::max(0.00005f, splineLength * 0.0000001f);

		if ( RoR::Application::GetInputEngine()->isKeyDown(OIS::KC_LSHIFT) || RoR::Application::GetInputEngine()->isKeyDown(OIS::KC_RSHIFT) )
		{
			splinePosDiff *= 3.0f;
		}

		if ( RoR::Application::GetInputEngine()->isKeyDown(OIS::KC_LMENU) )
		{
			splinePosDiff *= 0.1f;
		}

		splinePos += splinePosDiff;
		
		if ( ms.X.rel > 0 && splinePos > 0.99f )
		{
			if ( splineClosed )
			{
				splinePos -= 1.0f;
			} else
			{
				// u - turn
			}
		} else if ( ms.X.rel < 0 && splinePos < 0.01f )
		{
			if ( splineClosed )
			{
				splinePos += 1.0f;
			} else
			{
				// u - turn
			}
		}

		splinePos  = std::max(0.0f, splinePos);
		splinePos  = std::min(splinePos, 1.0f);

		camRatio = 0.0f;

		return true;
	} else
	{
		camRatio = 5.0f;

		return CameraBehaviorOrbit::mouseMoved(ctx, _arg);
	}
}
bool CameraBehaviorOrbit::mouseMoved(const CameraManager::CameraContext &ctx, const OIS::MouseEvent& _arg)
{
	const OIS::MouseState ms = _arg.state;

	if ( ms.buttonDown(OIS::MB_Right) )
	{
		camRotX += Degree( ms.X.rel * 0.13f);
		camRotY += Degree(-ms.Y.rel * 0.13f);
		camDist +=        -ms.Z.rel * 0.02f;
		return true;
	}

	return false;
}
Exemple #5
0
void Gui::useMouse()
{
	OIS::MouseState mState = mouse->getMouseState();
	CEGUI::System::getSingleton().injectMouseMove((float)(mState.X.rel),(float)(mState.Y.rel));


	if(mState.buttonDown(OIS::MB_Left)){
		if(!presionado){
			presionado = true;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);
		}
	}
	else{
		if(presionado){
			presionado = false;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);
		}
	}


}
bool CameraBehaviorVehicle::mousePressed(const CameraManager::CameraContext &ctx, const OIS::MouseEvent& _arg, OIS::MouseButtonID _id)
{
	const OIS::MouseState ms = _arg.state;

	if ( ms.buttonDown(OIS::MB_Middle) && RoR::Application::GetInputEngine()->isKeyDown(OIS::KC_LSHIFT) )
	{
		if ( ctx.mCurrTruck && ctx.mCurrTruck->m_custom_camera_node >= 0 )
		{
			// Calculate new camera distance
			Vector3 lookAt = ctx.mCurrTruck->nodes[ctx.mCurrTruck->m_custom_camera_node].AbsPosition;
			camDist = 2.0f * gEnv->mainCamera->getPosition().distance(lookAt);

			// Calculate new camera pitch
			Vector3 camDir = (gEnv->mainCamera->getPosition() - lookAt).normalisedCopy();
			camRotY = asin(camDir.y);

			// Calculate new camera yaw
			Vector3 dir = -ctx.mCurrTruck->getDirection();
			Quaternion rotX = dir.getRotationTo(camDir, Vector3::UNIT_Y);
			camRotX = rotX.getYaw();

			// Corner case handling
			Radian angle = dir.angleBetween(camDir);
			if ( angle > Radian(Math::HALF_PI) )
			{
				if ( std::abs(Radian(camRotX).valueRadians()) < Math::HALF_PI )
				{
					if ( camRotX < Radian(0.0f) )
						camRotX -= Radian(Math::HALF_PI);
					else
						camRotX += Radian(Math::HALF_PI);
				}
			}
		}
	}

	return false;
}
Exemple #7
0
//-------------------------------------------------------------------------------
void MaterialViewer::tick(const Ogre::FrameEvent &evt)
{
    OIS::MouseState ms = Util::getMouseState();
    if (ms.buttonDown(OIS::MB_Right))
    {
        Ogre::Degree hor(ms.X.rel * GlbVar.settings.controls.turningSensitivity * -0.4);
        Ogre::Degree ver(ms.Y.rel * GlbVar.settings.controls.turningSensitivity * 0.4);

        mCameraYawNode->yaw(hor);
		mCameraPitchNode->pitch(ver);
    }
    else if (ms.buttonDown(OIS::MB_Middle))
    {
        mCameraDist += ms.Y.rel * GlbVar.settings.controls.turningSensitivity * 0.02;
        mCameraDist = Util::clamp<Ogre::Real>(mCameraDist, 0.5, 10);
    }

    GlbVar.camNode->setPosition(mCameraPitchNode->_getDerivedOrientation() * Ogre::Vector3(0,0,-mCameraDist));
    GlbVar.camNode->lookAt(Ogre::Vector3::ZERO, Ogre::Node::TS_WORLD);

    if (Util::isKeyDown(OIS::KC_ESCAPE))
        Util::gotoWorld(0);
}
 bool InputManager::isMouseButtonDown( OIS::MouseButtonID buttonID )
 {
     OIS::MouseState ms = mMouse->getMouseState();
     return ms.buttonDown( buttonID );
 }
Exemple #9
0
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();
    }
}
bool SceneMouse::mouseMoved(const OIS::MouseEvent& _arg)
{
    const OIS::MouseState ms = _arg.state;

    // check if handled by the camera
    if (!gEnv->cameraManager || gEnv->cameraManager->mouseMoved(_arg))
        return true;

    // experimental mouse hack
    if (ms.buttonDown(OIS::MB_Left) && mouseGrabState == 0)
    {
        lastMouseY = ms.Y.abs;
        lastMouseX = ms.X.abs;

        Ray mouseRay = getMouseRay();

        // walk all trucks
        Beam** trucks = m_sim_controller->GetBeamFactory()->getTrucks();
        int trucksnum = m_sim_controller->GetBeamFactory()->getTruckCount();
        minnode = -1;
        grab_truck = NULL;
        for (int i = 0; i < trucksnum; i++)
        {
            if (trucks[i] && trucks[i]->state == SIMULATED)
            {
                // check if our ray intersects with the bounding box of the truck
                std::pair<bool, Real> pair = mouseRay.intersects(trucks[i]->boundingBox);
                if (!pair.first)
                    continue;

                for (int j = 0; j < trucks[i]->free_node; j++)
                {
                    if (trucks[i]->node_mouse_grab_disabled[j])
                        continue;

                    // check if our ray intersects with the node
                    std::pair<bool, Real> pair = mouseRay.intersects(Sphere(trucks[i]->nodes[j].AbsPosition, 0.1f));
                    if (pair.first)
                    {
                        // we hit it, check if its the nearest node
                        if (pair.second < mindist)
                        {
                            mindist = pair.second;
                            minnode = j;
                            grab_truck = trucks[i];
                            break;
                        }
                    }
                }
            }

            if (grab_truck)
                break;
        }

        // check if we hit a node
        if (grab_truck && minnode != -1)
        {
            mouseGrabState = 1;
            pickLineNode->setVisible(true);

            for (std::vector<hook_t>::iterator it = grab_truck->hooks.begin(); it != grab_truck->hooks.end(); it++)
            {
                if (it->hookNode->id == minnode)
                {
                    grab_truck->hookToggle(it->group, MOUSE_HOOK_TOGGLE, minnode);
                }
            }
        }
    }
    else if (ms.buttonDown(OIS::MB_Left) && mouseGrabState == 1)
    {
        // force applying and so forth happens in update()
        lastMouseY = ms.Y.abs;
        lastMouseX = ms.X.abs;
        // not fixed
        return false;
    }
    else if (!ms.buttonDown(OIS::MB_Left) && mouseGrabState == 1)
    {
        releaseMousePick();
        // not fixed
        return false;
    }

    return false;
}