proj home

Files   Classes   Functions   Hierarchy  

Public Member Functions | Public Attributes | List of all members
mazedisp03 Class Reference

Iterate over mazematrixD2 as a matrix drawing each cell. More...

#include <mazedisp03.h>

Inheritance diagram for mazedisp03:
Inheritance graph
Collaboration diagram for mazedisp03:
Collaboration graph

Public Member Functions

 mazedisp03 (mazegameD2state01 &mg_)
 Default maze draw.
 ~mazedisp03 ()
 Cleanup.
void draw ()
 Draws to the global graphics stream.
void construct ()
 Build the static geometry and add dynamic geometry.
void staticgraphics ()
 Geometry which does not change.
void mouseevent ()
 Processes mouse event.
void celldraw (cellD2< uint > const &x, point2< double > const &p)
 Draw cell.
void celldraw2 (cellD2< uint > const &x, point2< double > const &p)
 Draw cell with path istead of walls.
void game01default ()
 Default settings for game01.
stringc settings () const
 This class's command line settings.
point2< double > const cellmidpoint (uintc id) const
 Get the midpoint of the cell given the cells id.
void currentposdraw ()
void f01 ()
- Public Member Functions inherited from gobj
virtual ~gobj ()
 Destructor.

Public Attributes

graphicsImmediateDeferredSwitch gx
 Contains all the graphics.
uint staticgraphicsindex
 Index into gx for static geometry.
mazegameD2state01mg
 Maze game.
double dx
 Square cell side length.
bool displaycellid
 Display the cells id.
bool pipes
 Instead of drawing the walls, draw the paths.
point3< double > pipecolor
 Color of pipes.
bool walls
 Display the walls.
point3< double > wallcolor
 Color of cell walls.
point2< double > origin
 Initial translation of maze.
point3< double > backgroundcolor
 Background color.
double endpointratio
 Size of start and finish spheres.
point3< double > endpointcolor
 Start and finish sphere color.
point3< double > currentposcolor
 Current position and path color.
fnobj0Tfn< mazedisp03, void > mousecallback
 Functional object calling mouse(zpr&)
zprmousezm
buttonpanel02bp02
 Movement buttons.

Additional Inherited Members

- Static Public Member Functions inherited from gobj
static void globaldisplaylist (uintc id)
 Convert the global graphics into a display list.
- Static Public Attributes inherited from gobj
static gobjContainerglobal = 0
 The graphics stream.

Detailed Description

Iterate over mazematrixD2 as a matrix drawing each cell.

Interprets mazematrixD2 as a m by n matrix, iterating over each cell and drawing it.

Definition at line 21 of file mazedisp03.h.

Constructor & Destructor Documentation

mazedisp03::mazedisp03 ( mazegameD2state01 mg_)

Default maze draw.

Definition at line 15 of file mazedisp03.cpp.

{
}
mazedisp03::~mazedisp03 ( )

Cleanup.

Definition at line 20 of file mazedisp03.cpp.

References zm.

{
delete zm;
zm=0;
}

Member Function Documentation

void mazedisp03::celldraw ( cellD2< uint > const &  x,
point2< double > const &  p 
)

Draw cell.

Definition at line 194 of file mazedisp03.cpp.

References gobjpush, cellD2< T >::ni, point2< T >::x, and point2< T >::y.

Referenced by staticgraphics().

{
point2<double> p10 = p00;
p10.x += dx;
point2<double> p01 = p00;
p01.y += dx;
point2<double> p11 = p00;
p11.x += dx;
p11.y += dx;
if (x.ni[1]==0)
{
}
if (x.ni[3]==0)
{
}
if (x.ni[0]==0)
{
}
if (x.ni[2]==0)
{
}
}
void mazedisp03::celldraw2 ( cellD2< uint > const &  x,
point2< double > const &  p 
)

Draw cell with path istead of walls.

Definition at line 233 of file mazedisp03.cpp.

References gobjpush, cellD2< T >::ni, point2< T >::x, and point2< T >::y.

Referenced by staticgraphics().

{
double dx2 = dx*0.5;
point2<double> p3 = p00;
p3.y += dx2;
point2<double> p1 = p00;
p1.x += dx;
p1.y += dx2;
point2<double> p0 = p00;
p0.x += dx2;
p0.y += dx;
point2<double> p2 = p00;
p2.x += dx2;
point2<double> pcenter = p00;
pcenter.x += dx2;
pcenter.y += dx2;
if (x.ni[1]!=0)
{
gobjpush(new gobjglVertex2d(pcenter));
}
if (x.ni[3]!=0)
{
gobjpush(new gobjglVertex2d(pcenter));
}
if (x.ni[0]!=0)
{
gobjpush(new gobjglVertex2d(pcenter));
}
if (x.ni[2]!=0)
{
gobjpush(new gobjglVertex2d(pcenter));
}
}
point2< double > const mazedisp03::cellmidpoint ( uintc  id) const

Get the midpoint of the cell given the cells id.

Definition at line 85 of file mazedisp03.cpp.

References mazematrixD2< T >::dim, dx, mg, mazegameD2state01::mz, point2< T >::x, and point2< T >::y.

Referenced by currentposdraw(), and staticgraphics().

{
uint k = id-1;
uint m=mg.mz.dim[0];
uint n=mg.mz.dim[1];
pos1.x = k % n;
pos1.y = (m*n-1)/n-k/n;
pos2.x = dx*pos1.x;
pos2.y = dx*pos1.y;
return pos2+point2<double>(dx*0.5,dx*0.5);
}
void mazedisp03::construct ( )

Build the static geometry and add dynamic geometry.

Definition at line 47 of file mazedisp03.cpp.

References bp02, currentposdraw(), gobjcallbackcreatenew(), gx, graphicsImmediateDeferredSwitch::pushdeferred(), graphicsImmediateDeferredSwitch::pushimmediate(), staticgraphics(), staticgraphicsindex, graphicsImmediateDeferred::update(), and zm.

Referenced by maze004::eval(), and maze005::eval().

{
//gx.push(staticgraphicsindex,*this,&mazedisp03::staticgraphics);
uint index;
// Turned off mouse button
// gx.pushimmediate(index,bp02);
}
void mazedisp03::currentposdraw ( )

Definition at line 300 of file mazedisp03.cpp.

References cellmidpoint(), currentposcolor, dx, endpointratio, mg, mazegameD2state01::path, point2< T >::x, point3< T >::x, point2< T >::y, point3< T >::y, and point3< T >::z.

Referenced by construct().

{
assert(mg.path.empty()==false);
uint cp = mg.path[mg.path.size()-1];
glPushAttrib(GL_CURRENT_BIT);
// Assume model view
glPushMatrix();
glTranslated(cpx.x,cpx.y,0.0);
glutSolidSphere(dx*endpointratio,35,35);
glPopMatrix();
for (uint i=0; i<mg.path.size(); ++i)
{
glPushMatrix();
glTranslated(cppos.x,cppos.y,0.0);
glutSolidSphere(dx*endpointratio*0.5,35,35);
glPopMatrix();
}
glPopAttrib();
//f01();
}
void mazedisp03::draw ( )
virtual

Draws to the global graphics stream.

Implements gobj.

Definition at line 41 of file mazedisp03.cpp.

References graphicsImmediateDeferred::draw(), and gx.

{
//cout << "mazedisp03::draw()" << endl;
gx.draw();
}
void mazedisp03::f01 ( )

Definition at line 330 of file mazedisp03.cpp.

References zpr::height, SHOW, zpr::width, point2< T >::x, point2< T >::y, zm, and zprmouse::zz.

{
assert(zm);
// Code taken from tutorial
// http://basic4gl.wikispaces.com/2D+Drawing+in+OpenGL
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,zm->zz.width,zm->zz.height,0,0,1);
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslatef(0.375,0.375,0);
int radius=5;
int x1=320;
int y1=240;
//cout << "Drawing in 2D" << endl;
glPushAttrib(GL_CURRENT_BIT);
glPushAttrib(GL_LIGHTING_BIT);
glDisable(GL_LIGHTING);
glColor3f(1.0,0.0,0.0);
double rad=3.141592*2.0/360.0;
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x1,y1);
for (double angle=0; angle<=360; angle+=2)
{
point2<double> x2(x1+ sin(rad*angle)*radius, y1 + cos(rad*angle)*radius);
cout << SHOW(x2) << " ";
glVertex2d(x2.x,x2.y);
//glVertex2f(x1 + sin(rad*angle) * radius, y1 + cos(rad*angle) * radius);
//glVertex2f(x1 + sin(angle)*radius, y1 + cos(angle)*radius);
}
glEnd();
cout << endl;
glPopAttrib();
glPopAttrib();
// Returning to previous state.
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
}
void mazedisp03::game01default ( )

Default settings for game01.

Definition at line 26 of file mazedisp03.cpp.

References backgroundcolor, currentposcolor, displaycellid, dx, endpointcolor, endpointratio, origin, pipecolor, pipes, wallcolor, and walls.

{
dx=0.1;
pipes=false;
pipecolor=point3<double>(1.0,0.0,0.0);
walls=true;
wallcolor=point3<double>(0.0,0.0,1.0);
currentposcolor=point3<double>(0.0,1.0,205.0/255.0);
}
void mazedisp03::mouseevent ( )

Processes mouse event.

Definition at line 387 of file mazedisp03.cpp.

References zprmouse::update(), and zm.

{
assert(zm);
if (zm==0)
return;
zm->update();
//cout << "mouse() " << zm->mouse() << " " << zm->world() << endl;
// Turned off button code because of bad usablity
/*
assert(bp02);
bool res(false);
uint index;
bp02->process(res,index,zm->mouseint());
if (res==false)
return;
assertreturnfalse(index<4);
mg.currentmove(index);
glutPostRedisplay();
*/
}
stringc mazedisp03::settings ( ) const

This class's command line settings.

Definition at line 280 of file mazedisp03.cpp.

References backgroundcolor, currentposcolor, displaycellid, dx, endpointcolor, endpointratio, stringconvert::findandreplacefn(), origin, pipecolor, pipes, stringto(), stringconvert::tostring(), wallcolor, and walls.

{
string options="";
string s;
options += ( "dx=" + stringconvert::tostring(dx) + " ");
options += ( "id=" + stringconvert::tostring(displaycellid) + " ");
options += ( "pipes=" + stringconvert::tostring(pipes) + " ");
options += ( "pipecolor=" + stringconvert::findandreplacefn(stringto(pipecolor*255.0)," ",",") + " ");
options += ( "walls=" + stringconvert::tostring(walls) + " ");
options += ( "wallcolor=" + stringconvert::findandreplacefn(stringto(wallcolor*255.0)," ",",") + " ");
options += ( "origin=" + stringconvert::findandreplacefn(origin," ",",") + " ");
options += ( "backgroundcolor=" + stringconvert::findandreplacefn(stringto(backgroundcolor*255.0)," ",",") + " ");
options += ( "endpointratio=" + stringconvert::tostring(endpointratio) + " ");
options += ( "endpointcolor=" + stringconvert::findandreplacefn(stringto(endpointcolor*255.0)," ",",") + " ");
options += ( "currentposcolor=" + stringconvert::findandreplacefn(stringto(currentposcolor*255.0)," ",",") + " ");
return options;
}
void mazedisp03::staticgraphics ( )

Geometry which does not change.

Definition at line 102 of file mazedisp03.cpp.

References celldraw(), celldraw2(), cellmidpoint(), mazematrixD2< T >::dim, displaycellid, dx, endpointcolor, endpointratio, mazegameD2state01::gamefinish, mazegameD2state01::gamestart, gobj::global, gobjpush, mg, mazegameD2state01::mz, pipecolor, pipes, mazematrixD2< T >::valid(), mazematrixD2< T >::vi, wallcolor, walls, point2< T >::x, and point2< T >::y.

Referenced by construct().

{
assert(dx!=0.0);
assert(mg.mz.valid());
assert(mg.mz.vi.size()==(1+mg.mz.dim[2]));
gobjpush(new gobjglDisable(GL_LIGHTING));
gobjpush(new gobjglBegin(GL_LINES));
uint m=mg.mz.dim[0];
uint n=mg.mz.dim[1];
uint id;
uint K=m*n-1;
if (walls)
{
for (uint k=0; k<mg.mz.dim[2]; ++k)
{
id=k+1;
pos1.x = k % n;
pos1.y = K/n-k/n;
pos2.x = dx*pos1.x;
pos2.y = dx*pos1.y;
celldraw(mg.mz.vi[id],pos2);
}
}
if (pipes)
{
for (uint k=0; k<mg.mz.dim[2]; ++k)
{
id=k+1;
pos1.x = k % n;
pos1.y = K/n-k/n;
pos2.x = dx*pos1.x;
pos2.y = dx*pos1.y;
celldraw2(mg.mz.vi[id],pos2);
}
}
// Each cell has a midpoint in the maze, calculate it.
vector< point2<double> > pi;
pi.push_back(point2<double>());
for (uint k=0; k<mg.mz.dim[2]; ++k)
{
pi.push_back(cellmidpoint(k+1));
/*
id=k+1;
pos1.x = k % n;
pos1.y = K/n-k/n;
pos2.x = dx*pos1.x;
pos2.y = dx*pos1.y;
pi.push_back(pos2+point2<double>(dx*0.5,dx*0.5));
*/
}
{
gobjpush(new gobjglColor3f(point3<float>(1.0,0.0,0.0)));
}
gobjpush( new gobjglEnable(GL_LIGHTING) );
//double endpointsratio=0.25;
}

Member Data Documentation

point3<double> mazedisp03::backgroundcolor

Background color.

Definition at line 50 of file mazedisp03.h.

Referenced by maze004::eval(), maze005::eval(), game01default(), and settings().

buttonpanel02* mazedisp03::bp02

Movement buttons.

Definition at line 78 of file mazedisp03.h.

Referenced by construct().

point3<double> mazedisp03::currentposcolor

Current position and path color.

Definition at line 56 of file mazedisp03.h.

Referenced by currentposdraw(), game01default(), and settings().

bool mazedisp03::displaycellid

Display the cells id.

Definition at line 38 of file mazedisp03.h.

Referenced by game01default(), settings(), and staticgraphics().

double mazedisp03::dx

Square cell side length.

Definition at line 36 of file mazedisp03.h.

Referenced by cellmidpoint(), currentposdraw(), game01default(), settings(), and staticgraphics().

point3<double> mazedisp03::endpointcolor

Start and finish sphere color.

Definition at line 54 of file mazedisp03.h.

Referenced by game01default(), settings(), and staticgraphics().

double mazedisp03::endpointratio

Size of start and finish spheres.

Definition at line 52 of file mazedisp03.h.

Referenced by currentposdraw(), game01default(), settings(), and staticgraphics().

Contains all the graphics.

Definition at line 27 of file mazedisp03.h.

Referenced by construct(), and draw().

mazegameD2state01& mazedisp03::mg

Maze game.

Definition at line 33 of file mazedisp03.h.

Referenced by cellmidpoint(), currentposdraw(), and staticgraphics().

fnobj0Tfn<mazedisp03,void> mazedisp03::mousecallback

Functional object calling mouse(zpr&)

Definition at line 75 of file mazedisp03.h.

Referenced by maze004::eval(), and maze005::eval().

point2<double> mazedisp03::origin

Initial translation of maze.

Definition at line 48 of file mazedisp03.h.

Referenced by maze004::eval(), maze005::eval(), game01default(), and settings().

point3<double> mazedisp03::pipecolor

Color of pipes.

Definition at line 42 of file mazedisp03.h.

Referenced by game01default(), settings(), and staticgraphics().

bool mazedisp03::pipes

Instead of drawing the walls, draw the paths.

Definition at line 40 of file mazedisp03.h.

Referenced by game01default(), settings(), and staticgraphics().

uint mazedisp03::staticgraphicsindex

Index into gx for static geometry.

Definition at line 30 of file mazedisp03.h.

Referenced by construct().

point3<double> mazedisp03::wallcolor

Color of cell walls.

Definition at line 46 of file mazedisp03.h.

Referenced by game01default(), settings(), and staticgraphics().

bool mazedisp03::walls

Display the walls.

Definition at line 44 of file mazedisp03.h.

Referenced by game01default(), settings(), and staticgraphics().

zprmouse* mazedisp03::zm

Definition at line 76 of file mazedisp03.h.

Referenced by construct(), maze004::eval(), maze005::eval(), f01(), mouseevent(), and ~mazedisp03().


The documentation for this class was generated from the following files: