Al's Programming Resource Homepage  Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

bspline.cpp File Reference

#include <windows.h>
#include "bspline.h"
#include "tll.h"
#include "mmgr.h"

Go to the source code of this file.

Functions

void bspline (SPLINE *spline)
VECTOR bsplinepoint (SPLINE *spline)
float blend (int k, int t, int *u, float v)
void compute_intervals (int *u, int n, int t)
void compute_point (int *u, int n, int t, float v, VECTOR *control, VECTOR *output)

Variables

float ApplicationStartTime


Function Documentation

float blend int    k,
int    t,
int *    u,
float    v
 

Definition at line 119 of file bspline.cpp.

Referenced by compute_point().

00120 {
00121     float value;
00122 
00123     if (t == 1)            // base case for the recursion
00124     {
00125         if ((u[k] <= v) && (v < u[k+1]))
00126             value = 1;
00127         else
00128             value = 0;
00129     }
00130     else
00131     {
00132         if ((u[k+t-1] == u[k]) && (u[k+t] == u[k+1]))         // check for divide by zero
00133             value = 0;
00134         else
00135             if (u[k+t-1] == u[k])           // if a term's denominator is zero,use just the other
00136                 value = (u[k+t] - v) / (u[k+t] - u[k+1]) * blend(k+1, t-1, u, v);
00137             else
00138                 if (u[k+t]==u[k+1])
00139                     value = (v - u[k]) / (u[k+t-1] - u[k]) * blend(k, t-1, u, v);
00140                 else
00141                     value = (v - u[k]) / (u[k+t-1] - u[k]) * blend(k, t-1, u, v) + (u[k+t] - v) / (u[k+t] - u[k+1]) * blend(k+1, t-1, u, v);
00142     }
00143     return value;
00144 }

void bspline SPLINE   spline
 

Definition at line 29 of file bspline.cpp.

References compute_intervals(), compute_point(), SPLINE::Control, SPLINE::Degree, SPLINE::NumControl, SPLINE::NumPoints, SPLINE::Output, VECTOR::x, VECTOR::y, and VECTOR::z.

Referenced by DrawGLScene().

00030 {
00031     int t = spline->Degree;
00032     int n = spline->NumControl;
00033     int num_output = spline->NumPoints;
00034     VECTOR* control = spline->Control;
00035 
00036     int* u;
00037 
00038     int output_index;
00039     float increment,interval;
00040     VECTOR calcxyz;
00041 
00042     u = new int[n+t+1];
00043     compute_intervals(u, n, t);
00044 
00045     increment = (float) (n-t+2) / (num_output-1);  // how much parameter goes up each time
00046     interval = 0;
00047 
00048     for (output_index = 0; output_index < num_output - 1; output_index++)
00049     {
00050         compute_point(u, n, t, interval, control, &calcxyz);
00051         spline->Output[output_index].x = calcxyz.x;
00052         spline->Output[output_index].y = calcxyz.y;
00053         spline->Output[output_index].z = calcxyz.z;
00054         interval = interval + increment;  // increment our parameter
00055     }
00056     spline->Output[num_output-1].x = control[n].x;   // put in the last point
00057     spline->Output[num_output-1].y = control[n].y;
00058     spline->Output[num_output-1].z = control[n].z;
00059 
00060     delete u;
00061 }

VECTOR bsplinepoint SPLINE   spline
 

Definition at line 64 of file bspline.cpp.

References ApplicationStartTime, compute_intervals(), compute_point(), SPLINE::Control, SPLINE::CopyOfEndTime, SPLINE::CopyOfStartTime, SPLINE::Degree, SPLINE::EndTime, SPLINE::NumControl, SPLINE::Repeat, SPLINE::StartTime, VECTOR::x, VECTOR::y, and VECTOR::z.

Referenced by DrawGLScene().

00065 {
00066     int t = spline->Degree;
00067     int n = spline->NumControl;
00068     VECTOR *control = spline->Control;
00069 //    VECTOR *output = spline->Output;
00070 
00071     int* u;
00072     float increment;
00073     VECTOR calcxyz;
00074 
00075     u = new int[n+t+1];
00076     compute_intervals(u, n, t);
00077 
00078     float CurrentTime = (float)GetTickCount() - ApplicationStartTime;
00079 
00080     float TotalTime = spline->EndTime - spline->StartTime;
00081     float Position;
00082     float ActualTime;
00083 
00084     if (CurrentTime <= spline->CopyOfStartTime)
00085     {
00086         calcxyz.x = control[0].x;
00087         calcxyz.y = control[0].y;
00088         calcxyz.z = control[0].z;
00089         delete u;
00090         return calcxyz;
00091     }
00092     else if (CurrentTime >= spline->CopyOfEndTime)
00093     {
00094         if (spline->Repeat)
00095         {
00096             spline->CopyOfStartTime = CurrentTime;
00097             spline->CopyOfEndTime = CurrentTime + TotalTime;
00098         }
00099         calcxyz.x = control[n].x;
00100         calcxyz.y = control[n].y;
00101         calcxyz.z = control[n].z;
00102         delete u;
00103         return calcxyz;
00104     }
00105     else
00106     {
00107         ActualTime = CurrentTime - spline->CopyOfStartTime;
00108         Position = 1 / (TotalTime / ActualTime);
00109     }
00110     increment = (n - t + 2) * Position;  // how much parameter goes up each time
00111 
00112     compute_point(u, n, t, increment, control, &calcxyz);
00113 
00114     delete u;
00115 
00116     return calcxyz;
00117 }

void compute_intervals int *    u,
int    n,
int    t
 

Definition at line 146 of file bspline.cpp.

Referenced by bspline(), and bsplinepoint().

00147 {
00148     int j;
00149 
00150     for (j = 0; j <= n+t; j++)
00151     {
00152         if (j<t)
00153             u[j]=0;
00154         else
00155             if ((t <= j) && (j <= n))
00156                 u[j] = j-t+1;
00157             else
00158                 if (j > n)
00159                     u[j] = n-t+2;  // if n-t=-2 then we're screwed, everything goes to 0
00160     }
00161 }

void compute_point int *    u,
int    n,
int    t,
float    v,
VECTOR   control,
VECTOR   output
 

Definition at line 163 of file bspline.cpp.

References blend(), VECTOR::x, VECTOR::y, and VECTOR::z.

Referenced by bspline(), and bsplinepoint().

00164 {
00165     int k;
00166     float temp;
00167 
00168     // initialize the variables that will hold our outputted point
00169     output->x=0;
00170     output->y=0;
00171     output->z=0;
00172 
00173     for (k = 0; k <= n; k++)
00174     {
00175         temp = blend(k,t,u,v);  // same blend is used for each dimension coordinate
00176         output->x = output->x + (control[k]).x * temp;
00177         output->y = output->y + (control[k]).y * temp;
00178         output->z = output->z + (control[k]).z * temp;
00179     }
00180 }


Variable Documentation

float ApplicationStartTime
 

Definition at line 6 of file bspline.cpp.

Referenced by bsplinepoint(), and InitGL().


Generated on Fri Dec 23 05:22:05 2005 for Splines by doxygen1.2.15