Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 12302


Ignore:
Timestamp:
Apr 11, 2019, 4:52:57 PM (6 years ago)
Author:
mkarpf
Message:

getRadius added, example-level

Location:
code/branches/MouseAPI_FS19
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/MouseAPI_FS19/data/levels/MouseAPIExample.oxw

    r12297 r12302  
    3535        <Model position="0,0,0" mesh="cube.mesh" scale3D="10,10,10" />
    3636    </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>
    4043</MouseAPIExample>
    4144 
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapi.cc

    r12287 r12302  
    127127bool MouseAPI::changeRadiusOfClickableObject(ClickableObjectID id,float radius)
    128128{
    129     for(auto event:clickEvents)
     129    for(auto event = clickEvents.begin();event != clickEvents.end();event++ )
    130130    {
    131         if(event.id == id)
     131        if(event->id == id)
    132132        {
    133             event.radius = radius;
     133            event->radius = radius;
    134134            return true;
    135135        }
     
    139139bool MouseAPI::changeRadiusOfScrollableElement(ScrollableElementID id,float radius)
    140140{
    141     for(auto event:scrollEvents)
     141    for(auto event = scrollEvents.begin();event != scrollEvents.end();event++ )
    142142    {
    143         if(event.id == id)
     143        if(event->id == id)
    144144        {
    145             event.radius = radius;
     145            event->radius = radius;
    146146            return true;
    147147        }
     
    174174}
    175175
     176float 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     }
    176185}
     186
     187float 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  
    8484    bool deleteScrollableElement(ScrollableElementID id);
    8585
     86    float getRadiusClick(ClickableObjectID id);
     87    float getRadiusScroll(ScrollableElementID id);
     88
    8689    void activate();
    8790    static bool isActive(){return singletonPtr_s != nullptr && getInstance().active;}
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.cc

    r12296 r12302  
    1919    if(MouseAPI::isActive())
    2020        MouseAPI::getInstance().deactivate();
    21 
    2221}
    2322
    24 void MouseAPIExample::testfunction(MouseButtonCode::ByEnum mouse)
     23// change the size of the cube to a random number by clicking on it
     24void MouseAPIExample::changesizeonclick(MouseButtonCode::ByEnum mouse)
    2525{
    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
    2729    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}
    3133
     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);
    3239}
    3340
     
    3542{
    3643    SUPER(MouseAPIExample, XMLPort, xmlelement, mode);
     44    //todo: id xml-port
    3745    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);});
    4148
    4249}
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.h

    r12285 r12302  
    2020    ~MouseAPIExample();
    2121    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);
    2324    static std::list<MouseAPIExample> blocks;
     25    ClickableObjectID cubeid;
     26    ScrollableElementID sphereid;
    2427};
    2528}
Note: See TracChangeset for help on using the changeset viewer.