/** * \brief The constructor for the physical world. * * pre: * - none * * post: * - all private variables should be initialized correct * should correct be spezified? * - world, space, contactgroup and world_init to false (0) */ WorldPhysics::WorldPhysics(ControlCenter *control) { this->control = control; draw_contact_points = 0; fast_step = 0; world_cfm = 1e-10; world_erp = 0.1; world_gravity = Vector(0.0, 0.0, -9.81); ground_friction = 20; ground_cfm = 0.00000001; ground_erp = 0.1; world = 0; space = 0; contactgroup = 0; world_init = 0; num_contacts = 0; create_contacts = 1; log_contacts = 0; // the step size in seconds step_size = 0.01; // dInitODE is relevant for using trimesh objects as correct as // possible in the ode implementation MutexLocker locker(&iMutex); #ifdef ODE11 // for ode-0.11 dInitODE2(0); dAllocateODEDataForThread(dAllocateMaskAll); #else dInitODE(); #endif dSetErrorHandler (myErrorFunction); dSetDebugHandler (myDebugFunction); dSetMessageHandler (myMessageFunction); }
CPhysicManager::CPhysicManager(IEngine* _Engine):CBaseObject(_Engine){ SetParam("BaseClass","PhysicManager"); SetParam("Type","CPhysicManager"); SetParam("Name","-"); dSetErrorHandler (SilenceMessage); //затыкаем рот идиотским ошибкам dSetDebugHandler (SilenceMessage); //затыкаем рот идиотским ошибкам dSetMessageHandler (SilenceMessage); //затыкаем рот идиотским ошибкам calc_time= 0.0f; world = dWorldCreate(); dWorldSetGravity(world, 0, 0, -0.01 ); space=dHashSpaceCreate(0); contactgroup = dJointGroupCreate(0); LOGGER->LogMsg("+CPhysicManager"); ptr_world = world; ptr_contactgroup = contactgroup; dWorldSetCFM(world, 1e-5); dWorldSetERP(world, 0.2); dWorldSetContactMaxCorrectingVel(world, 0.9); dWorldSetContactSurfaceLayer(world, 0.001); dWorldSetAutoDisableFlag(world, 1); // ground = #define SHIRINA 1000 //dGeomID tmp = dCreateBox( space, SHIRINA, SHIRINA, 1); //dGeomSetPosition(tmp, SHIRINA/2, SHIRINA/2, 0); // двигаем центр координат //tmp = dCreateBox( space, 1, SHIRINA, SHIRINA); //dGeomSetPosition(tmp, 0, SHIRINA/2, SHIRINA/2); // двигаем центр координат //tmp = dCreateBox( space, SHIRINA, 1, SHIRINA); //dGeomSetPosition(tmp, SHIRINA/2, 0, SHIRINA/2); // двигаем центр координат dCreatePlane (space,0,0,1,0); //dCreatePlane (space,1,1,0,0); //dCreatePlane (space,0,1,0,0); //dCreatePlane (space,1,0,0,0); //dCreatePlane (space,0,0,20,0); //dCreatePlane (space,0,10,0,0); //dCreatePlane (space,10,0,0,0); //dCreatePlane (space,0,0,1,0); //dCreatePlane (space,0,0,1,0); //dCreatePlane (space,0,0,1,0); //dCreatePlane (space,0,0,1,0); //dCreatePlane (space,0,0,1,0); };
void myMessageFunction (int num, const char *msg, va_list ap) { printf ("(Message %d: ",num); vprintf (msg,ap); printf (")"); dSetMessageHandler (0); longjmp (jump_buffer,1); }
void PhysicsSim::initialize() { dInitODE(); dSetDebugHandler(ode_errorhandler); dSetErrorHandler(ode_errorhandler); dSetMessageHandler(ode_errorhandler); m_odeWorld = dWorldCreate(); dWorldSetGravity (m_odeWorld,0,0,0); m_odeSpace = dSimpleSpaceCreate(0); m_odeContactGroup = dJointGroupCreate(0); /* This is just to track haptics cursor during "grab" state. * We only need its position, so just use a generic OscObject. */ m_pCursor = new OscObject(NULL, "cursor", this); if (!m_pCursor) printf("Error creating PhysicsSim cursor.\n"); Simulation::initialize(); }
signed ODE_Init() { Quit = SDL_FALSE; dInitODE2(dInitFlagManualThreadCleanup); dSetMessageHandler(Error); dSetDebugHandler(Error); dSetErrorHandler(Error); World = dWorldCreate(); Space = dHashSpaceCreate(0); Group = dJointGroupCreate(0); Step = 1.0/50.0; lua_getglobal(State, "World"); int table = lua_gettop(State); if (!lua_isnil(State, table)) { lua_pushnil(State); while (lua_next(State, table)) { const char *key = lua_tostring(State, -2); #define tointeger lua_tointeger(State, -1) #define toboolean lua_toboolean(State, -1) #define tonumber lua_tonumber(State, -1) if (!SDL_strcasecmp(key, "FPS")) { Step = 1.0/tonumber; } else if (!SDL_strcasecmp(key, "ERP")) { dWorldSetERP(World, tonumber); } else if (!SDL_strcasecmp(key, "CFM")) { dWorldSetCFM(World, tonumber); } else if (!SDL_strcasecmp(key, "LINEAR_DAMPING")) { dWorldSetLinearDamping(World, tonumber); } else if (!SDL_strcasecmp(key, "LINEAR_DAMPING_THRESHOLD")) { dWorldSetLinearDampingThreshold(World, tonumber); } else if (!SDL_strcasecmp(key, "ANGULAR_DAMPING")) { dWorldSetAngularDamping(World, tonumber); } else if (!SDL_strcasecmp(key, "ANGULAR_DAMPING_THRESHOLD")) { dWorldSetAngularDampingThreshold(World, tonumber); } else if (!SDL_strcasecmp(key, "MAX_ANGULAR_SPEED")) { dWorldSetMaxAngularSpeed(World, tonumber); } else if (!SDL_strcasecmp(key, "CONTACT_MAX_CORRECTING_VELOCITY")) { dWorldSetContactMaxCorrectingVel(World, tonumber); } else if (!SDL_strcasecmp(key, "CONTACT_SURFACE_LAYER")) { dWorldSetContactSurfaceLayer(World, tonumber); } else if (!SDL_strcasecmp(key, "AUTO_DISABLE")) { dWorldSetAutoDisableFlag(World, toboolean); } else if (!SDL_strcasecmp(key, "AUTO_DISABLE_LINEAR_THRESHOLD")) { dWorldSetAutoDisableLinearThreshold(World, tonumber); } else if (!SDL_strcasecmp(key, "AUTO_DISABLE_ANGULAR_THRESHOLD")) { dWorldSetAutoDisableAngularThreshold(World, tonumber); } else if (!SDL_strcasecmp(key, "AUTO_DISABLE_STEPS")) { dWorldSetAutoDisableSteps(World, tointeger); } else if (!SDL_strcasecmp(key, "AUTO_DISABLE_TIME")) { dWorldSetAutoDisableTime(World, tonumber); } else { SDL_Log("World: %s does not match", key); } lua_pop(State, 1); } } lua_pop(State, 1); Cond = SDL_CreateCond(); if (!Cond) { dWorldDestroy(World); dSpaceDestroy(Space); dJointGroupDestroy(Group); SDL_perror("SDL_CreateCond"); return SDL_SetError("cannot create simulation signal"); } Mutex = SDL_CreateMutex(); if (!Mutex) { dWorldDestroy(World); dSpaceDestroy(Space); dJointGroupDestroy(Group); SDL_DestroyCond(Cond); SDL_perror("SDL_CreateMutex"); return SDL_SetError("cannot create simulation mutex"); } Thread = SDL_CreateThread(SimulationThread, "ODE", NULL); if (!Thread) { dWorldDestroy(World); dSpaceDestroy(Space); dJointGroupDestroy(Group); SDL_DestroyCond(Cond); SDL_DestroyMutex(Mutex); SDL_perror("SDL_CreateThread"); return SDL_SetError("cannot create simulation thread"); } TimerID = SDL_AddTimer(Uint32(1000*Step), SimulationTimer, NULL); if (!TimerID) { dWorldDestroy(World); dSpaceDestroy(Space); dJointGroupDestroy(Group); SDL_DestroyCond(Cond); SDL_DestroyMutex(Mutex); SDL_perror("SDL_AddTimer"); return SDL_SetError("cannot create simulation timer"); } return 0; }