home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / macraysh.sit / Code / Source / maccreate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-13  |  6.5 KB  |  299 lines

  1. #include "atmosphere.h"
  2. #include "surface.h"
  3. #include "texture.h"
  4. #include "image.h"
  5. #include "geom.h"
  6. #include "light.h"
  7. #include "options.h"
  8. #include "stats.h"
  9. #include "viewing.h"
  10.  
  11. #include "blob.h"
  12. #include "box.h"
  13. #include "cone.h"
  14. #include "csg.h"
  15. #include "cylinder.h"
  16. #include "disc.h"
  17. #include "grid.h"
  18. #include "hf.h"
  19. #include "instance.h"
  20. #include "list.h"
  21. #include "plane.h"
  22. #include "poly.h"
  23. #include "sphere.h"
  24. #include "torus.h"
  25. #include "triangle.h"
  26.  
  27. #include "point.h"
  28. #include "infinite.h"
  29. #include "spot.h"
  30. #include "jittered.h"
  31. #include "extended.h"
  32.  
  33. #include "blotch.h"
  34. #include "bump.h"
  35. #include "checker.h"
  36. #include "cloud.h"
  37. #include "fbm.h"
  38. #include "fbmbump.h"
  39. #include "gloss.h"
  40. #include "imagetext.h"
  41. #include "marble.h"
  42. #include "mount.h"
  43. #include "sky.h"
  44. #include "stripe.h"
  45. #include "windy.h"
  46. #include "wood.h"
  47.  
  48. #include "fog.h"
  49. #include "fogdeck.h"
  50. #include "mist.h"
  51.  
  52. #include "rotate.h"
  53. #include "scale.h"
  54. #include "translate.h"
  55.  
  56. #include "maccreate.h"
  57. #include "maceditor.h"
  58.  
  59. extern Vector crosshair ;
  60.  
  61. void LinkObject(Geom *obj, Geom *parent)
  62. {
  63.     List *list ;
  64.     Grid *grid;
  65.     Geom *listitem ;
  66.  
  67.     if(!obj || !parent)
  68.         RLerror(RL_WARN,"Invalid aguments have been passed to LinkObject",NULL,NULL,NULL) ;
  69.     switch(ObjectType(parent)) {
  70.         case LIST:
  71.             list = (List *)parent->obj ;
  72.             /* Check for unbounded object */
  73.             (obj->methods->bounds)(obj->obj,obj->bounds);
  74.             if(obj->bounds[LOW][X] > obj->bounds[HIGH][X]) {
  75.                 obj->next = list->unbounded;
  76.                 list->unbounded = obj;
  77.             }
  78.             else {
  79.                 obj->next = list->list;
  80.                 list->list = obj;
  81.             }
  82.             parent->prims++;
  83.             break ;
  84.         case GRID:
  85.             grid = (Grid *)parent->obj;
  86.             /* Check for unbounded object */
  87.             (obj->methods->bounds)(obj->obj,obj->bounds);
  88.             if(obj->bounds[LOW][X] > obj->bounds[HIGH][X]) {
  89.                 RLerror(RL_WARN,"Grids cannot contain unbounded objects",0,0,0);
  90.             }
  91.             else {
  92.                 obj->next = grid->objects;
  93.                 grid->objects = obj;
  94.                 parent->prims++;
  95.                 engrid(obj,grid);
  96.             }
  97.             break;
  98.         case CSG:
  99.             break;
  100.         default:
  101.             RLerror(RL_WARN,"Unsupported object type in link has been called", NULL,NULL,NULL) ;
  102.     }
  103. }
  104.  
  105.  
  106. Light *CreateProtoLight(short type)
  107. {
  108.     Light *light = NULL;
  109.     Vector vec;
  110.     Color col;
  111.  
  112.     col.r = col.g = col.b = 1.;
  113.     vec = crosshair;
  114.     switch(type) {
  115.         case L_POINT:
  116.             light = LightPointCreate(&col,&vec);
  117.             break;
  118.         case L_INFINITE:
  119.             /* Check to see if our crosshair is on the origin */
  120.             if(equal(vec.x,0.) && equal(vec.y,0.) && equal(vec.z,0.))
  121.                 vec.y = 1.;
  122.             light = LightInfiniteCreate(&col,&vec);
  123.             break;
  124.         case L_SPOT:
  125.             /* Not supported yet */
  126.             break;
  127.         case L_JITTERED:
  128.             /* Not supported yet */
  129.             break;
  130.         case L_EXTENDED:
  131.             light = LightExtendedCreate(&col,1.,&vec);
  132.             break;
  133.     }
  134.     return light;
  135. }
  136.  
  137.  
  138. /* This procedure will create a "protoype" object which is passed back to the parent procedure.
  139.  * The user can then edit this prototype to create their own object of the same type
  140.  */
  141. Geom *CreateProtoObject(short type, char *name) 
  142. {
  143.     Geom *obj = NULL ;
  144.     switch(type) {
  145.         case MPlane:
  146.             /* A plane going through crosshair with normal pointing upwards */
  147.             {
  148.                 Vector p,n,c ;
  149.     
  150.                 p = crosshair ;
  151.                 n.x = n.y = 0.; n.z = 1. ;
  152.     
  153.                 obj = GeomPlaneCreate(&p,&n) ;
  154.             }
  155.             break ;
  156.         case MSphere:
  157.             /* A sphere of radius 1 on the crosshair */
  158.             {
  159.                 Vector p ;
  160.  
  161.                 p = crosshair ;
  162.                 obj = GeomSphereCreate(1.0,&p) ;
  163.             }
  164.             break ;
  165.         case MCone:
  166.             /* A cone of height and width 1 with the base on the crosshair */
  167.             {
  168.                 Vector b,a ;
  169.                 a = b = crosshair  ;
  170.                 a.y += 1. ;
  171.                 obj = GeomConeCreate(1.,&b,0.,&a) ;
  172.             }
  173.             break ;
  174.         case MBox:
  175.             /* A box with bounds {0,0,0} and {1,1,1} relative to crosshair*/
  176.             {
  177.                 Vector b1,b2 ;
  178.                 
  179.                 b1 = b2 = crosshair ;
  180.                 b2.x += 1. ; b2.y += 1. ; b2.z += 1. ;
  181.                 
  182.                 obj = GeomBoxCreate(&b1,&b2) ;
  183.             }
  184.             break ;
  185.         case MTorus:
  186.             /* A torus of outside radius .5, inside radius .4 about crosshair - normal in z dir */
  187.             {
  188.                 Vector pos,norm ;
  189.                 pos = crosshair ;
  190.                 norm.x = norm.y = 0. ; norm.z = 1. ;
  191.                 obj = GeomTorusCreate(.5,.4,&pos,&norm) ;
  192.             }
  193.             break ;
  194.         case MBlob:
  195.             /* A blob of 1 ball of  radius 1  at the crosshair */
  196.             {
  197.                 MetaList mlist ;
  198.                 
  199.                 mlist.mvec.x = crosshair.x;
  200.                 mlist.mvec.y = crosshair.y;
  201.                 mlist.mvec.z = crosshair.z;
  202.                 mlist.mvec.rs = 1. ;
  203.                 mlist.mvec.c0 = 1. ;
  204.                 mlist.mvec.c2 = 1. ;
  205.                 mlist.mvec.c4 = 1. ;
  206.                 mlist.next = NULL ;
  207.                 obj = GeomBlobCreate(1.,&mlist,1) ;
  208.             }
  209.             break ;
  210.         case MDisc:
  211.             /* Disc at crosshair of radius 1 and normal in z direction */
  212.             {
  213.                 Vector p, n ;
  214.                 p = crosshair ;
  215.                 n.x = n.y = 0. ; n.z = 1. ;
  216.                 
  217.                 obj = GeomDiscCreate(1.,&p,&n) ;
  218.             }
  219.             break ;
  220.         case MTriangle:
  221.             /* A flat triangle with points at {0,0,0} {0,0,1} & {1,0,1} relative to cross hair*/
  222.             {
  223.                 Vector p1,p2,p3 ;
  224.                 
  225.                 p1 = p2 = p3 = crosshair ;
  226.                 p2.x += 1. ; p2.y += 1. ; p2.z += 1. ;
  227.                 p3.x += 1. ; p3.z += 1.;
  228.                 
  229.                 obj = GeomTriangleCreate(FLATTRI,&p1,&p2,&p3,NULL,NULL,NULL,NULL,NULL,NULL,0) ;
  230.             }
  231.             break ;
  232.         case MPolygon:
  233.             /* Create a polygon square about cross hair */
  234.             {
  235.                 PointList *plist ;
  236.                 char loop ;
  237.  
  238.                 plist = Malloc(4*sizeof(PointList)) ;
  239.                 plist[0].next = &plist[1] ;
  240.                 plist[1].next = &plist[2] ;
  241.                 plist[2].next = &plist[3] ;
  242.                 plist[3].next = NULL ;
  243.                 for(loop = 0 ; loop < 4 ; loop++) plist[loop].vec.z = crosshair.z ;
  244.                 plist[0].vec.x = crosshair.x -.5 ; plist[0].vec.y = crosshair.y+.5 ;
  245.                 plist[1].vec.x = crosshair.x -.5 ; plist[1].vec.y = crosshair.y-.5 ;
  246.                 plist[2].vec.x = crosshair.x +.5 ; plist[2].vec.y = crosshair.y-.5 ;
  247.                 plist[3].vec.x = crosshair.x +.5 ; plist[3].vec.y = crosshair.y+.5 ;
  248.                 obj = GeomPolygonCreate(plist,4,FALSE) ;
  249.             }
  250.             break ;
  251.         case MHf:
  252.             /* Create a "flat" heightfield */
  253.             break ;
  254.         case MCylinder:
  255.             /* Create a cylinder of radius 1 and height 1 , base centred on crosshair */
  256.             {
  257.                 Vector top, bottom ;
  258.                 
  259.                 top = bottom = crosshair ;
  260.                 top.x += 1 ;
  261.                 obj = GeomCylinderCreate(1.,&top,&bottom) ;
  262.             }
  263.             break ;
  264.         case MList:
  265.             /* Create an empty list */
  266.             obj = GeomListCreate() ;
  267.             ((List *)obj->obj)->list = NULL ;
  268.             ((List *)obj->obj)->unbounded = NULL ;
  269.             obj->prims = 0;
  270.             break ;
  271.         case MGrid:
  272.             /* Create an empty grid */
  273.             {
  274.                 int x,y,z;
  275.  
  276.                 GetGridSize(&x,&y,&z);
  277.                 if((x+y+z) > 0) {
  278.                     obj = GeomGridCreate(x,y,z);
  279.                 }
  280.                 obj->prims = 0;
  281.             }
  282.             break ;
  283.         case MDifference:
  284.             /* Create an empty csg */ 
  285.             break ;
  286.         case MIntersection:
  287.             break ;
  288.         case MUnion:
  289.             break ;
  290.     } ;
  291.     if(obj) {
  292.         (obj->methods->bounds)(obj->obj,obj->bounds);
  293.         obj->name = Malloc(strlen(name)+1) ;
  294.         if(obj->name)
  295.             strcpy(obj->name, name) ;
  296.     }
  297.  
  298.     return obj ;
  299. }