Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / How to make objects shake or wiggle in place?

Author
Message
huertaaj
18
Years of Service
User Offline
Joined: 3rd Dec 2006
Location:
Posted: 8th Dec 2006 16:27
I'm trying to design an educational biology animation in DBP showing several spheres wiggling more or less in place (Brownian motion). Is there an efficient way of writing code for randomly wiggling objects? I can do this in 3DS Max by applying "NOISE" to the X,Y,Z coordinates of each object but I can't find a good way of doing this in DBP.
Thanks,
huertaaj
huertaaj
18
Years of Service
User Offline
Joined: 3rd Dec 2006
Location:
Posted: 8th Dec 2006 16:38
Hi:
I forgot to say that the objects I want to animate, in addition to wiggling in 3D space, they should rotate randomly around their centers. If possible I would like to animate up to 50 or 100 of these objects, each wiggling and rotating more or less in place.
Thanks,
Huertaaj
Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 8th Dec 2006 16:42
I would do something like this:



That'll randomly rotate and position your object, but keeping it around a central position. It should look like a really fast vibration effect. Hope it helps.


tiresius
22
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 8th Dec 2006 16:42
You can take the current object's position and save off the x/y/z positions, then add -2 to +2 randomly via the rnd() function to each x/y/z value. Position the object at the new values. sync the display, then put the object back in the old position and repeat.

I'm not a real programmer but I play one with DBPro!
BatVink
Moderator
22
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 8th Dec 2006 17:31
I'm guessing this movement is part of a bigger simulation, and so it needs to run alongside other "happenings".

Here's the methodology I would use:

1. Create an array for the spheres, made up af a TYPE containing position, "next position", and speed.

2. Position is the default, idle position for the sphere.

3. "Next position" is a position you want to move to, located around the idle position.

4. Speed is the value at which you want to get to the next position from where you are now.

Now, you can create a function that iterates through all of your spheres. At random intervals, you can change the "next position" and the speed to new values. You would also move towards the new position each time, based on the speed value. As long as you make the change faster than the spheres can reach their new position, they will move continuously.

Because it's a function, you can call it in your main loop, and then go on to do other things too.



Login to post a reply

Server time is: 2025-05-06 03:40:56
Your offset time is: 2025-05-06 03:40:56