[Orxonox-commit 7713] r12306 - in code/branches/MouseAPI_FS19: data/levels src/modules/MouseAPI

mkarpf at orxonox.net mkarpf at orxonox.net
Thu Apr 18 14:49:44 CEST 2019


Author: mkarpf
Date: 2019-04-18 14:49:44 +0200 (Thu, 18 Apr 2019)
New Revision: 12306

Modified:
   code/branches/MouseAPI_FS19/data/levels/MouseAPIExample.oxw
   code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.cc
   code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.h
Log:
example level weiterentwickelt


Modified: code/branches/MouseAPI_FS19/data/levels/MouseAPIExample.oxw
===================================================================
--- code/branches/MouseAPI_FS19/data/levels/MouseAPIExample.oxw	2019-04-18 11:40:10 UTC (rev 12305)
+++ code/branches/MouseAPI_FS19/data/levels/MouseAPIExample.oxw	2019-04-18 12:49:44 UTC (rev 12306)
@@ -30,13 +30,13 @@
     <SpawnPoint team=0 position="-200,0,0" lookat="0,0,0"  />
     
 
-<MouseAPIExample position="100,0,0" direction="0,0,0">
+<MouseAPIExample position="100,0,0" direction="0,0,0" id=1>
     <attached> 
 	<Model position="0,0,0" mesh="cube.mesh" scale3D="10,10,10" /> 
     </attached> 
 </MouseAPIExample>
 
-<MouseAPIExample position="100,100,0" direction="0,0,0">
+<MouseAPIExample position="100,100,0" direction="0,0,0" id=2>
     <attached> 
 	<Model position="0,0,0" mesh="sphere.mesh" scale=10 /> 
     </attached> 

Modified: code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.cc
===================================================================
--- code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.cc	2019-04-18 11:40:10 UTC (rev 12305)
+++ code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.cc	2019-04-18 12:49:44 UTC (rev 12306)
@@ -1,8 +1,4 @@
 #include "mouseapiexample.h"
-#include "gametypes/Gametype.h"
-#include "infos/PlayerInfo.h"
-#include "worldentities/CameraPosition.h"
-#include "worldentities/ControllableEntity.h"
 
 namespace orxonox
 {
@@ -20,31 +16,48 @@
         MouseAPI::getInstance().deactivate();
 }
 
-// change the size of the cube to a random number by clicking on it
+// change the size of the cube by a random number between 0.5 and 5 by clicking on it
 void MouseAPIExample::changesizeonclick(MouseButtonCode::ByEnum mouse)
 {
-    // generate random number between 1 and 20
-    float randomnumber = std::fmax((rand()%100 + 1)/20.0,1);
-    // change the scale of the cube to this random number
+    // generate random number between 0.5 and 5
+    float randomnumber = (rand()%10+1)/2.0;
+    // scale of the cube with this random number
     this->setScale(randomnumber);
     // change the radius of the clickableObject to the new size
-    MouseAPI::getInstance().changeRadiusOfClickableObject(cubeid,randomnumber);
+    MouseAPI::getInstance().changeRadiusOfClickableObject(cubeid,randomnumber*10);
 }
 
 // change the size of the sphere by scrolling on it
 void MouseAPIExample::changesizeonscroll(int abs,int rel,const IntVector2& mousePos)
 {
-    // increase or decrease the size of the sphere
-    this->setScale(1+rel);
+    // get current radius of the sphere
+    float curRadius = MouseAPI::getInstance().getRadiusScroll(sphereid);
+    // set factor to 120% or 80% of the current size, depending on increase or decrease
+    float factor = curRadius/10*(1+rel/600.0);
+    //scale the sphere with this factor and change the radius
+    this->setScale(factor);
+    MouseAPI::getInstance().changeRadiusOfScrollableElement(sphereid,factor*10);
 }
 
+// standard XML-Port
 void MouseAPIExample::XMLPort(Element& xmlelement, XMLPort::Mode mode)
 {
     SUPER(MouseAPIExample, XMLPort, xmlelement, mode);
-    //todo: id xml-port
+
+    // differentiate between several objects by an identifier "id"
+    XMLPortParam(MouseAPIExample, "id", setId, getId, xmlelement, mode);
+    if(this->getId() == 1) // id == 1; cube
+    {
+        // 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
+        cubeid = MouseAPI::getInstance().addClickableObject(this->getWorldPosition(),10,std::list<MouseButtonCode::ByEnum>{MouseButtonCode::Left},[this](MouseButtonCode::ByEnum mouse){this->changesizeonclick(mouse);});
+    }
+    else if(this->getId() == 2) // id == 2; sphere
+    {
+        // add the sphere to the list with scrollable Objects, set the radius to 10, define the function changesizeonscroll to be called while scrolling
+        sphereid = MouseAPI::getInstance().addScrollElement(this->getWorldPosition(), 10, [this](int abs, int rel, const IntVector2& mousePos){this->changesizeonscroll(abs,rel,mousePos);});
+    }
+
+    // activate MouseAPI
     MouseAPI::getInstance().activate();
-    cubeid = MouseAPI::getInstance().addClickableObject(this->getWorldPosition(),10,std::list<MouseButtonCode::ByEnum>{MouseButtonCode::Left},[this](MouseButtonCode::ByEnum mouse){this->changesizeonclick(mouse);});
-    //sphereid = MouseAPI::addScrollElement(this->getWorldPosition(), 10, [this](int abs, int rel, const IntVector2& mousePos){this->changesizeonscroll(abs,rel,mousePos);});
-
 }
 }

Modified: code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.h
===================================================================
--- code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.h	2019-04-18 11:40:10 UTC (rev 12305)
+++ code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.h	2019-04-18 12:49:44 UTC (rev 12306)
@@ -1,15 +1,11 @@
 #ifndef MOUSEAPIEXAMPLE_H
 #define MOUSEAPIEXAMPLE_H
 
-#include "OrxonoxPrereqs.h"
 #include "core/XMLPort.h"
 #include "mouseapi.h"
-#include "util/output/OutputManager.h"
-#include "util/output/ConsoleWriter.h"
+#include "core/CoreIncludes.h"
 #include "worldentities/ControllableEntity.h"
-#include "core/CoreIncludes.h"
 #include <list>
-#include <stdlib.h>
 
 namespace orxonox
 {
@@ -21,9 +17,15 @@
     virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     void changesizeonclick(MouseButtonCode::ByEnum mouse);
     void changesizeonscroll(int abs,int rel,const IntVector2& mousePos);
-    static std::list<MouseAPIExample> blocks;
+    inline void setId(int id)
+        { this->id = id; }
+    inline int getId() const
+        { return this->id; }
+private:
+    int id;
     ClickableObjectID cubeid;
     ScrollableElementID sphereid;
+    static std::list<MouseAPIExample> blocks;
 };
 }
 #endif // MOUSEAPIEXAMPLE_H



More information about the Orxonox-commit mailing list