home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cutting-Edge 3D Game Programming with C++
/
CE3DC++.ISO
/
BOOK
/
CHAP03
/
STARF.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-10-20
|
2KB
|
77 lines
//
// File Name: StarF.hpp
//
// Description: The header file for the starfield demo
//
// Author: John De Goes
//
// Project: Cutting Edge 3D Game Programming
//
// ------------------------------------------------------------
// | Global include files: |
// ------------------------------------------------------------
#include <Stdlib.h>
// An approximation of pi - can't use const without compiler
// warning
#define PI 3.141592654
// Macros
#define COS(a) (CosTable[a&DEGREEMASK])
#define SIN(a) (SinTable[a&DEGREEMASK])
// The number of degrees in a circle:
const unsigned int NUMBEROFDEGREES = 1024;
const unsigned int DEGREEMASK = NUMBEROFDEGREES-1;
// Trig tables
extern float CosTable[NUMBEROFDEGREES];
extern float SinTable[NUMBEROFDEGREES];
// A "point in space" structure:
struct Vertex {
float Wx, Wy, Wz; // The world X, Y and Z.
};
// A "point on the screen" structure:
struct ScreenVertex {
long X, Y, Color;
};
// A view matrix class - view only, not true matrix class
class Matrix3D {
protected:
// Protected matrix functions
void MergeMatrix(float NewMatrix[4][4]);
float Matrix[4][4];
public:
// Misc functions:
void Rotate(int Xa, int Ya, int Za);
void Translate(float Xt, float Yt, float Zt);
void Scale(float Xs, float Ys, float Zs);
void Shear(float Xs, float Ys);
void Initialize();
Vertex &Transform(Vertex &V);
};
class Star {
protected:
// Protected data:
Vertex Point3D;
ScreenVertex Point2D;
int Visible;
// Protected member functions:
void Project();
void DrawPoint(unsigned char *Buffer);
public:
// Public functions:
void inline Initialize( float Nx, float Ny, float Nz );
void Transform(Matrix3D Matrix) { Matrix.Transform(Point3D); }
void Show(unsigned char *Buffer);
// Constructors:
Star() { Initialize(random(300)-150, random(300)-150, (random(4000)+100)); }
Star( float X, float Y, float Z ) { Initialize( X, Y, Z ); }
};