void SpaceshipGame::initializeEnvironment() { Material* material; std::vector<Node*> nodes; // Setup ground model _scene->findNodes("pGround", nodes, true, false); for (unsigned int i = 0, count = nodes.size(); i < count; ++i) { Node* pGround = nodes[i]; material = pGround->getModel()->setMaterial("res/shaders/colored-specular.vsh", "res/shaders/colored-specular.fsh"); material->getParameter("u_diffuseColor")->setValue(Vector4(0.280584f, 0.5584863f, 0.6928f, 1.0f)); initializeMaterial(material, true, true); } // Setup roof model nodes.clear(); _scene->findNodes("pRoof", nodes, true, false); for (unsigned int i = 0, count = nodes.size(); i < count; ++i) { Node* pRoof = nodes[i]; material = pRoof->getModel()->setMaterial("res/shaders/colored-specular.vsh", "res/shaders/colored-specular.fsh"); material->getParameter("u_diffuseColor")->setValue(Vector4(0.280584f, 0.5584863f, 0.6928f, 1.0f)); initializeMaterial(material, true, true); } // Setup background model nodes.clear(); Node* pBackground = _scene->findNode("pBackground"); material = pBackground->getModel()->setMaterial("res/shaders/diffuse.vsh", "res/shaders/diffuse.fsh"); material->getParameter("u_diffuseTexture")->setValue("res/background.png", true); initializeMaterial(material, true, false); }
void SpaceshipGame::initializeEnvironment() { Material* material; std::vector<Node*> nodes; // Setup ground model _scene->findNodes("pGround", nodes, true, false); for (size_t i = 0, count = nodes.size(); i < count; ++i) { Node* pGround = nodes[i]; material = pGround->getModel()->setMaterial("res/shaders/colored.vert", "res/shaders/colored.frag", "SPECULAR;DIRECTIONAL_LIGHT_COUNT 1"); material->getParameter("u_diffuseColor")->setValue(Vector4(0.280584f, 0.5584863f, 0.6928f, 1.0f)); initializeMaterial(material, true, true); } // Setup roof model nodes.clear(); _scene->findNodes("pRoof", nodes, true, false); for (size_t i = 0, count = nodes.size(); i < count; ++i) { Node* pRoof = nodes[i]; material = pRoof->getModel()->setMaterial("res/shaders/colored.vert", "res/shaders/colored.frag", "SPECULAR;DIRECTIONAL_LIGHT_COUNT 1"); material->getParameter("u_diffuseColor")->setValue(Vector4(0.280584f, 0.5584863f, 0.6928f, 1.0f)); initializeMaterial(material, true, true); } // Setup background model nodes.clear(); Node* pBackground = _scene->findNode("pBackground"); material = pBackground->getModel()->setMaterial("res/shaders/textured.vert", "res/shaders/textured.frag", "DIRECTIONAL_LIGHT_COUNT 1"); material->getParameter("u_diffuseTexture")->setValue("res/background.png", true); initializeMaterial(material, true, false); }
bool SceneViewer::initializeScene(Node* node) { Model* model = dynamic_cast<Model*>(node->getDrawable()); if (model) { if (model->getMeshPartCount() > 0) { for (int i = 0; i < model->getMeshPartCount(); i++) { if (model->getMaterial(i)) { initializeMaterial(_scene, node, model->getMaterial(i)); } } } /*else { if (model->getMaterial()) { initializeMaterial(_scene, node, model->getMaterial()); } }*/ } return true; }
FORCEINLINE void TVoxelData::setVoxelPointMaterial(int x, int y, int z, unsigned short material) { if (material_data == NULL) { initializeMaterial(); } const int index = clcLinearIndex(x, y, z); material_data[index] = material; }
bool CharacterGame::initializeScene(Node* node) { Model* model = node->getModel(); if (model && model->getMaterial()) { initializeMaterial(_scene, node, model->getMaterial()); } return true; }
void SpaceshipGame::initializeSpaceship() { Material* material; _shipGroupNode = _scene->findNode("gSpaceShip"); // Setup spaceship model // Part 0 _shipNode = _scene->findNode("pSpaceShip"); material = _shipNode->getModel()->setMaterial("res/shaders/colored-specular.vsh", "res/shaders/colored-specular.fsh", NULL, 0); material->getParameter("u_diffuseColor")->setValue(Vector4(0.53544f, 0.53544f, 0.53544f, 1.0f)); initializeMaterial(material, true, true); // Part 1 material = _shipNode->getModel()->setMaterial("res/shaders/colored-specular.vsh", "res/shaders/colored-specular.fsh", NULL, 1); material->getParameter("u_diffuseColor")->setValue(Vector4(0.8f, 0.8f, 0.8f, 1.0f)); _shipSpecularParameter = material->getParameter("u_specularExponent"); initializeMaterial(material, true, true); // Part 2 material = _shipNode->getModel()->setMaterial("res/shaders/colored-specular.vsh", "res/shaders/colored-specular.fsh", NULL, 2); material->getParameter("u_diffuseColor")->setValue(Vector4(0.280584f, 0.5584863f, 0.6928f, 1.0f)); initializeMaterial(material, true, true); // Setup spaceship propulsion model _propulsionNode = _scene->findNode("pPropulsion"); material = _propulsionNode->getModel()->setMaterial("res/shaders/colored-specular.vsh", "res/shaders/colored-specular.fsh"); material->getParameter("u_diffuseColor")->setValue(Vector4(0.8f, 0.8f, 0.8f, 1.0f)); initializeMaterial(material, true, true); // Glow effect node _glowNode = _scene->findNode("pGlow"); material = _glowNode->getModel()->setMaterial("res/shaders/textured.vsh", "res/shaders/textured.fsh"); material->getParameter("u_diffuseTexture")->setValue("res/propulsion_glow.png", true); _glowDiffuseParameter = material->getParameter("u_diffuseColor"); initializeMaterial(material, false, false); // Setup the sound _spaceshipSound = AudioSource::create("res/spaceship.wav"); if (_spaceshipSound) { //_spaceshipSound->setGain(0.5f); _spaceshipSound->setLooped(true); } }
FORCEINLINE void TVoxelData::setMaterial(const int x, const int y, const int z, const unsigned short material) { if (material_data == NULL) { initializeMaterial(); } if (x < voxel_num && y < voxel_num && z < voxel_num) { const int index = clcLinearIndex(x, y, z); material_data[index] = material; } }
void SpaceshipGame::initializeSpaceship() { Material* material; _shipGroupNode = _scene->findNode("gSpaceShip"); // Setup spaceship model // Part 0 _shipNode = _scene->findNode("pSpaceShip"); material = dynamic_cast<Model*>(_shipNode->getDrawable())->setMaterial("res/shaders/colored.vert", "res/shaders/colored.frag", "SPECULAR;DIRECTIONAL_LIGHT_COUNT 1", 0); material->getParameter("u_diffuseColor")->setValue(Vector4(0.53544f, 0.53544f, 0.53544f, 1.0f)); initializeMaterial(material, true, true); // Part 1 material = dynamic_cast<Model*>(_shipNode->getDrawable())->setMaterial("res/shaders/colored.vert", "res/shaders/colored.frag", "SPECULAR;DIRECTIONAL_LIGHT_COUNT 1", 1); material->getParameter("u_diffuseColor")->setValue(Vector4(0.8f, 0.8f, 0.8f, 1.0f)); _shipSpecularParameter = material->getParameter("u_specularExponent"); initializeMaterial(material, true, true); // Part 2 material = dynamic_cast<Model*>(_shipNode->getDrawable())->setMaterial("res/shaders/colored.vert", "res/shaders/colored.frag", "SPECULAR;DIRECTIONAL_LIGHT_COUNT 1", 2); material->getParameter("u_diffuseColor")->setValue(Vector4(0.280584f, 0.5584863f, 0.6928f, 1.0f)); initializeMaterial(material, true, true); // Setup spaceship propulsion model _propulsionNode = _scene->findNode("pPropulsion"); material = dynamic_cast<Model*>(_propulsionNode->getDrawable())->setMaterial("res/shaders/colored.vert", "res/shaders/colored.frag", "SPECULAR;DIRECTIONAL_LIGHT_COUNT 1"); material->getParameter("u_diffuseColor")->setValue(Vector4(0.8f, 0.8f, 0.8f, 1.0f)); initializeMaterial(material, true, true); // Glow effect node _glowNode = _scene->findNode("pGlow"); material = dynamic_cast<Model*>(_glowNode->getDrawable())->setMaterial("res/shaders/textured.vert", "res/shaders/textured.frag", "MODULATE_COLOR"); material->getParameter("u_diffuseTexture")->setValue("res/propulsion_glow.png", true); _glowDiffuseParameter = material->getParameter("u_modulateColor"); initializeMaterial(material, false, false); // Setup the sound _spaceshipSound = AudioSource::create("res/spaceship.wav"); if (_spaceshipSound) { _spaceshipSound->setLooped(true); } }
bool GameObjectManager::initializeNodeMaterials(Node* node) { Model* model = dynamic_cast<Model*>(node->getDrawable()); if (model) { for (int i = 0; i < (int)model->getMeshPartCount(); i++) { initializeMaterial(node, model->getMaterial(i)); } } return true; }
FORCEINLINE void TVoxelData::setVoxelPoint(int x, int y, int z, unsigned char density, unsigned short material) { if (density_data == NULL) { initializeDensity(); density_state = TVoxelDataFillState::MIXED; } if (material_data == NULL) { initializeMaterial(); } const int index = clcLinearIndex(x, y, z); material_data[index] = material; density_data[index] = density; }
void processImagePartC(int levelOfReflection, int howManyLights){ initializeMaterial(numberOfSpheres); initializeLights(howManyLights); int xAxis, yAxis; /* Looping through x and y */ for(yAxis = 0; yAxis < height; yAxis++){ for(xAxis = 0; xAxis < width; xAxis++){ red = 0; green = 0; blue = 0; //int level = 0; float levelDetail = 1.0; initializeRay(xAxis,yAxis); int i; for (i = 0; i < levelOfReflection; i++) { levelDetail = rayCalculation(levelDetail); }//for loop if (red > 0 || green > 0 || blue > 0) { processPixelImage(xAxis,yAxis); }else{ //processPixelSphereImage(x,y); processGrayBackGround(xAxis,yAxis); } } } }
bool ObjModel::loadMTLFile(const char* fileName) { cout << "Loading material file: " << fileName << endl; FILE* fp; string* modelPath = getCvarAddress_S("r_modelPath"); string canonicalPath = *modelPath + "obj/" + fileName; cout << "From file path: " << canonicalPath << endl; if( !(fp=fopen(canonicalPath.c_str(), "r")) ) { error = "OBJ Materials file not found"; Con_print("Obj: File not found - %s", canonicalPath.c_str()); return false; } MaterialManager* tm = getMaterialManager(); material_t* mat; while( !feof(fp) ) { char in[MAX_OBJ_LINE_LEN]; fgets(in, MAX_OBJ_LINE_LEN, fp); char incpy[MAX_OBJ_LINE_LEN]; #ifdef OBJMATDEBUG cout << "MAT Line: " << in << endl; #endif strcpy(incpy, in); // if its a comment or whitespace skip it if( in[0] == '#' || in[0] == ' ' || in[0] == '\n' || in[0] == '\r' || in[0] == '\t') continue; else { // otherwise we need to process some data char* token = strtok(in, WHITESPACE); if( token == NULL ) break; if( !strcmp(token, "newmtl") ) { material_t* newmat = new material_t; initializeMaterial(newmat); token = strtok(NULL, WHITESPACE); if( !tm->hasMaterial(token) ) { tm->addMaterial(token, newmat); mat = newmat; #ifdef OBJMATDEBUG cout << "New material created: " << token << endl; #endif } else { #ifdef OBJMATDEBUG cout << "MTL Error: Material redefinition: " << token << endl; #endif } } else if( !strcmp(token, "Ns") ) { sscanf(incpy, "Ns %f", &mat->Ns); } else if( !strcmp(token, "Ka") ) { sscanf(incpy, "Ka %f %f %f", &mat->Ka[0], &mat->Ka[1], &mat->Ka[2]); } else if( !strcmp(token, "Kd") ) { sscanf(incpy, "Kd %f %f %f", &mat->Kd[0], &mat->Kd[1], &mat->Kd[2]); } else if( !strcmp(token, "Ks") ) { sscanf(incpy, "Ks %f %f %f", &mat->Ks[0], &mat->Ks[1],& mat->Ks[2]); } else if( !strcmp(token, "Ni") ) { sscanf(incpy, "Ni %f", &mat->Ni); } else if( !strcmp(token, "d") ) { sscanf(incpy, "d %f", &mat->d); } else if( !strcmp(token, "illum") ) { sscanf(incpy, "illum %d", &mat->illum); } else if( !strcmp(token, "map_Kd") ) { token = strtok(NULL, WHITESPACE); strcpy(mat->map_Kd, token); #ifdef OBJMATDEBUG cout << "Loading texture: " << mat->map_Kd << endl; #endif getMaterialManager()->loadBitmap(mat->map_Kd); } } } fclose(fp); return true; }
int main(int argc, char* argv[]){ // domain variables int iter = 0; int i; int file_index; int max_iter; double max_time = 1.0; double dt = .0000001; double domain_box[4] = {0.0, 0.0, 1.0, 2.0}; double domain_m_box[4] = {.10, 0.2, 0.90, 2.00}; int domain_num_cells[2] = {10, 20}; int pp_cell[2] = {2,2}; double ipart_dim[2]; int domain_num_particles[2]; double test_px, test_py; char p_filename[40]; char p_filename2[40]; char g_filename[40]; //timing variables double start_time; double end_time; // patch variables int rank = 0; int size; int num_proc[2]; double box[4]; double m_box[4]; int num_cells[2]; int halo_cells[4] = {1,1,1,1}; int num_particles[2]; int sfactor = 2; GridData grid_data; Node** grid; InitialParticleData ipart_data; Particle* particles; Particle* post_particles; Particle* particle_list; Particle* rhalo_parts[8]; Particle* shalo_parts[8]; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Request halo_req[8][2]; MPI_Status halo_stat[8][2]; max_iter = (int)(max_time/dt); if(rank == 0){ if(argc == 3){ num_proc[0] = atoi(argv[1]); num_proc[1] = atoi(argv[2]); }else if(argc == 6){ num_proc[0] = atoi(argv[1]); num_proc[1] = atoi(argv[2]); domain_num_cells[0] = atoi(argv[3]); domain_num_cells[1] = atoi(argv[4]); max_iter = atoi(argv[5]); } } MPI_Bcast(num_proc, 2, MPI_INT, 0, MPI_COMM_WORLD); MPI_Bcast(domain_num_cells, 2, MPI_INT, 0, MPI_COMM_WORLD); MPI_Bcast(&max_iter, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD); grid_data.gravity[0] = 0; grid_data.gravity[1] = -900.8; grid_data.cell_dim[0] = (domain_box[2] - domain_box[0])/domain_num_cells[0]; grid_data.cell_dim[1] = (domain_box[3] - domain_box[1])/domain_num_cells[1]; test_px = grid_data.cell_dim[0]/pp_cell[0]; test_py = grid_data.cell_dim[1]/pp_cell[1]; domain_num_particles[0] = (int)((domain_m_box[2] - domain_m_box[0])/test_px); domain_num_particles[1] = (int)((domain_m_box[3] - domain_m_box[1])/test_py); ipart_dim[0] = (domain_m_box[2] - domain_m_box[0])/domain_num_particles[0]; ipart_dim[1] = (domain_m_box[3] - domain_m_box[1])/domain_num_particles[1]; decomposeGrid(rank, num_proc, domain_num_cells, num_cells, domain_box, box, halo_cells, &grid_data); decomposeMaterial(box, domain_m_box, m_box, ipart_dim, num_particles); ipart_data.density = 1000; ipart_data.bulk = 3; ipart_data.shear = 4; ipart_data.E = 90000; ipart_data.poisson = .30; ipart_data.idim[0] = ipart_dim[0]; ipart_data.idim[1] = ipart_dim[1]; ipart_data.velocity[0] = 0; ipart_data.velocity[1] = 0; ipart_data.box[0] = m_box[0]; ipart_data.box[1] = m_box[1]; ipart_data.box[2] = m_box[2]; ipart_data.box[3] = m_box[3]; ipart_data.num_particles[0] = num_particles[0]; ipart_data.num_particles[1] = num_particles[1]; ipart_data.domain_num_particles[0] = domain_num_particles[0]; ipart_data.domain_num_particles[1] = domain_num_particles[1]; grid = createGrid(&grid_data, box, num_cells); particles = createMaterial(&grid_data, &ipart_data); post_particles = createMaterial(&grid_data, &ipart_data); initializeGrid(&grid_data, grid); initializeMaterial(&grid_data, &ipart_data, particles); //allocate halo particles allocateHaloParticles(&grid_data, sfactor, pp_cell, rhalo_parts, shalo_parts); file_index = 0; start_time = MPI_Wtime(); for(iter = 0; iter <= max_iter; iter++){ gatherHaloParticles(&grid_data, particles, rhalo_parts, shalo_parts); sendRecvParticles(&grid_data, rhalo_parts, shalo_parts); clearGridValues(&grid_data, grid); mapToGrid(&grid_data, grid, particles); for(i = 0; i < 8; i++){ if(grid_data.rank[i] >= 0 && rhalo_parts[i][0].particle_count > 0){ mapToGrid(&grid_data, grid, rhalo_parts[i]); } } momentumToVelocityOnGrid(&grid_data, grid); computeForces(&grid_data, grid, particles); for(i = 0; i < 8; i++){ if(grid_data.rank[i] >= 0 && rhalo_parts[i][0].particle_count > 0){ computeForces(&grid_data, grid, rhalo_parts[i]); } } computeAcceleration(&grid_data, grid); /** particle_list = gatherParticles(rank, size, domain_num_particles[0] * domain_num_particles[1], particles, post_particles); if(rank == 0){ //if(iter%100 == 0){ sprintf(p_filename, "ppart%06d.vtk", file_index); //sprintf(p_filename2, "center%06d.vtk", file_index); //sprintf(g_filename, "grid_output%06d.vtk", file_index); //writeParticlesVtkFile(&grid_data, grid, rhalo_parts[0], p_filename); writeParticlesVtkFile(&grid_data, grid, particle_list, p_filename); //writeParticlesVtkFile(&grid_data, grid, particle_list, p_filename); //writeParticlesVtkFile(&grid_data, grid, particles, p_filename); //writeGridVtkFile(&grid_data, grid, g_filename); //writeGridVtkFile(&grid_data, grid, g_filename); //free(particle_list); file_index++; //} } **/ updateNodalValues(&grid_data, grid, dt); updateStressAndStrain(&grid_data, grid, particles, dt); pUpdateParticlePosition(&grid_data, grid, particles, post_particles, shalo_parts, dt); sendRecvParticles(&grid_data, rhalo_parts, shalo_parts); updateParticleList(&grid_data, particles, rhalo_parts); /** particle_list = gatherParticles(rank, size, domain_num_particles[0] * domain_num_particles[1], particles, post_particles); if(rank == 0){ sprintf(p_filename, "particle_output%06d.vtk", file_index); file_index++; //sprintf(g_filename, "grid_output%06d.vtk", file_index); writeParticlesVtkFile(&grid_data, grid, particles, p_filename); //writeParticlesVtkFile(&grid_data, grid, particle_list, p_filename); //writeParticlesVtkFile(&grid_data, grid, particles, p_filename); //writeGridVtkFile(&grid_data, grid, g_filename); free(particle_list); } **/ MPI_Barrier(MPI_COMM_WORLD); } end_time = MPI_Wtime(); MPI_Barrier(MPI_COMM_WORLD); //particle_list = gatherParticles(rank, size, domain_num_particles[0] * domain_num_particles[1], // particles, post_particles); if(rank == 0){ printf("Parallel, np: %d, iterations: %d, time: %f\n", size, max_iter, end_time-start_time); //writeParticlesVtkFile(&grid_data, grid, particle_list, "pparts.vtk"); //free(particle_list); } freeGrid(grid, &grid_data); freeMaterial(particles); freeMaterial(post_particles); freeHaloParticles(&grid_data, rhalo_parts, shalo_parts); //MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); return 0; }