예제 #1
0
void Object_Picking_Test::RunTest(float mX, float mY)
{
	CameraPtr ptr = scene->GetActiveCamera();
	Camera * cam = ptr.Get();
	cam->CalcPickingRay(mX, mY);

	using namespace DirectX;


	for (unsigned int i = 0; i < pickable.size(); i++)
	{
		SceneObj obj = pickable[i];
		StaticEntity * ent = obj.obj.Get();
		
		XMFLOAT4X4 mat = ent->GetWorldMatrix();

		XMMATRIX world = XMLoadFloat4x4((XMFLOAT4X4*)&mat);

		world = XMMatrixTranspose(world);

		XMVECTOR det = XMMatrixDeterminant(world);

		XMMATRIX invWorld = XMMatrixInverse(&det, world);

		Vector3 org = cam->GetPosition();
		Vector3 dir = cam->GetPickingRayDirection();

		XMVECTOR orgInv = XMVector3TransformCoord(XMLoadFloat3((XMFLOAT3*)&org), invWorld);
		XMVECTOR dirInv = XMVector3TransformNormal(XMLoadFloat3((XMFLOAT3*)&dir), invWorld);

		dirInv = XMVector3Normalize(dirInv);

		XMStoreFloat3((XMFLOAT3*)&org, orgInv);
		XMStoreFloat3((XMFLOAT3*)&dir, dirInv);

		AABB bbox = ent->GetAABB();

		/*XMVECTOR max = XMLoadFloat3((XMFLOAT3*)&bbox.max);
		XMVECTOR min = XMLoadFloat3((XMFLOAT3*)&bbox.min);

		max = XMVector3TransformCoord(max, world);
		min = XMVector3TransformCoord(min, world);

		XMStoreFloat3((XMFLOAT3*)&bbox.max, max);
		XMStoreFloat3((XMFLOAT3*)&bbox.min, min);*/

		if (bbox.RayIntersact(org, dir))
		{
			obj.bbox.Get()->SetVisible(!obj.bbox.Get()->IsVisible());
		}

	}
}
예제 #2
0
void Billboard_Test::Init(Scene * scene)
{
	BillboardPtr ptr = scene->AddBillboard();
	Billboard * b = ptr.Get();
	b->SetSize(20.0f, 20.0f);
	b->UseDiffuseTexture(true);
	b->SetDiffuseTexture("assets/fire.png");

	StaticVert verts[4];

	verts[0].pos = Vector3(-1.0f, -1.0f, 0.0f);
	verts[1].pos = Vector3(-1.0f, 1.0f, 0.0f);
	verts[2].pos = Vector3(1.0f, 1.0f, 0.0f);
	verts[3].pos = Vector3(1.0f, -1.0f, 0.0f);

	verts[0].u = 0.0f;
	verts[0].v = 1.0f;

	verts[1].u = 0.0f;
	verts[1].v = 0.0f;

	verts[2].u = 1.0f;
	verts[2].v = 0.0f;

	verts[3].u = 1.0f;
	verts[3].v = 1.0f;
	unsigned int ind[] = { 0, 1, 3, 1, 3, 2 };

	ModelCreator<StaticVert> creator;
	creator.StartMesh();
	creator.SetTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	creator.SetDrawMethod(DM_DRAW_INDEXED);
	creator.SetVertexBuffer(verts, sizeof(verts), sizeof(StaticVert));
	creator.SetIndexBuffer(ind, 6);
	creator.EndMesh();

	StaticEntityPtr triPtr = scene->AddStaticEntity(creator, "tri");
	StaticEntity * tri = triPtr.Get();
	tri->Illuminate(false);
	tri->SetPosition(50.0f, 0.0f, 0.0f);
	tri->SetScale(20.0f, 20.0f, 2.0f);

	Material * mat = tri->GetMaterial(0);
	mat->UseDiffuseMap(true);
	mat->SetDiffuseMap("assets/fire.png");
	mat->SetEmmisivePower(1);
}
예제 #3
0
//----------------------------------------------------------------------------------------------------------------------
void GameWorld::draw(ngl::Camera* _cam, ngl::Mat4 _mouseGlobalTX)
{
    ngl::Material a(ngl::Colour(0.2f,0.2f,0.2f, 1.0), ngl::Colour(0.32f,0.31f,0.3f, 1.), ngl::Colour(0.77391f,0.77391f,0.77391f, 1.0));
    a.setSpecularExponent(20.f);
    a.loadToShader("material");
    loadMatricesToShader(_cam, _mouseGlobalTX);
    m_streetMesh->draw();

    ngl::Material b(ngl::Colour(0.2f,0.2f,0.2f, 1.0), ngl::Colour(0.45f,0.45f,0.45f, 1.), ngl::Colour(0.77391f,0.77391f,0.77391f, 1.0));
    b.setSpecularExponent(20.f);
    b.loadToShader("material");
    loadMatricesToShader(_cam, _mouseGlobalTX);
    m_buildingMesh->draw();

    for(unsigned int a=0; a<m_numberOfObstacles; ++a)
    {
        StaticEntity* currentObstacle = m_obstacles[a];
        currentObstacle->draw(_cam, _mouseGlobalTX);
    }

    for(unsigned int a=0; a<m_numberOfRioters; ++a)
    {
        Rioter* currentRioter = m_rioters[a];
        currentRioter->draw(_cam, _mouseGlobalTX);
    }

    m_numberOfSquads = m_squads.size();

    for(unsigned int a=0; a<m_numberOfSquads; ++a)
    {
        Squad* currentSquad = m_squads[a];
        currentSquad->draw(_cam, _mouseGlobalTX);
        if(currentSquad->getSquadState() == squadMove)
        {
            currentSquad->drawTarget(_cam, _mouseGlobalTX);
        }
    }


}
예제 #4
0
void Object_Picking_Test::CreateLine(Vector3 begin, Vector3 end)
{
	StaticVert verts[2];
	verts[0].pos = begin;
	verts[1].pos = end;

	ModelCreator<StaticVert> modelCreator;
	modelCreator.StartMesh();
	modelCreator.SetDrawMethod(DM_DRAW);
	modelCreator.SetTopology(D3D10_PRIMITIVE_TOPOLOGY_LINELIST);
	modelCreator.SetVertexBuffer(verts, sizeof(verts), sizeof(StaticVert));
	modelCreator.EndMesh();

	StaticEntityPtr linePtr = scene->AddStaticEntity(modelCreator, "line " + std::to_string(currentBox));

	StaticEntity * line = linePtr.Get();
	line->Illuminate(false);
	Material * mat = line->GetMaterial(0);
	mat->UseDiffuseMap(false);
	mat->SetDiffuseColor(Color::Red());

	currentBox++;
}
예제 #5
0
파일: MainForm.cpp 프로젝트: dgi09/D3D
void MainForm::OnAddStaticEntity_Click(wxMouseEvent &evt)
{
	CreateEntityDialog dialog;
	dialog.Show();
	DialogResult res = dialog.GetResult();

	if(res == OK)
	{

		StaticEntityPtr enPtr = scene->AddStaticEntity(dialog.GetFilePath(),dialog.GetName());
		StaticEntity * en = enPtr.Get();
		en->SetPosition(10.0f,10.0f,0.0f);
		en->Illuminate(false);
		en->SetScale(10.0f,10.0f,10.0f);
		en->SetRotationY(90.0f);

		for (unsigned int i = 0; i < en->GetNumberOfMaterials(); i++)
		{
			Material * mat = en->GetMaterial(i);
			mat->UseDiffuseMap(false);
			mat->SetDiffuseColor(Color::White());
			mat->UseBumpMap(false);

			mat->SetEmmisivePower(1);
			mat->SetSpecularPower(1);
			mat->SetSpecularIntesity(1);
		}
		


		EditorEntity * entity = new EditorEntity(new EntityBase_StaticEntity(enPtr));
		EditorSceneObjectsManager::GetPtr()->AddElement(entity);

		ActiveTool::Set(new SelectTool);
	}

}
예제 #6
0
void Object_Picking_Test::Init(Scene * scene)
{
	this->scene = scene;
	currentBox = 0;

	StaticEntityPtr dogPtr2 = scene->AddStaticEntity("assets/sphere.smodel", "dog");
	StaticEntityPtr dogBBox = CreateBBox(dogPtr2);

	SceneObj obj;
	obj.obj = dogPtr2;
	obj.bbox = dogBBox;

	pickable.push_back(obj);

	StaticEntity * dog = dogPtr2.Get();

	dog->Illuminate(false);
	dog->SetPosition(20.0f, 0.0, 0.0f);
	dog->SetScale(100.0f, 100.0f, 100.0f);
	dog->SetRotationY(40.0f);
	dogBBox.Get()->SetScale(100.0f, 100.0f, 100.0f);
	//dogBBox.Get()->CalculateTransform(false);

	
	DirectX::XMFLOAT4X4 dogMat = dog->GetWorldMatrix();

	dogBBox.Get()->CalculateTransform(false);
	dogBBox.Get()->SetTransform(dogMat);

	DirectX::XMFLOAT4X4 boxMat = dogBBox.Get()->GetWorldMatrix();

	//dog->SetRotation(0.0f, -60.0f, 180.0f);
	//dog->SetRotationY(45.0f);

	Material * pMat = dog->GetMaterial(0);
	pMat->SetDiffuseColor(Color(1.0, 0.0f, 0.0f, 1.0f));
}
예제 #7
0
	static int main(const std::vector<std::string> &args){

#if _DEBUG
		clan::ConsoleWindow console("Debug Console", 80, 160);
		clan::Console::write_line("Arguments: %1", args.size());

		std::cout << "Arguments: " + args.size();

		for( unsigned int i = 0; i < args.size(); i++ )
		{
			clan::Console::write( "[%1] = %2\n", i, args[i] );
		}

		clan::Console::write_line("");
#endif

		int ret = 0;


		try
		{
			// Starting logog service
			//LOGOG_INITIALIZE();
	
			GameManager* manager = GameManager::getInstance();

#ifdef _DEBUG
			manager->loadXMLResource("../../data/resources.xml");
#else
			manager->loadXMLResource("./data/resources.xml");
#endif

			manager->setupPlayer(0);
	
			//Splash screen
			FadingScene* splashScreen = new FadingScene( 2000.0f, 2000.0f, 4000.0f, FadingScene::FM_FADE_INOUT );
			StaticEntity* newEntity = new StaticEntity( 0.0f, 0.0f, "scenes/logo" ); // Fading scene deletes this
			splashScreen->insertEntity( newEntity );
	
			//Menu screen
			MenuDifficulty* difficultyMenu = new MenuDifficulty();
	
			//Test scene
			TestScenePlayer* newTest = new TestScenePlayer();

			//Ending scene
			FadingScene* ending = new FadingScene( 2000.0f, 2000.0f, 2000.0f, FadingScene::FM_FADE_INOUT );
			newEntity = new StaticEntity( 0.0f, 0.0f, "scenes/congratulations" ); // Fading scene deletes this
			newEntity->setAlpha( 0.0f );
			ending->insertEntity( newEntity );
			
			newTest->setNextScene( ending );
			difficultyMenu->setNextScene( newTest );
			splashScreen->setNextScene( difficultyMenu );
			manager->pushScene( splashScreen );
			manager->pushScene( difficultyMenu );
	
			/* Main game loop */
			ret = manager->loop();
	
			delete newTest;
			delete splashScreen;
			delete ending;
			delete manager;

		}
		catch(clan::Exception &exception)
		{
			// Create a console window for text-output if not available
			clan::ConsoleWindow console("Console", 80, 160);
			clan::Console::write_line("Exception caught: " + exception.get_message_and_stack_trace());
			console.display_close_message();

			return -1;
		}
		/*catch(...)
		{
			CL_ConsoleWindow console("Console", 80, 160);
			CL_Console::write_line("Exception caught: " + exception.get_message_and_stack_trace());
			console.display_close_message()
			return -1;
		}*/


#ifdef _DEBUG
		console.display_close_message();
#endif

		// Ending logog service
		//LOGOG_SHUTDOWN();

		return ret;
	}
예제 #8
0
//----------------------------------------------------------------------------------------------------------------------
GameWorld::GameWorld(int _level)
{
    L = luaL_newstate();
    registerLua(L);

    m_entityMgr = new EntityManager();

    m_win = 0;
    m_lose = 0;

    m_numberOfRiotersDead = 0;
    m_numberOfRiotersHome = 0;
    m_activePolice = 0;

    m_resetID = 1;

    // get a different lua level based in input level
    switch (_level)
    {
    case 1 :
    {
        luabridge::LuaRef startLevel = luabridge::getGlobal(L, "level1");
        startLevel();
        break;
    }
    case 2 :
    {
        luabridge::LuaRef startLevel = luabridge::getGlobal(L, "level2");
        startLevel();
        break;
    }
    case 3 :
    {
        luabridge::LuaRef startLevel = luabridge::getGlobal(L, "level3");
        startLevel();
        break;
    }
    case 4 :
    {
        luabridge::LuaRef startLevel = luabridge::getGlobal(L, "level4");
        startLevel();
        break;
    }
    case 5 :
    {
        luabridge::LuaRef startLevel = luabridge::getGlobal(L, "level5");
        startLevel();
        break;
    }
    default :
    {
        std::cout<<"Error: Invalid level"<<std::endl;
        break;
    }
    }

    // load in the meshes
    m_streetMesh = new ngl::Obj(m_streetMeshFile); //Obj for roads, should be tris
    m_buildingMesh = new ngl::Obj(m_buildingMeshFile); //Obj for buildings, should be tris
    m_streetMesh->createVAO();
    m_buildingMesh->createVAO();

    m_cellGraph = new CellGraph(m_cellGraphFile, 1); //Obj for cell graph, must be quads
    m_cellGraph->generateWalls();

    m_policeMesh = new ngl::Obj("models/policeMan.obj");
    m_rioterMesh = new ngl::Obj("models/rioterMan.obj");
    m_treeMesh = new ngl::Obj("models/tree.obj");
    m_streetLightMesh = new ngl::Obj("models/streetLight.obj");

    std::vector<ngl::Vec3> wallCentres = m_cellGraph->getWallCentres();
    std::vector<ngl::Vec3> wallNormals = m_cellGraph->getWallNormals();
    std::vector<int> wallRotations = m_cellGraph->getWallRotations();

    m_policeMesh->createVAO();
    m_rioterMesh->createVAO();
    m_treeMesh->createVAO();
    m_streetLightMesh->createVAO();

    //initialise rioters
    for (int i = 0; i < m_initialNumberOfRioters ; ++i)
    {
        Rioter* newRioter = new Rioter(this, m_rioterMesh);
        newRioter->setBoudingRadius(0.5f);
        newRioter->setDetectionRadius(3.5f);
        newRioter->setHeading(ngl::Vec3(-1+2*((float)rand())/RAND_MAX, 0.f, -1+2*((float)rand())/RAND_MAX));
        newRioter->setPos(ngl::Vec3(-25+50*((float)rand())/RAND_MAX, 0.f, -25+50*((float)rand())/RAND_MAX));
        m_cellGraph->initializeCells(m_entityMgr->getEntityFromID(newRioter->getID()));
        while (newRioter->getCurrentCellID() < 0)
        {
            newRioter->setPos(ngl::Vec3(-50+100*((float)rand())/RAND_MAX, 0.f, -50+100*((float)rand())/RAND_MAX));
            m_cellGraph->initializeCells(m_entityMgr->getEntityFromID(newRioter->getID()));
        }
        m_rioters.push_back(newRioter);
    }
    m_numberOfRioters = m_rioters.size();

    // initialise trees
    for (int i = 0; i < m_numberOfTrees ; ++i)
    {
        StaticEntity* newTree = new StaticEntity(this, ngl::Vec3(0,0,0),ngl::Vec3(0.0f,360*((float)rand()/RAND_MAX),0.0f),1.0,obstacleTree,m_treeMesh);
        newTree->setPos(ngl::Vec3(-25+50*((float)rand())/RAND_MAX, 0.f, -25+50*((float)rand())/RAND_MAX));
        m_cellGraph->initializeCells(m_entityMgr->getEntityFromID(newTree->getID()));
        while (newTree->getCurrentCellID() < 0)
        {
            newTree->setPos(ngl::Vec3(-50+100*((float)rand())/RAND_MAX, 0.f, -50+100*((float)rand())/RAND_MAX));
            m_cellGraph->initializeCells(m_entityMgr->getEntityFromID(newTree->getID()));
        }
        m_obstacles.push_back(newTree);
    }

    int numberOfWalls = wallCentres.size();

    //pick random streetlight positions
    int sample[m_numberOfStreetLights];
    std::vector<int> choices;
    int choice;

    for (int i=0; i<numberOfWalls; i++)
    {
        choices.push_back(i);
    }

    srand (time(NULL));

    assert (m_numberOfStreetLights<=numberOfWalls && "too many streetlights for the map size!");

    for(int i=0; i<m_numberOfStreetLights; i++)
    {
        do
        {
            choice = rand() % numberOfWalls;
        }
        while((choices[choice]==-1));

        choices[choice]=-1; // prevents duplicate choices
        sample[i] = choice;

    }

    for (int i = 0; i < m_numberOfStreetLights ; i++)
    {
        StaticEntity* newStreetLight = new StaticEntity(this, wallCentres[sample[i]]+(0.3*wallNormals[sample[i]]), ngl::Vec3(0.0f,wallRotations[sample[i]],0.0f), 0.2, obstacleStreetLight, m_streetLightMesh);
        m_cellGraph->initializeCells(m_entityMgr->getEntityFromID(newStreetLight->getID()));
        m_obstacles.push_back(newStreetLight);
    }

    m_numberOfObstacles = m_obstacles.size();
}
예제 #9
0
StaticEntityPtr Object_Picking_Test::CreateBBox(StaticEntityPtr ptr)
{
	AABB bbox = ptr.Get()->GetAABB();
	
	Vector3 min = bbox.min;
	Vector3 max = bbox.max;

	StaticVert box[32];
	box[0].pos = Vector3(min.x, max.y, min.z);
	box[1].pos = Vector3(max.x, max.y, min.z);

	box[2].pos = Vector3(max.x, max.y, min.z);
	box[3].pos = Vector3(max.x, min.y, min.z);
	
	box[4].pos = Vector3(max.x, min.y, min.z);
	box[5].pos = Vector3(min.x,min.y,min.z);

	box[6].pos = Vector3(min.x, min.y, min.z);
	box[7].pos = Vector3(min.x, max.y, min.z);

	box[8].pos = Vector3(min.x, max.y, max.z);
	box[9].pos = Vector3(max.x, max.y, max.z);

	box[10].pos = Vector3(max.x, max.y, max.z);
	box[11].pos = Vector3(max.x, min.y, max.z);

	box[12].pos = Vector3(max.x, min.y, max.z);
	box[13].pos = Vector3(min.x, min.y, max.z);

	box[14].pos = Vector3(min.x, min.y, max.z);
	box[15].pos = Vector3(min.x, max.y, max.z);

	box[16].pos = Vector3(max.x, max.y, min.z);
	box[17].pos = Vector3(max.x, max.y, max.z);

	box[18].pos = Vector3(max.x, max.y, max.z);
	box[19].pos = Vector3(max.x, min.y, max.z);

	box[20].pos = Vector3(max.x, min.y, max.z);
	box[21].pos = Vector3(max.x, min.y, min.z);

	box[22].pos = Vector3(max.x, min.y, min.z);
	box[23].pos = Vector3(max.x, max.y, min.z);

	box[24].pos = Vector3(min.x, max.y, min.z);
	box[25].pos = Vector3(min.x, max.y, max.z);

	box[26].pos = Vector3(min.x, max.y, max.z);
	box[27].pos = Vector3(min.x, min.y, max.z);

	box[28].pos = Vector3(min.x, min.y, max.z);
	box[29].pos = Vector3(min.x, min.y, min.z);

	box[30].pos = Vector3(min.x, min.y, min.z);
	box[31].pos = Vector3(min.x, max.y, min.z);



	ModelCreator<StaticVert> cr;
	cr.StartMesh();
	cr.SetTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST);
	cr.SetDrawMethod(DM_DRAW);
	cr.SetVertexBuffer(box, sizeof(box), sizeof(StaticVert));
	cr.EndMesh();

	StaticEntityPtr boxPtr = scene->AddStaticEntity(cr, "box" + std::to_string(currentBox));

	StaticEntity * ent = boxPtr.Get();
	Material * mat = ent->GetMaterial(0);

	mat->SetDiffuseColor(Color::Blue());

	currentBox++;

	return boxPtr;
}
예제 #10
0
파일: main.cpp 프로젝트: scanberg/engine
int main(int argc, char *argv[])
{
    srand ( time(NULL) );
    int running = GL_TRUE;
    int mousebtn, lastmousebtn;

    //Did the init not succeed?
    if(!SceneHandler::Init())
    {
        //quit.
        return 0;
    }

    Light *moon = SceneHandler::CreateLight();
    moon->setPosition(-2000.0,0.0,1000.0);
    moon->setDiffuse(0.3,0.3,0.4);
    moon->setAmbient(0.2,0.2,0.3);
    moon->setSpecular(1.0,1.0,1.0);
    moon->setRadius(20000.0);

    int numLights=4;

    Light *lights[numLights];
    ParticleSystem *ps[numLights];

    ps[0] = SceneHandler::CreateParticleSystem();
    ps[0]->SetPosition(-307.0,-10.0,90.0);
    ps[0]->scale = 2.0;

    lights[0] = SceneHandler::CreateLight();
    lights[0]->setPosition(-307.0,-10.0,90.0);
    lights[0]->setDiffuse(1.0,1.0,0.8);
    lights[0]->setAmbient(0.1,0.1,0.1);
    lights[0]->setSpecular(1.0,1.0,1.0);
    lights[0]->setRadius(200.0);

    ps[1] = SceneHandler::CreateParticleSystem();
    ps[1]->SetPosition(-307.0,-188.0,90.0);
    ps[1]->scale = 2.0;

    lights[1] = SceneHandler::CreateLight();
    lights[1]->setPosition(-307.0,-188.0,90.0);
    lights[1]->setDiffuse(1.0,1.0,0.8);
    lights[1]->setAmbient(0.1,0.1,0.1);
    lights[1]->setSpecular(1.0,1.0,1.0);
    lights[1]->setRadius(200.0);

    ps[2] = SceneHandler::CreateParticleSystem();
    ps[2]->SetPosition(178.0,-45.0,64.0);
    ps[2]->scale = 2.0;

    lights[2] = SceneHandler::CreateLight();
    lights[2]->setPosition(178.0,-45.0,64.0);
    lights[2]->setDiffuse(1.0,1.0,0.8);
    lights[2]->setAmbient(0.1,0.1,0.1);
    lights[2]->setSpecular(1.0,1.0,1.0);
    lights[2]->setRadius(200.0);

    ps[3] = SceneHandler::CreateParticleSystem();
    ps[3]->SetPosition(178.0,-131.0,64.0);
    ps[3]->scale = 2.0;

    lights[3] = SceneHandler::CreateLight();
    lights[3]->setPosition(178.0,-131.0,64.0);
    lights[3]->setDiffuse(1.0,1.0,0.8);
    lights[3]->setAmbient(0.1,0.1,0.1);
    lights[3]->setSpecular(1.0,1.0,1.0);
    lights[3]->setRadius(200.0);

    mousebtn = lastmousebtn = GLFW_RELEASE;

    Camera camera;
    camera.setDirection(90.0,0.0,0.0);
    camera.setPosition(0.0,0.0,100.0);

    PlayerEntity *player;

    player = SceneHandler::CreatePlayerEntity();
    player->SetPosition(-400.0,-100.0,50.0);
    player->minBox=glm::vec4(-12.0,-12.0,-30.0,1.0f);
    player->maxBox=glm::vec4(12.0,12.0,30.0,1.0f);
    player->eyeHeight=25.0;

    PlayerEntity::SetCamera(&camera);

    StaticEntity *scene;
    StaticEntity *beast;
    StaticEntity *box;

    scene = SceneHandler::CreateStaticEntity("media/ny.ase",1.0);
    beast = SceneHandler::CreateStaticEntity("media/beast/beast1.ase",0.5);
    box = SceneHandler::CreateStaticEntity("media/box/box.ase",1.0);

    MD5Model *bob;

    bob = SceneHandler::CreateMD5Entity("models/monsters/hellknight/hellknight.md5mesh","models/monsters/hellknight/idle2.md5anim");
    bob->scale=0.7;
    bob->SetPosition(300.0,100.0,0.0);
	bob->SetRotation(0.0,0.0,-90.0);

    beast->SetPosition(0.0,100.0,50.0);
    beast->SetRotation(90.0,0.0,0.0);

    scene->SetPosition(500.0,200.0,0.0);
    scene->SetRotation(0.0,0.0,0.0);

    box->SetPosition(100.0,100.0,150.0);
    box->SetRotation(0.0,0.0,-20.0);

    SceneHandler::CreateBBoxCollision(box,10.0);
    SceneHandler::CreateBBoxCollision(beast,10.0);
    SceneHandler::CreateMeshCollision(scene);

    SceneHandler::CreatePlayerCollision(player);

    GLint tex_units;
    glGetIntegerv(GL_MAX_TEXTURE_UNITS, &tex_units);
    cout<<"Max Texture units: "<<tex_units<<endl;

    glfwSwapInterval(0); // Do not wait for screen refresh between frames

    GLuint errorID = glGetError();
    if(errorID != GL_NO_ERROR) {
        printf("\nOpenGL error: %s\n", gluErrorString(errorID));
        printf("Attempting to proceed anyway. Expect rendering errors or a crash.\n");
    }

    // Main loop
    while(running)
    {

        mousebtn=glfwGetMouseButton( GLFW_MOUSE_BUTTON_1 );

        if(mousebtn == GLFW_PRESS)
        {
            glfwDisable( GLFW_MOUSE_CURSOR );
            PlayerEntity::followMouse=true;
        }

        mousebtn=glfwGetMouseButton( GLFW_MOUSE_BUTTON_2 );
        if(mousebtn == GLFW_PRESS)
        {
            glfwEnable( GLFW_MOUSE_CURSOR );
            PlayerEntity::followMouse=false;
        }

        // Update the scene.
        SceneHandler::Update();

//        glm::vec3 minBBoxPoint = box->ClosestMeshBBoxPoint(0);
//        glm::vec3 dist = minBBoxPoint - Camera::getActiveCamera()->pos;
//        std::cout<<std::sqrt(glm::dot(dist,dist))<<std::endl;

        //bob.Update(SceneHandler::g_dt);

        camera.setUp();

        // Finally, draw the scene.
        SceneHandler::Render();
        //bob.Render();

        // Swap buffers, i.e. display the image and prepare for next frame.
        glfwSwapBuffers();

        // Check if the ESC key was pressed or the window was closed.
        if(glfwGetKey(GLFW_KEY_ESC) || !glfwGetWindowParam(GLFW_OPENED))
            running = GL_FALSE;
    }

    // Free the allocated resources
    SceneHandler::Destroy();

    return(0);
}
예제 #11
0
void Dragon_Dogs_ParticleSystem::Init(Scene * scene)
{

    StaticEntityPtr skyPtr = scene->AddStaticEntity("assets/sphere.smodel", "sky");
    StaticEntity * sky = skyPtr.Get();
    sky->Illuminate(false);
    sky->SetScale(10000, 10000, 10000);

    Material * m = sky->GetMaterial(0);
    m->SetDiffuseMap("assets/risinger.jpg");
    m->UseDiffuseMap(true);

    psPtr = scene->AddParticleSystem();
    ParticleSystem * ps = psPtr.Get();
    ps->SetColorTexture("assets/fire.png");
    ps->SetEmmiterPosition(Vector3(45.0f, 0.0f, 0.0f));
    ps->SetMinSpawnPosition(Vector3(-1.0f, 0.0f, 0.0f));
    ps->SetMaxSpawnPosition(Vector3(1.0f, 0.0f, 0.0f));
    ps->SetMaxLifeTime(70);
    ps->SetMinLifeTime(50);
    ps->SetMaxParticles(70);
    ps->SetSpawnTime(4.0);
    ps->SetMinSize(10);
    ps->SetMaxSize(14);
    ////entitiy->SetPosition(10.0f,0.0f,0.0f);


    drPtr = scene->AddParticleSystem();
    ps = drPtr.Get();

    ps->SetColorTexture("assets/fire.png");
    ps->SetEmmiterPosition(Vector3(-30.0f, 150.0, 10.0f));
    ps->SetMinSpawnPosition(Vector3(-0.2f, 0.3f, 0.0f));
    ps->SetMaxSpawnPosition(Vector3(0.2f, -0.3f, 0.0f));
    ps->SetMinSpawnVelocity(Vector3(-1.0f, -2.0f, -1.8f));
    ps->SetMaxSpawnVelocity(Vector3(1.0f, -2.0f, -1.0f));
    ps->SetMaxLifeTime(30);
    ps->SetMinLifeTime(45);
    ps->SetMaxParticles(70);
    ps->SetSpawnTime(4.0);
    ps->SetMinSize(10);
    ps->SetMaxSize(14);
    ps->AllowParticleAdd(false);

    plDragon = scene->AddPointLight();
    PointLight * plD = plDragon.Get();
    plD->SetDiffuse(1.0f, 0.4f, 0.0f, 1.0f);
    plD->SetRange(1.0f);
    plD->SetPosition(-30.0f, 150.0, 10.0f);

    dragonTime = 0;
    dragonOn = false;
    enPtr = scene->AddAnimatedEntity("assets/ninja.model", "ninja");

    AnimatedEntity * en = enPtr.Get();
    en->SetPosition(0.0f, 0.0f, 0.0f);
    en->Illuminate(true);
    en->SetScale(10.0f, 10.0f, 10.0f);
    en->SetPosZ(-100);
    //en->SetRotationY(90.0f);

    Material * mat = en->GetMaterial(0);
    mat->UseDiffuseMap(true);
    mat->SetDiffuseColor(Color::White());
    mat->SetDiffuseMap("assets/nskin.jpg");

    mat->SetEmmisivePower(1);
    mat->SetSpecularPower(0);
    mat->SetSpecularIntesity(0);

    mat = en->GetMaterial(1);
    mat->UseDiffuseMap(false);
    mat->SetEmmisivePower(1);
    mat->SetSpecularIntesity(0);
    mat->SetSpecularPower(0);
    mat->SetDiffuseColor(Color(0.3f, 0.3f, 0.3f, 1.0f));

    pointLight = scene->AddPointLight();

    PointLight * p = pointLight.Get();
    p->SetDiffuse(1.0f, 0.4f, 0.0f, 1.0f);
    p->SetRange(500.0f);
    p->SetPosition(45.0f, 4.0f, 0.0f);

    planePtr = scene->AddStaticEntity("assets/plane.model", "plane");
    StaticEntity * plane = planePtr.Get();
    plane->Illuminate(true);
    plane->SetScale(500.0f, 1.0f, 500.0f);

    Material * pMat = plane->GetMaterial(0);
    pMat->UseDiffuseMap(false);
    pMat->SetDiffuseColor(Color(0.3f, 0.3f, 0.3f, 1.0f));
    pMat->SetEmmisivePower(1);
    pMat->SetSpecularPower(0);
    pMat->SetSpecularIntesity(0);

    plane->SetPosition(0.0f, -7.0f, 0.0f);

    dogPtr = scene->AddStaticEntity("assets/dog.smodel", "dog");
    StaticEntity * dog = dogPtr.Get();
    dog->Illuminate(true);
    dog->SetPosition(80.0f, 10.0, 60.0f);
    dog->SetScale(400.0f, 400.0f, 400.0f);
    dog->SetRotation(0.0f, 60.0f, 180.0f);
    dog->SetRotationY(45.0f);

    pMat = dog->GetMaterial(0);
    pMat->SetDiffuseColor(Color(0.2f, 0.2f, 0.2f, 1.0f));

    dogPtr2 = scene->AddStaticEntity("assets/dog.smodel", "dog");
    dog = dogPtr2.Get();

    dog->Illuminate(true);
    dog->SetPosition(-100.0f, 10.0, 60.0f);
    dog->SetScale(400.0f, 400.0f, 400.0f);
    dog->SetRotation(0.0f, -60.0f, 180.0f);
    //dog->SetRotationY(45.0f);

    pMat = dog->GetMaterial(0);
    pMat->SetDiffuseColor(Color(0.2f, 0.0f, 0.0f, 1.0f));

    lightChangeTime = 0.0f;

    powerMin = 0.6f;
    powerMax = 1.0f;

    animContr = enPtr.Get()->LoadAnimationFromFile("assets/ninja.anim", "animPack");
    enPtr.Get()->SetCurrentAnimationController(animContr);
    animContr->AddAnimationState(0, 14, LOOP, "idle");
    animContr->SetCurrentAnimationState("idle");

    torchPtr = scene->AddStaticEntity("assets/smaug.smodel", "m24");
    StaticEntity * torch = torchPtr.Get();
    torch->SetPosition(-30.0f, 100.0, 70.0f);
    torch->SetScale(3.0f, 3.0f, 3.0f);
    torch->Illuminate(true);

    mat = torch->GetMaterial(0);
    mat->SetEmmisivePower(1);
    mat->SetSpecularPower(1);

    treePtr = scene->AddStaticEntity("assets/tree.smodel", "tree");
    StaticEntity * tree = treePtr.Get();

    tree->SetPosition(150.0f, 23.0f, 0.0f);
    tree->SetScale(10.0f, 10.0f, 10.0f);
    tree->Illuminate(true);


    mat = tree->GetMaterial(0);
    mat->UseDiffuseMap(true);
    mat->SetDiffuseMap("assets/w3.jpg");

    swordPtr = scene->AddStaticEntity("assets/sword.smodel", "sword");
    StaticEntity * sword = swordPtr.Get();
    sword->SetPosition(150.0f, 80.0f, 0.0f);
    sword->Illuminate(false);
    sword->SetScale(2.0f, 2.0f, 2.0f);
    sword->SetRotationZ(180.0f);
    mat = sword->GetMaterial(0);
    mat->UseDiffuseMap(false);
    mat->SetDiffuseColor(Color::White());
    mat->SetEmmisivePower(20);


}