home *** CD-ROM | disk | FTP | other *** search
- #include "atmosphere.h"
- #include "surface.h"
- #include "texture.h"
- #include "image.h"
- #include "geom.h"
- #include "light.h"
- #include "options.h"
- #include "stats.h"
- #include "viewing.h"
-
- #include "blob.h"
- #include "box.h"
- #include "cone.h"
- #include "csg.h"
- #include "cylinder.h"
- #include "disc.h"
- #include "grid.h"
- #include "hf.h"
- #include "instance.h"
- #include "list.h"
- #include "plane.h"
- #include "poly.h"
- #include "sphere.h"
- #include "torus.h"
- #include "triangle.h"
-
- #include "point.h"
- #include "infinite.h"
- #include "spot.h"
- #include "jittered.h"
- #include "extended.h"
-
- #include "blotch.h"
- #include "bump.h"
- #include "checker.h"
- #include "cloud.h"
- #include "fbm.h"
- #include "fbmbump.h"
- #include "gloss.h"
- #include "imagetext.h"
- #include "marble.h"
- #include "mount.h"
- #include "sky.h"
- #include "stripe.h"
- #include "windy.h"
- #include "wood.h"
-
- #include "fog.h"
- #include "fogdeck.h"
- #include "mist.h"
-
- #include "rotate.h"
- #include "scale.h"
- #include "translate.h"
-
- #include "maccreate.h"
- #include "maceditor.h"
-
- extern Vector crosshair ;
-
- void LinkObject(Geom *obj, Geom *parent)
- {
- List *list ;
- Grid *grid;
- Geom *listitem ;
-
- if(!obj || !parent)
- RLerror(RL_WARN,"Invalid aguments have been passed to LinkObject",NULL,NULL,NULL) ;
- switch(ObjectType(parent)) {
- case LIST:
- list = (List *)parent->obj ;
- /* Check for unbounded object */
- (obj->methods->bounds)(obj->obj,obj->bounds);
- if(obj->bounds[LOW][X] > obj->bounds[HIGH][X]) {
- obj->next = list->unbounded;
- list->unbounded = obj;
- }
- else {
- obj->next = list->list;
- list->list = obj;
- }
- parent->prims++;
- break ;
- case GRID:
- grid = (Grid *)parent->obj;
- /* Check for unbounded object */
- (obj->methods->bounds)(obj->obj,obj->bounds);
- if(obj->bounds[LOW][X] > obj->bounds[HIGH][X]) {
- RLerror(RL_WARN,"Grids cannot contain unbounded objects",0,0,0);
- }
- else {
- obj->next = grid->objects;
- grid->objects = obj;
- parent->prims++;
- engrid(obj,grid);
- }
- break;
- case CSG:
- break;
- default:
- RLerror(RL_WARN,"Unsupported object type in link has been called", NULL,NULL,NULL) ;
- }
- }
-
-
- Light *CreateProtoLight(short type)
- {
- Light *light = NULL;
- Vector vec;
- Color col;
-
- col.r = col.g = col.b = 1.;
- vec = crosshair;
- switch(type) {
- case L_POINT:
- light = LightPointCreate(&col,&vec);
- break;
- case L_INFINITE:
- /* Check to see if our crosshair is on the origin */
- if(equal(vec.x,0.) && equal(vec.y,0.) && equal(vec.z,0.))
- vec.y = 1.;
- light = LightInfiniteCreate(&col,&vec);
- break;
- case L_SPOT:
- /* Not supported yet */
- break;
- case L_JITTERED:
- /* Not supported yet */
- break;
- case L_EXTENDED:
- light = LightExtendedCreate(&col,1.,&vec);
- break;
- }
- return light;
- }
-
-
- /* This procedure will create a "protoype" object which is passed back to the parent procedure.
- * The user can then edit this prototype to create their own object of the same type
- */
- Geom *CreateProtoObject(short type, char *name)
- {
- Geom *obj = NULL ;
- switch(type) {
- case MPlane:
- /* A plane going through crosshair with normal pointing upwards */
- {
- Vector p,n,c ;
-
- p = crosshair ;
- n.x = n.y = 0.; n.z = 1. ;
-
- obj = GeomPlaneCreate(&p,&n) ;
- }
- break ;
- case MSphere:
- /* A sphere of radius 1 on the crosshair */
- {
- Vector p ;
-
- p = crosshair ;
- obj = GeomSphereCreate(1.0,&p) ;
- }
- break ;
- case MCone:
- /* A cone of height and width 1 with the base on the crosshair */
- {
- Vector b,a ;
- a = b = crosshair ;
- a.y += 1. ;
- obj = GeomConeCreate(1.,&b,0.,&a) ;
- }
- break ;
- case MBox:
- /* A box with bounds {0,0,0} and {1,1,1} relative to crosshair*/
- {
- Vector b1,b2 ;
-
- b1 = b2 = crosshair ;
- b2.x += 1. ; b2.y += 1. ; b2.z += 1. ;
-
- obj = GeomBoxCreate(&b1,&b2) ;
- }
- break ;
- case MTorus:
- /* A torus of outside radius .5, inside radius .4 about crosshair - normal in z dir */
- {
- Vector pos,norm ;
- pos = crosshair ;
- norm.x = norm.y = 0. ; norm.z = 1. ;
- obj = GeomTorusCreate(.5,.4,&pos,&norm) ;
- }
- break ;
- case MBlob:
- /* A blob of 1 ball of radius 1 at the crosshair */
- {
- MetaList mlist ;
-
- mlist.mvec.x = crosshair.x;
- mlist.mvec.y = crosshair.y;
- mlist.mvec.z = crosshair.z;
- mlist.mvec.rs = 1. ;
- mlist.mvec.c0 = 1. ;
- mlist.mvec.c2 = 1. ;
- mlist.mvec.c4 = 1. ;
- mlist.next = NULL ;
- obj = GeomBlobCreate(1.,&mlist,1) ;
- }
- break ;
- case MDisc:
- /* Disc at crosshair of radius 1 and normal in z direction */
- {
- Vector p, n ;
- p = crosshair ;
- n.x = n.y = 0. ; n.z = 1. ;
-
- obj = GeomDiscCreate(1.,&p,&n) ;
- }
- break ;
- case MTriangle:
- /* A flat triangle with points at {0,0,0} {0,0,1} & {1,0,1} relative to cross hair*/
- {
- Vector p1,p2,p3 ;
-
- p1 = p2 = p3 = crosshair ;
- p2.x += 1. ; p2.y += 1. ; p2.z += 1. ;
- p3.x += 1. ; p3.z += 1.;
-
- obj = GeomTriangleCreate(FLATTRI,&p1,&p2,&p3,NULL,NULL,NULL,NULL,NULL,NULL,0) ;
- }
- break ;
- case MPolygon:
- /* Create a polygon square about cross hair */
- {
- PointList *plist ;
- char loop ;
-
- plist = Malloc(4*sizeof(PointList)) ;
- plist[0].next = &plist[1] ;
- plist[1].next = &plist[2] ;
- plist[2].next = &plist[3] ;
- plist[3].next = NULL ;
- for(loop = 0 ; loop < 4 ; loop++) plist[loop].vec.z = crosshair.z ;
- plist[0].vec.x = crosshair.x -.5 ; plist[0].vec.y = crosshair.y+.5 ;
- plist[1].vec.x = crosshair.x -.5 ; plist[1].vec.y = crosshair.y-.5 ;
- plist[2].vec.x = crosshair.x +.5 ; plist[2].vec.y = crosshair.y-.5 ;
- plist[3].vec.x = crosshair.x +.5 ; plist[3].vec.y = crosshair.y+.5 ;
- obj = GeomPolygonCreate(plist,4,FALSE) ;
- }
- break ;
- case MHf:
- /* Create a "flat" heightfield */
- break ;
- case MCylinder:
- /* Create a cylinder of radius 1 and height 1 , base centred on crosshair */
- {
- Vector top, bottom ;
-
- top = bottom = crosshair ;
- top.x += 1 ;
- obj = GeomCylinderCreate(1.,&top,&bottom) ;
- }
- break ;
- case MList:
- /* Create an empty list */
- obj = GeomListCreate() ;
- ((List *)obj->obj)->list = NULL ;
- ((List *)obj->obj)->unbounded = NULL ;
- obj->prims = 0;
- break ;
- case MGrid:
- /* Create an empty grid */
- {
- int x,y,z;
-
- GetGridSize(&x,&y,&z);
- if((x+y+z) > 0) {
- obj = GeomGridCreate(x,y,z);
- }
- obj->prims = 0;
- }
- break ;
- case MDifference:
- /* Create an empty csg */
- break ;
- case MIntersection:
- break ;
- case MUnion:
- break ;
- } ;
- if(obj) {
- (obj->methods->bounds)(obj->obj,obj->bounds);
- obj->name = Malloc(strlen(name)+1) ;
- if(obj->name)
- strcpy(obj->name, name) ;
- }
-
- return obj ;
- }