Graphics::Graphics(HWND outputWindow, int width, int height) : width(width), height(height) { initializeDirect3d11App(outputWindow, width, height); light.diffuse = 0.6; light.ambient = XMFLOAT4(0.3, 0.3, 0.3, 0.0); light.position = XMFLOAT3(3.0, 7.0, 10.0); Model *bunny = loadObjModel("resources\\bunny.3dobj", 0.01); Model *cube = createCube(); Model *allModel = concatModel(createCube(), bunny, 3, 0, 0); model = bunny; initCamera(); initPass(); initDebugPass(); XMMATRIX trans = XMMatrixTranslation(3, 0, 0); XMFLOAT4X4 transMatrix; XMStoreFloat4x4(&transMatrix, trans); pass->setWorldMatrix(transMatrix); skyMapPass = new SkyMapPass(device, context, camera, defaultRenderTarget); skyMapPass->init("resources\\skymap.dds", width, height); renderDepthPass = new RenderDepthPass(device, context, camera, depthRenderTarget); renderDepthPass->init(allModel, &light, width, height); shadowMapPass = new ShadowMapPass(device, context, camera, defaultRenderTarget); shadowMapPass->init(createPlane(), &light, "resources\\grass.jpg", depthRenderTarget->getTexture(), width, height); normalMapPass = new NormalMapPass(device, context, camera, defaultRenderTarget); normalMapPass->init(createCube(), "resources\\brick_bump.jpg", "resources\\brick.jpg", &light, width, height); // instances InstanceType* instances = new InstanceType[2]; instances[0].offset = XMFLOAT3(1, 0, 0); instances[1].offset = XMFLOAT3(5, 0, 0); ModelInstance *twoCube = new ModelInstance(*createCube(), instances, 2); instancesPass = new InstancesPass(device, context, camera, defaultRenderTarget); instancesPass->init(twoCube, width, height); }
ObjFileReader::ObjFileReader(std::string path) : file_path(path), vertex_data(std::vector<vec3>()), normal_data(std::vector<vec3>()), texcoords_data(std::vector<vec3>()), vertex_face(std::vector<face>()), normal_face(std::vector<face>()), texcoords_face(std::vector<face>()), normal_r(std::vector<vec3>()), texcoords_r(std::vector<vec3>()), poly_count(0), num_materials(0) { std::string dir = "../Test Files/Meshes/"; loadObjModel(dir.append(path)); //ensureIndices(); //ensureNormals(all_buffers); //most recently uncommented: //ensureNormalsFlat(all_buffers); //setVertexIndices(all_buffers); //most recently uncommented: //setVerticesFlat(all_buffers); //bufferMemory(all_buffers); std::vector< std::pair<IndexBuffer, std::string> >::iterator iter; int num_tris = 0; int num_absolute_tris = all_buffers.vertex_face.size(); for (iter = component_indices.begin(); iter != component_indices.end(); iter++) { num_tris += iter->first.vertex_face.size(); } //Check to see that all of the triangles are represented in components if (num_tris != num_absolute_tris) { std::cout << "Inconsistent triangle counts, sum of the components not equal to absolute count." << std::endl; } for (iter = component_indices.begin(); iter != component_indices.end();) { if (iter->first.vertex_face.size() == 0) { iter = component_indices.erase(iter); } else iter++; } num_tris = 0; num_absolute_tris = all_buffers.vertex_face.size(); for (iter = component_indices.begin(); iter != component_indices.end(); iter++) { num_tris += iter->first.vertex_face.size(); } //Check to see that all of the triangles are represented in components if (num_tris != num_absolute_tris) { std::cout << "Inconsistent triangle counts, sum of the components not equal to absolute count." << std::endl; } }