www.pudn.com > FrustumCulling.rar > main.h


#ifndef _MAIN_H 
#define _MAIN_H 
 
#include  
#include  
#include  
#include                                       // Header File For The OpenGL32 Library 
#include                                      // Header File For The GLu32 Library 
 
# include  
# include  
 
#include "SDL.h" 
 
using namespace std; 
 
typedef unsigned char BYTE; 
 
 
#define SCREEN_WIDTH 800                                // We want our screen width 800 pixels 
#define SCREEN_HEIGHT 600                               // We want our screen height 600 pixels 
#define SCREEN_DEPTH 16                                 // We want 16 bits per pixel 
 
 
/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * 
 
// We added new stuctures for our camera and frustum code.  These should eventually 
// go inside of a new .h file like camera.h and frustum.h 
 
// This is our sphere structure for keeping track of the spheres 
struct Sphere  
{ 
    float xPos, yPos, zPos, radius;                     // We want to hold a XYZ position and radius 
    BYTE  r, g, b;                                      // These will store the color of the sphere 
}; 
 
 
// This is our basic 3D point/vector class 
class CVector3 
{ 
public: 
     
    // A default constructor 
    CVector3() {} 
 
    // This is our constructor that allows us to initialize our data upon creating an instance 
    CVector3(float X, float Y, float Z)  
    {  
        x = X; y = Y; z = Z; 
    } 
 
    // Here we overload the + operator so we can add vectors together  
    CVector3 operator+(CVector3 vVector) 
    { 
        // Return the added vectors result. 
        return CVector3(vVector.x + x, vVector.y + y, vVector.z + z); 
    } 
 
    // Here we overload the - operator so we can subtract vectors  
    CVector3 operator-(CVector3 vVector) 
    { 
        // Return the subtracted vectors result 
        return CVector3(x - vVector.x, y - vVector.y, z - vVector.z); 
    } 
     
    // Here we overload the * operator so we can multiply by scalars 
    CVector3 operator*(float num) 
    { 
        // Return the scaled vector 
        return CVector3(x * num, y * num, z * num); 
    } 
 
    // Here we overload the / operator so we can divide by a scalar 
    CVector3 operator/(float num) 
    { 
        // Return the scale vector 
        return CVector3(x / num, y / num, z / num); 
    } 
 
    float x, y, z;                       
}; 
 
 
// This will allow us to create an object to keep track of our frustum 
class CFrustum { 
 
public: 
 
    // Call this every time the camera moves to update the frustum 
    void CalculateFrustum(); 
 
    // This takes a 3D point and returns TRUE if it's inside of the frustum 
    bool PointInFrustum(float x, float y, float z); 
 
    // This takes a 3D point and a radius and returns TRUE if the sphere is inside of the frustum 
    bool SphereInFrustum(float x, float y, float z, float radius); 
 
    // This takes the center and half the length of the cube. 
    bool CubeInFrustum( float x, float y, float z, float size ); 
 
private: 
 
    // This holds the A B C and D values for each side of our frustum. 
    float m_Frustum[6][4]; 
}; 
 
/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * 
 
extern int VideoFlags;                                    // The Pixel Format flags 
extern SDL_Surface * MainWindow;                        // Our Drawable portion of the window 
 
// This Controls our MainLoop 
void MainLoop(void); 
 
// This toggles between the Full Screen mode and the windowed mode 
void ToggleFullScreen(void); 
 
void CreateTexture(unsigned int textureArray[],char *strFileName,int textureID); 
 
// This allows us to configure our window for OpenGL and backbuffered 
void SetupPixelFormat(void); 
 
// This is our own function that makes creating a window modular and easy 
void CreateMyWindow(const char *strWindowName, int width, int height, int VideoFlags); 
 
// This inits our screen translations and projections 
void SizeOpenGLScreen(int width, int height); 
 
// This sets up OpenGL 
void InitializeGL(int width, int height); 
 
// This initializes the whole program 
void Init(); 
 
bool isExtensionSupported(string ext); 
 
// This handles the keypress events generated when the user presses a key 
void HandleKeyPressEvent(SDL_keysym * keysym); 
 
// This draws everything to the screen 
void RenderScene(); 
 
// This shuts down SDL and quits program 
void Quit(int ret_val); 
 
#endif  // _MAIN_H_ 
///////////////////////////////////////////////////////////////////////////////// 
// 
// * QUICK NOTES *  
// 
// We added new structures and classes for our camera and frustum code. 
//  
//  
// Ben Humphrey (DigiBen) 
// Game Programmer 
// DigiBen@GameTutorials.com 
// Co-Web Host of www.GameTutorials.com 
// 
//