void Scene::RefreshParticle(Particle* particle) { Emitter* parent = particle->m_parent; // If the emitter mode is explosion, // there is no more refreshing precess if (parent->GetExplosionToggle()) { // Reset the original position if (parent->GetMode() == FIRE) { parent->SetDirection(vec3(0.f, 1.f)); float repos_offset = 3.f / 5.f; float new_pos = parent->GetBoundary() * repos_offset; particle->SetPosition(parent->GetPosition() + vec3( Random::GetInstance().GetRandomFloat(-new_pos, new_pos), Random::GetInstance().GetRandomFloat(-new_pos, new_pos))); } else if (parent->GetMode() == SNOW) { particle->SetPosition(parent->GetPosition() + vec3( Random::GetInstance().GetRandomFloat(parent->GetSnowStartingPoint().x, parent->GetSnowEndingPoint().x), Random::GetInstance().GetRandomFloat(parent->GetSnowStartingPoint().y, parent->GetSnowEndingPoint().y))); } else particle->SetPosition(parent->GetPosition()); // Rescale? if (parent->GetRandomScaleToggle()) { float randomSize = Random::GetInstance().GetRandomFloat(parent->GetRandomScaleRange().x, parent->GetRandomScaleRange().y); particle->SetScale(vec3(randomSize, randomSize)); } // Reset life particle->m_life = 1.f; // Reset color particle->SetColor(vec4( parent->GetColor().x, parent->GetColor().y, parent->GetColor().z, particle->m_life)); // Set Velocity; if (!parent->GetDirection().Length()) { particle->m_velocity = vec3( Random::GetInstance().GetRandomFloat(-1.f, 1.f), Random::GetInstance().GetRandomFloat(-1.f, 1.f)); particle->m_velocity = particle->m_velocity.Normalize(); } // Set speed particle->m_speed = parent->GetSpeed() * vec3( Random::GetInstance().GetRandomFloat(0.f, 1.f), Random::GetInstance().GetRandomFloat(0.f, 1.f)); // Reset vanishing speed particle->m_fade = Random::GetInstance().GetRandomFloat(DELTA_TIME, 1.f); if (parent->GetMode() == EXPLOSION && parent->GetRefreshingToggle()) parent->ActivateExplosion(false); } }
int main () { printf ("Results of test 'test':\n"); try { Timer timer (bind (&Application::Exit, 0), TEST_WORK_TIME); srand ((unsigned int)time (NULL)); SoundManager manager ("OpenAL", "*"); Listener listener; Emitter emitter; emitter.SetSource ("declaration1"); emitter.SetSampleIndex (rand ()); /* Testing basic manager properties */ printf ("Initial volume = %f,", manager.Volume ()); manager.SetVolume (0.7f); printf (" new volume = %f.\n", manager.Volume ()); printf ("Initial mute: "); print (manager.IsMuted ()); manager.SetMute (true); printf ("Mute: "); print (manager.IsMuted ()); manager.SetMute (false); printf ("Mute: "); print (manager.IsMuted ()); printf ("Initial listener status: "); print (manager.Listener ()); listener.position = vec3f (0.f, 1.f, 0.f); listener.direction = vec3f (0.f, 0.f, 1.f); listener.up = vec3f (0.f, -1.f, 0.f); listener.velocity = vec3f (1.f, 0.f, 0.f); manager.SetListener (listener); printf ("New listener status: "); print (manager.Listener ()); manager.LoadSoundLibrary (library_file); /* Testing basic emitter properties */ printf ("Emitter source - %s\n", emitter.Source ()); printf ("Initial emitter volume = %f,", emitter.Volume ()); emitter.SetVolume (0.9f); printf (" new emitter volume = %f.\n", emitter.Volume ()); printf ("Initial position: "); print (emitter.Position ()); printf ("\nInitial direction: "); print (emitter.Direction ()); printf ("\nInitial velocity: "); print (emitter.Velocity ()); emitter.SetPosition (vec3f (-50.f, 2.f, 4.f)); emitter.SetDirection (vec3f (-2.f, -2.f, -4.f)); emitter.SetVelocity (vec3f (0.f, 0.f, 0.1f)); printf ("\nNew position: "); print (emitter.Position ()); printf ("\nNew direction: "); print (emitter.Direction ()); printf ("\nNew velocity: "); print (emitter.Velocity ()); printf ("\n"); /* Testing manager work */ manager.PlaySound (emitter, 0.3f); printf ("Current offset in seconds = %f\n", manager.Tell (emitter)); printf ("Duration in seconds = %f\n", manager.Duration (emitter)); printf ("Looping = %c\n", manager.IsLooping (emitter) ? 'y' : 'n'); printf ("Is Playing = %c\n", manager.IsPlaying (emitter) ? 'y' : 'n'); Timer timer2 (bind (&TimerHandler, ref (emitter)), ACTION_TIME); Application::Run (); } catch (std::exception& exception) { printf ("exception: %s\n",exception.what ()); } catch (...) { printf ("unknown exception\n"); } printf ("exit\n"); return Application::GetExitCode (); }