Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

example level weiterentwickelt

Location:
code/branches/MouseAPI_FS19/src/modules/MouseAPI
Files:
2 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}
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.h

    r12302 r12306  
    22#define MOUSEAPIEXAMPLE_H
    33
    4 #include "OrxonoxPrereqs.h"
    54#include "core/XMLPort.h"
    65#include "mouseapi.h"
    7 #include "util/output/OutputManager.h"
    8 #include "util/output/ConsoleWriter.h"
     6#include "core/CoreIncludes.h"
    97#include "worldentities/ControllableEntity.h"
    10 #include "core/CoreIncludes.h"
    118#include <list>
    12 #include <stdlib.h>
    139
    1410namespace orxonox
     
    2218    void changesizeonclick(MouseButtonCode::ByEnum mouse);
    2319    void changesizeonscroll(int abs,int rel,const IntVector2& mousePos);
    24     static std::list<MouseAPIExample> blocks;
     20    inline void setId(int id)
     21        { this->id = id; }
     22    inline int getId() const
     23        { return this->id; }
     24private:
     25    int id;
    2526    ClickableObjectID cubeid;
    2627    ScrollableElementID sphereid;
     28    static std::list<MouseAPIExample> blocks;
    2729};
    2830}
Note: See TracChangeset for help on using the changeset viewer.