home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Desktop Works 1995 - 1996
/
desktopworks1995-1996.iso
/
scrnsave
/
win_maze
/
maze3d.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1996-01-01
|
28KB
|
850 lines
#include <owl\owlpch.h>
#include <owl\applicat.h>
#include <owl\framewin.h>
#include <owl\dc.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include "oracle.h"
#include "cell.h"
#include "hexmaze.h"
#include "sqrmaze.h"
#include "plot3d.h"
#include "maze3d.rh"
#ifndef TRUE
#define TRUE -1
#endif
#ifndef FALSE
#define FALSE 0
#endif
static int hex_external_to_plot(double,double);
static double hex_f(double,double);
static int hex_red(double,double);
static int sqr_external_to_plot(double,double);
static double sqr_f(double,double);
static int sqr_red(double,double);
// maze constants
#define PIXELS_PER_HEXAGONAL_ROOM 60
#define PIXELS_PER_SQUARE_ROOM 40
#define RESOLUTION 4 // larger values takes more time (and
// virtual memory) but produce a better
// image.
hexmaze *hexmaze_ptr; // pointer to generator for maze with hexagonal rooms
sqrmaze *sqrmaze_ptr; // pointer to generator for maze with square rooms
class MazeWindow : public TFrameWindow
{
public:
MazeWindow(TWindow* parent,const char far* title);
void CleanupWindow();
BOOL IdleAction(long IdleCount);
// So that the program remains responsive, the plotting is done here.
void Paint(TDC &dc,BOOL erase,TRect &dirty);
// This method is invoked when part of the display has been made
// "dirty" (for example, when another window has been moved from
// atop the display).
protected:
void CeActionClear(TCommandEnabler &ce);
// Determines whether the action "Clear" may be selected.
void CeActionSolve(TCommandEnabler &ce);
// Determines whether the action "Solve" may be selected.
void CeStyleSquare(TCommandEnabler &ce);
// Determines whether a check mark should appear to the left of the
// style "Square rooms".
void CeStyleHexagon(TCommandEnabler &ce);
// Determines whether a check mark should appear to the left of the
// style "Hexagonal rooms".
void CmActionNew();
// Processes a request for a new maze.
void CmActionSolve();
// Processes a request that a maze be solved.
void CmActionClear();
// Processes a request that the solution be cleared from a maze.
void CmHelpAbout();
// Processes a request for information about the author.
void CmHelpUsage();
// Processes a request for information about using this program.
void CmStyleSquare();
// Processes a request for square rooms.
void CmStyleHexagon();
// Processes a request for hexagonal rooms.
void EvHScroll(UINT code,UINT pos,HWND wnd);
// Processes a change in the horizontal scroll bar -- a request for
// a new angle of rotation.
void EvSize(UINT sizeType,TSize &size);
// Processes resizing of the window -- a request for a different size
// maze.
void EvVScroll(UINT code,UINT pos,HWND wnd);
// Processes a change in the vertical scroll bar -- a request for a
// new angle of tilt.
private:
void DisplayMessage(const string& msg);
// Pops up a message to the user.
double light_x;
double light_y;
double light_z;
// Vector to the major source of light.
int num_columns;
// Number of columns in the current maze.
int num_rows;
// Number of rows in the current maze.
int only_plot_solution;
// If TRUE, only plot the outline to the solution of the maze.
plot3d *plot3d_ptr;
// Pointer to an instance of the 3D plotting class.
TRect region_to_paint;
// The part of the maze to be plotted.
int rotation;
// The number of degrees the maze is rotated about a line
// perpendicular to its base.
char seed [9];
// Random number seed (derived from the system clock) used to
// generate the maze.
int solve;
// TRUE if the maze is to be solved.
int solved;
// TRUE if the solution is currently displayed.
char state;
// State of the plotting; one of the following:
// 'B' -- beginning
// 'M' -- maze being generated
// 'S' -- preparing plot
// 'P' -- plotting
// 'F' -- failure
// 'D' -- done
char style;
// 'H' for hexagonal rooms; 'S' for square rooms.
int tilt;
// The number of degrees the maze is tilted towards the viewer.
DECLARE_RESPONSE_TABLE(MazeWindow);
// Associates user commands with methods in this program.
};
DEFINE_RESPONSE_TABLE1(MazeWindow,TFrameWindow)
EV_COMMAND(CM_ACTION_NEW,CmActionNew),
EV_COMMAND(CM_ACTION_SOLVE,CmActionSolve),
EV_COMMAND(CM_ACTION_CLEAR,CmActionClear),
EV_COMMAND(CM_HELP_ABOUT,CmHelpAbout),
EV_COMMAND(CM_HELP_USAGE,CmHelpUsage),
EV_COMMAND(CM_STYLE_SQUARE,CmStyleSquare),
EV_COMMAND(CM_STYLE_HEXAGON,CmStyleHexagon),
EV_COMMAND_ENABLE(CM_ACTION_SOLVE,CeActionSolve),
EV_COMMAND_ENABLE(CM_ACTION_CLEAR,CeActionClear),
EV_COMMAND_ENABLE(CM_STYLE_SQUARE,CeStyleSquare),
EV_COMMAND_ENABLE(CM_STYLE_HEXAGON,CeStyleHexagon),
EV_WM_HSCROLL,
EV_WM_VSCROLL,
EV_WM_SIZE,
END_RESPONSE_TABLE;
MazeWindow::MazeWindow(
TWindow *parent,
const char far *title) : TFrameWindow(parent, title)
{
Attr.Style |= WS_VSCROLL | WS_HSCROLL;
// Scroll bars are used to specify tilt and rotation.
AssignMenu("MAZE_MENU");
state='B'; // beginning plot
style='S'; // square rooms
rotation=0; // (degrees)
tilt=30; // (degrees)
light_x=(double) 1.5; // vector to light source
light_y=(double) -1.0;
light_z=(double) 2.6;
solve=FALSE; // initially, don't show the solution
plot3d_ptr=new plot3d((TFrameWindow *) this); // 3D plotter
}
void MazeWindow::CleanupWindow()
{
delete plot3d_ptr; // destroy 3D plotter
TFrameWindow::CleanupWindow();
}
void MazeWindow::DisplayMessage(const string &msg)
// Pops up a message to the user.
{
MessageBox(msg.c_str(),GetApplication()->GetName(),
MB_OK | MB_ICONEXCLAMATION);
return;
}
BOOL MazeWindow::IdleAction(long IdleCount)
// So that the program remains responsive, the plotting is done here.
{
switch (state)
// State of the plotting; one of the following:
// 'B' -- beginning
// 'R' -- restarting
// 'M' -- maze being generated
// 'S' -- preparing plot
// 'P' -- plotting
// 'F' -- failure
// 'D' -- done
{
case 'B': // begin
{
solved=FALSE;
// The solution is not (or soon won't be) completely displayed.
GetClientRect(region_to_paint);
// The whole maze is being plotted.
SetScrollRange(SB_VERT,0,90);
// The maze may be tilted between 0 and 90 degrees.
SetScrollRange(SB_HORZ,0,360);
// The maze may be rotated between 0 and 360 degrees.
SetScrollPos(SB_VERT,90-tilt);
// Display the current tilt on the vertical scroll bar.
SetScrollPos(SB_HORZ,rotation);
// Display the current rotation on the horizontal scroll bar.
only_plot_solution=FALSE;
// Plot the base, walls, etc.
// Pick a maze at random.
time_t quotient;
time_t remainder;
time_t start_time;
time(&start_time);
for (int i=0; i < 8; i++)
{
quotient=start_time/10;
remainder=start_time