home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / r / raylat10.zip / RAYLATHE.C < prev    next >
Text File  |  1993-03-27  |  4KB  |  130 lines

  1. /*   RayLathe (c) Koehler
  2.    - Thick <0 = draw solid, =0 = move, >0 = draw hollow
  3.    Revision History:
  4.    03-24-93 1.0 KJK  New. Inspired by uLathe.
  5. */
  6.  
  7. #include <math.h>
  8. #include <stdio.h>
  9.  
  10. #define min(a,b) (a<b ? a : b)
  11. #define max(a,b) (a>b ? a : b)
  12.  
  13. #define VERSION 1.00
  14.  
  15. double intercept(double, double, double, double);
  16. void  lathe_cut(double, double, double, double, double);
  17.  
  18. void main()
  19.    {
  20.    double oldx = 0.01, oldy = 0.01;
  21.    double x, y, thick;
  22.    double boundminx=10000000, boundmaxx=-10000000, boundmaxy=0;
  23.    double length, center, eye_distance;
  24.  
  25.    fprintf(stderr,"RayLathe v%2.2f (c) 1993 Koehler\n",VERSION);
  26.    printf("// POVRAY 1.0 object created by RayLathe v%2.2f (c) 1993 Koehler\n",VERSION);
  27.    printf("// See suggested camera vectors at end of this file\n\n");
  28.    printf("#declare LatheWork =\n");
  29.    printf("   composite\n");
  30.    printf("      {\n");
  31.    scanf("%lf %lf %lf", &x, &y, &thick);
  32.    do
  33.        {
  34.        if ((thick)  && (x != oldx))
  35.        lathe_cut(oldx, oldy, x, y, thick);
  36.        boundmaxx = max(boundmaxx, x);
  37.        boundminx = min(boundminx, x);
  38.        boundmaxy = max(boundmaxy, y);
  39.        oldx = x;
  40.        oldy = y;
  41.        scanf("%lf %lf %lf", &x, &y, &thick);
  42.        }
  43.    while (y >= 0);
  44.    printf("      bounded_by\n");
  45.    printf("         {\n");
  46.    printf("         box {<%f %f %f>  <%f %f %f> }\n",boundminx,-boundmaxy,-boundmaxy, boundmaxx, boundmaxy, boundmaxy);
  47.    printf("         }\n");
  48.    printf("      }\n");
  49.    length = boundmaxx - boundminx;
  50.    center = length / 2 + boundminx;
  51.    printf("\n#declare Look_At = <%f 0 0>   // Center of object\n", center);
  52.    eye_distance = -max(fabs(length), boundmaxy*2.4);
  53.    printf("#declare Location = <%f 0 %f>    // Good camera position\n", center, eye_distance);
  54.    }
  55.  
  56. void lathe_cut(x1, y1, x2, y2, thick)
  57.    double x1, y1, x2, y2, thick;
  58.    {
  59.    double minx, miny, minz, maxx, maxy, maxz, origin;
  60.  
  61.    minx = min(x1,x2)*1.001;
  62.    maxx = max(x1,x2)*1.001;
  63.    maxy = max(y1,y2)*1.001;
  64.    miny = -maxy;
  65.    maxz = maxy;
  66.    minz = miny;
  67.    printf("      object       // (%lf, %lf, %lf)\n", x2, y2, thick);
  68.    printf("         {\n");
  69.    printf("         intersection\n");
  70.    printf("            {\n");
  71.    if (y1 == y2)
  72.        {
  73.        if (y1 > 0)
  74.        {
  75.        printf("            quadric {Cylinder_X  ");
  76.        printf("scale <1 %f %f> }\n", y1, y1);
  77.        }
  78.        }
  79.    else
  80.        {
  81.        if ((x1 == 0) || (x2 == 0))
  82.        origin = 0;
  83.        else
  84.        origin=intercept(x1, y1, x2, y2);
  85.        printf("            quadric {QCone_X  ");
  86.        if (x1 == 0)
  87.        printf("scale <%f %f %f>  ", fabs(origin-x2), y2, y2);
  88.        else
  89.        printf("scale <%f %f %f>  ", fabs(origin-x1), y1, y1);
  90.        printf("translate <%f 0 0> }\n", origin);
  91.        }
  92.    if ((thick >= 0) && (((y1-thick)>0) || ((y2-thick)>0)))
  93.        {
  94.        if (y1 == y2)
  95.        {
  96.        if ((y1-thick) > 0)
  97.            {
  98.            printf("            quadric {Cylinder_X  ");
  99.            printf("scale <1 %f %f> inverse }\n", y1-thick, y1-thick);
  100.            }
  101.        }
  102.        else
  103.        {
  104.        if ((x1 == 0) || (x2 == 0))
  105.            origin = 0;
  106.        else
  107.            origin = (((y1-thick)/y1)*(origin-x1))+x1;
  108.        printf("            quadric {QCone_X  ");
  109.        if ((origin-x1) == 0)
  110.            printf("scale <%f %f %f>  ", fabs(origin-x2), y2-thick, y2-thick);
  111.        else
  112.            printf("scale <%f %f %f>  ", fabs(origin-x1), y1-thick, y1-thick);
  113.        printf("translate <%f 0 0> inverse }\n", origin);
  114.        }
  115.        }
  116.    printf("            box {<%f %f %f>  <%f %f %f> }\n",minx,miny,minz,maxx,maxy,maxz);
  117.    printf("            }\n");
  118.    printf("         bounded_by\n");
  119.    printf("            { box {<%f %f %f>  <%f %f %f> } }\n",minx,miny,minz,maxx,maxy,maxz);
  120.    printf("         texture { LatheWorkTex }\n");
  121.    printf("         }\n");
  122.    }
  123.  
  124. double intercept(x1, y1, x2, y2)
  125.    double x1, y1, x2, y2;
  126.    {
  127.    double result;
  128.    return(x2 - ((x2-x1) / (y2-y1) * y2));
  129.    }
  130.