Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 21, 2019, 4:06:42 PM (6 years ago)
Author:
tkuonen
Message:
 
Location:
code/branches/MouseAPI_FS19/src/modules/MouseAPI
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.cc

    r12213 r12217  
    11#include "mouseapi.h"
    22
    3 MouseAPI::MouseAPI()
     3MouseAPI::MouseAPI(Camera& camera)
    44{
     5    cam = camera.getOgreCamera();
     6    state = InputManager::getInstance().createInputState("MouseAPI");
     7    state->setMouseExclusive(false);
     8    state->setMouseHandler(this);
     9    InputManager::getInstance().enterState("MouseAPI");
    510
    611}
    712
    8 MouseAPI::~MouseAPI(){}
     13MouseAPI::~MouseAPI(){
     14    //todo look at gslevel destructor and implement this one
     15}
    916
    10 virtual void MouseAPI::buttonPressed (MouseButtonCode::ByEnum button){}
    11 virtual void MouseAPI::mouseMoved    (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize){}
    12 virtual void MouseAPI::mouseScrolled (int abs, int rel){}
     17virtual void MouseAPI::buttonPressed (MouseButtonCode::ByEnum button)
     18{
     19    Ogre::Viewport vp = GraphicsManager::getInstance().getViewport();
     20    Ogre::Ray ray = getCameraToViewPortRay(mousePos.x/((float)vp.getActualWidth()),mousePos.y/((float)vp.getActualHeight()));
     21    for(auto event: clickEvents)
     22    {
     23        for(auto wantedButton:buttons){
     24            if(wantedButton == button && ray.intersects(Ogre::Sphere(event.position,radius)))
     25                (&(event.onClickedFunction))(button);
     26        }
     27    }
     28}
    1329
    14 void addClickableObject(const Vector3& position,float radius,const list<ClickEvent>& events,void (*onClickedFunction)())
     30virtual void MouseAPI::mouseMoved    (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
    1531{
    16     clickEvents.insert({position,radius,events,onClickedFunction});
     32    mousePos = abs;
    1733}
    18 void addScrollElement(const Vector3& position,float radius,void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos))
     34
     35virtual void MouseAPI::mouseScrolled (int abs, int rel)
     36{
     37    Ogre::Viewport vp = GraphicsManager::getInstance().getViewport();
     38    Ogre::Ray ray = getCameraToViewPortRay(mousePos.x/((float)vp.getActualWidth()),mousePos.y/((float)vp.getActualHeight()));
     39    for(auto event:scrollEvents){
     40        if(!event.considerPosition || ray.intersects(Ogre::Sphere(event.position,radius)))
     41            (*(event.onScrolledFunction))(abs,rel,mousePos);
     42    }
     43}
     44
     45void MouseAPI::addClickableObject(const Vector3& position,float radius,const list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button))
     46{
     47    clickEvents.insert({position,radius,buttons,onClickedFunction});
     48}
     49void MouseAPI::addScrollElement(const Vector3& position,float radius,void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos))
    1950{
    2051    scrollEvents.insert(position,radius,onScrolledFunction);
    2152}
    22 void addScrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos))
     53void MouseAPI::addScrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos))
    2354{
    2455    scrollEvents.insert(onScrolledFunction);
    2556}
     57
     58void MouseAPI::changeCamera(Camera& camera)
     59{
     60    cam = camera.getOgreCamera();
     61}
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.h

    r12213 r12217  
    55#include <list>
    66#include <core/input/InputHandler.h>
     7#include <graphics/Camera.h>
     8#include <core/GraphicsManager.h>
     9#include <core/input/InputState.h>
    710
    811namespace orxonox
     
    1821        Vector3 position;
    1922        float radius;
    20         list<ClickEvent> events;
    21         void (*onClickedFunction)();
    22         clickableElement(const Vector3& position,float radius,const list<ClickEvent>& events,void (*onClickedFunction)()):position(position),
    23             radius(radius), events(events), onClickedFunction(onClickedFunction){}
     23        list<MouseButtonCode::ByEnum> buttons;
     24        void (*onClickedFunction)(MouseButtonCode::ByEnum button);
     25        clickableElement(const Vector3& position,float radius,const list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)()):position(position),
     26            radius(radius), buttons(buttons), onClickedFunction(onClickedFunction){}
    2427    };
    2528
     
    3942    std::list<clickableElement> clickEvents;
    4043    std::list<scrollElement> scrollEvents;
     44    Ogre::Camera cam;
     45    IntVector2 mousePos;
     46    InputState* state;
    4147
    4248
    4349public:
    44     enum ClickEvent
    45     {
    46         rightClick,leftClick,middleCLick
    47     };
    4850
    49     MouseAPI();
     51    MouseAPI(Camera& cam);
    5052    ~MouseAPI();
    51     virtual void buttonPressed (MouseButtonCode::ByEnum button);
    52     virtual void buttonReleased(MouseButtonCode::ByEnum button){}
    53     virtual void buttonHeld    (MouseButtonCode::ByEnum button){}
    54     virtual void mouseMoved    (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
    55     virtual void mouseScrolled (int abs, int rel);
     53    virtual void buttonPressed (MouseButtonCode::ByEnum button) override;
     54    virtual void buttonReleased(MouseButtonCode::ByEnum button)  override{}
     55    virtual void buttonHeld    (MouseButtonCode::ByEnum button) override{}
     56    virtual void mouseMoved    (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) override;
     57    virtual void mouseScrolled (int abs, int rel) override;
    5658
    57     void addClickableObject(const Vector3& position,float radius,const list<ClickEvent>& events,void (*onClickedFunction)());
     59    void addClickableObject(const Vector3& position,float radius,const list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button));
    5860    void addScrollElement(const Vector3& position,float radius,void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos));
    5961    void addScrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos));
     62
     63    void changeCamera(Camera& camera);
    6064};
    6165}
Note: See TracChangeset for help on using the changeset viewer.