Changeset 12306
- Timestamp:
- Apr 18, 2019, 2:49:44 PM (6 years ago)
- Location:
- code/branches/MouseAPI_FS19
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/MouseAPI_FS19/data/levels/MouseAPIExample.oxw
r12302 r12306 31 31 32 32 33 <MouseAPIExample position="100,0,0" direction="0,0,0" >33 <MouseAPIExample position="100,0,0" direction="0,0,0" id=1> 34 34 <attached> 35 35 <Model position="0,0,0" mesh="cube.mesh" scale3D="10,10,10" /> … … 37 37 </MouseAPIExample> 38 38 39 <MouseAPIExample position="100,100,0" direction="0,0,0" >39 <MouseAPIExample position="100,100,0" direction="0,0,0" id=2> 40 40 <attached> 41 41 <Model position="0,0,0" mesh="sphere.mesh" scale=10 /> -
code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.cc
r12302 r12306 1 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 2 7 3 namespace orxonox … … 21 17 } 22 18 23 // change the size of the cube to a random numberby clicking on it19 // change the size of the cube by a random number between 0.5 and 5 by clicking on it 24 20 void MouseAPIExample::changesizeonclick(MouseButtonCode::ByEnum mouse) 25 21 { 26 // generate random number between 1 and 2027 float randomnumber = std::fmax((rand()%100 + 1)/20.0,1);28 // change the scale of the cube tothis random number22 // 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 29 25 this->setScale(randomnumber); 30 26 // change the radius of the clickableObject to the new size 31 MouseAPI::getInstance().changeRadiusOfClickableObject(cubeid,randomnumber );27 MouseAPI::getInstance().changeRadiusOfClickableObject(cubeid,randomnumber*10); 32 28 } 33 29 … … 35 31 void MouseAPIExample::changesizeonscroll(int abs,int rel,const IntVector2& mousePos) 36 32 { 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); 39 40 } 40 41 42 // standard XML-Port 41 43 void MouseAPIExample::XMLPort(Element& xmlelement, XMLPort::Mode mode) 42 44 { 43 45 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 45 61 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 62 } 50 63 } -
code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.h
r12302 r12306 2 2 #define MOUSEAPIEXAMPLE_H 3 3 4 #include "OrxonoxPrereqs.h"5 4 #include "core/XMLPort.h" 6 5 #include "mouseapi.h" 7 #include "util/output/OutputManager.h" 8 #include "util/output/ConsoleWriter.h" 6 #include "core/CoreIncludes.h" 9 7 #include "worldentities/ControllableEntity.h" 10 #include "core/CoreIncludes.h"11 8 #include <list> 12 #include <stdlib.h>13 9 14 10 namespace orxonox … … 22 18 void changesizeonclick(MouseButtonCode::ByEnum mouse); 23 19 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; } 24 private: 25 int id; 25 26 ClickableObjectID cubeid; 26 27 ScrollableElementID sphereid; 28 static std::list<MouseAPIExample> blocks; 27 29 }; 28 30 }
Note: See TracChangeset
for help on using the changeset viewer.