void renderGame()
{
	// Clear the color buffer
	glClear(GL_COLOR_BUFFER_BIT);

	// Reset transformations
	glLoadIdentity();

	// Set the viewport to the entire window
	viewport.x = 0;
	viewport.y = 0;
	viewport.width = window.width;
	viewport.height = window.height;
	glViewport(viewport.x, viewport.y, viewport.width, viewport.height);

	drawUI();

	// Draw game objects
	ball.draw();

	player.draw();
	ai.draw();

	o1.draw();
	o2.draw();

	// Draw debug stuff
	DebugDrawing::getInstance().draw(timer.getGameTime());

	// Present
	glutSwapBuffers();
}
        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);
                }
            }
        }
Exemple #3
0
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();
}
Exemple #4
0
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);
    }

}
	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();
	}
Exemple #6
0
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);
	}
}
Exemple #7
0
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';
}
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;
}
Exemple #9
0
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;
}
Exemple #10
0
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);
	
}
Exemple #11
0
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;
}
Exemple #12
0
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));
  }
}
Exemple #13
0
void ObstacleManager::Resume()
{
    for (unsigned int i = 0 ; i < allObstacles->count() ; i++)
    {
        Obstacle *obstacleObj = (Obstacle*)allObstacles->objectAtIndex(i);
        obstacleObj->Resume();
    }
}
Exemple #14
0
//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;
}
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;
}
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);
}
bool World::IsReachable(const Robot& robot, const Tree& tree, const Obstacle& obstacle) const
{
	Vector3  treePos = tree.GetPosition(); int room = ( tree.GetPosition()(1) > 0 ) ? 1 : - 1;
	const matrices::Matrix4& transform( robot.ToRobotCoordinates());
	numeric p1robPos = matrices::matrix4TimesVect3( transform, obstacle.GetP1())(1) + 0.05 * room;
	numeric p3robPos = matrices::matrix4TimesVect3( transform, obstacle.GetP3())(1) + 0.05 * room;
	if(! (p1robPos * room >= 0 || p3robPos * room >= 0))
	{
		return false;
	}
	//assert(pImpl_->instantiated_);
	return pImpl_->intersection_.Intersect(robot, tree, obstacle);
}
void Amoeba::collision(Sprite* obj)
{ 
	if( obj->getIdentifier() == AI_TYPE || obj->getIdentifier() == AMOEBA_TYPE)
	{
		 AmoebaCollision( (Amoeba*) obj);
	}
	if( obj->getIdentifier() == OBSTACLE_TYPE){
		Obstacle *ob = (Obstacle*)obj;
		std::pair<double, double>positions[2];
		double radiuses[2];
		ob->getPositions( positions);
		ob->getRadiuses(radiuses);
		
		for( int i = 0; i<2; i++){
			if( (px - positions[i].first) * (px - positions[i].first) + (py - positions[i].second) * (py - positions[i].second) <= radius * radius + radiuses[i] * radiuses[i] - 5){
				isCollision = true;
				retractAttackArm();
				retractDefendArm();
				balls.decreaseRadius(10);
				if( radius > 10)
				{
					radius -= 10;
				}
				else
				{
					radius = 5;
				}
				if(px < positions[i].first)
				{
					velX = -10;
				}
				else
				{
					velX = 10;
				}

				if(py < positions[i].second)
				{
					velY = -10;
				}
				else
				{
					velY = 10;
				}

			}
		}
	}

};
Exemple #19
0
Obstacle* Obstacle::create(Obstacle::Type type)
{
    Obstacle *ret = new Obstacle();
    
    if (ret && ret->init(type))
    {
        ret->autorelease();
    }
    else
    {
        CC_SAFE_DELETE(ret);
    }
    return ret;
};
// initialize each object that will be shown on screen
void init()
{
	glutIgnoreKeyRepeat(1);

	glEnable(GL_LINE_STIPPLE);

	ball.init();

	player.init();
	ai.init();

	o1.init();
	o2.init();
}
Exemple #21
0
void updateGrid(Obstacle &particle)
{

    float posX = particle.getPosX();
    float posY= particle.getPosY();
    float rad = particle.getRad();

    for(int j=0; j<N; j++) {
        for(int i=0; i<N; i++) {
            occupiedGrid[IX(i,j)] = ((i-posX)*(i-posX) + (j-posY)*(j-posY) < rad*rad) ? 1:0;
        }
    }

}
Exemple #22
0
void MainScene::createObstacle( float dt )
{
    Obstacle* obstacle = dynamic_cast<Obstacle*>(CSLoader::createNode("Obstacle.csb"));
    this->obstacles.pushBack( obstacle );
    this->back->addChild( obstacle );
    
    float obstacleY = ( OBSTACLE_MAX_Y - OBSTACLE_MIN_Y ) * CCRANDOM_0_1() + OBSTACLE_MIN_Y;
    obstacle->setPosition( Vec2( OBSTACLE_INIT_X, obstacleY ) );
    
    if( this->obstacles.size() > OBSTACLE_LIMIT )
    {
        this->obstacles.front()->removeFromParent();
        this->obstacles.erase(this->obstacles.begin());
    }
}
//--------------------------------------------------------------
void Scenario::pushObject(ofxBulletWorldRigid &world, int typeObject, ofVec3f pos){
    
 //   ScenarioObjects.push_back(&m_obstable1);

/*
    ofVec3f pos;
    pos.x = ScenarioXml.getValue("positionX",0.0, 0);
    pos.y = ScenarioXml.getValue("positionY",0.0, 0);
    pos.z = ScenarioXml.getValue("positionZ",0.0, 0);
*/

    switch(typeObject){

        case SimpleObject::ShapeTypeBall:{
            Ball *oBall = new Ball(currentMissions);
            oBall->setup(world, pos);
            oBall->setDefaultZ();
            ScenarioObjects.push_back(oBall);
        }
        break;
            
        case SimpleObject::ShapeTypeHammer:{
            Hammer *oHammer = new Hammer(currentMissions);
            oHammer->setup(world, pos);
            oHammer->setDefaultZ();
            ScenarioObjects.push_back(oHammer);
        }
        break;
            
        case SimpleObject::ShapeTypeLever:{
            Lever *oLever = new Lever(currentMissions);
            int dir = 0;
            oLever->setup(world, pos, "cylinder.stl", ofVec3f(0.05, 0.05, 0.05), dir);
            oLever->setDefaultZ();
            ScenarioObjects.push_back(oLever);
        }
        break;
            
        case SimpleObject::ShapeTypeObstacle:{
            Obstacle *oObstable = new Obstacle(currentMissions);
            oObstable->setup(world, pos, "cylinder.stl", ofVec3f(0.05, 0.05, 0.05));
            oObstable->setDefaultZ();
            ScenarioObjects.push_back(oObstable);
        }
        break;
            
    }
}
Exemple #24
0
void World::init() {
  freopen("input/1.in","r",stdin);
  string line;
  
  for( int j = 0; cin >> line; ++j ){
    for( int i = 0; i < line.size(); ++i ){
      if(line[i] == '1'){
        Obstacle temp;
        temp.set_obstacle(i,j+1);
        obstacles.pb(temp);
      }
    }
  }
  
  tripi.set_coordinates(0,0,3);
}
Exemple #25
0
sv::Obstacle* sv::ObstacleManager::CreateObstacle(uchar category, uchar lane)
{
	Obstacle* obstacle = Get();
	uchar pos = GetGrid()->GetInnerPos(lane);
	obstacle->Init(m_IdCount, GetGrid(), category);
	obstacle->Start(pos);

	LOG2(DEBUG_OBSTACLES, "Obstacle created: id: %i, pos: %i", m_IdCount, pos);
	
	if(m_IdCount == 255)
		m_IdCount = 1;
	else
		m_IdCount++;

	return obstacle;
}
Exemple #26
0
int main (int argc, char* argv[]) {
	width=atoi(argv[1]);
	height=atoi(argv[2]);
	initialize();
	initBg();
	obstacleBuffer.clear();//clear buffer
	normalObj.reset();//reset the normal objects
	glutInit (&argc, argv);
	glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowSize (width, height);
	glutInitWindowPosition (0,0);
	glutCreateWindow ("Glutle");
	glutFullScreen();
	glutDisplayFunc(display);
	glutIdleFunc (display);
	glutReshapeFunc (reshape);
	glutSpecialFunc(special);
	glutKeyboardFunc(keyboard);
	glutMouseFunc(mouse);//for click
	glutPassiveMotionFunc(hover);//this is for hover
	glutMotionFunc(draw);//for drag
	system("mplayer ~/.glutrix/ambient.ogg -loop 0&");//bg music
	glutMainLoop();
	return 0;
}
bool PlanningProblem::hasCollision(const Station &st, const Obstacle &ob)
{
    b2Transform st_Transform;
    st_Transform.Set(st.getPosition().to2D().toB2vec2(), st.getPosition().Teta());

    return b2TestOverlap(ob.shape, 0, agent->shape, 1, ob.predictedTransform(0), st_Transform);
}
void OpenGLESRenderer::renderObstacle(Obstacle &obstacle)
{
    for (std::vector<std::unique_ptr<SpikeGameObject>>::iterator itr = obstacle.getSpikes().begin(); itr != obstacle.getSpikes().end(); ++itr)
    {
        renderGameObject((**itr), Assets::getWorldSpikeTextureRegion((**itr).getType()));
    }
}
Exemple #29
0
void sv::ObstacleManager::Update(ulong deltaTime)
{
	Iterator iter = First();
	while(iter)
	{
		Obstacle* obstacle = Get(iter);
		iter = Next(iter);

		obstacle->Update(deltaTime);
		if( obstacle->IsEdge() )
			HandleCollision(obstacle);
		if( obstacle->GetPos() == Grid::InvalidPos )
			DeleteObstacle(obstacle);
	}

	UpdateLevel(deltaTime);
}
Exemple #30
0
bool BezierPatch::objectWithinBoundingBox(Obstacle testObj)
{
	//test each bounding box
	for(int i=0;i<levelOfDetail;i++)
	{
		if (   testObj.getOrigin().x>=boundingBoxes[i].minPoints.x
			&& testObj.getOrigin().x<=boundingBoxes[i].maxPoints.x
			&& testObj.getOrigin().y>=boundingBoxes[i].minPoints.y 
			&& testObj.getOrigin().y<=boundingBoxes[i].maxPoints.y
			&& testObj.getOrigin().z>=boundingBoxes[i].minPoints.z
			&& testObj.getOrigin().z<=boundingBoxes[i].maxPoints.z)
		{ 
				return true;
		}
	}
	return false;
}