Changeset 12302 for code/branches/MouseAPI_FS19
- Timestamp:
- Apr 11, 2019, 4:52:57 PM (6 years ago)
- Location:
- code/branches/MouseAPI_FS19
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/MouseAPI_FS19/data/levels/MouseAPIExample.oxw
r12297 r12302 35 35 <Model position="0,0,0" mesh="cube.mesh" scale3D="10,10,10" /> 36 36 </attached> 37 <collisionShapes> 38 <BoxCollisionShape position="0,0,0" halfExtents="10,10,10" /> 39 </collisionShapes> 37 </MouseAPIExample> 38 39 <MouseAPIExample position="100,100,0" direction="0,0,0"> 40 <attached> 41 <Model position="0,0,0" mesh="sphere.mesh" scale=10 /> 42 </attached> 40 43 </MouseAPIExample> 41 44 -
code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.cc
r12287 r12302 127 127 bool MouseAPI::changeRadiusOfClickableObject(ClickableObjectID id,float radius) 128 128 { 129 for(auto event :clickEvents)129 for(auto event = clickEvents.begin();event != clickEvents.end();event++ ) 130 130 { 131 if(event .id == id)131 if(event->id == id) 132 132 { 133 event .radius = radius;133 event->radius = radius; 134 134 return true; 135 135 } … … 139 139 bool MouseAPI::changeRadiusOfScrollableElement(ScrollableElementID id,float radius) 140 140 { 141 for(auto event :scrollEvents)141 for(auto event = scrollEvents.begin();event != scrollEvents.end();event++ ) 142 142 { 143 if(event .id == id)143 if(event->id == id) 144 144 { 145 event .radius = radius;145 event->radius = radius; 146 146 return true; 147 147 } … … 174 174 } 175 175 176 float MouseAPI::getRadiusClick(ClickableObjectID id) 177 { 178 for(auto eventIt = clickEvents.begin();eventIt != clickEvents.end();eventIt++ ) 179 { 180 if(eventIt->id == id) 181 { 182 return eventIt->radius; 183 } 184 } 176 185 } 186 187 float MouseAPI::getRadiusScroll(ScrollableElementID id) 188 { 189 for(auto eventIt = scrollEvents.begin();eventIt != scrollEvents.end();eventIt++ ) 190 { 191 if(eventIt->id == id) 192 { 193 return eventIt->radius; 194 } 195 } 196 } 197 198 } -
code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.h
r12287 r12302 84 84 bool deleteScrollableElement(ScrollableElementID id); 85 85 86 float getRadiusClick(ClickableObjectID id); 87 float getRadiusScroll(ScrollableElementID id); 88 86 89 void activate(); 87 90 static bool isActive(){return singletonPtr_s != nullptr && getInstance().active;} -
code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.cc
r12296 r12302 19 19 if(MouseAPI::isActive()) 20 20 MouseAPI::getInstance().deactivate(); 21 22 21 } 23 22 24 void MouseAPIExample::testfunction(MouseButtonCode::ByEnum mouse) 23 // change the size of the cube to a random number by clicking on it 24 void MouseAPIExample::changesizeonclick(MouseButtonCode::ByEnum mouse) 25 25 { 26 float randomnumber = (rand()%100 + 1)/20.0; 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 27 29 this->setScale(randomnumber); 28 orxout() << "Blah\n";29 //this->getGametype()->getPlayers().begin()->first->getControllableEntity()->mouseLook();//getCurrentCameraPosition()->setAllowMouseLook(false);30 //this->getGametype()->getPlayers().begin()->first->stopControl(); 30 // change the radius of the clickableObject to the new size 31 MouseAPI::getInstance().changeRadiusOfClickableObject(cubeid,randomnumber); 32 } 31 33 34 // change the size of the sphere by scrolling on it 35 void MouseAPIExample::changesizeonscroll(int abs,int rel,const IntVector2& mousePos) 36 { 37 // increase or decrease the size of the sphere 38 this->setScale(1+rel); 32 39 } 33 40 … … 35 42 { 36 43 SUPER(MouseAPIExample, XMLPort, xmlelement, mode); 44 //todo: id xml-port 37 45 MouseAPI::getInstance().activate(); 38 MouseAPI::getInstance().addClickableObject(this->getWorldPosition(),10,std::list<MouseButtonCode::ByEnum>{MouseButtonCode::Left},[this](MouseButtonCode::ByEnum mouse){this->testfunction(mouse);}); 39 //this->getGametype()->getPlayers().begin()->first->getControllableEntity()->mouseLook(); 40 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);}); 41 48 42 49 } -
code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.h
r12285 r12302 20 20 ~MouseAPIExample(); 21 21 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 22 void testfunction(MouseButtonCode::ByEnum mouse); 22 void changesizeonclick(MouseButtonCode::ByEnum mouse); 23 void changesizeonscroll(int abs,int rel,const IntVector2& mousePos); 23 24 static std::list<MouseAPIExample> blocks; 25 ClickableObjectID cubeid; 26 ScrollableElementID sphereid; 24 27 }; 25 28 }
Note: See TracChangeset
for help on using the changeset viewer.