//-------------------------------------------------------------------------------------------------- // MAIN int main(int argc, char* argv[]) { // Validate arguments if (argc != 2) { std::cout << "Usage: " << argv[0] << " OutputDirectory" << std::endl; return -1; } std::string outputPath(argv[1]); // Init simulator std::cout << "Initializing simulator..." << std::endl; const Vec3d volumeMin(-3, 0, -1); const Vec3d volumeMax( 3, 3, 1); const double mass = 1.0; const double restDensity = 998.23; const double h = 0.2; const double k = 100.0; const double dt = 0.001; BasicSPH sph(volumeMin, volumeMax, mass, restDensity, h, k, dt); sph.enableAdaptiveTimeStep(); // Init particles std::cout << "Initializing particles" << std::endl; Vec3d boxMin(-3, 0, -1); Vec3d boxMax(-1, 2, 1); initParticlesBox(boxMin, boxMax, 0.1, sph.particles()); // Output first frame (initial frames) const std::string filePrefix("particles_"); SPHParticleHoudiniIO::outputParticles(sph.particles(), outputPath, filePrefix, 1); // Run simulation and output a frame every 1/24 second std::cout << "Running simulation!" << std::endl; const double frameTime = 1.0/24.0; const double totalSimulationTime = 10.0; double time = 0.0; int currentFrame = 2; while (time < totalSimulationTime) { std::cout << "Simulating frame " << currentFrame << " (" << (frameTime+time) << "s)"; std::cout << std::endl; // Run simulation sph.run(frameTime); // Output particles SPHParticleHoudiniIO::outputParticles(sph.particles(), outputPath, filePrefix, currentFrame); // Update simulation time time += frameTime; ++currentFrame; } std::cout << "Done!" << std::endl; return 0; }
void GameEngine::Octree::OctreeNode::GetTriangleData( const Octree *i_octree, const D3DXVECTOR3 &i_startPoint, const D3DXVECTOR3 &i_endPoint, std::vector<Utilities::S_TRIANGLE> &o_triangleData ) { float boxSize = 2 * m_size; D3DXVECTOR3 boxMax = m_maxDimension; D3DXVECTOR3 boxMin( boxMax.x - boxSize, boxMax.y - boxSize, boxMax.z - boxSize ); D3DXVECTOR3 d = (i_endPoint - i_startPoint) * 0.5f; D3DXVECTOR3 e = (boxMax - boxMin) * 0.5f; D3DXVECTOR3 c = i_startPoint + d - (boxMin + boxMax) * 0.5f; D3DXVECTOR3 ad( abs(d.x), abs(d.y), abs(d.z) ); if( fabsf(c.x) > (e.x + ad.x) ) return; if( fabsf(c.y) > (e.y + ad.y) ) return; if( fabsf(c.z) > (e.z + ad.z) ) return; if( fabsf(d.y * c.z - d.z * c.y) > (e.y * ad.z + e.z * ad.y + FLT_EPSILON) ) return; if( fabsf(d.z * c.x - d.x * c.z) > (e.z * ad.x + e.x * ad.z + FLT_EPSILON) ) return; if( fabsf(d.x * c.y - d.y * c.x) > (e.x * ad.y + e.y * ad.x + FLT_EPSILON) ) return; if( _bShowOctree ) g_debugMenu::Get().DrawBox( m_maxDimension, m_size * 2 ); for( UINT32 i = 0; i < m_u32TotalData; ++i ) o_triangleData.push_back( i_octree->m_triangleDatabase->at(m_u32StartIndex + i) ); if( m_bHasChildren ) { for( UINT8 i = 0; i < Utilities::E_OCTANT_TOTAL; ++i ) { if( m_children[i] != NULL ) m_children[i]->GetTriangleData( i_octree, i_startPoint, i_endPoint, o_triangleData ); } } }
bool Grid::initInfiniteRay (const Vec3r &orig, const Vec3r& dir, unsigned timestamp) { _ray_dir = dir; _t_end = FLT_MAX; _t = 0; _ray_dir.normalize(); _timestamp = timestamp; // check whether the origin is in or out the box: Vec3r boxMin(_orig); Vec3r boxMax(_orig+_size); BBox<Vec3r> box(boxMin, boxMax); if(box.inside(orig)){ for(unsigned i = 0; i < 3; i++) { _current_cell[i] = (unsigned)floor((orig[i] - _orig[i]) / _cell_size[i]); unsigned u = _current_cell[i]; _pt[i] = orig[i] - _orig[i] - _current_cell[i] * _cell_size[i]; } }else{ // is the ray intersecting the box? real tmin(-1.0), tmax(-1.0); if(GeomUtils::intersectRayBBox(orig, _ray_dir, boxMin, boxMax, 0, _t_end, tmin, tmax)){ assert(tmin != -1.0); Vec3r newOrig = orig + tmin*_ray_dir; for(unsigned i = 0; i < 3; i++) { _current_cell[i] = (unsigned)floor((newOrig[i] - _orig[i]) / _cell_size[i]); if(_current_cell[i] == _cells_nb[i]) _current_cell[i] = _cells_nb[i] - 1; unsigned u = _current_cell[i]; _pt[i] = newOrig[i] - _orig[i] - _current_cell[i] * _cell_size[i]; } }else{ return false; } } //_ray_occluders.clear(); return true; }
void CUmbralActor::RebuildActorRenderables() { uint32 modelFolder = m_baseModelId % 10000; uint32 modelClass = m_baseModelId / 10000; const char* charaFolder = ""; const char* charaPrefix = ""; switch(modelClass) { case 1: charaFolder = "mon"; charaPrefix = "m"; break; case 2: charaFolder = "bgobj"; charaPrefix = "b"; break; case 4: charaFolder = "wep"; charaPrefix = "w"; break; default: assert(0); break; } uint32 subModelId = m_topModelId >> 10; uint32 variation = m_topModelId & 0x3FF; auto gamePath = CFileManager::GetGamePath(); auto modelPath = string_format("%s/client/chara/%s/%s%0.3d/equ/e%0.3d/top_mdl/0001", gamePath.string().c_str(), charaFolder, charaPrefix, modelFolder, subModelId); Framework::CStdStream inputStream(modelPath.c_str(), "rb"); auto modelResource = CSectionLoader::ReadSection(ResourceNodePtr(), inputStream); auto modelChunk = modelResource->SelectNode<CModelChunk>(); assert(modelChunk); if(!modelChunk) return; auto boundingBox = modelChunk->SelectNode<CCompChunk>(); CVector3 boxMin(boundingBox->GetMinX(), boundingBox->GetMinY(), boundingBox->GetMinZ()); CVector3 boxMax(boundingBox->GetMaxX(), boundingBox->GetMaxY(), boundingBox->GetMaxZ()); CVector3 modelSize = (boxMax - boxMin) / 2; CVector3 modelPos = (boxMax + boxMin) / 2; auto model = std::make_shared<CUmbralModel>(modelChunk); model->SetPosition(modelPos); model->SetScale(modelSize); AppendChild(model); auto modelBoundingSphere = model->GetBoundingSphere(); modelBoundingSphere.radius *= std::max(std::max(modelSize.x, modelSize.y), modelSize.z); modelBoundingSphere.position += modelPos; m_boundingSphere = modelBoundingSphere; uint32 textureId = 0; if(modelClass == 4) { uint32 varWepId = 1000000000 + (modelFolder * 1000000) + (subModelId * 1000) + variation; auto var = CWeaponVars::GetInstance().GetVarForId(varWepId); textureId = var.textureId; for(const auto& meshNode : model->GetChildren()) { if(auto mesh = std::dynamic_pointer_cast<CUmbralMesh>(meshNode)) { auto meshName = mesh->GetName(); int materialId = 0; if(meshName.find("_a") != std::string::npos) { materialId = 0; } if(meshName.find("_b") != std::string::npos) { materialId = 1; } if(meshName.find("_c") != std::string::npos) { materialId = 2; } if(meshName.find("_d") != std::string::npos) { assert(0); } const auto& varWepMaterial = var.materials[materialId]; auto material = mesh->GetMaterial(); ReplaceMaterialParam(material, "ps_diffuseColor", varWepMaterial.diffuseColor); ReplaceMaterialParam(material, "ps_multiDiffuseColor", varWepMaterial.multiDiffuseColor); ReplaceMaterialParam(material, "ps_specularColor", varWepMaterial.specularColor); ReplaceMaterialParam(material, "ps_multiSpecularColor", varWepMaterial.multiSpecularColor); ReplaceMaterialParam(material, "ps_reflectivity", varWepMaterial.specularColor); ReplaceMaterialParam(material, "ps_multiReflectivity", varWepMaterial.multiSpecularColor); ReplaceMaterialParam(material, "ps_shininess", varWepMaterial.shininess); ReplaceMaterialParam(material, "ps_multiShininess", varWepMaterial.multiShininess); mesh->SetActivePolyGroups(var.polyGroupState); } } } { auto texturePath = string_format("%s/client/chara/%s/%s%0.3d/equ/e%0.3d/top_tex2/%0.4d", gamePath.string().c_str(), charaFolder, charaPrefix, modelFolder, subModelId, textureId); Framework::CStdStream inputStream(texturePath.c_str(), "rb"); auto textureResource = CSectionLoader::ReadSection(ResourceNodePtr(), inputStream); model->SetLocalTexture(textureResource); } m_renderableDirty = false; }