void ParticleRenderer::RenderFireBillboard(float angle, float _size, const vec3& color, float opacity, const vec3& position) { ScopeLock lock(lock_); temp_fires_.push_back(Billboard()); Billboard& billboard = temp_fires_.back(); billboard.position_ = position; billboard.color_ = color; billboard.texture_index_ = total_texture_count_-1; billboard.depth_ = 1000.0f; billboard.size_factor_ = _size; billboard.angle_ = angle; billboard.opacity_ = opacity; }
void BattleView::UpdateTerrainTrees(bounds2f bounds) { if (_smoothTerrainSurface != nullptr && _simulator->GetGroundMap() != nullptr) { auto pos2 = std::remove_if(_billboardModel->staticBillboards.begin(), _billboardModel->staticBillboards.end(), [bounds](const Billboard& billboard) { return bounds.contains(billboard.position.xy()); }); _billboardModel->staticBillboards.erase(pos2, _billboardModel->staticBillboards.end()); static random_generator* _randoms = nullptr; if (_randoms == nullptr) _randoms = new random_generator(997); int treeType = 0; random_iterator random(*_randoms); bounds2f mapbounds = _simulator->GetGroundMap()->GetBounds(); glm::vec2 center = mapbounds.center(); float radius = mapbounds.width() / 2; float d = 5 * mapbounds.width() / 1024; for (float x = mapbounds.min.x; x < mapbounds.max.x; x += d) for (float y = mapbounds.min.y; y < mapbounds.max.y; y += d) { float dx = d * (random.next() - 0.5f); float dy = d * (random.next() - 0.5f); int shape = (int)(15 * random.next()) & 15; glm::vec2 position = glm::vec2(x + dx, y + dy); if (bounds.contains(position) && glm::distance(position, center) < radius) { if (_simulator->GetHeightMap()->InterpolateHeight(position) > 0 && _simulator->GetGroundMap()->IsForest(position)) { const float adjust = 0.5 - 2.0 / 64.0; // place texture 2 texels below ground _billboardModel->staticBillboards.push_back(Billboard(GetTerrainPosition(position, adjust * 5), 0, 5, _billboardModel->_billboardTreeShapes[shape])); } } ++treeType; } } }
void ParticleRenderer::CreateBillboards(const vec3& position, float strength, const vec3& velocity, const vec3& target_velocity, float end_turbulence, float time_factor, float size_factor, const vec3& start_color, const vec3& color, BillboardArray& billboards, int count) { for (int x = 0; x < count; ++x) { billboards.push_back(Billboard()); Billboard& billboard = billboards.back(); billboard.velocity_ = velocity + RNDVEC(strength); const vec3 this_particles_target_velocity = Math::Lerp(target_velocity*0.8f, target_velocity, Random::Uniform(0.0f, 2.0f)); billboard.target_velocity_ = RNDVEC(end_turbulence) + this_particles_target_velocity; billboard.position_ = position; billboard.start_color_ = RNDCOL(start_color, 0.9f, 1.1f); billboard.color_ = RNDCOL(color, 0.7f, 1.3f); billboard.texture_index_ = Random::GetRandomNumber() % gas_texture_count_; billboard.depth_ = 1000.0f; billboard.size_factor_ = Random::Uniform(size_factor*0.7f, size_factor*1.4f); billboard.angle_ = Random::Uniform(0.0f, 2*PIF); billboard.angular_velocity_ = Random::Uniform(-5.0f, +5.0f); billboard.opacity_ = 0; billboard.opacity_factor_ = 1; billboard.opacity_time_ = Random::Uniform(0.0f, 0.3f); deb_assert(time_factor > 0); billboard.time_factor_ = Random::Uniform(time_factor*0.7f, time_factor*1.3f); } }