// ROTLIB.CPP
//
// Author : Saket Soni
// Requirements : DOS/Windows, Turbo C++ 3.0
//
// Description : 3D - Animation definition library file
//
//
////////////////////////////////////////////////////////////////////////////
// Header files ...
////////////////////////////////////////////////////////////////////////////
#include
#include
#include
#include
#include
#include"rotlib.h"
////////////////////////////////////////////////////////////////////////////
// Global constant declarations ...
////////////////////////////////////////////////////////////////////////////
float MaxX;
float MaxY;
float MidX;
float MidY;
////////////////////////////////////////////////////////////////////////////
// Global function declarations ...
////////////////////////////////////////////////////////////////////////////
void drawLine(int x1, int y1, int x2, int y2, int color) // to draw a line
{
setcolor(color);
line (x1+MidX, MidY-y1, x2+MidX, MidY-y2);
}
void fillSurface(int x, int y, int fillcolor) // to fill a surface
{
// setfillstyle(SOLID_FILL,fillcolor);
// floodfill(x+MidX,MidY-y,YELLOW);
}
////////////////////////////////////////////////////////////////////////////
// CVertex Class definitions ...
////////////////////////////////////////////////////////////////////////////
float CVertex::scale;
float CVertex::Theta;
float CVertex::stheta;
float CVertex::ctheta;
float CVertex::xn;
float CVertex::yn;
float CVertex::zn;
int CVertex::VertexCount=0;
float CVertex::tx;
float CVertex::ty;
////////////////////////////////////////////////////////////////////////////
// CEdge Class definitions ...
////////////////////////////////////////////////////////////////////////////
int CEdge::EdgeCount=0;
////////////////////////////////////////////////////////////////////////////
// CSurface Class definitions ...
////////////////////////////////////////////////////////////////////////////
int CSurface::f1;
int CSurface::f2;
int CSurface::f3;
int CSurface::f4;
int CSurface::SurfaceCount=0;
float CSurface::xt;
float CSurface::yt;
float CSurface::m;
float CSurface::c;
float CSurface::d1;
float CSurface::d2;
////////////////////////////////////////////////////////////////////////////
// CBox Sample Class definitions ...
////////////////////////////////////////////////////////////////////////////
void CBox::rotate_x() { // to rotate along x axis
for ( k = 0 ; k < 8 ; k++ ) // by theta
verArr[k].rotate_x();
}
void CBox::rotate_y() { // to rotate along y axis
for ( k = 0 ; k < 8 ; k++ ) // by theta
verArr[k].rotate_y();
}
void CBox::rotate_z() { // to rotate along z axis
for ( k = 0 ; k < 8 ; k++ ) // by theta
verArr[k].rotate_z();
}
void CBox::draw() { // to draw the cube
for ( k = 0 ; k < 12 ; k++ )
EdgArr[k].draw();
}
void CBox::hide() { // to hide the cube
for ( k = 0 ; k < 12 ; k++ )
EdgArr[k].hide();
}
int CBox::k;
////////////////////////////////////////////////////////////////////////////
// CBoxS Sample Class definitions ...
////////////////////////////////////////////////////////////////////////////
void CBoxS::draw()
{
static int k;
FindHiddenSurfaces();
for ( k = 0 ; k < 6 ; k++ )
surfArr[k].draw();
}
void CBoxS::hide()
{
static int k;
for ( k = 0 ; k < 6 ; k++ )
surfArr[k].hide();
}
void CBoxS::FindHiddenPoints()
{
for ( j = 0 ; j < 8 ; j++ )
verArr[j].hidden = false;
for ( i = 0 ; i < 6 ; i++ )
{
if ( surfArr[i].p1->hidden || surfArr[i].p2->hidden ||
surfArr[i].p3->hidden || surfArr[i].p4->hidden )
{
surfArr[i].hidden = true;
continue;
}
for ( j = 0 ; j < 8 ; j++ )
if ( !verArr[j].hidden &&
!surfArr[i].isVertex(&verArr[j]) &&
surfArr[i].isFarther(&verArr[j]) &&
surfArr[i].checkInside(&verArr[j]) )
verArr[j].hidden = true;
}
}
void CBoxS::FindHiddenSurfaces()
{
FindHiddenPoints();
for ( j = 0 ; j < 6 ; j++ )
surfArr[j].hidden = false;
for ( j = 0 ; j < 6 ; j++ )
if ( surfArr[j].hidden == false )
if ( surfArr[j].p1->hidden || surfArr[j].p2->hidden ||
surfArr[j].p3->hidden || surfArr[j].p4->hidden )
surfArr[j].hidden = true;
}
int CBoxS::i;
int CBoxS::j;