Chryfi
Chryfi

Reputation: 300

Implementing randomness for physics (like in Blender)

I am referring, as an example, to Blender's particle collision system, where you can set the randomness for particle damping between 0.0 and 1.0. My question now is: how does it exactly work? Yes, there will be a random number between 0.0 and 1.0 but how is it applied to the damping factor? I want to create something similar in Java and therefore I want to fully understand the calculation behind that. Is the random factor the probability p and the calculation something like a gaussian distribution? As an application example: I want to randomize the direction of a vector.

vector.y += random1; vector.y += random2; vector.z += random3; vector.scale(prevLength/vector.length);

However, it might appear, that all vector components become zero, it's very unlikely but not impossible. So clearly this is not the right solution.

Upvotes: 1

Views: 154

Answers (1)

Chryfi
Chryfi

Reputation: 300

I found out the answer for the damping

public Vector3f damping(Vector3f vector) 
{
    float random = (float) (this.randomDamp*(Math.random()*2-1));
    float clampedValue = Math.max(0, Math.min(1, (1-damp)+random)); //clamp between 0 and 1
    vector.scale(clampedValue);
    return vector;
}

It appears so that blender just adds the random number so with a factor of 0.5 and a random factor of 1, the final factor will vary between -0.5 (0) and 1.5 (1).

Upvotes: 1

Related Questions