1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| typedef struct point_3d { // Structure for a 3 dimensional point (NEW)
double x, y, z;
} point_3d;
typedef struct bpatch { // Structure for a 3rd degree bezier patch (NEW)
point_3danchors[4][4]; // 4x4 grid of anchor points
GLuint dlBPatch; // Display List for Bezier Patch
GLuint texture; // Texture for the patch
}
BEZIER_PATCH;
HDC hDC=NULL; // Private GDI Device Context
HGLRC hRC=NULL; // Permanent Rendering Context
HWND hWnd=NULL; // Holds Our Window Handle
HINSTANCE hInstance; // Holds The Instance Of The Application
DEVMODE DMsaved; // Saves the previous screen settings (NEW)
//bool
keys[256]; // Array Used For The Keyboard Routine
//bool
active=TRUE; // Window Active Flag Set To TRUE By Default
//bool
fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default
GLfloat rotz = 0.0f; // Rotation about the Z axis
BEZIER_PATCH mybezier; // The bezier patch we're going to use (NEW)
BOOL showCPoints=TRUE;// Toggles displaying the control point grid (NEW)
int divs = 7; // Number of intrapolations (conrols poly resolution) (NEW)
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
glEnd(); // End the haptic shape.
hlEndShape();
//End the haptic frame.
hlEndFrame();
}
// Adds 2 points. Don't just use '+' ;)
point_3d pointAdd(double
point_3d p, point_3d q) {
p.x += q.x; p.y += q.y; p.z += q.z;
return p;
}
// Multiplies a point and a constant. Don't just use '*'
double point_3d pointTimes(double c, point_3d p) {
p.x *= c; p.y *= c; p.z *= c;
return p;
}
// Function for quick point creation
double point_3d makePoint(double a, double b, double c) {
point_3d p;
p.x = a; p.y = b; p.z = c;
return p;
}
// Calculates 3rd degree polynomial based on array of 4 points
// and a single variable (u) which is generally between 0 and 1
point_3d Bernstein(float u, point_3d *p) {
point_3d a, b, c, d, r;
a = pointTimes(pow(u,3), p[0]);
b = pointTimes(3*pow(u,2)*(1-u), p[1]);
c = pointTimes(3*u*pow((1-u),2), p[2]);
d = pointTimes(pow((1-u),3), p[3]);
r = pointAdd(pointAdd(a, b), pointAdd(c, d));
return r;
} |
Partager