/* -*- compile-command: "msdev modeler.dsp /make \"Modeler - Win32 Debug\"" -*- */ #ifndef _MODELER_H #define _MODELER_H #include #include #include #include #include #define MAX_CONTROL_NAME 80 #define MAX_MENU_ITEMS 20 typedef struct { int type; Tcl_Obj* widget; int curveid; void* data; } control; typedef struct { double min, max, res, start; char name[MAX_CONTROL_NAME+1]; } scale_data; typedef struct { double start; } curve_data; typedef struct { int state; char name[MAX_CONTROL_NAME+1]; } checkbox_data; typedef struct { int start; int count; char name[MAX_CONTROL_NAME+1]; char item[MAX_MENU_ITEMS][MAX_CONTROL_NAME+1]; } menu_data; typedef struct { int n; double* x; double* y; double def; } evaluatedcurve; typedef struct { char* name; void (*generate)(double,double,int,double,int,double*,double*,int*,double**,double**); } curvetype; /* grrr. why does Microsoft not put the value of pi in any of its standard include files? */ #define M_PI 3.14159265358979323846 /* we'll use static shared buffers for constructing Tcl commands (which are evaluated and immediately thrown away). */ #define BUFFER_SIZE 1024 extern char command_buffer[BUFFER_SIZE]; extern char convert_buffer[BUFFER_SIZE]; extern FILE* g_rayfile; extern int g_drawmode; extern Tcl_Interp* g_interp; extern GLfloat mat_ambient[4]; extern GLfloat mat_diffuse[4]; extern GLfloat mat_specular[4]; extern GLfloat mat_shininess; /* CONVERT (used in controls.c) takes the string variable "s" and escapes spaces and funny characters in it according to Tcl rules, placing the result in convert_buffer. */ #define CONVERT(s) {int flags=0; \ assert( Tcl_ScanElement( s, &flags ) < BUFFER_SIZE );\ Tcl_ConvertElement( s, convert_buffer, flags );} /* g_quality controls polygonalization of the sphere and cylinder primitives. higher g_quality --> more polygons --> prettier but slower. */ extern int g_quality; /* the Tcl variable g_drawmode should be some of these constants, OR'd together. choose exactly one from the first group and one from the second group. */ #define MODE_NORMAL 1 #define MODE_WIREFRAME 2 #define MODE_FLATSHADE 4 #define MODE_RAYTRACE 8 #define MODE_HIGH_QUALITY 256 #define MODE_MED_QUALITY 512 #define MODE_LOW_QUALITY 1024 #define MODE_SETUP (1<<16) /* * function prototypes: anything marked with "__declspec(dllexport)" * is something you can call from your modeler function(s). anything * without this declaration is only needed internally, and you can't * call it (so don't try!). */ LRESULT CALLBACK WndProc( HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam ); HGLRC SetupOpenGL( HWND hwnd ); /** general setup and animation stuff **/ /* Debug is like printf, but prints to the MSVC debugger "output" window. */ void __declspec( dllexport ) Debug( char* fmt, ... ); double __declspec( dllexport ) get_time( void ); int __declspec( dllexport ) draw_mode_setup( void ); int __declspec( dllexport ) draw_mode_finish( void ); /** material properties **/ void __declspec( dllexport ) ambient_color( double r, double g, double b ); void __declspec( dllexport ) diffuse_color( double r, double g, double b ); void __declspec( dllexport ) specular_color( double r, double g, double b ); void __declspec( dllexport ) shininess( double s ); /** geometric primitives **/ /* sphere of radius r */ void __declspec( dllexport ) sphere( double r ); /* axis-aligned box from origin to (x,y,z). */ void __declspec( dllexport ) box( double x, double y, double z ); /* cylinder from z=0 to z=h with radius r1 at origin and r2 at z=h. */ void __declspec( dllexport ) cylinder( double h, double r1, double r2 ); /* triangle with three given vertices. */ void __declspec( dllexport ) triangle( double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3 ); /** user interface widgets **/ /* internal stuff, can't call these. */ int Controls_Init( Tcl_Interp* interp ); control* new_control( int, int ); void reset_controls ( void ); void rebuild_controls ( void ); #define CONTROL_SCALE 1 #define CONTROL_CHECKBOX 2 #define CONTROL_RADIOBUTTON 3 #define CONTROL_MENU 4 #define CONTROL_CURVE 5 /* for all controls, interp is the Tcl_Interp parameter passed to Model_SetupCmd, id is an integer unique to that control, and name is a string used for the label. */ int __declspec( dllexport ) curve( Tcl_Interp* interp, int id, char* name, double min, double max, double start ); void curve_widget( control* ); /* slider from "min" to "max" in steps of "res", initial value "start". */ int __declspec( dllexport ) scale( Tcl_Interp* interp, int id, char* name, double min, double max, double res, double start ); void scale_widget( control* ); /* checkbox, initial state "state". */ int __declspec( dllexport ) checkbox( Tcl_Interp* interp, int id, char* name, int state ); void checkbox_widget( control* ); /* set of radiobuttons with labels "..." (NULL-terminated). "start" is the number of the one initially checked. */ int __declspec( dllexport ) radiobutton( Tcl_Interp* interp, int id, char* name, int start, ... ); void radiobutton_widget( control* ); /* menu with radiobutton-type options "..." (NULL-terminated). "start" is the one initially checked. */ int __declspec( dllexport ) menu( Tcl_Interp* interp, int id, char* name, int start, ... ); void menu_widget( control* ); /* read the value of a control as a double, int, or boolean. */ double __declspec( dllexport ) get_control_d( int id ); int __declspec( dllexport ) get_control_i( int id ); int __declspec( dllexport ) get_control_b( int id ); /* put the MODEL macro (with the filename of your DLL) in your modeler file to create a boilerplate initialization function. "name" must be all lowercase, except for the first letter which must be capitalized. */ #define MODEL(name) extern "C" { \ int Model_ResizeCmd( ClientData clientData, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[] );\ int Model_RedrawCmd( ClientData clientData, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[] );\ int Model_SetupCmd( ClientData clientData, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[] );\ int __declspec(dllexport) name##_Init( Tcl_Interp* interp ); \ } \ int name##_Init( Tcl_Interp* interp ) { \ Tcl_CreateObjCommand( interp, "::model::resize", Model_ResizeCmd, NULL, NULL ); \ Tcl_CreateObjCommand( interp, "::model::redraw", Model_RedrawCmd, NULL, NULL ); \ Tcl_CreateObjCommand( interp, "::model::setup", Model_SetupCmd, NULL, NULL ); \ return TCL_OK; } extern "C" { int Curves_Init( Tcl_Interp* ); int EvaluateCurveCmd( ClientData clientdata, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[] ); int GetEvaluatedCurveCmd( ClientData clientdata, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[] ); int SetCurveTimeCmd( ClientData clientdata, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[] ); int GetCurveTypesCmd( ClientData clientdata, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[] ); } double interpolate_curve_value( evaluatedcurve* ec, double t ); void linear_generate( double xmin, double xmax, int wrapflag, double def, int nc, double* xc, double* yc, int* np, double** xp, double** yp ); void catmullrom_generate( double xmin, double xmax, int wrapflag, double def, int nc, double* xc, double* yc, int* np, double** xp, double** yp ); void c2interp_generate( double xmin, double xmax, int wrapflag, double def, int nc, double* xc, double* yc, int* np, double** xp, double** yp ); void bezier_generate( double xmin, double xmax, int wrapflag, double def, int nc, double* xc, double* yc, int* np, double** xp, double** yp ); void bspline_generate( double xmin, double xmax, int wrapflag, double def, int nc, double* xc, double* yc, int* np, double** xp, double** yp ); void quadratic_generate( double xmin, double xmax, int wrapflag, double def, int nc, double* xc, double* yc, int* np, double** xp, double** yp ); #endif