Пример #1
0
void Mesh_File_Reader::load(
    Meshes & final_meshes,
    const std::set<Label> & names,
    bool load_vertices,
    bool load_triangles,
    bool load_mapping,
    bool load_triangle_strips)
{
    Meshes meshes;
    for (std::set<Label>::const_iterator name = names.begin();
         name != names.end();
         ++name) {
        insert_new_or_updated(*name, final_meshes, meshes,
                              load_vertices, load_triangles, 
                              load_triangle_strips, load_mapping);
    }

    // Final insertion from local container to result
    for (Meshes::iterator i = meshes.begin();
         i != meshes.end();
         ++i)
    {
        // This insertion replaces old existing meshes with its updated 
        // version also
        final_meshes.insert(i.label(), i.ptr());
    }
}
Пример #2
0
    void Geometry::import_meshes(const Meshes& m) {
        meshes_.clear();
        vertices_.clear();
        unsigned n_vert_max = 0;
        unsigned iit = 0;
        std::map<const Vertex *, Vertex *> map_vertices;

        // count the vertices
        for (Meshes::const_iterator mit=m.begin();mit!=m.end();++mit)
            n_vert_max += mit->nb_vertices();
        
        vertices_.reserve(n_vert_max);
        meshes_.reserve(m.size());

        for (Meshes::const_iterator mit=m.begin();mit!=m.end();++mit,++iit) {
            meshes_.push_back(Mesh(vertices_,mit->name()));
            for (Mesh::const_vertex_iterator vit=mit->vertex_begin();vit!=mit->vertex_end();vit++) {
                meshes_[iit].add_vertex(**vit);
                map_vertices[*vit] = *meshes_[iit].vertex_rbegin();
            }
        }

        // Copy the triangles in the geometry.
        iit = 0;
        for (Meshes::const_iterator mit=m.begin();mit!=m.end();++mit,++iit) {
            for (Mesh::const_iterator tit=mit->begin();tit!=mit->end();++tit)
                meshes_[iit].push_back(Triangle(map_vertices[(*tit)[0]], 
                                                map_vertices[(*tit)[1]], 
                                                map_vertices[(*tit)[2]]));
            meshes_[iit].update();
        }
    }
Пример #3
0
void Mesh_File_Reader::load(
    Meshes & final_meshes,
    const Cell_Target & cells, 
    const URI & circuit_source,
    bool load_vertices,
    bool load_triangles,
    bool load_mapping,
    bool load_triangle_strips)
{
    Meshes meshes;

    boost::filesystem::path mvd_file = uri_to_filename(circuit_source);
    if (mvd_file == "" || boost::filesystem::extension(mvd_file) != ".mvd2")
    {
        throw_exception(Bad_Data_Source("Loading meshes: circuit_source '" + 
                                        circuit_source + "' "), 
                        FATAL_LEVEL, __FILE__, __LINE__);
    }
    MVD_File_Parser mvd_parser(mvd_file);

    mvd_parser.parse_file(cells);
    for (Cell_Target::iterator cell_gid = cells.begin(); 
         cell_gid != cells.end();
         ++cell_gid)
    {
        MVD_Cell_Index index = mvd_parser.cell_index(*cell_gid);
        if (index == UNDEFINED_MVD_CELL_INDEX)
        {
            std::stringstream msg;
            msg << "Loading meshes: bad cell target, neuron gid " 
                << *cell_gid << " not in mvd file '" << mvd_file << "'";
            throw_exception(Bad_Data(msg.str()), 
                            FATAL_LEVEL, __FILE__, __LINE__);
        }

        const Label & label = mvd_parser.morphology_names()[index];
        if (meshes.find(label) == meshes.end())
        {
            insert_new_or_updated(label, final_meshes, meshes, 
                                  load_vertices, load_triangles,
                                  load_triangle_strips, load_mapping);
        }
    }

    // Final insertion from local container to result
    for (Meshes::iterator i = meshes.begin();
         i != meshes.end();
         ++i)
    {
        // This insertion replaces old existing meshes with its updated 
        // version also
        final_meshes.insert(i.label(), i.ptr());
    }
}
Пример #4
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	dInstance = hInstance;
	// Windows structure
	WNDCLASSEX wcex;
	ZeroMemory(&wcex, sizeof(wcex));

    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = dInstance;
    wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = NULL;
    wcex.lpszClassName  = "gameDemoWindow";
    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));

	// register a new type of window
	if (!RegisterClassEx(&wcex))
    {
        MessageBox(
        NULL,
        "Window Error",
        "Could not create window",
        NULL);
    }

	static TCHAR szWindowClass[] = "gameDemoWindow";
	static TCHAR szTitle[] = "Game Demo";

	hWnd = CreateWindow(
		szWindowClass,
		szTitle,
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT,
		1920, 1080,
		NULL,
		NULL,
		dInstance,
		NULL);


	// Display the window
	ShowWindow(hWnd,nCmdShow);
	UpdateWindow(hWnd);

	int width;
	int height;
	bool windowed;

	

	
	//create engine, using MainCore
	MainCore* main_core = new MainCore();
	main_core->Startup(hWnd);

	//create pointer to access each core through MainCore
	AISystem* ai_core = main_core->GetAIManager();
	Sound* sound_core = main_core->GetAudioCoreSound();
	SoundEffect* sfx_core = main_core->GetAudioCoreSoundEffect();
	PhysicsInterface* physics_core = main_core->GetPhysicsManager();
	Input* input_core = main_core->GetInputManager();
	UI* ui_core = main_core->GetUIManager();
	ScriptingCore* script_core = main_core->GetScriptManager();
	EntityManager* entity_core = main_core->GetEntityManager();
	Clock* clock_manager = main_core->GetClock();

	width = script_core->width;
	height = script_core->height;
	windowed = true;
	Init(width, height);
	/*
	TO DO IN CASE 2
	setup UI and Graphics for game logic
	*/
	//load music stream
	sound_core->Load("Song1.ogg");
	//load sound effect
	sfx_core = new SoundEffect("Jump.wav"); //#5 to play
			
	//variables used for entity setups
	LPCSTR fileName;
	float pos[3];
	float rot[3];
	float scale[3];
	for(int i = 0; i < 3; i++)
	{
		pos[i] = 0;
		rot[i] = 0;
		scale[i] = .1;
	}
	rot[0] = 180;

	//setup for player
	//DO SOMETHING HERE
	Entity* player;
	player = new Entity;
	player->SetEntity("player", "player");
	//REPLACE 0'S WITH POSITION VALUES
	pos[0] = -3, pos[1] = 2.5, pos[2] = 20;
	scale[0] = .1, scale[1] = .1, scale[2] = .1; 
	player->agentData.setPosition(pos);
	player->agentData.setRotation(rot);
	player->agentData.setScale(scale);
	physics_core->setAABB(D3DXVECTOR3(-3, 2.5, 20), D3DXVECTOR3(-3.01, 2.51, 20.01), true, "player");
	ai_core->regeisterPlayer(&player->agentData);

	//setup for enemy
	//DO SOMETHING HERE
	Entity* enemy;
	enemy = new Entity;
	enemy->SetEntity("enemy", "basic");
	//REPLACE 0'S WITH POSITION VALUES
	pos[0] = -3, pos[1] = 2.5, pos[2] = 20;
	scale[0] = .1, scale[1] = .1, scale[2] = .1; 
	enemy->agentData.setPosition(pos);
	enemy->agentData.setRotation(rot);
	enemy->agentData.setScale(scale);
	physics_core->setAABB(D3DXVECTOR3(-3, 2.5, 20), D3DXVECTOR3(-3.01, 2.51, 20.01), true, "enemy");
	ai_core->registerAgent(&enemy->agentData); //look at removing the 0 here for a behavior isnt needed as AI sits, it automatically cycles through all states of an enemy already
			
			
	//setup for platforms
	//DO SOMETHING HERE
	Entity* platform;
	platform = new Entity;
	platform->SetEntity("platform", "platform");
	//REPLACE 0'S WITH POSITION VALUES
	pos[0] = 0, pos[1] = 0, pos[2] = 20; //THIS WILL MOST LIKELY BE REMOVED AS MULTIPLE PLATFORMS NEED DIFFERENT POSITION AND ROTATION VALUES, DO BEFORE RENDERING WHEN CREATEING MULTIPLES OF THIS MESH
	scale[0] = 100, scale[1] = .01, scale[2] = .1; 
	platform->agentData.setPosition(pos);
	platform->agentData.setRotation(rot);
	platform->agentData.setScale(scale);
	physics_core->setAABB(D3DXVECTOR3(0, 0, 20), D3DXVECTOR3(0.01, 0.01, 20.01), true,  "platform");
	
	//load the mesh model to use
	Meshes cube;
	cube.load_meshes("cube.X", pD3DDevice);
	//cube.set_meshes(pos, rot, scale);
	//camera setup
	//DO SOMETHING HERE
	Camera camera;
	camera.Init();
	camera.SetAR(width, height);
	
	//tex to use to write
	Text gText;
	D3DXCreateFont(pD3DDevice, 30, 0, FW_BOLD, 0, false, 
                  DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY,
                  DEFAULT_PITCH | FF_DONTCARE, TEXT("Times New Roman"), 
                  &pFont);
	gText.Init(22, pD3DDevice);

	//light setup
	//DO SOMETHING HERE
	//graphics_core->PointLight(
		//D3DXVECTOR3(/*FILL IN*/),	//position
		//D3DXCOLOR(1, 1, 1, 1),		//diffuse
		//D3DXCOLOR(1, 1, 1, 1));		//ambient
			
			
			
	/*
	TEST THIS CHANGE WHERE NEEDED IF NEEDED
	Z AXIS LOCKED AT 50 FOR PLAYER AND GAME OBJECTS
	Z AXIS LOCKED AT 10 FOR CAMERA
	X AXIS AT 100 FOR BASE LINE OF DEMO
	X AXIS MATCHING PLAYER FOR CAMERA
	Y AXIS AT 100 FOR BASE LINE OF DEMO
	Y AXIS + 25 ABOVE PLAYER
	*/
	//variables for game loop
	bool jump;
	jump = false;
	float time;
	int gameState = 1;
	/*
	gamestate to tell the engine what state the game is in. Menu, Game Logic, Credtis, etc.
	swtich cases to switch between the different states running the appropiate functions
	state 1 - Menu
	state 2 - Game Logic
	state 3 - Credits
	state 4 - shutdown application
	*/
	MSG  msg;
    msg.message = WM_NULL;
	char str[128];
	RECT rect;
	sound_core->Play(false);
	if(clock_manager->GetFPS() < 60)
	{
		while(msg.message != WM_QUIT)
		{
			// If there are Window messages then process them.
			if(PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
			{
		       TranslateMessage( &msg );
		        DispatchMessage( &msg );
			}
			// Otherwise, do animation/game stuff.
			else
	     {
				switch(gameState)
				{
				case (1)://menu state
					/*
					TO DO IN CASE 1
					setup menu with UI and Graphics
					update
					render
					loop till user input to change gamestate
					*/
					//DO SOMETHING HERE
					
					pD3DDevice->BeginScene();
					pD3DDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0) , 1.0f, 0);
				
					GetClientRect(hWnd, &rect);
					sprintf(str, "Engine Demo");
					pFont->DrawText(NULL, str, -1, &rect,
							DT_TOP | DT_CENTER | DT_NOCLIP , D3DCOLOR_ARGB(255, 
							255, 
							255, 
							255			
							));
					gText.DisplayText("Play Demo - (1)", width / 2, height * 0.25f, 50, 25, WHITE);
					gText.DisplayText("Credits - (2)", width / 2, height * 0.5f, 50, 25, WHITE);
					gText.DisplayText("Exit Demo - (3)", width / 2, height * 0.75f, 50, 25, WHITE);
					pD3DDevice->EndScene();
					pD3DDevice->Present(0, 0, 0, 0);
					main_core->Update(enemy, gameState);
					if(input_core->OnePressed())
					{
						gameState = 2;
					}

					if(input_core->TwoPressed())
					{
						gameState = 3;
					}

					if(input_core->ThreePressed())
					{
						gameState = 4;
					}

					break;
				case (2)://game logic state
					float temp[3];
					float temp2[3];
					player->agentData.getPosition(temp);
					if(temp[1] <= 101)
						jump = false;

					if(input_core->EscPressed()) gameState = 1;

					if(input_core->APressed())
					{
						player->agentData.getPosition(temp);
						player->agentData.getAcceleration(temp2);
						temp[0] -= .2f;
						player->agentData.setPosition(temp);
						sfx_core->Play();
						/*
						temp2[0] -= .1f;
						physics_core->setAccel(temp2, "player");
						D3DXVECTOR3 vec;
						vec = physics_core->getVel("player");
						player->agentData.setAcceleration(temp2);
						temp[0] += vec.x;
						temp[1] += vec.y;
						temp[2] += vec.z;
						player->agentData.setPosition(temp);
						*/
					}

					if(input_core->DPressed())
					{
						player->agentData.getPosition(temp);
						player->agentData.getAcceleration(temp2);
						temp[0] += .2f;
						player->agentData.setPosition(temp);
						sfx_core->Play();
						/*
						temp2[0] += .1f;
						physics_core->setAccel(temp2, "player");
						D3DXVECTOR3 vec;
						vec = physics_core->getVel("player");
						player->agentData.setAcceleration(temp2);
						temp[0] += vec.x;
						temp[1] += vec.y;
						temp[2] += vec.z;
						player->agentData.setPosition(temp);
						*/
					}

					if(!jump)
					{
						if(input_core->SpaceBar())
						{
							jump = true;
							player->agentData.getPosition(temp);
							player->agentData.getAcceleration(temp2);
							/*
							temp2[1] += 1.0f;
							physics_core->setAccel(temp2, "player");
							D3DXVECTOR3 vec;
							vec = physics_core->getVel("player");
							player->agentData.setAcceleration(temp2);
							temp[0] += vec.x;
							temp[1] += vec.y;
							temp[2] += vec.z;
							player->agentData.setPosition(temp);
							*/
						}
					}

					//update
					main_core->Update(enemy, gameState);

for(int i = 0; i < physics_core->Core._collisions->length();i++)
{
//Pop the next collision off the stack:
physics_core->Core._collisions->getNext();
msgbuffer << physics_core->Core._collisions->currentCollision.boxA_ID;
msgbuffer << " is colliding with ";
msgbuffer << physics_core->Core._collisions->currentCollision.boxB_ID;
msgbuffer << "!\n";

char * tempString = new char[msgbuffer.str().length() + 1];
strcpy(tempString, msgbuffer.str().c_str());
//Sample collision handling (this just prints which box ID's are colliding in the output window in visual studio)
OutputDebugString(tempString);
}
				
					if (Wireframe)
					{
						pD3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
					}
					else
					{
						pD3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
					}
					pD3DDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0) , 1.0f, 0);
					camera.dxSetProjection(pD3DDevice);
					camera.dxSetView(pD3DDevice);
					pD3DDevice->BeginScene();

					enemy->agentData.getPosition(pos);
					enemy->agentData.getScale(scale);
					enemy->agentData.getRotation(rot);
					cube.set_meshes(pos, rot, scale);
					cube.draw_meshes(pD3DDevice);

					player->agentData.getPosition(pos);
					player->agentData.getScale(scale);
					player->agentData.getRotation(rot);
					cube.set_meshes(pos, rot, scale);
					cube.draw_meshes(pD3DDevice);

					platform->agentData.getPosition(pos);
					platform->agentData.getScale(scale);
					platform->agentData.getRotation(rot);
					cube.set_meshes(pos, rot, scale);
					cube.draw_meshes(pD3DDevice);

					GetClientRect(hWnd, &rect);
					sprintf(str, "GSP 420 Running Demo");
					pFont->DrawText(NULL, str, -1, &rect,
							DT_TOP | DT_LEFT | DT_NOCLIP , D3DCOLOR_ARGB(255, 
							255, 
							255, 
							255			
							));
					pD3DDevice->EndScene();
					pD3DDevice->Present(0, 0, 0, 0);
					break;
				case (3)://credits state
					//setup credits with UI and Graphics
					//loop till gameState changes
					//update
					pD3DDevice->BeginScene();
					pD3DDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(122, 0, 0) , 1.0f, 0);
				
					GetClientRect(hWnd, &rect);

					pFont->DrawText(NULL, str, -1, &rect,
							DT_TOP | DT_CENTER | DT_NOCLIP , D3DCOLOR_ARGB(255, 
							255, 
							255, 
							255			
							));

					gText.DisplayText("CREDITS:", width / 2, 35, 50, 25, WHITE);

					for (int i = 0; i < AUTHORS; i++)
					{
						gText.DisplayText(authors[i], width / 2, i * 25 + 60, 100, 10, WHITE);
					}

				
					pD3DDevice->EndScene();
					pD3DDevice->Present(0, 0, 0, 0);
					main_core->Update(enemy, gameState);

					if(input_core->EscPressed()) gameState = 1;

					break;
				case (4):	//shutdown application
					//shutdown
					main_core->Shutdown();
					pD3DDevice->Release();
					pD3DObject->Release();
					//destroy application
					msg.message = WM_QUIT;
					break;
				}
			}	
		}
		return (int)msg.wParam;
	}
}
Пример #5
0
void Mesh_File_Reader::insert_new_or_updated
(const std::string & name, Meshes & final_meshes, Meshes & meshes,
 bool load_vertices, bool load_triangles, bool load_triangle_strips,
 bool load_mapping)
{
    Mesh_Ptr mesh;
    
    // Serching if the mesh already exists
    Meshes::iterator old_mesh = final_meshes.find(name);
    if (old_mesh != final_meshes.end())
    {
        bool needs_vertices = 
            load_vertices && old_mesh->vertices().pointer() == 0;
        bool needs_triangles = 
            load_triangles && old_mesh->triangles().pointer() == 0;
        bool needs_triangle_strips = 
            load_triangle_strips && old_mesh->triangle_strip().pointer() == 0;
        bool needs_mapping = 
            load_mapping && old_mesh->vertex_sections().pointer() == 0;
        
        if (needs_vertices || needs_triangles || 
            needs_triangle_strips || needs_mapping)
        {
            // Loading missing datasets into mesh variable
            mesh = read(name, needs_vertices, needs_triangles, 
                        needs_triangle_strips, needs_mapping);

            // Add data not loaded from original mesh (if it has it)
            if (!needs_vertices)
            {
                vertices(*mesh) = vertices(*old_mesh);
                vertex_count(*mesh) = vertex_count(*old_mesh);
            }
            if (!needs_triangles)
            {
                triangles(*mesh) = triangles(*old_mesh);
                triangle_count(*mesh) = triangle_count(*old_mesh);
            }
            if (!needs_triangle_strips)
            {
                triangles(*mesh) = triangles(*old_mesh);
                triangle_count(*mesh) = triangle_count(*old_mesh);
            }
            if (!needs_mapping)
            {
                vertex_sections(*mesh) = vertex_sections(*old_mesh);
                vertex_relative_distances(*mesh) = 
                    vertex_relative_distances(*old_mesh);
            }
            normals(*mesh) = normals(*old_mesh);
        }
    }
    else
    {
        mesh = read(name, load_vertices, load_triangles, 
                    load_triangle_strips, load_mapping);
    }

    // Checking if something new has been read
    if (mesh.get() == 0)
        return;

    // computing additionnal data from the raw data if needed
    if (mesh->vertices().pointer() != 0 && 
        (mesh->triangles().pointer() != 0 || 
         mesh->triangle_strip().pointer() != 0) && 
        mesh->normals().pointer() == 0)
    {
        compute_per_vertex_normals(*mesh);
    }

    // Writing binary file if the whole mesh has been loaded and the binary
    // file doesn't exist yet.
    Filename binary_filename(_mesh_path / (name + ".bin"));    
    if(!boost::filesystem::exists(binary_filename)) 
    {
        if (mesh->vertices().pointer() != 0 && 
            mesh->triangles().pointer() != 0 && 
            mesh->triangle_strip().pointer() != 0 &&
            mesh->vertex_sections().pointer() != 0)
        {
            try
            {
                Mesh_Binary_File_Writer writer;
                writer.write_mesh(binary_filename, *mesh);
            } 
            catch (IO_Error)
            {
                std::cerr << "Error when writing the Binary file !\n";
            }
        }
    }

    if (old_mesh == final_meshes.end())
    {
        final_meshes.insert(name, mesh);
    }
    else
    {
        vertices(*old_mesh) = vertices(*mesh);
        vertex_count(*old_mesh) = vertex_count(*mesh);
        triangles(*old_mesh) = triangles(*mesh);
        triangle_count(*old_mesh) = triangle_count(*mesh);
        vertex_sections(*old_mesh) = vertex_sections(*mesh);
        vertex_relative_distances(*old_mesh) = vertex_relative_distances(*mesh);
        normals(*old_mesh) = normals(*mesh);
    }
}