Appendix - Program Modules
~ ~ The following is a listing of the headers for the C functions used in SNEAKERS. They are separated by module and included for those interested in modifying the source code.
/******************************************************************** * ADD_PARTS.C - this module contains functions which are used in * * adding user selected parts to the design of the tower. * * * * Written by : Rob Douglas * ********************************************************************/ /******************************************************************** * void add_connector(PointStr, char *) * * adds a connector of a specific type to the tower at the * * chosen point. * ********************************************************************/ /******************************************************************** * void add_rod(PointStr, int, char *) * * adds a rod of given length and material to tower at point * * given. * ********************************************************************/ /******************************************************************* * void add_bracing(PointStr, PointStr) * * adds bracing between the two given points. * *******************************************************************/ /******************************************************************* * void find_connector(PointStr, DATA_OBJECT **) * * finds the connector which is located at the point given, * * returning a pointer to the connector in the DATA_OBJECT. * *******************************************************************/ /******************************************************************* * void find_rod(PointStr, DATA_OBJECT **) * * the find the rod that ends at the point given, and return * * it in DATA_OBJECT. * *******************************************************************/ /******************************************************************* * void include_rod(PointStr, PointStr, PointStr, int, char *) * * fill in slots for a rod and create an instance for it, then * * include it in the tower. * *******************************************************************/ /******************************************************************* * void get_destination(DATA_OBJECT *, PointStr, PointStr *) * * find the ultimate destination of the rod given, based on * * tower style and other rods in the tower, and their * * destinations. This destination is usually out of reach of * * a single rod, but is the guide for the combination of rods. * * If NULL is given as the rod, generate a new destination. * *******************************************************************/ /******************************************************************* * VOID *get_point_instance(PointStr) * * returns a pointer to the instance of a point at the * * location given, returns NULL if there is no such point * * instance. * *******************************************************************/ /******************************************************************* * PointStr get_endpoint(PointStr,PointStr,DATA_OBJECT *, * * DATA_OBJECT *,int) * * finds where the end point of a newly placed rod should be, * * including the angle at which it should be placed. * *******************************************************************/ /******************************************************************* * PointStr find_point(float,float,PointStr,PointStr,PointStr,int) * * uses geometry and given angles to determine the numeric * * values of the point to be found. * *******************************************************************/ /******************************************************************* * PointStr find_easy_point(PointStr, PointStr, int) * * uses simple geometry for non-complicated angles to find a * * point. * *******************************************************************/ /******************************************************************* * void add_platform_point(PointStr) * * adds one of the corners of the platform to that instance * * necessary. * *******************************************************************/ /******************************************************************* * CLIPS_FUN.C - this module contains functions which access CLIPS * * objects, and are used by CLIPS. * * * * Written by : Rob Douglas * *******************************************************************/ /******************************************************************* * void inform_user() * * this is a function called by CLIPS expert systems to output * * a message to the screen, and thereby the user. * *******************************************************************/ /******************************************************************* * void add_start_points() * * adds the first rod placement points to the list of valid * * rod points. * *******************************************************************/ /******************************************************************* * PointStr return_3D(int, int, int *) * * returns a valid 3D point from the design and increases i * * if a point exists. Otherwise, returns an ignored value and * * does not increase i. * *******************************************************************/ /******************************************************************* * short connector_at(VOID *) * * returns 1 if there exists a connector at the given * * position. * *******************************************************************/ /******************************************************************* * DRAW_FUN.C - this module contains most of the functions needed * * to draw the pieces of the tower during graphics rendering. * * * * Written by : Rob Douglas * *******************************************************************/ /******************************************************************* * int DrawFilledCircle(int, int, int, int) * * draws a filled circle of given color, of a given diameter, * * centered a given point. * *******************************************************************/ /******************************************************************* * int DrawThickLine(int, int, int, int, int, int) * * draws a line of given color and thickness from one given * * point to another. * *******************************************************************/ /******************************************************************* * void cross(PointStr, PointStr, PointStr *) * * returns the cross product of two three-dimensional vectors. * *******************************************************************/ /******************************************************************* * float dot(PointStr, PointStr) * * returns the dot product of two three-dimensional vectors. * *******************************************************************/ /******************************************************************* * void Normalize (PointStr *) * * normalizes a given vector, giving it a length of 1. * *******************************************************************/ /******************************************************************* * void BuildMatrices(PointStr, PointStr, PointStr, PointStr) * * builds transformation matrices from vectors describing * * viewing position and arrangements. * *******************************************************************/ /******************************************************************* * void InitViewVectors(int) * * sets up the viewing vectors based on the viewing angle * * selected. * *******************************************************************/ /******************************************************************* * void transfer(PointStr) * * changes coordinates from world values to device values. * *******************************************************************/ /******************************************************************* * void Cnvt3DTo2D(PointStr *, XPoint *) * * converts a three dimensional point to a two dimensional * * projection. * *******************************************************************/ /******************************************************************* * void DrawROD(DATA_OBJECT) * * draws the rod passed onto the screen. * *******************************************************************/ /******************************************************************* * void DrawConnector(DATA_OBJECT) * * draws the connector passed onto the screen. * *******************************************************************/ /******************************************************************* * void DrawPlatform() * * draw the platform on top of the completed tower. * *******************************************************************/ /******************************************************************* * void Draw_A(int, int, int) * * draws an abstract version of an A-tower of given dimensions.* *******************************************************************/ /******************************************************************* * void Draw_I(int, int, int) * * draws an abstract version of an I-tower of given dimensions.* *******************************************************************/ /******************************************************************* * void Draw_X(int, int, int) * * draws an abstract version of an X-tower of given dimensions.* *******************************************************************/ /******************************************************************* * void Render() * * calls the drawing functions to draw the various pieces of * * the tower. * *******************************************************************/ /******************************************************************* * void DrawGrid() * * Draws the lines that make a drawing area grid which is the * * floor. * *******************************************************************/ /******************************************************************* * MATH_FUN.C - this module contains several useful math functions * * used in other modules. * * * * Written by : Rob Douglas * *******************************************************************/ /******************************************************************* * float sqr(float) * * squares a given number. * *******************************************************************/ /******************************************************************* * float find_angle(PointStr, PointStr) * * returns the angle between two vectors. * *******************************************************************/ /******************************************************************* * float vector_length(PointStr *) * * returns the length of a vector. * *******************************************************************/ /******************************************************************* * int swap_row(float **, int, int, int, int) * * a useful utility function which is used by the inversion * * and Gaussian functions. It simply swaps the rows whose * * indexes are passed to it in the vector passed in. Out of * * bounds is checked, and will return an error. * * Written by Jeff Choate. Modified by Rob Douglas. * *******************************************************************/ /******************************************************************* * void gaussian_elimination(float **, int, int, float **) * * This function does Gaussian elimination. It is written by * * Jeff Choate with no help from the books. Therefore, this * * one is the one to follow if you do not understand the * * process. The algorithm goes right down the diagonal * * elimination all entries below it, and making itself 1 for * * possible later solutions. It can be used to quickly check * * linear dependence, for if any diagonal entry is 0 after the * * algorithm finishes, the matrix has some linear dependance. * * This algorithm is not as numerically precise as the previous* * inverter, for it does no row swapping unless the diagonal * * entry is zero. And only then because you have to. This is * * a big no no, for it leads to big roundoff problems. Also * * the row is divided by the pivoting column first, which only * * leads to numeric problems. Therefore I have left this in * * not so much for use as for reference. It could be easily * * changed to be just as precise as the previous inverter was. * * This is a non-destructive function, so the original matrix * * will be preserved. However, the result of the inversion will* * be stored in the result array which must be previously * * allocated. It has to be at least as big as * * xdim * ydim * sizeof(float). * * Written by Jeff Choate. Modified by Rob Douglas. * *******************************************************************/ /******************************************************************* * void back_substitute(float **, int, float **) * * performs back substitution on a matrix that has been * * diagonalized by Gaussian elimination. * *******************************************************************/ /******************************************************************* * int vecmult(float *, float **, float *) * * This routine multiplies a (4X1) vector by a (4X4) matrix and * * puts the result in the (4X1) vector specified. * *******************************************************************/ /******************************************************************* * float pointdist(PointStr, PointStr) * * returns the distance between two points in 3 space. * *******************************************************************/ /******************************************************************* * MEMORY.C - this module contains functions which are used for * * managing memory in the whole program. * * * * Written by : Rob Douglas * *******************************************************************/ /******************************************************************* * void *newitem(int) * * returns a generic pointer to a block of memory of the * * required size. * *******************************************************************/ /******************************************************************* * void *olditem(void *,int) * * returns a generic pointer to a block of memory of the * * required size, reallocating for the old item. * *******************************************************************/ /******************************************************************* * POINT.C - this module contains functions used in keeping track * * of the points that the user might wish to place various objects.* * * * Written by : Rob Douglas * *******************************************************************/ /******************************************************************* * short pointlist_empty(int) * * checks whether or not one of the global points lists are * * empty. * *******************************************************************/ /******************************************************************* * void clear_pointlists() * * empties all of the global points lists. * *******************************************************************/ /******************************************************************* * void get_point(int) * * controls the selection of a point on the screen, checking * * to see if it is on the proper list. * *******************************************************************/ /******************************************************************* * void validate(int, int, int, PointStr **) * * checks whether or not a certain point is on one of the global* * lists, *and removes it if it is, returning the 3D value * * of the point. * *******************************************************************/ /******************************************************************* * void add_valid_point(int, PointStr *) * * adds a point to the proper list. * *******************************************************************/ /******************************************************************* * void add_A_points(int, int, int) * * adds the initial points for an A-tower of given dimensions * * to the global rod points list. * *******************************************************************/ /******************************************************************* * void add_I_points(int, int, int) * * adds the initial points for an I-tower of given dimensions * * to the global rod points list. * *******************************************************************/ /******************************************************************* * void add_X_points(int, int, int) * * adds the initial points for an X-tower of given dimensions * * to the global rod points list. * *******************************************************************/ /******************************************************************* * int get_two_points(PointStr *) * * get two points which could be used to place bracing. * *******************************************************************/ /******************************************************************* * SCREEN.C - contains all of the functions which control the user * * interface including all callbacks and any functions which access* * widgets directly. * * * * Written by : Rob Douglas and VUIT * *******************************************************************/ /******************************************************************* * UserFunctions() * * necessary function when including CLIPS in another C * * program. Describes the user defined functions that may be * * CLIPS expert systems. * *******************************************************************/ /******************************************************************* * void init_datastructs() * * initializes some of the global variables. * *******************************************************************/ /******************************************************************* * void create_procedure(Widget, int *, unsigned long *) * * called by most widgets when they are created to add them to * * the widget array so they can be easily accessed. * *******************************************************************/ /******************************************************************* * void quit_button_press(Widget, int *, unsigned long *) * * callback for exiting the program when quit button is * * pressed. * *******************************************************************/ /******************************************************************* * void DisplayTower(Widget, int *, unsigned long *) * * callback to display the tower when the drawing area is in * * view. * *******************************************************************/ /******************************************************************* * void InitGraphics(Widget, int *, unsigned long *) * * opens display and sets up drawing area to act as graphics * * window. * *******************************************************************/ /******************************************************************* * void new_button_press(Widget, int *, unsigned long *) * * callback for when the new button is pressed. * *******************************************************************/ /******************************************************************* * void requirements_reset(Widget, int *, unsigned long *) * * callback to reset the requirements selections to their * * default values. * *******************************************************************/ /******************************************************************* * void requirements_ok(Widget, int *, unsigned long *) * * callback to accept selected requirements. * *******************************************************************/ /******************************************************************* * void requirements_cancel(Widget, int *, unsigned long *) * * callback to cancel selection of requirements and return to * * previous point in the program. * *******************************************************************/ /******************************************************************* * void colormap_ok(Widget, int *, unsigned long *) * * callback to acknowledge that the black and white version * * does not have all of the features of the color version. * *******************************************************************/ /******************************************************************* * void colormap_cancel(Widget, int *, unsigned long *) * * exit program if black and white screen is not acceptable. * *******************************************************************/ /******************************************************************* * void activate_aspect(int) * * turns on an aspect or agent button, and highlights it. * *******************************************************************/ /******************************************************************* * void aspect_pressed(Widget, int *, unsigned long *) * * callback for when one of the aspect buttons is pressed. * *******************************************************************/ /******************************************************************* * void agent_pressed(Widget, int *, unsigned long *) * * callback for when one of the agent buttons is pressed. * *******************************************************************/ /******************************************************************* * void return_pressed(Widget, int *, unsigned long *) * * callback to return from the agent specific information * * window. * *******************************************************************/ /******************************************************************* * void deactivate_aspect(int) * * unhighlight an aspect or agent button when new information * * is no longer available. * *******************************************************************/ /******************************************************************* * void tower_style_select(Widget, int *, unsigned long *) * * callback for abstract tower type selections from palette. * *******************************************************************/ /******************************************************************* * void redraw() * * force a refresh of the screen. * *******************************************************************/ /******************************************************************* * void change_int_scale(Widget, int *, XmScaleCallbackStruct *) * * callback assigned to handle changes in the values of the * * intermediate level scales, which determine the dimensions * * of the tower. * *******************************************************************/ /******************************************************************* * void manage_scales() * * set the initial values of the intermediate level, dimension * * selecting scales, before they are managed. * *******************************************************************/ /******************************************************************* * void intermediate_accept(Widget, int *, unsigned long *) * * accept intermediate values chosen, and propagate the * * values chosen. * *******************************************************************/ /******************************************************************* * void Undo(Widget, int *, unsigned long *) * * callback for when undo is selected, starts all of the * * necessary functions for removing pieces and resetting * * values. * *******************************************************************/ /******************************************************************* * void desense_place_buttons(Widget, int *, unsigned long *) * * turn sensitivity off for palette buttons during detailed * * design. * *******************************************************************/ /******************************************************************* * void place_rod(Widget, int *, unsigned long *) * * perform functions necessary for placing a rod into the tower* * design. * *******************************************************************/ /******************************************************************* * void place_bracing(Widget, int *, unsigned long *) * * perform functions necessary for placing bracing into the * * tower design. * *******************************************************************/ /******************************************************************* * void place_connector(Widget, int *, unsigned long *) * * perform functions necessary for placing a connector into * * the tower design. * *******************************************************************/ /******************************************************************* * void place_platform(Widget, int *, unsigned long *) * * perform functions necessary for placing the platform at the * * top of the tower. * *******************************************************************/ /******************************************************************* * void set_placing_buttons() * * set the sensitivity of the palette buttons during detailed * * design on. * *******************************************************************/ /******************************************************************* * void rod_select_ok(Widget, int *, unsigned long *) * * accept the selected parameters for the rod to be placed. * *******************************************************************/ /******************************************************************* * void rod_select_cancel(Widget, int *, unsigned long *) * * cancel placing of a rod. * *******************************************************************/ /******************************************************************* * void connector_select_ok(Widget, int *, unsigned long *) * * accept the selected parameters for the connector to be * * placed. * *******************************************************************/ /******************************************************************* * void connector_select_cancel(Widget, int *, unsigned long *) * * cancel placing of a connector. * *******************************************************************/ /******************************************************************* * void out_to_screen(char *, char *, char *, char *) * * outputs recommendations to themessages window, and stores * * information for the individual agents' output. * *******************************************************************/ /******************************************************************* * void show_aspects() * * activate those aspect buttons that have new information. * *******************************************************************/ /******************************************************************* * void show_agents() * * activate the agent buttons that have new information. * *******************************************************************/ /******************************************************************* * void list_selection(Widget, int *, XmListCallbackStruct *) * * callback for changing values of selections for attributes * * of objects added to the design. * *******************************************************************/ /******************************************************************* * void change_view_scale(Widget, int *, XmScaleCallbackStruct *) * * rotate the view of the tower as selected by the rotation * * bar. * *******************************************************************/ /******************************************************************* * void change_information() * * changes the information in the information text window. * *******************************************************************/ /******************************************************************* * void DeleteAgents() * * Removes all data from agent lists. * *******************************************************************/ /******************************************************************* * TOYS.C - contains functions which affect various objects in * * COOL, the CLIPS Object Oriented Language. * * * * Written by : Rob Douglas * *******************************************************************/ /******************************************************************* * void change_height(int) * * changes the height of the tower. * *******************************************************************/ /******************************************************************* * void change_base(int) * * changes the base of the tower. * *******************************************************************/ /******************************************************************* * void change_platform(int) * * changes the platform size of the tower. * *******************************************************************/ /******************************************************************* * float choose_valid_angle(float, DATA_OBJECT) * * returns the closest angle to the given angle, allowed by * * the given connector. * *******************************************************************/ /******************************************************************* * VOID *get_last_instance() * * gets a pointer to the last instance created, for use in * * undoing. * *******************************************************************/ /******************************************************************* * short undo_last_added() * * removes the last object added to the tower. * *******************************************************************/ /******************************************************************* * short member_of_class(char *, VOID *) * * checks whether or not an instance is a member of a given * * class. This had to be written because of a bug in the * * CLIPS code which normally would perform this function. * *******************************************************************/ /******************************************************************* * void remove_from_tower(VOID *) * * takes care of superficial details concerned with removing a * * piece from the tower. * *******************************************************************/ /******************************************************************* * void replace_valid_point(VOID *) * * replaces the points taken off of the global point lists by * * adding a piece to the tower, when that piece is removed. * *******************************************************************/