- Timestamp:
- Mar 28, 2019, 1:33:50 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.cc
r12218 r12247 1 1 #include "mouseapi.h" 2 3 namespace orxonox{ 2 4 3 5 MouseAPI::MouseAPI(Camera& camera) … … 12 14 13 15 MouseAPI::~MouseAPI(){ 14 //todo look at gslevel destructor and implement this one 16 InputManager::getInstance().leaveState("MouseAPI"); 17 state->setMouseHandler(nullptr); 18 InputManager::getInstance().destroyState("MouseAPI"); 15 19 } 16 20 17 v irtual void MouseAPI::buttonPressed(MouseButtonCode::ByEnum button)21 void MouseAPI::buttonPressed(MouseButtonCode::ByEnum button) 18 22 { 19 Ogre::Viewport vp = GraphicsManager::getInstance().getViewport();20 Ogre::Ray ray = getCameraToViewPortRay(mousePos.x/((float)vp.getActualWidth()),mousePos.y/((float)vp.getActualHeight()));23 Ogre::Viewport *vp = GraphicsManager::getInstance().getViewport(); 24 Ogre::Ray ray = cam->getCameraToViewportRay(mousePos.x/((float)vp->getActualWidth()),mousePos.y/((float)vp->getActualHeight())); 21 25 for(auto event: clickEvents) 22 26 { 23 for(auto wantedButton: buttons){24 if(wantedButton == button && ray.intersects(Ogre::Sphere(event.position, radius)))25 ( &(event.onClickedFunction))(button);27 for(auto wantedButton:event.buttons){ 28 if(wantedButton == button && ray.intersects(Ogre::Sphere(event.position,event.radius)).first) 29 (*(event.onClickedFunction))(button); 26 30 } 27 31 } 28 32 } 29 33 30 v irtual void MouseAPI::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)34 void MouseAPI::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) 31 35 { 32 36 mousePos = abs; 33 37 } 34 38 35 v irtual void MouseAPI::mouseScrolled(int abs, int rel)39 void MouseAPI::mouseScrolled(int abs, int rel) 36 40 { 37 Ogre::Viewport vp = GraphicsManager::getInstance().getViewport();38 Ogre::Ray ray = getCameraToViewPortRay(mousePos.x/((float)vp.getActualWidth()),mousePos.y/((float)vp.getActualHeight()));41 Ogre::Viewport *vp = GraphicsManager::getInstance().getViewport(); 42 Ogre::Ray ray = cam->getCameraToViewportRay(mousePos.x/((float)vp->getActualWidth()),mousePos.y/((float)vp->getActualHeight())); 39 43 for(auto event:scrollEvents){ 40 if(!event.considerPosition || ray.intersects(Ogre::Sphere(event.position, radius)))44 if(!event.considerPosition || ray.intersects(Ogre::Sphere(event.position,event.radius)).first) 41 45 (*(event.onScrolledFunction))(abs,rel,mousePos); 42 46 } 43 47 } 44 48 45 void MouseAPI::addClickableObject(const Vector3& position,float radius,const list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button))49 void MouseAPI::addClickableObject(const Vector3& position,float radius,const std::list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button)) 46 50 { 47 clickEvents.insert( {position,radius,buttons,onClickedFunction});51 clickEvents.insert(clickEvents.begin(),{position,radius,buttons,onClickedFunction}); 48 52 } 49 53 void MouseAPI::addScrollElement(const Vector3& position,float radius,void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)) 50 54 { 51 scrollEvents.insert( position,radius,onScrolledFunction);55 scrollEvents.insert(scrollEvents.begin(),{position,radius,onScrolledFunction}); 52 56 } 53 57 void MouseAPI::addScrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)) 54 58 { 55 scrollEvents.insert( onScrolledFunction);59 scrollEvents.insert(scrollEvents.begin(),{onScrolledFunction}); 56 60 } 57 61 … … 60 64 cam = camera.getOgreCamera(); 61 65 } 66 67 }
Note: See TracChangeset
for help on using the changeset viewer.