Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Comlete initial version of MouseAPI
remove compile errors

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.