Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.cc @ 12253

Last change on this file since 12253 was 12253, checked in by mkarpf, 6 years ago

Test Level created
ATTENTION: Level is buggy and freezes Screen!

File size: 2.5 KB
RevLine 
[12213]1#include "mouseapi.h"
2
[12247]3namespace orxonox{
4
[12253]5MouseAPI::MouseAPI()
[12213]6{
7
8}
9
[12253]10void MouseAPI::activate()
11{
12     if(InputManager::exists())
13     {
14        cam = CameraManager::getInstance().getActiveCamera()->getOgreCamera();
15        state = InputManager::getInstance().createInputState("MouseAPI");
16        state->setMouseExclusive(false);//does this work
17        state->setMouseHandler(this);
18        InputManager::getInstance().enterState("MouseAPI");
19    }
20
[12217]21}
[12213]22
[12253]23void MouseAPI::deactivate()
24{
25    if(InputManager::exists())
26    {
27        InputManager::getInstance().leaveState("MouseAPI");
28        state->setMouseHandler(nullptr);
29        InputManager::getInstance().destroyState("MouseAPI");
30    }
31}
32
33MouseAPI::~MouseAPI()
34{
35
36}
37
[12247]38void MouseAPI::buttonPressed(MouseButtonCode::ByEnum button)
[12217]39{
[12247]40    Ogre::Viewport *vp = GraphicsManager::getInstance().getViewport();
41    Ogre::Ray ray = cam->getCameraToViewportRay(mousePos.x/((float)vp->getActualWidth()),mousePos.y/((float)vp->getActualHeight()));
[12217]42    for(auto event: clickEvents)
43    {
[12247]44        for(auto wantedButton:event.buttons){
45            if(wantedButton == button && ray.intersects(Ogre::Sphere(event.position,event.radius)).first)
[12253]46                event.onClickedFunction(button);
[12217]47        }
48    }
49}
[12213]50
[12247]51void MouseAPI::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
[12213]52{
[12217]53    mousePos = abs;
[12213]54}
[12217]55
[12247]56void MouseAPI::mouseScrolled(int abs, int rel)
[12213]57{
[12247]58    Ogre::Viewport *vp = GraphicsManager::getInstance().getViewport();
59    Ogre::Ray ray = cam->getCameraToViewportRay(mousePos.x/((float)vp->getActualWidth()),mousePos.y/((float)vp->getActualHeight()));
[12217]60    for(auto event:scrollEvents){
[12247]61        if(!event.considerPosition || ray.intersects(Ogre::Sphere(event.position,event.radius)).first)
[12217]62            (*(event.onScrolledFunction))(abs,rel,mousePos);
63    }
64}
65
[12253]66void MouseAPI::addClickableObject(const Vector3& position, float radius, const std::list<MouseButtonCode::ByEnum>& buttons, std::function<void(MouseButtonCode::ByEnum)> onClickedFunction)
[12217]67{
[12247]68    clickEvents.insert(clickEvents.begin(),{position,radius,buttons,onClickedFunction});
[12217]69}
70void MouseAPI::addScrollElement(const Vector3& position,float radius,void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos))
71{
[12247]72    scrollEvents.insert(scrollEvents.begin(),{position,radius,onScrolledFunction});
[12213]73}
[12217]74void MouseAPI::addScrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos))
[12213]75{
[12247]76    scrollEvents.insert(scrollEvents.begin(),{onScrolledFunction});
[12213]77}
[12217]78
79void MouseAPI::changeCamera(Camera& camera)
80{
81    cam = camera.getOgreCamera();
82}
[12247]83
84}
Note: See TracBrowser for help on using the repository browser.