Changeset 12247 for code/branches
- Timestamp:
- Mar 28, 2019, 1:33:50 PM (6 years ago)
- Location:
- code/branches/MouseAPI_FS19/src/modules/MouseAPI
- Files:
-
- 2 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 } -
code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.h
r12217 r12247 2 2 #define MOUSEAPI_H 3 3 4 5 #include "OrxonoxPrereqs.h" 6 #include "util/OgreForwardRefs.h" 7 #include "graphics/Camera.h" 4 8 #include <util/Math.h> 5 9 #include <list> … … 8 12 #include <core/GraphicsManager.h> 9 13 #include <core/input/InputState.h> 14 #include <OgreCamera.h> 15 #include <OgreViewport.h> 10 16 11 17 namespace orxonox … … 21 27 Vector3 position; 22 28 float radius; 23 list<MouseButtonCode::ByEnum> buttons;29 std::list<MouseButtonCode::ByEnum> buttons; 24 30 void (*onClickedFunction)(MouseButtonCode::ByEnum button); 25 clickableElement(const Vector3& position,float radius,const list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)()):position(position),31 clickableElement(const Vector3& position,float radius,const std::list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button)):position(position), 26 32 radius(radius), buttons(buttons), onClickedFunction(onClickedFunction){} 27 33 }; … … 33 39 float radius; 34 40 void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos); 35 scrollE vents(void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)):considerPosition(false),41 scrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)):considerPosition(false), 36 42 onScrolledFunction(onScrolledFunction){} 37 scrollE vents(Vector3& position, float radius, void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)):considerPosition(true),43 scrollElement(const Vector3& position, float radius, void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)):considerPosition(true), 38 44 position(position), radius(radius), onScrolledFunction(onScrolledFunction){} 39 45 }; … … 42 48 std::list<clickableElement> clickEvents; 43 49 std::list<scrollElement> scrollEvents; 44 Ogre::Camera cam;50 Ogre::Camera *cam ; 45 51 IntVector2 mousePos; 46 52 InputState* state; … … 57 63 virtual void mouseScrolled (int abs, int rel) override; 58 64 59 void addClickableObject(const Vector3& position,float radius,const list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button));65 void addClickableObject(const Vector3& position,float radius,const std::list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button)); 60 66 void addScrollElement(const Vector3& position,float radius,void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)); 61 67 void addScrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos));
Note: See TracChangeset
for help on using the changeset viewer.