anyKode Marilou
ContentsIndexHome
Example
//Sample from Samples/Simple/5.0_DebugGeom\C++

#include "ModaCpp.h"
#include "conio.h"

//Settings:
#define MODASERVER "localhost"

using namespace ModaCPP;
using namespace Moda::Commons;

int main(int argc, char* argv[])
{
ModaCPP::Connection *connection=new ModaCPP::Connection(true);

//Connect to MODA server
if(connection->Connect(MODASERVER))
    {
    _cprintf("Connexion to %s ok\r\n",MODASERVER);

    //Find the robot
    ModaCPP::RobotPHX *pWorld=connection->QueryRobotPHX("/");
    if(pWorld)
        {
        ModaCPP::Geom *pLight=pWorld->QueryGeom("light0");
        ModaCPP::Geom *pSphere=pWorld->QueryGeom("sphere0");

        if(pLight && pSphere)
            {
            //reset simulation for getting geoms startup position
            connection->ResetSimulation();
            MODAVECTOR3 vLightInitialPos;
            MODAVECTOR3 vSphereInitialPos;
            MODAVECTOR3 temp;
            float angle=0;
            float r;

            pLight->GetPosition(vLightInitialPos);
            pSphere->GetPosition(vSphereInitialPos);

            r=vLightInitialPos.Length();

            while(true)
                {
                //move sphere to initial position if near the floor
                pSphere->GetPosition(temp);
                _cprintf("spherepos: %f %f %f\r\n",temp.x,temp.y,temp.z);
                if(temp.z<0.1f)    pSphere->SetPosition(vSphereInitialPos);

                //make the light turns around center
                temp.x=r*sinf(angle);
                temp.y=r*cosf(angle);
                temp.z=vLightInitialPos.z;
                pLight->SetPosition(temp);
                angle+=xkode::lib::Math::_PI_FLOAT/200.0f;

                //update every 50 simulated ms
                connection->Sleep(50);
                }
            }
        else
            {
            _cprintf("Unable to find light or sphere geom(s) (%p %p)\r\n",pLight,pSphere);
            }
        delete pWorld;
        }
    }
else
    {
    _cprintf("Unable to connect to moda server : be sure Exec is running and MODA TCP/UDP ports are open\r\n");
    }
connection->Disconnect();
delete connection;
_getch();
return 0;
}
Documentation v4.7 (18/01/2015), Copyright (c) 2015 anyKode. All rights reserved.