home *** CD-ROM | disk | FTP | other *** search
- /*
- * FILE: cube.c
- * AUTHOR: R. Gonzalez
- * CREATED: October 6, 1990
- *
- * defines methods of Cube nested segment and Fast_Cube segment
- */
-
- # include "cube.h"
- # include "line.h"
- # include "trans.h"
-
- /******************************************************************
- * initialize cube
- ******************************************************************/
- boolean Cube::init(void)
- {
- int i;
- /* The following temp needed due to a bug in Think C dealing with
- arrays of pointers, when the array is an instance variable.
- */
- Segment *temp_seg;
-
- Nested_Segment::init();
-
- num_segments = 12;
-
- for (i=0 ; i<12 ; i++)
- {
- temp_seg = new(Line);
- segment[i] = temp_seg;
- segment[i]->init();
- segment[i]->set_color(WHITE);
- }
-
- ((Line*) segment[0])->set_coord(0.,0.,0.,0.,0.,1.);
- ((Line*) segment[1])->set_coord(0.,0.,1.,0.,1.,1.);
- ((Line*) segment[2])->set_coord(0.,1.,1.,0.,1.,0.);
- ((Line*) segment[3])->set_coord(0.,1.,0.,0.,0.,0.);
- ((Line*) segment[4])->set_coord(1.,0.,0.,1.,0.,1.);
- ((Line*) segment[5])->set_coord(1.,0.,1.,1.,1.,1.);
- ((Line*) segment[6])->set_coord(1.,1.,1.,1.,1.,0.);
- ((Line*) segment[7])->set_coord(1.,1.,0.,1.,0.,0.);
- ((Line*) segment[8])->set_coord(0.,0.,0.,1.,0.,0.);
- ((Line*) segment[9])->set_coord(0.,0.,1.,1.,0.,1.);
- ((Line*) segment[10])->set_coord(0.,1.,1.,1.,1.,1.);
- ((Line*) segment[11])->set_coord(0.,1.,0.,1.,1.,0.);
-
- return TRUE;
- }
-
- /******************************************************************
- * initialize fast cube
- ******************************************************************/
- boolean Fast_Cube::init(void)
- {
- int i;
- /* The following temp needed due to a bug in Think C dealing with
- arrays of pointers, when the array is an instance variable.
- */
- Coord3 *temp_coord;
-
- for (i=0 ; i<8 ; i++)
- {
- temp_coord = new(Coord3);
- c[i] = temp_coord;
- c[i]->init();
- }
-
- c[0]->set(0.,0.,0.);
- c[1]->set(0.,0.,1.);
- c[2]->set(0.,1.,1.);
- c[3]->set(0.,1.,0.);
- c[4]->set(1.,0.,0.);
- c[5]->set(1.,0.,1.);
- c[6]->set(1.,1.,1.);
- c[7]->set(1.,1.,0.);
-
- set_color(CYAN);
-
- return TRUE;
- }
-
- /******************************************************************
- * color fast cube
- ******************************************************************/
- void Fast_Cube::set_color(color cube_color_val)
- {
- cube_color = cube_color_val;
- }
-
- /******************************************************************
- * draw fast cube
- ******************************************************************/
- void Fast_Cube::draw(Camera* camera,Projector* projector,
- Transformation* trans)
- {
- int i;
- boolean success = TRUE;
- Coord2 *image[8];
- Coord3 *new_coord;
-
- new_coord = new(Coord3);
- new_coord->init();
-
- for (i=0 ; i<8 ; i++)
- {
- image[i] = new(Coord2);
- image[i]->init();
- new_coord->apply(c[i],trans);
- if (!camera->take_photo(image[i],new_coord))
- success = FALSE;
- }
-
- if (success)
- {
- projector->show_line(image[0],image[1],cube_color);
- projector->show_line(image[1],image[2],cube_color);
- projector->show_line(image[2],image[3],cube_color);
- projector->show_line(image[3],image[0],cube_color);
- projector->show_line(image[0],image[4],cube_color);
- projector->show_line(image[4],image[5],cube_color);
- projector->show_line(image[5],image[6],cube_color);
- projector->show_line(image[6],image[7],cube_color);
- projector->show_line(image[7],image[4],cube_color);
- projector->show_line(image[1],image[5],cube_color);
- projector->show_line(image[2],image[6],cube_color);
- projector->show_line(image[3],image[7],cube_color);
- }
-
- for (i=0 ; i<8 ; i++)
- {
- image[i]->destroy();
- delete(image[i]);
- }
-
- new_coord->destroy();
- delete(new_coord);
- }
-
- /******************************************************************
- * move fast cube coordinates
- ******************************************************************/
- void Fast_Cube::move(Transformation* trans)
- {
- Coord3 *temp;
- int i;
-
- temp = new(Coord3);
- temp->init();
-
- for (i=0 ; i<8 ; i++)
- {
- temp->equate(c[i]);
- c[i]->apply(temp,trans);
- }
-
- temp->destroy();
- delete(temp);
- }
-
- /******************************************************************
- * destroy fast cube
- ******************************************************************/
- boolean Fast_Cube::destroy(void)
- {
- int i;
-
- for (i=0 ; i<8 ; i++)
- {
- c[i]->destroy();
- delete(c[i]);
- }
-
- return TRUE;
- }
-
-
-