home *** CD-ROM | disk | FTP | other *** search
- /*
- * File: teapot.c
- *
- * Author: Rick LaMont
- *
- * Date: 3/29/96
- *
- * Purpose: Demonstrate Windows app which uses RenderDotC interface.
- *
- */
-
- #include <windows.h>
- #include "rdc.h" /* RenderDotC interface definition */
-
- /*
- * Constants
- */
- #define MAXNPTS 100 /* Can revolve this many points */
- #define BEZIERWIDTH 12 /* Number of points in Bezier circle */
- #define F 0.4142135 * 4/3 /* Magic number for Bezier circles */
-
- /*
- * Typedefs
- */
- typedef struct {
- RDCfloat x, z; /* Define 2D points in X-Z plane */
- } Point2D;
-
- /*
- * function: revolve
- *
- * input: An array of 2D points and the number of points in the array.
- *
- * returns: void
- *
- * purpose: Creates Bezier surface of revolution around Z-axis.
- *
- */
- static void revolve(const Point2D *points, int npoints)
- {
- /* Use control points for 2D Bezier circle as revolution coefficients */
- static RDCfloat coeff[][2] = {
- { 1, 0}, { 1, F}, { F, 1}, {0, 1}, {-F, 1}, {-1, F},
- {-1, 0}, {-1, -F}, {-F, -1}, {0, -1}, { F, -1}, { 1, -F}
- };
-
- int u, v;
- RDCpoint mesh[MAXNPTS][BEZIERWIDTH]; /* Build 3D mesh here */
-
- for (v = 0; v < npoints; v++)
- for (u = 0; u < BEZIERWIDTH; u++) {
- mesh[v][u][0] = points[v].x * coeff[u][0];
- mesh[v][u][1] = points[v].x * coeff[u][1];
- mesh[v][u][2] = points[v].z;
- }
-
- rdcPatchMesh(RDC_BICUBIC, BEZIERWIDTH, RDC_WRAP, npoints, RDC_NOWRAP,
- RDC_POINT, (RDCvoid *)mesh,
- RDC_NULL);
- }
-
- /*
- * function: teapot
- *
- * input: none
- *
- * returns: void
- *
- * purpose: Renders Utah Teapot.
- *
- */
- static void teapot(void)
- {
- /*
- * Components that are radially symmetric about the Z-axis may
- * be defined in the 2D X-Z plane and automatically revolved around
- * the Z-axis.
- */
- Point2D body[] = {
- {60, 0}, {60, 3}, {80, 12}, {80, 30}, {80, 48}, {70, 69},
- {60, 90}, {57.5, 95.25}, {53.5, 95.25}, {56, 90}
- };
- Point2D lid[] = {
- {8, 102}, {16, 96}, {52, 96}, {52, 90}
- };
- Point2D knob[] = {
- {0, 120}, {32, 120}, {0, 108}, {8, 102}
- };
- Point2D lip[] = {
- {50, 90}, {52, 90}, {54, 90}, {56, 90}
- };
-
- /*
- * Components which are not symmetric must be fully specified in 3D.
- */
- RDCpoint spout[7][6] = {
- {{68, 0, 51}, {68, 26.4, 51}, {68, 26.4, 18},
- {68, 0, 18}, {68, -26.4, 18}, {68, -26.4, 51}},
- {{104, 0, 51}, {104, 26.4, 51}, {124, 26.4, 27},
- {124, 0, 27}, {124, -26.4, 27}, {104, -26.4, 51}},
- {{92, 0, 78}, {92, 10, 78}, {96, 10, 75},
- {96, 0, 75}, {96, -10, 75}, {92, -10, 78}},
- {{108, 0, 90}, {108, 10, 90}, {132, 10, 90},
- {132, 0, 90}, {132, -10, 90}, {108, -10, 90}},
- {{112, 0, 93}, {112, 10, 93}, {141, 10, 93.75},
- {141, 0, 93.75}, {141, -10, 93.75}, {112, -10, 93}},
- {{116, 0, 93}, {116, 6, 93}, {138, 6, 94.5},
- {138, 0, 94.5}, {138, -6, 94.5}, {116, -6, 93}},
- {{112, 0, 90}, {112, 6, 90}, {128, 6, 90},
- {128, 0, 90}, {128, -6, 90}, {112, -6, 90}}
- };
- RDCpoint handle[7][6] = {
- {{-64, 0, 75}, {-64, 12, 75}, {-60, 12, 84},
- {-60, 0, 84}, {-60, -12, 84}, {-64, -12, 75}},
- {{-92, 0, 75}, {-92, 12, 75}, {-100, 12, 84},
- {-100, 0, 84}, {-100, -12, 84}, {-92, -12, 75}},
- {{-108, 0, 75}, {-108, 12, 75}, {-120, 12, 84},
- {-120, 0, 84}, {-120, -12, 84}, {-108, -12, 75}},
- {{-108, 0, 66}, {-108, 12, 66}, {-120, 12, 66},
- {-120, 0, 66}, {-120, -12, 66}, {-108, -12, 66}},
- {{-108, 0, 57}, {-108, 12, 57}, {-120, 12, 48},
- {-120, 0, 48}, {-120, -12, 48}, {-108, -12, 57}},
- {{-100, 0, 39}, {-100, 12, 39}, {-106, 12, 31.5},
- {-106, 0, 31.5}, {-106, -12, 31.5}, {-100, -12, 39}},
- {{-80, 0, 30}, {-80, 12, 30}, {-76, 12, 18},
- {-76, 0, 18}, {-76, -12, 18}, {-80, -12, 30}}
- };
-
- /*
- * Lighting values
- */
- RDCfloat ambintensity = 0.4;
- RDCfloat distintensity1 = 1.0;
- RDCfloat distintensity2 = 0.2;
- RDCpoint from1= {-50, 300, 200};
- RDCpoint from2= {-50, -300, 200};
- RDCpoint to = {0, 0, 0};
- RDCcolor ambcolor = {0.4, 0, 1};
- RDCcolor color1 = {1, 0.8, 0.7};
-
- /*
- * Shading values
- */
- RDCcolor tan = {1, 0.5, 0.3};
- RDCcolor specolor = {1, 0.4, 0.1};
- RDCfloat ka = 0.1, kd = 0.05, ks = 1, rough = 0.1;
-
- /*
- * Set parameters
- */
- rdcOutputDisplay("Utah Teapot");
- rdcRasterViewport(0, 199, 0, 124);
- rdcColorGamma(2.2);
-
- /*
- * Set view
- */
- rdcViewPerspective(25);
- rdcTranslate(0, 0, 400);
- rdcRotate(-115, 1, 0, 0);
- rdcRotate(19, 0, 0, 1);
- rdcTranslate(-25, 0, -50);
-
- rdcSceneBegin();
- /*
- * Define lights
- */
- rdcLightSource(RDC_AMBIENT,
- RDC_INTENSITY, (RDCvoid *)&ambintensity,
- RDC_LIGHTCOLOR, (RDCvoid *)ambcolor,
- RDC_NULL);
- rdcLightSource(RDC_DISTANT,
- RDC_INTENSITY, (RDCvoid *)&distintensity1,
- RDC_FROM, (RDCvoid *)&from1,
- RDC_TO, (RDCvoid *)&to,
- RDC_LIGHTCOLOR, (RDCvoid *)color1,
- RDC_NULL);
- rdcLightSource(RDC_DISTANT,
- RDC_INTENSITY, (RDCvoid *)&distintensity2,
- RDC_FROM, (RDCvoid *)&from2,
- RDC_TO, (RDCvoid *)&to,
- RDC_NULL);
-
- /*
- * Define surface
- */
- rdcColor(tan);
- rdcSurface(RDC_PLASTIC,
- RDC_KA, (RDCvoid *)&ka,
- RDC_KD, (RDCvoid *)&kd,
- RDC_KS, (RDCvoid *)&ks,
- RDC_ROUGHNESS, (RDCvoid *)&rough,
- RDC_SPECULARCOLOR, (RDCvoid *)specolor,
- RDC_NULL);
-
- /*
- * Define primitives
- */
- revolve(body, sizeof(body) / sizeof(Point2D));
- revolve(lid, sizeof(lid) / sizeof(Point2D));
- revolve(knob, sizeof(knob) / sizeof(Point2D));
- revolve(lip, sizeof(lip) / sizeof(Point2D));
- rdcPatchMesh(RDC_BICUBIC, 6, RDC_WRAP, 7, RDC_NOWRAP,
- RDC_POINT, (RDCvoid *)spout,
- RDC_NULL);
- rdcPatchMesh(RDC_BICUBIC, 6, RDC_WRAP, 7, RDC_NOWRAP,
- RDC_POINT, (RDCvoid *)handle,
- RDC_NULL);
-
- rdcSceneEnd();
- }
-
- /*
- * function: MainWndProc
- *
- * input: Window handle, message id, first and second message parameters.
- *
- * returns: LRESULT - Result of message processing.
- *
- * purpose: Destroys app when main window closes. Calls default for rest.
- *
- */
- static LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg,
- WPARAM wParam, LPARAM lParam)
- {
- switch(msg) {
- case WM_DESTROY:
- PostQuitMessage(0); /* Kill the app when the window goes */
- break;
-
- default: /* Do the default thing */
- return DefWindowProc(hWnd, msg, wParam, lParam);
- }
-
- return FALSE;
- }
-
- /*
- * function: WinMain
- *
- * input: Handles to current and previous instances, command line, show state.
- *
- * returns: int APIENTRY - 0 on success
- *
- * purpose: Main entry point for 32 bit windows program.
- *
- */
- int APIENTRY WinMain(HANDLE hInstance, HANDLE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- {
- HWND hMainWnd;
- WNDCLASS wc;
- MSG msg;
-
- /*
- * Create a main window
- */
- wc.style = 0;
- wc.hInstance = hInstance;
- wc.lpfnWndProc = MainWndProc;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.lpszClassName = "TEAPOT:MAIN";
- wc.lpszMenuName = NULL;
- wc.cbClsExtra = wc.cbWndExtra = 0;
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- if (!RegisterClass(&wc))
- return 1;
- hMainWnd = CreateWindow("TEAPOT:MAIN", "Teapot App", WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, 0, 100, 100, NULL, NULL, hInstance, NULL);
- if (!hMainWnd)
- return 1;
- ShowWindow(hMainWnd, nCmdShow);
- UpdateWindow(hMainWnd);
-
- /*
- * If creating a ".rdc" file by running this program, link
- * with import library for "rdc.dll" instead of "rendc.dll".
- *
- * The following line sets the name of the output rdc file.
- * It has no effect when using "rendc.dll".
- */
- rdcOutputFile(RDC_BYTESTREAM, "teapot.rdc");
-
- /*
- * Draw the teapot
- * Note: No user interaction while rendering.
- */
- teapot();
-
- /*
- * Run message loop until user closes main window.
- */
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
-
- return 0;
- }
-