Random position in a entity

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Danthekilla
Posts: 136
Joined: Sun Jan 17, 2010 11:35 am

Random position in a entity

Post by Danthekilla »

Hey norbo how would you suggest getting a random point in a box?

I want to get a random point in a body and also want to make a function for getting on on the surface of a body as well

Its for spawning particles on the surface of a animated charictor with a ragdoll that is mapped to it uses box entitys...

Any idea?
Should i just attempt to get each plane and size of the box and then find a random x and y for it in local space?

I was hoping that there may be a easier way somewhere already in the engine that could help...


Also it needs to be fast as it will be spawning many particles (i.e for fire) over the objects...


Thanks for any help you can provide.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Random position in a entity

Post by Norbo »

I'd do it in local space and transform the resulting point with the entity's world transform.

So for a point in the volume, use the width/height/length of the box as bounds for your random number on each respective axis. For a point on the surface, pick one of the three axes as the surface normal, and then use the positive or negative halfsize for that coordinate. The other two coordinates would be randomly picked like before.

In the general non-box case, you could generate a random point in the entity's bounding box and then test to see if it's inside the entity. Another option might be raycasting inwards from some point guaranteed to be outside of the entity (beyond the entity's maximum radius, for example). These options would be significantly slower than the box special case, though. These general options also aren't uniformly random.
Danthekilla
Posts: 136
Joined: Sun Jan 17, 2010 11:35 am

Re: Random position in a entity

Post by Danthekilla »

Yer thats what i thought i would go with.

Just thought i should check if there was anything built in that could help.

Any chance of a built in function for more complex entitys in the future? I think havok has something similar which is quite useful for particle spawning and placeing other graphical details etc...

Anyway it only needs to support boxs right now so i think ill go with that.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Random position in a entity

Post by Norbo »

I also forgot to mention the option of just using the GetExtremePoint function on entities with a random direction. Still not truly random (it obviously prefers extreme locations).

I'll consider something built in, but right now I can't think of anything that would be substantially easier/better than using one of these approaches.
Post Reply