void init(gecom::Scene* s) override { gecom::Entity::init(s); addComponent<gecom::DrawableComponent>(std::make_shared<ProjectileDrawable>(shared_from_this())); auto phys = std::make_shared<ProjectilePhysics>(shared_from_this(), half_width, half_height); phys->registerWithWorld(getWorld()); /*gecom::log("proj") << "impulse: " << impulse;*/ phys->applyLinearImpulse(m_dir); addComponent<gecom::B2PhysicsComponent > (phys); }
ScriptObjectType<BlipData> ScriptArguments::getScriptObject( unsigned int arg) const { auto& param = (*this)[arg]; RW_CHECK(param.isLvalue(), "Non lvalue passed as object"); auto& blips = getWorld()->state->radarBlips; BlipData* blip = nullptr; auto it = blips.find(*param.handleValue()); if (it != blips.end()) { blip = &it->second; } return ScriptObjectType<BlipData>(param.handleValue(), blip); }
//--------------------------------------------------------------------------------- //-- Send Parameter (Index Based) void MavESP8266Component::_sendParameter(MavESP8266Bridge* sender, uint16_t index) { //-- Build message mavlink_param_value_t msg; msg.param_count = MavESP8266Parameters::ID_COUNT; msg.param_index = index; strncpy(msg.param_id, getWorld()->getParameters()->getAt(index)->id, MAVLINK_MSG_PARAM_VALUE_FIELD_PARAM_ID_LEN); uint32_t val = 0; memcpy(&val, getWorld()->getParameters()->getAt(index)->value, getWorld()->getParameters()->getAt(index)->length); memcpy(&msg.param_value, &val, sizeof(uint32_t)); msg.param_type = getWorld()->getParameters()->getAt(index)->type; mavlink_message_t mmsg; mavlink_msg_param_value_encode( getWorld()->getVehicle()->systemID(), MAV_COMP_ID_UDP_BRIDGE, &mmsg, &msg ); sender->sendMessage(&mmsg); }
bool setCollisionState(Hand * h, std::vector<bool> & collisionStatus) { World * w = getWorld(); if(collisionStatus.size() != w->getNumGB() + 1) return false; Body * experiment_table = getOrAddExperimentTable(); w->toggleCollisions(collisionStatus[0], h, experiment_table); for (int i = 0; i < w->getNumGB(); ++i) { w->toggleCollisions(collisionStatus[i+1], h, w->getGB(i)); } return true; }
ValuePtr Zone::getProperty(string p) { lock_guard<recursive_mutex> lock(value_m); if (p == "color") return make_shared<Color>(getColor()); if (p == "parent") return getParent(); if (p == "world") return getWorld(); return Agent::getProperty(p); }
void PauseState::draw(GameRenderer* r) { MapRenderer::MapInfo map; auto& vp = r->getRenderer()->getViewport(); map.scale = 0.2f; map.mapScreenTop = glm::vec2(vp.x, vp.y); map.mapScreenBottom = glm::vec2(0.f, 0.f); game->getRenderer()->map.draw(getWorld(), map); State::draw(r); }
CollisionWorldDistanceField::CollisionWorldDistanceField(const WorldPtr& world, double size_x, double size_y, double size_z, bool use_signed_distance_field, double resolution, double collision_tolerance, double max_propogation_distance) : CollisionWorld(world), size_x_(size_x), size_y_(size_y), size_z_(size_z), use_signed_distance_field_(use_signed_distance_field), resolution_(resolution), collision_tolerance_(collision_tolerance), max_propogation_distance_(max_propogation_distance) { distance_field_cache_entry_ = generateDistanceFieldCacheEntry(); // request notifications about changes to world observer_handle_ = getWorld()->addObserver(boost::bind(&CollisionWorldDistanceField::notifyObjectChange, this, _1, _2)); getWorld()->notifyObserverAllObjects(observer_handle_, World::CREATE); }
// Motion bool Catoms2DBlock::canMove(Rotation2DMove &m) { // physical moving condition // pivot is a neighbor (physically connected) // move CW around i connector: i+1, i+2 and i+3 should be free // move CCW around i connector: i-1, i-2 and i-3 should be free RelativeDirection::Direction direction = m.getDirection(); Catoms2DBlock *pivot = m.getPivot(); if ((direction != RelativeDirection::CW) && (direction != RelativeDirection::CCW)) { cerr << "undefined move direction" << endl; return false; } P2PNetworkInterface *p2p = getP2PNetworkInterfaceByBlockRef(pivot); if (p2p == NULL) { cerr << "undefined move interface" << endl; return false; } int p2pDirection = getDirection(p2p); bool res = true; for (int i = 0; i < 3; i++) { if (direction == RelativeDirection::CW) { if (p2pDirection == HLattice::BottomRight) { p2pDirection = HLattice::Right; } else { p2pDirection++; } } else if (direction == RelativeDirection::CCW) { if (p2pDirection == HLattice::Right) { p2pDirection = HLattice::BottomRight; } else { p2pDirection--; } } Cell3DPosition p = getPosition((HLattice::Direction)p2pDirection); if (!getWorld()->lattice->isFree(p)) { //cout << "somebody is connected there" << endl; res = false; } } return res; }
ScriptObjectType<PlayerController> ScriptArguments::getScriptObject( unsigned int arg) const { auto& param = (*this)[arg]; RW_CHECK(param.isLvalue(), "Non lvalue passed as object"); /// @todo suport more than one player auto player = getState()->playerObject; auto object = getWorld()->pedestrianPool.find(player); PlayerController* ctrl = nullptr; if (object) { auto playerObject = static_cast<CharacterObject*>(object); ctrl = static_cast<PlayerController*>(playerObject->controller); } return ScriptObjectType<PlayerController>(param.handleValue(), ctrl); }
TinkertoyWorldNode(const dart::simulation::WorldPtr& world) : dart::gui::osg::RealTimeWorldNode(world), mForceCoeff(DefaultForceCoeff), mWasSimulating(false) { mTarget = dart::gui::osg::InteractiveFrame::createShared( dart::dynamics::Frame::World()); getWorld()->addSimpleFrame(mTarget); createShapes(); createInitialToy1(); createInitialToy2(); createForceLine(); }
/*! * \brief Create a waste zone for the meteor. * \param x horizontal position * \param y vertical position * \param size size of the meteor */ static void CreateMeteor(UInt16 x, UInt16 y, Int16 size) { UInt16 j; UInt16 i = (Int16)(x - size) < 0 ? 0 : (UInt16)(x - size); zone_lock(lz_world); zone_lock(lz_flags); UILockScreen(); for (; i <= x + size; i++) { j = (Int16)(y - size) < 0 ? 0 : (UInt16)(y - size); for (; j <= y + size; j++) { if (i < getMapWidth() && j < getMapHeight()) { if (GetRandomNumber(5) < 2) { if (getWorld(WORLDPOS(i, j)) != Z_REALWATER) { CreateWaste(i, j); } } else if (GetRandomNumber(5) < 4) { if (getWorld(WORLDPOS(i, j)) != Z_REALWATER && getWorld(WORLDPOS(i, j)) != Z_FAKEWATER) { BurnField(i, j, 1); } } } } } Build_Destroy(x, y); setWorldAndFlag(WORLDPOS(x, y), Z_CRATER, 0); zone_unlock(lz_flags); zone_unlock(lz_world); UIUnlockScreen(); RedrawAllFields(); }
void resetHandCollisions(Hand * h, bool setting, std::vector<bool> & collisionStatus) { World * w = getWorld(); Body * experiment_table = getOrAddExperimentTable(); collisionStatus.push_back(!w->collisionsAreOff(h, experiment_table)); w->toggleCollisions(setting, h, experiment_table); for (int i = 0; i < w->getNumGB(); ++i) { collisionStatus.push_back(!w->collisionsAreOff(h, w->getGB(i))); w->toggleCollisions(setting, h, w->getGB(i)); } }
PhysicsTriangleSoup::PhysicsTriangleSoup( PhysicsWorld* world, ConstWeakArray<Vec3> positions, ConstWeakArray<U32> indices, Bool convex) : PhysicsCollisionShape(world, ShapeType::TRI_MESH) { if(!convex) { ANKI_ASSERT((indices.getSize() % 3) == 0); m_mesh.init(); for(U i = 0; i < indices.getSize(); i += 3) { m_mesh->addTriangle( toBt(positions[indices[i]]), toBt(positions[indices[i + 1]]), toBt(positions[indices[i + 2]])); } // Create the dynamic shape m_triMesh.m_dynamic.init(m_mesh.get()); m_triMesh.m_dynamic->setMargin(getWorld().getCollisionMargin()); m_triMesh.m_dynamic->updateBound(); m_triMesh.m_dynamic->setUserPointer(static_cast<PhysicsObject*>(this)); // And the static one m_triMesh.m_static.init(m_mesh.get(), true); m_triMesh.m_static->setMargin(getWorld().getCollisionMargin()); m_triMesh.m_static->setUserPointer(static_cast<PhysicsObject*>(this)); } else { m_type = ShapeType::CONVEX; // Fake the type m_convex.init(&positions[0][0], positions.getSize(), sizeof(Vec3)); m_convex->setMargin(getWorld().getCollisionMargin()); m_convex->setUserPointer(static_cast<PhysicsObject*>(this)); } }
collision_detection::CollisionWorldFCL::CollisionWorldFCL(const CollisionWorldFCL &other, const WorldPtr& world) : CollisionWorld(other, world) { fcl::DynamicAABBTreeCollisionManager* m = new fcl::DynamicAABBTreeCollisionManager(); // m->tree_init_level = 2; manager_.reset(m); fcl_objs_ = other.fcl_objs_; for (std::map<std::string, FCLObject>::iterator it = fcl_objs_.begin() ; it != fcl_objs_.end() ; ++it) it->second.registerTo(manager_.get()); // manager_->update(); // request notifications about changes to new world observer_handle_ = getWorld()->addObserver(boost::bind(&CollisionWorldFCL::notifyObjectChange, this, _1, _2)); }
void Engine::Graphics::initialize() { camera.setCenter({ window.getSize().x / 2.f, window.getSize().y / 2.f }); camera.setSize({ window.getSize().x * 1.f, window.getSize().y* 1.f }); window.setView(camera); camera.zoom(0.5f); camera.setCenter({ window.getSize().x / 4.f, window.getSize().y / 4.f }); e = getWorld().createEntity(); e.addComponent<Interactible>(this); e.activate(); auto size = window.getSize(); rt.create(size.x, size.y); ppSprite.setTexture(rt.getTexture()); ppShader.loadFromFile("glow.frag", sf::Shader::Fragment); ppShader.setParameter("texture", sf::Shader::CurrentTexture); }
void InventorySystem::drop(Entity * entity, Entity * object, sf::Vector2i coord) { if ( !entity->haveTrait("canDrop") ) { return; } if ( !object->cmgr.getComponent<Item>()->dropable ) { return; } std::vector<uint>& s = entity->cmgr.getComponent<Storage>()->items; std::vector<uint>& t = getWorld()->at(coord.x, coord.y).objects; s.erase(std::remove(s.begin(), s.end(), object->id), s.end()); object->cmgr.createComponent<Position>(coord.x, coord.y); t.push_back(object->id); }
ramPyramidPrimitive::ramPyramidPrimitive(const ofMatrix4x4& mat, float size) { size *= 0.5; mesh.addVertex(ofVec3f(1, 1, 1) * size); mesh.addVertex(ofVec3f(-1, 1, -1) * size); mesh.addVertex(ofVec3f(-1, -1, 1) * size); mesh.addVertex(ofVec3f(1, -1, -1) * size); mesh.addTriangle(0, 1, 2); mesh.addTriangle(0, 2, 3); mesh.addTriangle(0, 3, 1); mesh.addTriangle(3, 2, 1); body = getWorld().addMesh(mesh, mat.getTranslation(), mat.getRotate().getEuler()); }
void createForceLine() { dart::dynamics::SimpleFramePtr lineFrame = std::make_shared<dart::dynamics::SimpleFrame>( dart::dynamics::Frame::World()); mForceLine = std::make_shared<dart::dynamics::LineSegmentShape>( Eigen::Vector3d::Zero(), Eigen::Vector3d::Zero(), 3.0); mForceLine->addDataVariance(dart::dynamics::Shape::DYNAMIC_VERTICES); lineFrame->setShape(mForceLine); lineFrame->createVisualAspect(); lineFrame->getVisualAspect()->setColor(DefaultForceLineColor); getWorld()->addSimpleFrame(lineFrame); }
bool testGraspCollisions(Hand * h, const GraspPlanningState * s) { bool result = false; //std::vector<bool> currentCollisionState; //resetHandCollisions(h, true, currentCollisionState); s->execute(h); World * w = getWorld(); w->toggleCollisions(false, h, s->getObject()); if(getNumHandCollisions(h)) result = true; if(testPreGraspCollisions(h, -50.0)) result = true; w->toggleCollisions(true, h, s->getObject()); //setCollisionState(h, currentCollisionState); return result; }
PistonJoint::PistonJoint(World& worldRef, RigidBody& bodyA, RigidBody& bodyB, const bool collide, const glm::vec3& anchor, const glm::quat& jRot) : Joint(worldRef, bodyA, bodyB, collide), m_jointL(nullptr) { btTransform ctwt = btTransform::getIdentity(); glm::vec3 p = defaultCenter(anchor); ctwt.setOrigin(btVector3(p.x, p.y, p.z)); ctwt.setRotation(btQuaternion(jRot.x, jRot.y, jRot.z, jRot.w)); btTransform tInA = getBody(bodyA)->getCenterOfMassTransform().inverse() * ctwt; btTransform tInB = getBody(bodyB)->getCenterOfMassTransform().inverse() * ctwt; m_joint = std::make_unique<btSliderConstraint>(*getBody(bodyA), *getBody(bodyB), tInA, tInB, true); getWorld(worldRef).addConstraint(m_joint.get(), !collide); m_jointL = static_cast<btSliderConstraint*>(m_joint.get()); }
ramPyramidPrimitive::ramPyramidPrimitive(const ofVec3f& pos, float size) { size *= 0.5; mesh.addVertex(ofVec3f(1, 1, 1) * size); mesh.addVertex(ofVec3f(-1, 1, -1) * size); mesh.addVertex(ofVec3f(-1, -1, 1) * size); mesh.addVertex(ofVec3f(1, -1, -1) * size); mesh.addTriangle(0, 1, 2); mesh.addTriangle(0, 2, 3); mesh.addTriangle(0, 3, 1); mesh.addTriangle(3, 2, 1); body = getWorld().addMesh(mesh, pos); }
void Debugger::onDraw() { if (debug) { if (cursor_spr) { Sprite::draw(Input::mouseX(), Input::mouseY(), "debug_cursor"); } for (auto o : getWorld() -> instanceGet<Object>()) { Vector tl = o -> boundTopLeft(); Vector dm = o -> getDimensions(); sf::Color col(128, 128, 128); if (Input::mouseX() > tl.x && Input::mouseX() < tl.x + dm.x && Input::mouseY() > tl.y && Input::mouseY() < tl.y + dm.y) { col = sf::Color::Red; } graphicDrawRectangleOutline(tl, dm, col); } } }
void BlinkyBlocksBlock::stop(uint64_t date, State s) { OUTPUT << "Simulator: stop scheduled" << endl; lock(); state = s; if (s == STOPPED) { // patch en attendant l'objet 3D qui modelise un BB stopped color = Color(0.1, 0.1, 0.1, 0.5); } unlock(); getWorld()->updateGlData(this); if(BaseSimulator::Simulator::getType() == BaseSimulator::Simulator::MELDPROCESS){ getScheduler()->scheduleLock(new MeldProcess::VMStopEvent(getScheduler()->now(), this)); } else if (BaseSimulator::Simulator::getType() == BaseSimulator::Simulator::MELDINTERPRET) { getScheduler()->scheduleLock(new MeldInterpret::VMStopEvent(getScheduler()->now(), this)); } }
void IngameState::startTest() { auto playerChar = getWorld()->createPlayer({270.f, -605.f, 40.f}); auto player = new PlayerController(playerChar); getWorld()->state->playerObject = playerChar->getGameObjectID(); /*auto bat = new WeaponItem(getWorld()->data.weaponData["ak47"]); _playerCharacter->addToInventory(bat); _playerCharacter->setActiveItem(bat->getInventorySlot());*/ glm::vec3 itemspawn( 276.5f, -609.f, 36.5f); for(int i = 1; i < maxInventorySlots; ++i) { ItemPickup* pickup = new ItemPickup( getWorld(), itemspawn, getWorld()->getInventoryItem(i)); getWorld()->pickupPool.insert(pickup); getWorld()->allObjects.push_back(pickup); itemspawn.x += 2.5f; } auto carPos = glm::vec3( 286.f, -591.f, 37.f ); auto carRot = glm::angleAxis(glm::radians(90.f), glm::vec3(0.f, 0.f, 1.f)); //auto boatPos = glm::vec3( -1000.f, -1040.f, 5.f ); int i = 0; for( auto& vi : getWorld()->data->objectTypes ) { switch( vi.first ) { case 140: continue; case 141: continue; } if( vi.second->class_type == ObjectInformation::_class("CARS") ) { if ( i++ > 20 ) break; auto vehicle = std::static_pointer_cast<VehicleData>(vi.second); auto& sp = carPos; auto& sr = carRot; auto v = getWorld()->createVehicle(vi.first, sp, sr); sp += sr * glm::vec3( 2.f + v->info->handling.dimensions.x, 0.f, 0.f); } } }
int ScriptArguments::getModel(unsigned int arg) const { RW_CHECK(arg < getParameters().size(), "arg out of range"); if (arg >= getParameters().size()) { return 0; } int id = getParameters()[arg].integerValue(); /// @todo verify this behaviour if (id < 0) { id = -id; const auto& model = getVM()->getFile()->getModels()[id]; id = getWorld()->data->findModelObject(model); } return id; }
void InventorySystem::take(Entity * entity, Entity * object, sf::Vector2i coord) { if ( !entity->haveTrait("canPick") ) { return; } std::cout << object->cmgr.getComponent<Item>()->price << std::endl; if ( !object->cmgr.getComponent<Item>()->pickable ) { return; } std::vector<uint>& o = getWorld()->at(coord.x,coord.y).objects; o.erase(std::remove(o.begin(), o.end(), object->id), o.end()); std::cout << "TAKEN OBJECT ID: " << object->id << std::endl; entity->cmgr.getComponent<Storage>()->items.push_back(object->id); object->cmgr.removeComponent<Position>(); }
std::vector<b2Body*> Box2dContainer::getBodiesFromTouch(cocos2d::Touch& touch) { auto loc = convertTouchToNodeSpace(&touch); auto pos = convertToBox2d(loc); // Make a small box. b2AABB aabb; b2Vec2 d(0.001f, 0.001f); aabb.lowerBound = pos - d; aabb.upperBound = pos + d; // Query the world for overlapping shapes. QueryCallback callback(pos); getWorld().QueryAABB(&callback, aabb); return callback.results; }
void Prototype::testSimple() { b2PolygonShape shape; m_bodyDef.position.Set(m_centerPoint.x/PTM_RATIO, m_centerPoint.y/PTM_RATIO); b2Body* body = getWorld()->CreateBody(&m_bodyDef); shape.SetAsBox(4, 4); m_fixtureDef.shape = &shape; body->CreateFixture(&m_fixtureDef); // Only need below to attach box2d body to a cocos2d sprite... PhysicsSprite* ps = new PhysicsSprite(); ps->setTag(1); ps->setPosition( CCPointMake( m_centerPoint.x+300, m_centerPoint.y ) ); ps->setPhysicsBody(body); body->SetUserData(ps); m_sprites[ps->getTag()] = ps; }
void Exit::doSomething() { //if active and player is on exit if (m_revealed && getWorld()->getPlayer()->getX() == getX() && getWorld()->getPlayer()->getY() == getY()) { getWorld()->playSound(SOUND_FINISHED_LEVEL); getWorld()->FinishedLevel(); getWorld()->increaseScore(getWorld()->getBonus()); } }
void DoRandomDisaster(void) { UInt32 randomTile; Int16 i, type, random; UInt16 x, y; UInt8 disaster_level; disaster_level = getDisasterLevel(); /* for those who can't handle the game (truth?) */ if (disaster_level == 0) return; zone_lock(lz_world); zone_lock(lz_flags); for (i = 0; i < 100; i++) { /* 100 tries to hit a useful tile */ randomTile = GetRandomNumber(MapMul()); type = getWorld(randomTile); if (type != Z_DIRT && type != Z_REALWATER && type != Z_CRATER) { x = (UInt16)(randomTile % getMapWidth()); y = (UInt16)(randomTile / getMapHeight()); /* TODO: should depend on difficulty */ random = (Int16)GetRandomNumber(1000 / disaster_level); WriteLog("Random Disaster: %d\n", (int)random); if (random < 10 && vgame.BuildCount[bc_fire] == 0) { DoSpecificDisaster(diFireOutbreak, x, y); } else if (random < 15 && game.objects[obj_monster].active == 0) { DoSpecificDisaster(diMonster, x, y); } else if (random < 17 && game.objects[obj_dragon].active == 0) { DoSpecificDisaster(diDragon, x, y); } else if (random < 19) { DoSpecificDisaster(diMeteor, x, y); } /* only one chance for disaster per turn */ break; } } zone_unlock(lz_flags); zone_unlock(lz_world); }