本文整理汇总了C++中Obstacle类的典型用法代码示例。如果您正苦于以下问题:C++ Obstacle类的具体用法?C++ Obstacle怎么用?C++ Obstacle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Obstacle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getFIFO
void DistanceToObjectsReport::report(const odcore::wrapper::Time &t) {
cerr << "Call to DistanceToObjectsReport for t = " << t.getSeconds() << "." << t.getPartialMicroseconds() << ", containing " << getFIFO().getSize() << " containers." << endl;
// Get last EgoState.
KeyValueDataStore &kvds = getKeyValueDataStore();
Container c = kvds.get(opendlv::data::environment::EgoState::ID());
EgoState es = c.getData<EgoState>();
const uint32_t SIZE = getFIFO().getSize();
for (uint32_t i = 0; i < SIZE; i++) {
c = getFIFO().leave();
cerr << "Received: " << c.toString() << endl;
if (c.getDataType() == opendlv::data::environment::Obstacle::ID()) {
Obstacle o = c.getData<Obstacle>();
const float DISTANCE = (es.getPosition().getDistanceTo(o.getPosition()));
cerr << "DistanceToObjectsReport: Distance to object: " << DISTANCE << ", E: " << es.toString() << ", o: " << o.getPosition().toString() << endl;
// Continuously check distance.
m_correctDistance &= (DISTANCE > m_threshold);
vector<Point3> shape = o.getPolygon().getVertices();
Point3 head = shape.front();
shape.push_back(head);
const uint32_t NUMVERTICES = shape.size();
for(uint32_t j = 1; j < NUMVERTICES; j++) {
Point3 pA = shape.at(j-1);
Point3 pB = shape.at(j);
// TODO: Check polygonal data as well as perpendicular to all sides.
// Create line.
Line l(pA, pB);
// Compute perpendicular point.
Point3 perpendicularPoint = l.getPerpendicularPoint(es.getPosition());
// Compute distance between current position and perpendicular point.
const float DISTANCE_PP = (es.getPosition().getDistanceTo(perpendicularPoint));
cerr << "DistanceToObjectsReport: Distance to object's shape: " << DISTANCE_PP << ", E: " << es.toString() << ", o: " << o.getPosition().toString() << ", perpendicular point:" << perpendicularPoint.toString() << endl;
// Continuously check distance.
m_correctDistance &= (DISTANCE > m_threshold);
}
}
if (c.getDataType() == opendlv::data::environment::OtherVehicleState::ID()) {
OtherVehicleState o = c.getData<OtherVehicleState>();
const float DISTANCE = (es.getPosition().getDistanceTo(o.getPosition()));
// Compute distance between current position and perpendicular point.
cerr << "DistanceToObjectsReport: Distance to other vehicle: " << DISTANCE << ", E: " << es.toString() << ", o: " << o.getPosition().toString() << endl;
// Continuously check distance.
m_correctDistance &= (DISTANCE > m_threshold);
}
}
}
示例2: updateGui
void updateGui(Map map){
ofstream guiFile;
guiFile.open ("/home/opencvdev/workplace6/socG2/server/data");
// Add to gui
// Add Balls
vector<Ball> ballVector = map.getBalls();
for(int i=0; i<ballVector.size();i++){
Ball ball = ballVector.at(i);
Location ballLocation = ball.getLocation();
guiFile<<""<<ballLocation.getX()<<"b"<<ballLocation.getY()<<"\n";
}
// Add obstacles
vector<Obstacle> obsVector = map.getObstacles();
for(int i=0; i<obsVector.size();i++){
Obstacle obs = obsVector.at(i);
Location obsLocation = obs.getLocation();
guiFile<<""<<obsLocation.getX()<<"o"<<obsLocation.getY()<<"\n";
}
// Add target point to data
Location target = brain.getTarget();
guiFile<<target.getX()<<"t"<<target.getY()<<"\n";
// Add robot and locationB
Robot ourRobot = map.getOurRobot();
// Fake the locationB of the robot
//ourRobot.addLocationB(ourRobot.getLocation().getX(), ourRobot.getLocation().getY());
//cout << "--->Robot Location in Test: (" << ourRobot.getLocationB().getX() << "," << ourRobot.getLocationB().getY() << ")\n";
guiFile<<ourRobot.getLocation().getX()<<"r"<<ourRobot.getLocation().getY()<<"\n";
guiFile<<ourRobot.getLocationB().getX()<<"n"<<ourRobot.getLocationB().getY()<<"\n";
guiFile.close();
}
示例3: oldPos
void Map::createMap()
{
//TODO : Add a quadrant system
const int w = m_pSurface->w / World::ratio;
const int h = m_pSurface->h / World::ratio;
b2Vec2 oldPos(0.0f,0.f);
const float minDis = 3;
for(unsigned int i=0; i<16*5; i++)
{
bool foundPos = false;
while(foundPos == false)
{
b2Vec2 pos(rand()%w, rand()%h);
if(b2DistanceSquared(pos, oldPos) >= minDis)
{
foundPos = true;
oldPos = pos;
}
}
Obstacle * obs = new Obstacle(m_pWorld, oldPos);
obs->init();
m_Obstacles.push_back(obs);
}
}
示例4: sillyRotation
void ObstacleFactory::update( float time )
{
Obstacle* b;
std::string name;
for (ObstacleIterator ei = ObstacleList.begin(); ei != ObstacleList.end(); ){
b = *ei;
b->update(time);
ei++;
if(b->die)
{
delete b;
b = 0;
}
name = b->getName();
sillyRotation(time, b->getSceneNode());
if(hit)
sillyHitCamera(time, b->getSceneNode());
}
if(!hit)
debug->setText("false");
//resetPath();
//ObstacleList.clear();
}
示例5: CreateObstacle
void sv::ObstacleManager::UpdateLevel(ulong deltaTime)
{
m_PassedTime += deltaTime;
if(m_PassedTime > SPAWN_TIME_OB)
{
m_PassedTime -= SPAWN_TIME_OB;
m_Step ++;
if(m_Step == m_LevelSize)
m_Step = 0;
ObstacleMsg obstacleMsg;
bool obstacleCreated = false;
for(uchar i=0; i<GetGrid()->GetNumberLanes(); ++i)
{
if(m_Level[m_Step][i] != ' ')
{
uchar category = m_Level[m_Step][i] - 'a' +1;
Obstacle* ob = CreateObstacle(category, i);
obstacleMsg.AddObstacle(ob->GetId(), category, ob->GetPos());
obstacleCreated = true;
}
}
if(obstacleCreated)
GetGame()->SendMsg(&obstacleMsg);
}
}
示例6: doHitTest
char TGame::doHitTest(int x, int y) {
//do hit test
if(Tank1.hitTest(x,y,2,2))//could be for dynamic bullet size
{
//delete &Tank1
Tank1.isHit = true;
return '1';
}
if(Tank2.hitTest(x,y,2,2))//could be for dynamic bullet size
{
//delete &Tank2
Tank2.isHit = true;
return '2';
}
for(int i=0;i<vObs.size();i++)
{
Obstacle O = (Obstacle) vObs[i];
int w,h;
w = .5;
h = .5;
if(O.hitTest(x,y,w,h))
return 'w';
}
return 'n';
}
示例7: onContactBegin
bool SoaringLayer::onContactBegin(PhysicsContact& contact)
{
Node* nodes[2];
nodes[0] = contact.getShapeA()->getBody()->getNode();
nodes[1] = contact.getShapeB()->getBody()->getNode();
if (nodes[0] && nodes[1])
{
for (int i = 0; i < 2; i++)
{
int j = (i + 1) % 2;
if (nodes[i]->getTag() == FLYPLANT_TAG)
{
FlyPlant *flyPlant = dynamic_cast<FlyPlant*>(nodes[i]);
if (flyPlant)
{
flyPlant->onContactBegin(nodes[j]);
}
}
if (nodes[i]->getTag() == OBSTACLE_TAG)
{
Obstacle *obstacle = dynamic_cast<Obstacle*>(nodes[i]);
if (obstacle)
{
obstacle->onContactBegin(nodes[j]);
}
}
}
}
return false;
}
示例8: switch
Obstacle *Obstacle::getInstanceByGid(unsigned int gid)
{
Obstacle *obstacle = nullptr;
//gid = convertGidToOld(gid);
switch(gid)
{
case 1089: //case 273:
obstacle = (Obstacle *) ObjectCache::getInstance()->getObject(COT_MAZE_BLOCK);
break;
case 999999999:
obstacle = (Obstacle *) ObjectCache::getInstance()->getObject(COT_LEVER_BLOCK);
break;
case 1092: //case 276:
obstacle = (Obstacle *) ObjectCache::getInstance()->getObject(COT_DESTROYABLE_BLOCK);
break;
case 1026: //case 258:
case 2639:
obstacle = (Obstacle *) ObjectCache::getInstance()->getObject(COT_PUSHABLE_BLOCK);
break;
default:
obstacle = (Obstacle *) ObjectCache::getInstance()->getObject(COT_MAZE_BLOCK);
printf("Obstacle::getInstanceByGid - unknown obstacle gid %u\n", gid);
}
obstacle->setGid(gid);
return obstacle;
}
示例9:
void TGame::moveTank2(char direction) {
bool canMove = true;
point tm;
tm = Tank2.getMovePoint(direction);
if(!Tank1.hitTest(tm.x,tm.y,Tank2.width,Tank2.height))//check contact with opposing tank
{
for(int i=0;i<vObs.size();i++)
{
Obstacle O = (Obstacle) vObs[i];
int x,y,w,h;
point p = Tank2.getMovePoint(direction);
x= p.x;
y= p.y;
w = Tank1.width;
h = Tank1.height;
if(O.hitTest(x,y,w+2,h+2))
canMove = false;
}
}
else{canMove = false;}
if(canMove)
Tank2.move(direction);
}
示例10: getSelectedAtPosition
Obstacle* Game::getSelectedAtPosition(V2f position, long mask) {
for (int i = 0; i < selectedObstacles.size(); ++i) {
Obstacle * obs = selectedObstacles[i];
if (obs->contains(position, mask))
return obs;
}
return 0;
}
示例11:
void Obstacle::fusion2D(Obstacle& one, const Obstacle& other)
{
if(!twoDimSquareEquation(one.center, one.covariance, other.center, other.covariance))
{
OUTPUT_ERROR("Call Florian: one's type " << one.type << " cov: " << one.covariance(0, 0) << " " << one.covariance(1, 1)
<< " other type " << other.type << " cov: " << other.covariance(0, 0) << " " << other.covariance(1, 1));
}
}
示例12: Resume
void ObstacleManager::Resume()
{
for (unsigned int i = 0 ; i < allObstacles->count() ; i++)
{
Obstacle *obstacleObj = (Obstacle*)allObstacles->objectAtIndex(i);
obstacleObj->Resume();
}
}
示例13: objectWithinBoundingBox
//test if object is within BoundingBox
bool Obstacle::objectWithinBoundingBox(Obstacle testObj)
{
if ( (testObj.getOrigin().x>=minX && testObj.getOrigin().x<=maxX)
&& (testObj.getOrigin().y>=minY && testObj.getOrigin().y<=maxY)
&& (testObj.getOrigin().z>=minZ && testObj.getOrigin().z<=maxZ))
{
return true;
}
return false;
}
示例14: detectObstacle
bool RobotClass::detectObstacle(Obstacle obstacle)
{
int xdiff = getXPosition() - obstacle.getXPosition();
int ydiff = getYPosition() - obstacle.getYPosition();
int distance = getSize() + obstacle.getSize();
if (xdiff * xdiff + ydiff * ydiff <= distance * distance)
{
return true;
}
else return false;
}
示例15: spawnObstacle
void GameStateUpdater::spawnObstacle(unsigned int obstacleGid, Coordinates coords, unsigned int spawnerId)
{
Obstacle *obstacle = Obstacle::getInstanceByGid(obstacleGid);
obstacle->setId(coords.y*_state->getWidth() + coords.x);
obstacle->setPosition(coords.x*TILE_WIDTH, coords.y*TILE_HEIGHT);
obstacle->setSize(TILE_WIDTH, TILE_HEIGHT);
_state->getObstacleLayer()->addObject(obstacle);
_state->getObstacleLayer()->updateGrid();
this->logObstacleSpawn(obstacleGid, obstacle, spawnerId);
}