Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 18, 2019, 2:49:44 PM (5 years ago)
Author:
mkarpf
Message:

example level weiterentwickelt

File:
1 edited

Legend:

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

    r12302 r12306  
    11#include "mouseapiexample.h"
    2 #include "gametypes/Gametype.h"
    3 #include "infos/PlayerInfo.h"
    4 #include "worldentities/CameraPosition.h"
    5 #include "worldentities/ControllableEntity.h"
    62
    73namespace orxonox
     
    2117}
    2218
    23 // change the size of the cube to a random number by clicking on it
     19// change the size of the cube by a random number between 0.5 and 5 by clicking on it
    2420void MouseAPIExample::changesizeonclick(MouseButtonCode::ByEnum mouse)
    2521{
    26     // generate random number between 1 and 20
    27     float randomnumber = std::fmax((rand()%100 + 1)/20.0,1);
    28     // change the scale of the cube to this random number
     22    // generate random number between 0.5 and 5
     23    float randomnumber = (rand()%10+1)/2.0;
     24    // scale of the cube with this random number
    2925    this->setScale(randomnumber);
    3026    // change the radius of the clickableObject to the new size
    31     MouseAPI::getInstance().changeRadiusOfClickableObject(cubeid,randomnumber);
     27    MouseAPI::getInstance().changeRadiusOfClickableObject(cubeid,randomnumber*10);
    3228}
    3329
     
    3531void MouseAPIExample::changesizeonscroll(int abs,int rel,const IntVector2& mousePos)
    3632{
    37     // increase or decrease the size of the sphere
    38     this->setScale(1+rel);
     33    // get current radius of the sphere
     34    float curRadius = MouseAPI::getInstance().getRadiusScroll(sphereid);
     35    // set factor to 120% or 80% of the current size, depending on increase or decrease
     36    float factor = curRadius/10*(1+rel/600.0);
     37    //scale the sphere with this factor and change the radius
     38    this->setScale(factor);
     39    MouseAPI::getInstance().changeRadiusOfScrollableElement(sphereid,factor*10);
    3940}
    4041
     42// standard XML-Port
    4143void MouseAPIExample::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    4244{
    4345    SUPER(MouseAPIExample, XMLPort, xmlelement, mode);
    44     //todo: id xml-port
     46
     47    // differentiate between several objects by an identifier "id"
     48    XMLPortParam(MouseAPIExample, "id", setId, getId, xmlelement, mode);
     49    if(this->getId() == 1) // id == 1; cube
     50    {
     51        // add the cube to the list with clickable Objects, set the radius to 10, define the function changesizeonclick to be called after a left-click
     52        cubeid = MouseAPI::getInstance().addClickableObject(this->getWorldPosition(),10,std::list<MouseButtonCode::ByEnum>{MouseButtonCode::Left},[this](MouseButtonCode::ByEnum mouse){this->changesizeonclick(mouse);});
     53    }
     54    else if(this->getId() == 2) // id == 2; sphere
     55    {
     56        // add the sphere to the list with scrollable Objects, set the radius to 10, define the function changesizeonscroll to be called while scrolling
     57        sphereid = MouseAPI::getInstance().addScrollElement(this->getWorldPosition(), 10, [this](int abs, int rel, const IntVector2& mousePos){this->changesizeonscroll(abs,rel,mousePos);});
     58    }
     59
     60    // activate MouseAPI
    4561    MouseAPI::getInstance().activate();
    46     cubeid = MouseAPI::getInstance().addClickableObject(this->getWorldPosition(),10,std::list<MouseButtonCode::ByEnum>{MouseButtonCode::Left},[this](MouseButtonCode::ByEnum mouse){this->changesizeonclick(mouse);});
    47     //sphereid = MouseAPI::addScrollElement(this->getWorldPosition(), 10, [this](int abs, int rel, const IntVector2& mousePos){this->changesizeonscroll(abs,rel,mousePos);});
    48 
    4962}
    5063}
Note: See TracChangeset for help on using the changeset viewer.