[Home] |
[Download] |
[Links] |
Dave G's Bezier Curve System (DGBZ) and Dave G's Multiple Curve System (DGMBZ) are written to give fill a void I found in POV-Ray.
POV-Ray is an incredibly powerful renderer, but other than the supplied clock variable there are not too many facilities for animation. If you want to move a particle along a curve, or a complex path, you've been out of luck so far.
There have been some external path utilities, but they're system specific. If you don't use DOS then the DOS utilities are useless to you.
There have been a few bezier curve files around but they have two limitations.
Both systems are just include files. Three include files make up the system (DGBZ.INC and DGMBZ.INC which you include, and DGBZINT.INC which is called by the first two include files).
For single bezier curves it is very simple. To calculate a traditional (and fast) bezier curve position, here is all you have to do.
You simply define the curve or path and call the file. I use the notation of C0 through C3, which seems to be the standard in all textbooks on computer graphics and curves. Simply fill in the value and DGBZ will calculate the point for you. |
#declare DGBZCommand = "POSITION" |
If you want to find an accurate position along the length of the curve, you simply add one line before the #include:
To change the calculation, just specify an exact calculation rather than an approximate one. There is a downside to this accuracy. The calculation takes a long time. Many seconds, not just a fraction of a second. |
#declare DGBZCalc_Type = "EXACT" |
Its actually very simple. I fake it. Instead of re-learning calculus and advanced math I simply use brute force. I integrate the curve the old fashioned way. Watch, and I'll step through the process. Maybe this will help explain why it takes so long.
First step through the curve using the traditional calculation. Since the points along the curve are not equally spaced I default to 1000 increments to give more precision. (You can change the number of steps if you need finer control) |
|
As each step is calculated DGBZ finds the length from the previous position. It keeps a running total that allows it to approximate the length of the curve. |
|
Then, with the total length calculated DGBZ finds out how far through the curve the point has to be. |
|
Next, it re-steps along the curve. Calculating a running total of the curves length as it goes. As soon as its running total oversteps the distance it is trying to find DGBZ stops and declares the latest step the correct position. |
The second part of the bezier system Dave G's Multiple Curve System (DGMBZ) simply takes the previous method to its logical (but possibly extreme) conclusion.
A path is just curves that are travelled one after the other. Since DGBZ can calculate the length of a single curve, DGMBZ can calculate the length of a path by totalling the length of the individual curves. With that total in hand it can calculate which curve the point is on, how far through that curve the point is, and then calculate the point itself. (wheww... does that make sense?)
Step through each curve in the path and calculate its length. |
|
Find the distance through the total path. |
|
Find which which specific curve the point is within, and how far the point is within that curve. |
|
Calculate the point along the curve and voila, the correct position. |
And this is why paths take longer than curves. If a path is made up of ten curve, then ten curve lengths must be computed, and then a distance through a single curve calculated as well. All in all it can take a while. But if you are calculating only a few paths for each frame (the camera and a main object, for instance) then the overhead isn't too bad.
Instead of DGBZC0 through DGBZC3 there are new variables to be set. DGMBZxxC0 through DGMBZxxC3 are used to store the points of the individual curves. DGMBZCurves stores the number of curves in the current path. There can be up to 99 curves in a path. I added that many for computer programs that generate POV-Ray code. They could automatically type as complicated a curve as you might wish for. If even this two curve path seems like a lot of work, don't panic. Remember system is designed so that you only have to enter the values once for any path. During the course of an animation POV-Ray will calculate the correct value for each frame. |
#declare DGMBZCurves = 2 |
[ Go Home ]
Hosted by Geocities, your free personal home page on the web.
This page copyright David Govoni 1997
Any
comments, or suggestions?
E-mail
me.