home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Virtual Reality Zone
/
VRZONE.ISO
/
mac
/
PC
/
PCGLOVE
/
GLOVE
/
OBJGLV.ZIP
/
SRC
/
BGIACTOR.CPP
next >
Wrap
C/C++ Source or Header
|
1993-05-10
|
6KB
|
250 lines
//
// BGIActor.cpp:
// Implementation of classes BGI_XYZ, and BGIgraphicsActor.
// Example use of Object Glove.
//
// Purpose:
// Outputs graphics and text using Borland BGI toolkit.
//
// Compatibility:
// DOS only!
//
// Copyright 1993 Mark Thomas Pflaging
//
// Date: 3/22/93 (Release 3.0)
//
#include "BGIActor.hpp"
#include "BGIgest.hpp"
#include <stdio.h>
#include <conio.h>
#include <math.h>
Boolean BGIgraphicsActor::textActive;
void BGI_XYZ::erase(int leaveTrail)
{
int erased[5 * 2] = {
right, top, right, bottom, left, bottom, left, top,
right, top
};
setfillstyle(SOLID_FILL,/*EGA_BLACK*/0);
fillpoly( 5, erased);
if (!leaveTrail) {
setcolor(0);
::rectangle(left, top, right, bottom);
}
}
void BGIgraphicsActor::eraseGlove()
{
// erase old box.
oldData.erase(leaveTrails);
}
// draw square cursor
void BGIgraphicsActor::drawGlove(gloveDriver &gd)
{
BGI_XYZ newRect;
newRect.scaleToGlove(gd, getmaxx(), getmaxy());
// prevent redundant drawing.
if ((newRect == oldData) && (gd.getFingers() == oldFingers) &&
(gd.getKeys() == -1))
return;
setcolor(currentColor);
if( drawn ) eraseGlove();
newRect.rectangle(currentColor);
setcolor(currentColor);
newRect.displayGlove(gd, *this);
setfillstyle(fillMode, currentColor);
poly_space->drawAll();
setfillstyle (SOLID_FILL,EGA_LIGHTGRAY);
drawn = 1;
oldData = newRect; // save pos'n for next erase
oldFingers = gd.getFingers();
}
void BGIgraphicsActor::Process(gloveDriver& gd)
{
gd.checkGestures();
postCheck();
if (!textActive) {
if (gloveActive)
drawGlove(gd); // animate glove cursor
if (handActive)
drawFingers(gd, getInstance()); // draw the nonmoving "hand"
if (infoActive)
infoDisplay(gd);
if (gestureActive)
gests.draw();
}
}
void BGIgraphicsActor::displayHelp()
{
cleardevice();
// output a message
int x = getmaxx() / 2;
int y = 5; // getmaxy() / 2;
settextjustify(CENTER_TEXT, CENTER_TEXT);
int height = textheight("Tq");
moveto(x,y+=height);
outtext("This program tests the Nintendo Power Glove");
moveto(x,y+=height);
outtext("when connected to an IBM PC parallel port.");
moveto(x,y+=height);
moveto(x-=(getmaxx()/4),y+=height);
settextjustify(LEFT_TEXT, TOP_TEXT);
moveto(x,y+=height);
outtext("The following POWER GLOVE keys (NOT keyboard keys!)");
moveto(x,y+=height);
outtext("have been defined:");
moveto(x,y+=height);
outtext("1 - display this help screen");
moveto(x,y+=height);
outtext("2 - toggle drawing of moving hand.");
moveto(x,y+=height);
outtext("3 - toggle drawing of nonmoving hand.");
moveto(x,y+=height);
outtext("4 - to toggle info display.");
moveto(x,y+=height);
outtext("5 - toggle display of gestures.");
moveto(x,y+=height);
moveto(x,y+=height);
outtext("A - to toggle \"trails\" behind the rectangle (try it!)");
moveto(x,y+=height);
outtext("B - to clear screen.");
moveto(x,y+=height);
moveto(x,y+=height);
outtext("* Arrows - change color of moving hand *");
moveto(x,y+=height);
moveto(x,y+=height);
outtext("Press any KEYBOARD key to exit the program.");
moveto(x,y+=height);
moveto(x,y+=height);
}
#define LINES 4
#define XOFF 20
#define YOFF 25
#define NUMSTART 17
void BGIgraphicsActor::infoErase(int start)
{
int unit_wid = textwidth("W");
static char hightxt[] = "Tq";
int height = textheight(hightxt);
int x = XOFF + unit_wid * start, y = YOFF + (height * LINES + 1) * getInstance();
int width = unit_wid * (33 - start);
setviewport(x, y, width + x, height * LINES + y, 1);
clearviewport();
setviewport(0, 0, getmaxx(), getmaxy(), 0);
}
void BGIgraphicsActor::infoDisplay(gloveDriver & gd)
{
char temp[255];
int height = textheight("Tq");
int width = textwidth("W");
infoErase(NUMSTART);
int x = XOFF, y = YOFF + (height * LINES + 1) * getInstance();
setcolor(EGA_LIGHTGRAY);
// print constant text:
moveto(x + width * 8, y);
outtext("X, Y, Z:");
// print rot, fingers, keys
moveto(x + width * NUMSTART, y);
sprintf(temp, "%4d, %4d, %4d",
gd.getX(), gd.getY(), gd.getZ());
outtext(temp);
moveto(x,y+=height);
outtext(" Rotation, Keys:");
sprintf(temp, " %2d, %-2x %-3d",
gd.getRotation(), gd.getKeys(), gd.getKeys());
moveto(x + width * NUMSTART, y);
outtext(temp);
moveto(x + width * 8, y += height);
outtext("Fingers:");
sprintf(temp, " %2x, %2x, %2x, %2x",
gd.getThumb(),
gd.getIndex(),
gd.getMiddle(),
gd.getRing());
moveto(x + width * NUMSTART, y);
outtext(temp);
}
void BGIgraphicsActor::Setup()
{
if (!getInstance()) {
int gdriver = DETECT, gmode, errorcode;
// detect graphics hardware available
detectgraph(&gdriver, &gmode);
// gdriver now contains detected hardware info.
// (see graphics_drivers enum type in Borland help)
initgraph(&gdriver, &gmode, NULL); // detect best graphics mode
// read result of initialization
errorcode = graphresult();
if (errorcode != grOk) // an error occurred
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); // exit with error code
}
}
upIncrement = (int)sqrt((double)(getmaxcolor() + 1));
if (currentColor == -1) currentColor = getmaxcolor();
}
void BGIgraphicsActor::Init(InitFile & ini)
{
drawn = 0;
xx = 0;
keyDown = False;
textActive = False;
currentColor = ini.find(title, "startColor", -1);
fillMode = ini.find(title, "fillMode", 0);
}
BGIgraphicsActor::BGIgraphicsActor(InitFile & ini, BGIGestureActor & garg) :
graphicsActor(ini, *(new BGI_PolySpace)), gests(garg)
{
Init(ini);
}
BGIgraphicsActor::BGIgraphicsActor(InitFile & ini, BGIGestureActor & garg, ButtonGestSet & buttons) :
graphicsActor(ini, *(new BGI_PolySpace), buttons), gests(garg)
{
Init(ini);
}
void BGIgraphicsActor::displayGestures()
{
gests.draw();
}
void BGIgraphicsActor::clearGestures()
{
gests.clear();
}