Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 12247


Ignore:
Timestamp:
Mar 28, 2019, 1:33:50 PM (6 years ago)
Author:
tkuonen
Message:

Comlete initial version of MouseAPI
remove compile errors

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  
    11#include "mouseapi.h"
     2
     3namespace orxonox{
    24
    35MouseAPI::MouseAPI(Camera& camera)
     
    1214
    1315MouseAPI::~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");
    1519}
    1620
    17 virtual void MouseAPI::buttonPressed (MouseButtonCode::ByEnum button)
     21void MouseAPI::buttonPressed(MouseButtonCode::ByEnum button)
    1822{
    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()));
    2125    for(auto event: clickEvents)
    2226    {
    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);
    2630        }
    2731    }
    2832}
    2933
    30 virtual void MouseAPI::mouseMoved    (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
     34void MouseAPI::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
    3135{
    3236    mousePos = abs;
    3337}
    3438
    35 virtual void MouseAPI::mouseScrolled (int abs, int rel)
     39void MouseAPI::mouseScrolled(int abs, int rel)
    3640{
    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()));
    3943    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)
    4145            (*(event.onScrolledFunction))(abs,rel,mousePos);
    4246    }
    4347}
    4448
    45 void MouseAPI::addClickableObject(const Vector3& position,float radius,const list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button))
     49void MouseAPI::addClickableObject(const Vector3& position,float radius,const std::list<MouseButtonCode::ByEnum>& buttons,void (*onClickedFunction)(MouseButtonCode::ByEnum button))
    4650{
    47     clickEvents.insert({position,radius,buttons,onClickedFunction});
     51    clickEvents.insert(clickEvents.begin(),{position,radius,buttons,onClickedFunction});
    4852}
    4953void MouseAPI::addScrollElement(const Vector3& position,float radius,void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos))
    5054{
    51     scrollEvents.insert(position,radius,onScrolledFunction);
     55    scrollEvents.insert(scrollEvents.begin(),{position,radius,onScrolledFunction});
    5256}
    5357void MouseAPI::addScrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos))
    5458{
    55     scrollEvents.insert(onScrolledFunction);
     59    scrollEvents.insert(scrollEvents.begin(),{onScrolledFunction});
    5660}
    5761
     
    6064    cam = camera.getOgreCamera();
    6165}
     66
     67}
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.h

    r12217 r12247  
    22#define MOUSEAPI_H
    33
     4
     5#include "OrxonoxPrereqs.h"
     6#include "util/OgreForwardRefs.h"
     7#include "graphics/Camera.h"
    48#include <util/Math.h>
    59#include <list>
     
    812#include <core/GraphicsManager.h>
    913#include <core/input/InputState.h>
     14#include <OgreCamera.h>
     15#include <OgreViewport.h>
    1016
    1117namespace orxonox
     
    2127        Vector3 position;
    2228        float radius;
    23         list<MouseButtonCode::ByEnum> buttons;
     29        std::list<MouseButtonCode::ByEnum> buttons;
    2430        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),
    2632            radius(radius), buttons(buttons), onClickedFunction(onClickedFunction){}
    2733    };
     
    3339        float radius;
    3440        void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos);
    35         scrollEvents(void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)):considerPosition(false),
     41        scrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2& mousePos)):considerPosition(false),
    3642            onScrolledFunction(onScrolledFunction){}
    37         scrollEvents(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),
    3844            position(position), radius(radius), onScrolledFunction(onScrolledFunction){}
    3945    };
     
    4248    std::list<clickableElement> clickEvents;
    4349    std::list<scrollElement> scrollEvents;
    44     Ogre::Camera cam;
     50    Ogre::Camera *cam ;
    4551    IntVector2 mousePos;
    4652    InputState* state;
     
    5763    virtual void mouseScrolled (int abs, int rel) override;
    5864
    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));
    6066    void addScrollElement(const Vector3& position,float radius,void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos));
    6167    void addScrollElement(void (*onScrolledFunction)(int abs,int rel,const IntVector2&  mousePos));
Note: See TracChangeset for help on using the changeset viewer.