Exemplo n.º 1
0
void MovingObjectModel::RecalculatePath()
{
	//Only do stuff if the path contains elements.
	if(m_Path != NULL && !m_Path->empty())
	{
		auto next = m_Path->at(0);

		Point tempDirection = next - GetPosition();
		float distance = tempDirection.GetLength();
		tempDirection = tempDirection.GetNormalizedPoint();

		Point oppositDirection = m_Direction.GetNegatedPoint();
		oppositDirection = oppositDirection.GetNormalizedPoint();

		//If direction got negated, we overshot our target or if we have reached our next goal
		if(tempDirection == &oppositDirection || distance < 0.01f)
		{
			m_Path->erase(m_Path->begin());

			if(m_Path->empty())
			{
				m_MovementSpeed = 0;
			}
			else
			{
				next = m_Path->at(0);
				auto pos = GetPosition();

				Point newDirection = next - pos;
				newDirection = newDirection.GetNormalizedPoint();

				if(m_Owner != NULL)
				{
					m_Owner->setLookAt2D(newDirection.X, newDirection.Y);
				}
				else
				{
					SetDirection(newDirection.X, newDirection.Y);
				}
			}

		}
	}
}
Exemplo n.º 2
0
void MovingObjectModel::calcDirection()
{
	if(m_Path != NULL && !m_Path->empty())
	{
		auto next = m_Path->at(0);

		auto pos = GetPosition();

		Point tempDirection = next - pos;

		tempDirection = tempDirection.GetNormalizedPoint(); 
		if(m_Owner != NULL)
		{
			m_Owner->setLookAt2D(tempDirection.X, tempDirection.Y);
		}
		else
		{
			SetDirection(tempDirection.X, tempDirection.Y);
		}
	}
}
Exemplo n.º 3
0
SceneGraphManager *createGraph()
{
	int lightIndex = SINGLETONINSTANCE(LightingManager)->getAvailableLightIndex();
	SINGLETONINSTANCE(LightingManager)->lights[lightIndex].enable(true);
	SINGLETONINSTANCE(LightingManager)->lights[lightIndex].setDiffuse(0.5f,0.5f,0.5f, 1.0f);
	SINGLETONINSTANCE(LightingManager)->lights[lightIndex].setSpecular(0.7f,0.2f,0.1f, 1.0f);
	SINGLETONINSTANCE(LightingManager)->lights[lightIndex].setAmbient(0.2f,0.2f,0.2f, 1.0f);
	SINGLETONINSTANCE(LightingManager)->lights[lightIndex].setPos(10.0f,10.0f,10.0f);

	auto root = new Object();
	root->Name = "Root";
	root->transformation->Reset();

	float mapWidth = 40.0f;
	auto ground = new Object();
	ground->Name = "Ground";
	ground->model =  SINGLETONINSTANCE( MediaManager )->ground;
	ground->transformation->Reset();
	ground->SetPos2D(20.0f,20.0f);
	ground->SetScale(mapWidth,mapWidth,1.0f);
	SINGLETONINSTANCE(PathPlanner)->StartUp(mapWidth);

	auto underground = new Object();
	underground->Name = "Underground";
	underground->model =  SINGLETONINSTANCE( MediaManager )->ground;
	underground->transformation->Reset();
	underground->getPos()->SetZ(-10.0f);
	underground->SetScale(mapWidth*10,mapWidth*10,1.0f);

	Rectangle physicsBox(Point(-0.5f, -0.5f), 1.0f, 1.0f);

	auto box = new Object();
	box->Name = "Box";
	box->model =  SINGLETONINSTANCE( MediaManager )->boxModel;
	StaticObjectModel* tempStaticObject = new StaticObjectModel(RECTANGULARSHAPE);
	box->physicsModel = tempStaticObject;
	box->physicsModel->InitializeAsRectangle(physicsBox);
	SINGLETONINSTANCE(PhysicsSystem)->AddStaticObject(tempStaticObject);
	box->SetPos2D(20.0f, 0.0f);
	box->SetScale(40.0f, 1.0f, 3.0f);
	//box->physicsModel->debug();
	
	auto box1 = new Object();
	box1->Name = "Box1";
	tempStaticObject = new StaticObjectModel(RECTANGULARSHAPE);
	box1->model =  SINGLETONINSTANCE( MediaManager )->boxModel;
	box1->physicsModel = tempStaticObject;
	box1->physicsModel->InitializeAsRectangle(physicsBox);
	SINGLETONINSTANCE(PhysicsSystem)->AddStaticObject(tempStaticObject);
	box1->SetPos2D(20.0f, 40.0f);
	box1->SetScale(40.0f, 1.0f, 3.0f);

	auto box2 = new Object();
	box2->Name = "Box2";
	box2->model =  SINGLETONINSTANCE( MediaManager )->boxModel;
	tempStaticObject = new StaticObjectModel(RECTANGULARSHAPE);
	box2->physicsModel = tempStaticObject;
	box2->physicsModel->InitializeAsRectangle(physicsBox);
	SINGLETONINSTANCE(PhysicsSystem)->AddStaticObject(tempStaticObject);
	box2->SetPos2D(0.0f, 20.0f);
	box2->SetScale(1.0f, 40.0f, 3.0f);

	auto box3 = new Object();
	box3->Name = "Box3";
	box3->model =  SINGLETONINSTANCE( MediaManager )->boxModel;
	tempStaticObject = new StaticObjectModel(RECTANGULARSHAPE);
	box3->physicsModel = tempStaticObject;
	box3->physicsModel->InitializeAsRectangle(physicsBox);
	SINGLETONINSTANCE(PhysicsSystem)->AddStaticObject(tempStaticObject);
	box3->SetPos2D(40.0f, 20.0f);
	box3->SetScale(1.0f, 40.0f, 3.0f);

	auto box4 = new Object();
	box4->Name = "Box4";
	box4->model =  SINGLETONINSTANCE( MediaManager )->boxModel;
	tempStaticObject = new StaticObjectModel(RECTANGULARSHAPE);
	box4->physicsModel = tempStaticObject;
	box4->physicsModel->InitializeAsRectangle(physicsBox);
	SINGLETONINSTANCE(PhysicsSystem)->AddStaticObject(tempStaticObject);
	box4->SetPos2D(27.0f, 15.0f);
	box4->SetScale(1.0f, 30.0f, 3.0f);

	auto box5 = new Object();
	box5->Name = "Box5";
	box5->model =  SINGLETONINSTANCE( MediaManager )->boxModel;
	tempStaticObject = new StaticObjectModel(RECTANGULARSHAPE);
	box5->physicsModel = tempStaticObject;
	box5->physicsModel->InitializeAsRectangle(physicsBox);
	SINGLETONINSTANCE(PhysicsSystem)->AddStaticObject(tempStaticObject);
	box5->SetPos2D(13.0f, 25.0f);
	box5->SetScale(1.0f, 30.0f, 3.0f);
	

	root->children->push_back(*underground);
	root->children->push_back(*ground);
	
	root->children->push_back(*box);
	root->children->push_back(*box1);
	root->children->push_back(*box2);
	root->children->push_back(*box3);
	root->children->push_back(*box4);
	root->children->push_back(*box5);

	SINGLETONINSTANCE(PhysicsSystem)->SetStaticPathMap();

	Point forward;
	forward.X = 0;
	forward.Y = -1;
	forward = forward.GetNormalizedPoint();

	auto player = new Object();
	SINGLETONINSTANCE(PlayerInteraction)->StartUp(player);

	player->Name = "Player";
	player->model =  SINGLETONINSTANCE( MediaManager )->crazyModel;
	MovingObjectModel* tempMovingObject = new MovingObjectModel(CIRCULARSHAPE, PLAYERTYPE, forward, player);
	player->physicsModel = tempMovingObject;
	Circle circle(Point(0.0f,0.0f),0.5f);
	player->physicsModel->InitializeAsCircle(circle);
	SINGLETONINSTANCE(PhysicsSystem)->AddMovingObject(tempMovingObject);
	player->SetPos2D(15,20);
	player->Rotate(90.0f, 1.0f, 0.0f, 0.0f);
	player->SetForward(0.0f, 1.0f);
	player->setLookAt2D(forward.X,forward.Y);
	
	root->children->push_back(*player);

	player->physicsModel->SetTargetPosition(new Point(50,5));

	auto camera = new Camera();
	camera->Position.SetX(20);
	camera->Position.SetY(5);
	camera->Position.SetZ(50);
	camera->LookAt.SetX(20);
	camera->LookAt.SetY(20);
	camera->LookAt.SetZ(-1);
	camera->Up.SetX(0);
	camera->Up.SetY(1);
	camera->Up.SetZ(0);

	SceneGraphManager *sceneGraph = new SceneGraphManager(camera, root);

	return sceneGraph;
}