SetVelocity
This function sets the initial velocity or the random velocity of released particles.
Syntax
- void SetVelocity(float x, float y, const flost& z, int index=0, const bool global=false)
Parameters
- x: - specified velocity along the x-axis
- y: - specified velocity along the y-axis
- z: - specified velocity along the z-axis
- index: - differentiates between setting initial velocity or random velocity. 0 = initial velocity, 1 = random velocity.
- global: if set to true, emitted particle velocity will be calculated in global space instead of local space.
Remarks
Starting velocity is calculated as follows: StartVelocity = velocity[0] + Random(-.5*velocity[1], .5*velocity[1])
Example
#include "Leadwerks.h"
using namespace Leadwerks;
int main(int argc, const char *argv[])
{
float time = 0.5;
Leadwerks::Window* window = Leadwerks::Window::Create();
Context* context = Context::Create(window);
World* world = World::Create();
Camera* camera = Camera::Create();
camera->SetRotation(35, 0, 0);
camera->Move(0, 0, -3);
//Create an emitter
Emitter* emitter = Emitter::Create(100);
int timercount = 0;
while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
Leadwerks::Leadwerks::Time::Update();
world->Update();
world->Render();
if (++timercount % 100 == 0)
{
emitter->SetVelocity(Math::Random(-1, 1), Math::Random(-1, 1), Math::Random(-1, 1), 0);
emitter->SetVelocity(Math::Random(-1, 1), Math::Random(-1, 1), Math::Random(-1, 1), 1);
}
context->SetBlendMode(Blend::Alpha);
context->DrawText("Current Base Velocity: " + (emitter->GetVelocity(0)).ToString(), 2, 2);
context->DrawText("Current Random Velocity: " + (emitter->GetVelocity(1)).ToString(), 2, 20);
context->SetBlendMode(Blend::Solid);
context->Sync();
}
}