Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.cc @ 12302

Last change on this file since 12302 was 12302, checked in by mkarpf, 5 years ago

getRadius added, example-level

File size: 1.7 KB
Line 
1#include "mouseapiexample.h"
2#include "gametypes/Gametype.h"
3#include "infos/PlayerInfo.h"
4#include "worldentities/CameraPosition.h"
5#include "worldentities/ControllableEntity.h"
6
7namespace orxonox
8{
9
10RegisterClass(MouseAPIExample);
11
12MouseAPIExample::MouseAPIExample(Context* context) : ControllableEntity(context)
13{
14    RegisterObject(MouseAPIExample);
15}
16
17MouseAPIExample::~MouseAPIExample()
18{
19    if(MouseAPI::isActive())
20        MouseAPI::getInstance().deactivate();
21}
22
23// change the size of the cube to a random number by clicking on it
24void MouseAPIExample::changesizeonclick(MouseButtonCode::ByEnum mouse)
25{
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
29    this->setScale(randomnumber);
30    // change the radius of the clickableObject to the new size
31    MouseAPI::getInstance().changeRadiusOfClickableObject(cubeid,randomnumber);
32}
33
34// change the size of the sphere by scrolling on it
35void MouseAPIExample::changesizeonscroll(int abs,int rel,const IntVector2& mousePos)
36{
37    // increase or decrease the size of the sphere
38    this->setScale(1+rel);
39}
40
41void MouseAPIExample::XMLPort(Element& xmlelement, XMLPort::Mode mode)
42{
43    SUPER(MouseAPIExample, XMLPort, xmlelement, mode);
44    //todo: id xml-port
45    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
49}
50}
Note: See TracBrowser for help on using the repository browser.