First commit of APE files
This was SVN commit r478.
This commit is contained in:
parent
5276a527ae
commit
101e6d4fa0
157
source/ape/ape.dsp
Executable file
157
source/ape/ape.dsp
Executable file
@ -0,0 +1,157 @@
|
||||
# Microsoft Developer Studio Project File - Name="ape" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=ape - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "ape.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "ape.mak" CFG="ape - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "ape - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "ape - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "ape - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
|
||||
!ELSEIF "$(CFG)" == "ape - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib glui32.lib glut32.lib glu32.lib opengl32.lib glaux.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "ape - Win32 Release"
|
||||
# Name "ape - Win32 Debug"
|
||||
# Begin Group "ext"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ext\MathUtil.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ext\Particle.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ext\Particle.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ext\ParticleEmitter.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ext\ParticleEmitter.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ext\ParticleSystem.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ext\ParticleSystem.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ext\Sprite.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ext\Sprite.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ext\tex_.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ext\tex_.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ext\timer_.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ext\timer_.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ext\Types.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ext\Vector3D.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ext\Vector3D.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\main.cpp
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
29
source/ape/ape.dsw
Executable file
29
source/ape/ape.dsw
Executable file
@ -0,0 +1,29 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "ape"=.\ape.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
27
source/ape/ext/MathUtil.h
Executable file
27
source/ape/ext/MathUtil.h
Executable file
@ -0,0 +1,27 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: MathUtil.H
|
||||
// Last Update: 28/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: This file contains some maths related
|
||||
// utility macros and fucntions.
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef MATHUTIL_H
|
||||
#define MATHUTIL_H
|
||||
|
||||
#define PI 3.14159265358979323846f
|
||||
|
||||
#define DEGTORAD(a) ((a) * (PI/180.0f))
|
||||
#define RADTODEG(a) ((a) * (180.0f/PI))
|
||||
#define SQR(x) ((x) * (x))
|
||||
#define MAX(a,b) ((a < b) ? (b) : (a))
|
||||
#define MIN(a,b) ((a < b) ? (a) : (b))
|
||||
#define MAX3(a,b,c) ( MAX (MAX(a,b), c) )
|
||||
#define ABS(a) ((a > 0) ? (a) : (-a))
|
||||
|
||||
//extern unsigned int F2DW (float f);
|
||||
|
||||
#endif
|
93
source/ape/ext/Particle.cpp
Executable file
93
source/ape/ext/Particle.cpp
Executable file
@ -0,0 +1,93 @@
|
||||
/*==================================================================
|
||||
|
|
||||
| Name: Particle.cpp
|
||||
|
|
||||
|===================================================================
|
||||
|
|
||||
| Author: Ben Vinegar
|
||||
| Contact: benvinegar () hotmail ! com
|
||||
|
|
||||
|
|
||||
| Last Modified: 03/08/04
|
||||
|
|
||||
| Overview: A single particle, currently only utilized by
|
||||
| CParticleEmitter. Public variables are for performance
|
||||
| reasons.
|
||||
|
|
||||
|
|
||||
| Usage: Instantiate a particle, set public variables, then call
|
||||
| Frame() every frame.
|
||||
|
|
||||
| To do: TBA
|
||||
|
|
||||
| More Information: TBA
|
||||
|
|
||||
==================================================================*/
|
||||
|
||||
#include "Particle.h"
|
||||
#include "timer_.h"
|
||||
#include <GL/gl.h>
|
||||
#include <assert.h>
|
||||
|
||||
CParticle::CParticle() :
|
||||
m_duration(0.0f),
|
||||
m_timeElapsedTotal(0.0f),
|
||||
m_position(0.0f, 0.0f, 0.0f),
|
||||
m_velocity(0.0f, 0.0f, 0.0f),
|
||||
m_gravity(0.0f, 0.0f, 0.0f)
|
||||
{
|
||||
m_timeOfLastFrame = get_time();
|
||||
|
||||
}
|
||||
|
||||
CParticle::~CParticle()
|
||||
{
|
||||
}
|
||||
|
||||
void CParticle::Init()
|
||||
{
|
||||
// calculate colour increment per second in order to fade to black
|
||||
m_colourInc[0] = - (m_colour[0] / m_duration);
|
||||
m_colourInc[1] = - (m_colour[1] / m_duration);
|
||||
m_colourInc[2] = - (m_colour[2] / m_duration);
|
||||
}
|
||||
|
||||
void CParticle::Frame()
|
||||
{
|
||||
Update();
|
||||
Render();
|
||||
}
|
||||
|
||||
void CParticle::Render()
|
||||
{
|
||||
assert(m_sprite);
|
||||
|
||||
m_sprite->SetColour(m_colour);
|
||||
m_sprite->SetTranslation(m_position);
|
||||
m_sprite->Render();
|
||||
}
|
||||
|
||||
void CParticle::Update()
|
||||
{
|
||||
float timeElapsed = float(get_time() - m_timeOfLastFrame);
|
||||
|
||||
m_velocity += m_gravity * timeElapsed;
|
||||
m_position += m_velocity * timeElapsed;
|
||||
|
||||
// fade colour
|
||||
m_colour[0] += m_colourInc[0] * timeElapsed;
|
||||
m_colour[1] += m_colourInc[1] * timeElapsed;
|
||||
m_colour[2] += m_colourInc[2] * timeElapsed;
|
||||
|
||||
m_timeOfLastFrame = get_time();
|
||||
m_timeElapsedTotal += timeElapsed;
|
||||
}
|
||||
|
||||
void CParticle::Reset() {
|
||||
m_duration = 0.0f;
|
||||
m_timeElapsedTotal = 0.0f;
|
||||
m_timeOfLastFrame = get_time();
|
||||
|
||||
// default white colour
|
||||
m_colour[0] = m_colour[1] = m_colour[2] = m_colour[3] = 1.0f;
|
||||
}
|
73
source/ape/ext/Particle.h
Executable file
73
source/ape/ext/Particle.h
Executable file
@ -0,0 +1,73 @@
|
||||
/*==================================================================
|
||||
|
|
||||
| Name: Particle.h
|
||||
|
|
||||
|===================================================================
|
||||
|
|
||||
| Author: Ben Vinegar
|
||||
| Contact: benvinegar () hotmail ! com
|
||||
|
|
||||
|
|
||||
| Last Modified: 03/08/04
|
||||
|
|
||||
| Overview: A single particle, currently only utilized by
|
||||
| CParticleEmitter. Public variables are for performance
|
||||
| reasons.
|
||||
|
|
||||
|
|
||||
| Usage: Instantiate a particle, set public variables, then call
|
||||
| Frame() every frame.
|
||||
|
|
||||
| To do: TBA
|
||||
|
|
||||
| More Information: TBA
|
||||
|
|
||||
==================================================================*/
|
||||
|
||||
#ifndef PARTICLE_H
|
||||
#define PARTICLE_H
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
|
||||
#include "Vector3D.h"
|
||||
#include "Sprite.h"
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
class CParticle
|
||||
{
|
||||
public:
|
||||
CParticle();
|
||||
~CParticle();
|
||||
|
||||
// necessary pre-processing immediately before first update call
|
||||
void Init();
|
||||
|
||||
void Frame();
|
||||
void Update();
|
||||
void Render();
|
||||
|
||||
void Reset();
|
||||
|
||||
void SetColour(float r, float g, float b, float a);
|
||||
|
||||
CSprite * m_sprite;
|
||||
|
||||
float m_duration;
|
||||
double m_timeOfLastFrame;
|
||||
double m_timeElapsedTotal;
|
||||
|
||||
CVector3D m_position;
|
||||
CVector3D m_velocity;
|
||||
CVector3D m_gravity;
|
||||
|
||||
float m_colour[4];
|
||||
float m_colourInc[3];
|
||||
};
|
||||
|
||||
|
||||
#endif // PARTICLE_H
|
407
source/ape/ext/ParticleEmitter.cpp
Executable file
407
source/ape/ext/ParticleEmitter.cpp
Executable file
@ -0,0 +1,407 @@
|
||||
/*==================================================================
|
||||
|
|
||||
| Name: ParticleEmitter.cpp
|
||||
|
|
||||
|===================================================================
|
||||
|
|
||||
| Author: Ben Vinegar
|
||||
| Contact: benvinegar () hotmail ! com
|
||||
|
|
||||
|
|
||||
| Last Modified: 05/11/04
|
||||
|
|
||||
| Overview: Particle emitter class that emits particles from
|
||||
| an origin (or area) with a variety of set colours,
|
||||
| durations, forces and a single common sprite.
|
||||
|
|
||||
|
|
||||
| Usage: Instantiate one emitter per desired effect. Set the
|
||||
| various fields (preferably all, the defaults are rather
|
||||
| boring) and then call Frame() - you guessed it - every
|
||||
| frame.
|
||||
|
|
||||
| To do: TBA
|
||||
|
|
||||
| More Information: TBA
|
||||
|
|
||||
==================================================================*/
|
||||
|
||||
#include "ParticleEmitter.h"
|
||||
|
||||
#include "timer_.h"
|
||||
#include <GL/gl.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#define EMITTER_MAX_PARTICLES 10000
|
||||
|
||||
|
||||
CParticleEmitter::CParticleEmitter() :
|
||||
m_particles(NULL),
|
||||
m_origin(0.0f, 0.0f, 0.0f),
|
||||
m_originSpread(0.0f, 0.0f, 0.0f),
|
||||
m_velocity(0.0f, 0.0f, 0.0f),
|
||||
m_velocitySpread(0.0f, 0.0f, 0.0f),
|
||||
m_gravity(0.0f, 0.0f, 0.0f),
|
||||
m_maxParticles(25),
|
||||
m_minParticles(25),
|
||||
m_numParticles(0),
|
||||
m_maxLifetime(1.0f),
|
||||
m_minLifetime(1.0f),
|
||||
m_timeOfLastFrame(0.0f),
|
||||
m_timeSinceLastEmit(0.0f),
|
||||
m_width(1.0f),
|
||||
m_height(1.0f),
|
||||
m_timeLimit(0.0f)
|
||||
{
|
||||
m_particles.clear();
|
||||
m_disabled.clear();
|
||||
|
||||
m_startColour[0] = m_startColour[1] = m_startColour[2] = m_startColour[3] = 1.0f;
|
||||
m_endColour[0] = m_endColour[1] = m_endColour[2] = m_endColour[3] = 1.0f;
|
||||
}
|
||||
|
||||
CParticleEmitter::~CParticleEmitter()
|
||||
{
|
||||
// upon destruction, delete particles
|
||||
std::vector<CParticle *>::iterator itor = m_particles.begin();
|
||||
while (itor != m_particles.end())
|
||||
{
|
||||
m_particles.erase(itor);
|
||||
delete (*itor);
|
||||
++itor;
|
||||
}
|
||||
|
||||
// delete vertices, colours, etc.
|
||||
if (m_vertices != NULL)
|
||||
delete m_vertices;
|
||||
|
||||
if (m_texCoords != NULL)
|
||||
delete m_texCoords;
|
||||
|
||||
if (m_colours != NULL)
|
||||
delete m_colours;
|
||||
}
|
||||
|
||||
|
||||
bool CParticleEmitter::Init() {
|
||||
m_vertices = new vertex3f[EMITTER_MAX_PARTICLES * 4];
|
||||
m_texCoords = new vertex2f[EMITTER_MAX_PARTICLES * 4];
|
||||
m_colours = new color4f[EMITTER_MAX_PARTICLES * 4];
|
||||
|
||||
// every particle has the same texture coordinates
|
||||
for (int i = 0; i < EMITTER_MAX_PARTICLES * 4; i += 4) {
|
||||
m_texCoords[i].x = 0.0f;
|
||||
m_texCoords[i].y = 0.0f;
|
||||
|
||||
m_texCoords[i + 1].x = 0.0f;
|
||||
m_texCoords[i + 1].y = 1.0f;
|
||||
|
||||
m_texCoords[i + 2].x = 1.0f;
|
||||
m_texCoords[i + 2].y = 1.0f;
|
||||
|
||||
m_texCoords[i + 3].x = 1.0f;
|
||||
m_texCoords[i + 3].y = 0.0f;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CParticleEmitter::Frame()
|
||||
{
|
||||
Update();
|
||||
Render();
|
||||
}
|
||||
|
||||
void CParticleEmitter::Render()
|
||||
{
|
||||
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
glAlphaFunc(GL_GREATER, 0.0f);
|
||||
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
|
||||
|
||||
// bind loaded texture
|
||||
glBindTexture(GL_TEXTURE_2D, m_texture);
|
||||
|
||||
CVector3D pos;
|
||||
|
||||
std::vector<CParticle *>::iterator itor = m_particles.begin();
|
||||
int i = 0;
|
||||
float w = m_width / 2;
|
||||
float h = m_height / 2;
|
||||
|
||||
// update vertices based on current particle position
|
||||
while (itor != m_particles.end())
|
||||
{
|
||||
CParticle * curParticle = (*itor);
|
||||
|
||||
curParticle->Update();
|
||||
pos = curParticle->m_position;
|
||||
|
||||
m_vertices[i].x = pos.X - w;
|
||||
m_vertices[i].y = pos.Y - h;
|
||||
m_vertices[i].z = pos.Z;
|
||||
|
||||
m_vertices[i + 1].x = pos.X - w;
|
||||
m_vertices[i + 1].y = pos.Y + h;
|
||||
m_vertices[i + 1].z = pos.Z;
|
||||
|
||||
m_vertices[i + 2].x = pos.X + w;
|
||||
m_vertices[i + 2].y = pos.Y + h;
|
||||
m_vertices[i + 2].z = pos.Z;
|
||||
|
||||
m_vertices[i + 3].x = pos.X + w;
|
||||
m_vertices[i + 3].y = pos.Y - h;
|
||||
m_vertices[i + 3].z = pos.Z;
|
||||
|
||||
memcpy(&m_colours[i], curParticle->m_colour, sizeof(color4f));
|
||||
memcpy(&m_colours[i + 1], curParticle->m_colour, sizeof(color4f));
|
||||
memcpy(&m_colours[i + 2], curParticle->m_colour, sizeof(color4f));
|
||||
memcpy(&m_colours[i + 3], curParticle->m_colour, sizeof(color4f));
|
||||
|
||||
i += 4;
|
||||
++itor;
|
||||
}
|
||||
// enable vertex arrays
|
||||
glEnable(GL_VERTEX_ARRAY);
|
||||
glEnable(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnable(GL_COLOR_ARRAY);
|
||||
|
||||
// set vertex arrays
|
||||
glVertexPointer(3, GL_FLOAT, 0, m_vertices);
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, m_texCoords);
|
||||
glColorPointer(4, GL_FLOAT, 0, m_colours);
|
||||
|
||||
glDrawArrays(GL_QUADS, 0, m_numParticles * 4);
|
||||
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
void CParticleEmitter::Update()
|
||||
{
|
||||
float timeElapsed = (float)(get_time() - m_timeOfLastFrame);
|
||||
|
||||
// update existing particles
|
||||
std::vector<CParticle *>::iterator itor = m_particles.begin();
|
||||
while (itor != m_particles.end())
|
||||
{
|
||||
CParticle * curParticle = (*itor);
|
||||
|
||||
curParticle->Update();
|
||||
|
||||
// destroy particle if it has lived beyond its duration
|
||||
if (curParticle->m_timeElapsedTotal >= curParticle->m_duration)
|
||||
{
|
||||
m_particles.erase(itor);
|
||||
m_disabled.push_back(curParticle);
|
||||
--m_numParticles;
|
||||
}
|
||||
|
||||
++itor;
|
||||
}
|
||||
|
||||
float secondsPerEmit = (float)(1 / (m_minParticles / m_minLifetime));
|
||||
|
||||
if (m_timeSinceLastEmit > secondsPerEmit)
|
||||
{
|
||||
|
||||
float duration;
|
||||
CVector3D position, velocity;
|
||||
float colour[4];
|
||||
|
||||
bool moreParticlesToEmit = true;
|
||||
while (moreParticlesToEmit) {
|
||||
CParticle * newParticle = NULL;
|
||||
if (m_disabled.empty())
|
||||
newParticle = new CParticle();
|
||||
else {
|
||||
newParticle = m_disabled.back();
|
||||
m_disabled.pop_back();
|
||||
newParticle->Reset();
|
||||
}
|
||||
|
||||
// calculate particle duration
|
||||
duration = (float)m_minLifetime;
|
||||
duration += (rand() % (int)((m_maxLifetime - m_minLifetime) * 1000.0f + 1)) / 1000.0f;
|
||||
newParticle->m_duration = duration;
|
||||
|
||||
// calculate particle start position from spread
|
||||
position = m_origin;
|
||||
position.X += (rand() % (int)(m_originSpread.X * 2000.0f + 1)) / 1000.0f - m_originSpread.X;
|
||||
position.Y += (rand() % (int)(m_originSpread.Y * 2000.0f + 1)) / 1000.0f - m_originSpread.Y;
|
||||
position.Z += (rand() % (int)(m_originSpread.Z * 2000.0f + 1)) / 1000.0f - m_originSpread.Z;
|
||||
newParticle->m_position = position;
|
||||
|
||||
// calculate particle velocity from spread
|
||||
velocity = m_velocity;
|
||||
velocity.X += (rand() % (int)(m_velocitySpread.X * 2000.0f + 1)) / 1000.0f - m_velocitySpread.X;
|
||||
velocity.Y += (rand() % (int)(m_velocitySpread.Y * 2000.0f + 1)) / 1000.0f - m_velocitySpread.Y;
|
||||
velocity.Z += (rand() % (int)(m_velocitySpread.Z * 2000.0f + 1)) / 1000.0f - m_velocitySpread.Z;
|
||||
newParticle->m_velocity = velocity;
|
||||
|
||||
newParticle->m_gravity = m_gravity;
|
||||
|
||||
// calculate and assign colour
|
||||
memcpy(colour, m_startColour, sizeof(float) * 4);
|
||||
colour[0] -= (rand() % (int)((m_startColour[0] - m_endColour[0]) * 1000.0f + 1)) / 1000.0f;
|
||||
colour[1] -= (rand() % (int)((m_startColour[1] - m_endColour[1]) * 1000.0f + 1)) / 1000.0f;
|
||||
colour[2] -= (rand() % (int)((m_startColour[2] - m_endColour[2]) * 1000.0f + 1)) / 1000.0f;
|
||||
colour[3] -= (rand() % (int)((m_startColour[3] - m_endColour[3]) * 1000.0f + 1)) / 1000.0f;
|
||||
memcpy(newParticle->m_colour, colour, sizeof(float) * 4);
|
||||
|
||||
// assign sprite
|
||||
//newParticle->m_sprite = m_sprite;
|
||||
|
||||
// final pre-processing init call
|
||||
newParticle->Init();
|
||||
|
||||
// add to vector of particles
|
||||
m_particles.push_back(newParticle);
|
||||
|
||||
timeElapsed -= secondsPerEmit;
|
||||
if (timeElapsed < secondsPerEmit)
|
||||
{
|
||||
moreParticlesToEmit = false;
|
||||
}
|
||||
|
||||
|
||||
++m_numParticles;
|
||||
}
|
||||
m_timeSinceLastEmit = 0.0f;
|
||||
}
|
||||
else
|
||||
m_timeSinceLastEmit += timeElapsed;
|
||||
|
||||
m_timeOfLastFrame = get_time();
|
||||
}
|
||||
|
||||
|
||||
bool CParticleEmitter::IsFinished() {
|
||||
if (m_timeElapsedTotal >= m_timeLimit && m_timeLimit > 0.0f)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetTimelimit(double time) {
|
||||
m_timeLimit = time;
|
||||
}
|
||||
|
||||
// deprecated
|
||||
/*/void CParticleEmitter::SetSprite(CSprite * sprite)
|
||||
{
|
||||
//m_sprite = sprite;
|
||||
}/*/
|
||||
|
||||
void CParticleEmitter::SetTexture(GLuint tex) {
|
||||
m_texture = tex;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetWidth(float width) {
|
||||
m_width = width;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetHeight(float height) {
|
||||
m_height = height;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetOrigin(CVector3D origin)
|
||||
{
|
||||
m_origin = origin;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetOrigin(float x, float y, float z)
|
||||
{
|
||||
m_origin.X = x;
|
||||
m_origin.Y = y;
|
||||
m_origin.Z = z;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetOriginSpread(CVector3D spread)
|
||||
{
|
||||
m_originSpread = spread;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetOriginSpread(float x, float y, float z)
|
||||
{
|
||||
m_originSpread.X = x;
|
||||
m_originSpread.Y = y;
|
||||
m_originSpread.Z = z;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetGravity(CVector3D gravity)
|
||||
{
|
||||
m_gravity = gravity;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetGravity(float x, float y, float z)
|
||||
{
|
||||
m_gravity.X = x;
|
||||
m_gravity.Y = y;
|
||||
m_gravity.Z = z;
|
||||
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetVelocity(CVector3D velocity)
|
||||
{
|
||||
m_velocity = velocity;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetVelocity(float x, float y, float z)
|
||||
{
|
||||
m_velocity.X = x;
|
||||
m_velocity.Y = y;
|
||||
m_velocity.Z = z;
|
||||
}
|
||||
|
||||
|
||||
void CParticleEmitter::SetVelocitySpread(CVector3D spread)
|
||||
{
|
||||
m_velocitySpread = spread;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetVelocitySpread(float x, float y, float z)
|
||||
{
|
||||
m_velocitySpread.X = x;
|
||||
m_velocitySpread.Y = y;
|
||||
m_velocitySpread.Z = z;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetStartColour(float r, float g, float b, float a)
|
||||
{
|
||||
m_startColour[0] = r;
|
||||
m_startColour[1] = g;
|
||||
m_startColour[2] = b;
|
||||
m_startColour[3] = a;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetEndColour(float r, float g, float b, float a)
|
||||
{
|
||||
m_endColour[0] = r;
|
||||
m_endColour[1] = g;
|
||||
m_endColour[2] = b;
|
||||
m_endColour[3] = a;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetMaxLifetime(double maxLife)
|
||||
{
|
||||
m_maxLifetime = maxLife;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetMinLifetime(double minLife)
|
||||
{
|
||||
m_minLifetime = minLife;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetMaxParticles(int maxParticles)
|
||||
{
|
||||
m_maxParticles = maxParticles;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetMinParticles(int minParticles)
|
||||
{
|
||||
m_minParticles = minParticles;
|
||||
}
|
147
source/ape/ext/ParticleEmitter.h
Executable file
147
source/ape/ext/ParticleEmitter.h
Executable file
@ -0,0 +1,147 @@
|
||||
/*==================================================================
|
||||
|
|
||||
| Name: ParticleEmitter.h
|
||||
|
|
||||
|===================================================================
|
||||
|
|
||||
| Author: Ben Vinegar
|
||||
| Contact: benvinegar () hotmail ! com
|
||||
|
|
||||
|
|
||||
| Last Modified: 03/08/04
|
||||
|
|
||||
| Overview: Particle emitter class that emits particles from
|
||||
| an origin (or area) with a variety of set colours,
|
||||
| durations, forces and a single common sprite.
|
||||
|
|
||||
|
|
||||
| Usage: Instantiate one emitter per desired effect. Set the
|
||||
| various fields (preferably all, the defaults are rather
|
||||
| boring) and then call Frame() - you guessed it - every
|
||||
| frame.
|
||||
|
|
||||
| To do: TBA
|
||||
|
|
||||
| More Information: TBA
|
||||
|
|
||||
==================================================================*/
|
||||
|
||||
#ifndef PARTICLE_EMITTER_H
|
||||
#define PARTICLE_EMITTER_H
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
|
||||
#include "Particle.h"
|
||||
#include "Vector3D.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
typedef struct {
|
||||
GLfloat x, y, z;
|
||||
} vertex3f;
|
||||
|
||||
typedef struct {
|
||||
GLfloat x, y;
|
||||
} vertex2f;
|
||||
|
||||
typedef struct {
|
||||
GLfloat r, g, b, a;
|
||||
} color4f;
|
||||
|
||||
class CParticleEmitter
|
||||
{
|
||||
public:
|
||||
CParticleEmitter();
|
||||
~CParticleEmitter();
|
||||
|
||||
// must be performed before first frame/render/update call
|
||||
bool Init();
|
||||
|
||||
// renders and updates particles
|
||||
void Frame();
|
||||
|
||||
// renders without updating particles
|
||||
void Render();
|
||||
|
||||
void Update();
|
||||
|
||||
bool IsFinished();
|
||||
|
||||
void SetTimelimit(double time);
|
||||
|
||||
// void SetSprite(CSprite * sprite); // deprecated
|
||||
void SetTexture(GLuint tex);
|
||||
void SetWidth(float width);
|
||||
void SetHeight(float height);
|
||||
|
||||
void SetOrigin(CVector3D origin);
|
||||
void SetOrigin(float x, float y, float z);
|
||||
|
||||
void SetOriginSpread(CVector3D spread);
|
||||
void SetOriginSpread(float x, float y, float z);
|
||||
|
||||
void SetGravity(CVector3D gravity);
|
||||
void SetGravity(float x, float y, float z);
|
||||
|
||||
void SetVelocity(CVector3D direction);
|
||||
void SetVelocity(float x, float y, float z);
|
||||
|
||||
void SetVelocitySpread(CVector3D spread);
|
||||
void SetVelocitySpread(float x, float y, float z);
|
||||
|
||||
void SetStartColour(float r, float g, float b, float a);
|
||||
void SetEndColour(float r, float g, float b, float a);
|
||||
|
||||
// in milliseconds
|
||||
void SetMaxLifetime(double maxLife);
|
||||
|
||||
// in milliseconds
|
||||
void SetMinLifetime(double minLife);
|
||||
|
||||
void SetMaxParticles(int maxParticles);
|
||||
void SetMinParticles(int minParticles);
|
||||
|
||||
private:
|
||||
GLuint m_texture;
|
||||
|
||||
vertex3f *m_vertices;
|
||||
vertex2f *m_texCoords;
|
||||
color4f *m_colours;
|
||||
|
||||
float m_width;
|
||||
float m_height;
|
||||
|
||||
std::vector<CParticle *> m_particles;
|
||||
std::vector<CParticle *> m_disabled;
|
||||
|
||||
CVector3D m_origin;
|
||||
CVector3D m_originSpread;
|
||||
|
||||
CVector3D m_velocity;
|
||||
CVector3D m_velocitySpread;
|
||||
|
||||
CVector3D m_gravity;
|
||||
|
||||
float m_startColour[4];
|
||||
float m_endColour[4];
|
||||
|
||||
int m_maxParticles;
|
||||
int m_minParticles;
|
||||
int m_numParticles;
|
||||
|
||||
double m_maxLifetime;
|
||||
double m_minLifetime;
|
||||
|
||||
double m_timeOfLastFrame;
|
||||
double m_timeSinceLastEmit;
|
||||
double m_timeElapsedTotal;
|
||||
double m_timeLimit;
|
||||
};
|
||||
|
||||
#endif // PARTICLE_EMITTER_H
|
80
source/ape/ext/ParticleSystem.cpp
Executable file
80
source/ape/ext/ParticleSystem.cpp
Executable file
@ -0,0 +1,80 @@
|
||||
/*==================================================================
|
||||
|
|
||||
| Name: ParticleSystem.cpp
|
||||
|
|
||||
|===================================================================
|
||||
|
|
||||
| Author: Ben Vinegar
|
||||
| Contact: benvinegar () hotmail ! com
|
||||
|
|
||||
|
|
||||
| Last Modified: 04/23/04
|
||||
|
|
||||
| Overview: TBA
|
||||
|
|
||||
| Usage: TBA
|
||||
|
|
||||
| To do: TBA
|
||||
|
|
||||
| More Information: TBA
|
||||
|
|
||||
==================================================================*/
|
||||
|
||||
#include "ParticleSystem.h"
|
||||
#include <assert.h>
|
||||
|
||||
CParticleSystem::CParticleSystem()
|
||||
{
|
||||
}
|
||||
|
||||
CParticleSystem::~CParticleSystem()
|
||||
{
|
||||
}
|
||||
|
||||
void CParticleSystem::Render()
|
||||
{
|
||||
CParticleEmitter * curEmitter = NULL;
|
||||
|
||||
std::vector<CParticleEmitter *>::iterator itor = m_Emitters.begin();
|
||||
while (itor != m_Emitters.end())
|
||||
{
|
||||
curEmitter = (*itor);
|
||||
curEmitter->Render();
|
||||
|
||||
itor++;
|
||||
}
|
||||
}
|
||||
|
||||
void CParticleSystem::Update()
|
||||
{
|
||||
CParticleEmitter * curEmitter = NULL;
|
||||
|
||||
std::vector<CParticleEmitter *>::iterator itor = m_Emitters.begin();
|
||||
while (itor != m_Emitters.end())
|
||||
{
|
||||
curEmitter = (*itor);
|
||||
curEmitter->Update();
|
||||
|
||||
if (curEmitter->IsFinished()) {
|
||||
m_Emitters.erase(itor);
|
||||
delete curEmitter;
|
||||
}
|
||||
++itor;
|
||||
}
|
||||
}
|
||||
|
||||
void CParticleSystem::Frame()
|
||||
{
|
||||
Render();
|
||||
Update();
|
||||
}
|
||||
|
||||
CParticleEmitter * CParticleSystem::CreateNewEmitter()
|
||||
{
|
||||
CParticleEmitter *newEmitter = new CParticleEmitter;
|
||||
assert(newEmitter);
|
||||
|
||||
m_Emitters.push_back(newEmitter);
|
||||
|
||||
return newEmitter;
|
||||
}
|
45
source/ape/ext/ParticleSystem.h
Executable file
45
source/ape/ext/ParticleSystem.h
Executable file
@ -0,0 +1,45 @@
|
||||
/*==================================================================
|
||||
|
|
||||
| Name: ParticleSystem.h
|
||||
|
|
||||
|===================================================================
|
||||
|
|
||||
| Author: Ben Vinegar
|
||||
| Contact: benvinegar () hotmail ! com
|
||||
|
|
||||
|
|
||||
| Last Modified: 04/23/04
|
||||
|
|
||||
| Overview: TBA
|
||||
|
|
||||
| Usage: TBA
|
||||
|
|
||||
| To do: TBA
|
||||
|
|
||||
| More Information: TBA
|
||||
|
|
||||
==================================================================*/
|
||||
|
||||
#ifndef PARTICLE_SYSTEM_H
|
||||
#define PARTICLE_SYSTEM_H
|
||||
|
||||
#include "ParticleEmitter.h"
|
||||
#include <vector>
|
||||
|
||||
class CParticleSystem
|
||||
{
|
||||
public:
|
||||
CParticleSystem();
|
||||
~CParticleSystem();
|
||||
|
||||
void Render();
|
||||
void Update();
|
||||
void Frame();
|
||||
|
||||
CParticleEmitter *CreateNewEmitter();
|
||||
private:
|
||||
std::vector<CParticleEmitter *> m_Emitters;
|
||||
};
|
||||
|
||||
|
||||
#endif // PARTICLE_SYSTEM_H
|
210
source/ape/ext/Sprite.cpp
Executable file
210
source/ape/ext/Sprite.cpp
Executable file
@ -0,0 +1,210 @@
|
||||
/*==================================================================
|
||||
|
|
||||
| Name: Sprite.cpp
|
||||
|
|
||||
|===================================================================
|
||||
|
|
||||
| Author: Ben Vinegar
|
||||
| Contact: benvinegar () hotmail ! com
|
||||
|
|
||||
|
|
||||
| Last Modified: 03/08/04
|
||||
|
|
||||
| Overview: Billboarding sprite class - always faces the camera. It
|
||||
| does this by getting the current model view matrix state.
|
||||
|
|
||||
|
|
||||
| Usage: The functions speak for themselves. Instantiate, then be
|
||||
| sure to pass a loaded (using tex_load()) texture before
|
||||
| calling Render().
|
||||
|
|
||||
| To do: TBA
|
||||
|
|
||||
| More Information: TBA
|
||||
|
|
||||
==================================================================*/
|
||||
|
||||
#include "Sprite.h"
|
||||
#include <stdio.h>
|
||||
CSprite::CSprite() :
|
||||
m_texture(NULL)
|
||||
{
|
||||
|
||||
// default scale 1:1
|
||||
m_scale.X = m_scale.Y = m_scale.Z = 1.0f;
|
||||
|
||||
// default position (0.0f, 0.0f, 0.0f)
|
||||
m_translation.X = m_translation.Y = m_translation.Z = 0.0f;
|
||||
|
||||
// default size 1.0 x 1.0
|
||||
SetSize(1.0f, 1.0f);
|
||||
|
||||
// default colour, white
|
||||
m_colour[0] = m_colour[1] = m_colour[2] = m_colour[3] = 1.0f;
|
||||
}
|
||||
|
||||
CSprite::~CSprite()
|
||||
{
|
||||
}
|
||||
|
||||
void CSprite::Render()
|
||||
{
|
||||
BeginBillboard();
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
glTranslatef(m_translation.X, m_translation.Y, m_translation.Z);
|
||||
glScalef(m_scale.X, m_scale.Y, m_scale.Z);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, m_texture);
|
||||
|
||||
glColor4fv(m_colour);
|
||||
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
// bottom left
|
||||
glTexCoord2f(0.0f, 0.0f);
|
||||
glVertex3fv((GLfloat *) &m_coords[0]);
|
||||
|
||||
// top left
|
||||
glTexCoord2f(0.0f, 1.0f);
|
||||
glVertex3fv((GLfloat *) &m_coords[1]);
|
||||
|
||||
// bottom right
|
||||
glTexCoord2f(1.0f, 0.0f);
|
||||
glVertex3fv((GLfloat *) &m_coords[2]);
|
||||
|
||||
// top left
|
||||
glTexCoord2f(1.0f, 1.0f);
|
||||
glVertex3fv((GLfloat *) &m_coords[3]);
|
||||
glEnd();
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
EndBillboard();
|
||||
}
|
||||
|
||||
int CSprite::SetTexture(GLuint tex)
|
||||
{
|
||||
m_texture = tex;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CSprite::SetSize(float width, float height)
|
||||
{
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
|
||||
float xOffset = m_width / 2;
|
||||
float yOffset = m_height / 2;
|
||||
|
||||
// bottom left
|
||||
m_coords[0].X = - (xOffset);
|
||||
m_coords[0].Y = - (yOffset);
|
||||
m_coords[0].Z = 0.0f;
|
||||
|
||||
// top left
|
||||
m_coords[1].X = - (xOffset);
|
||||
m_coords[1].Y = yOffset;
|
||||
m_coords[1].Z = 0.0f;
|
||||
|
||||
// bottom right
|
||||
m_coords[2].X = xOffset;
|
||||
m_coords[2].Y = - (yOffset);
|
||||
m_coords[2].Z = 0.0f;
|
||||
|
||||
// top right
|
||||
m_coords[3].X = xOffset;
|
||||
m_coords[3].Y = yOffset;
|
||||
m_coords[3].Z = 0.0f;
|
||||
}
|
||||
|
||||
float CSprite::GetWidth()
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
void CSprite::SetWidth(float width)
|
||||
{
|
||||
SetSize(width, m_height);
|
||||
}
|
||||
|
||||
float CSprite::GetHeight()
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
void CSprite::SetHeight(float height)
|
||||
{
|
||||
SetSize(m_width, height);
|
||||
}
|
||||
|
||||
CVector3D CSprite::GetTranslation()
|
||||
{
|
||||
return m_translation;
|
||||
}
|
||||
|
||||
void CSprite::SetTranslation(CVector3D trans)
|
||||
{
|
||||
m_translation = trans;
|
||||
}
|
||||
|
||||
void CSprite::SetTranslation(float x, float y, float z)
|
||||
{
|
||||
m_translation.X = x;
|
||||
m_translation.Y = y;
|
||||
m_translation.Z = z;
|
||||
}
|
||||
|
||||
CVector3D CSprite::GetScale()
|
||||
{
|
||||
return m_scale;
|
||||
}
|
||||
|
||||
void CSprite::SetScale(CVector3D scale)
|
||||
{
|
||||
m_scale = scale;
|
||||
}
|
||||
|
||||
void CSprite::SetScale(float x, float y, float z)
|
||||
{
|
||||
m_scale.X = x;
|
||||
m_scale.Y = y;
|
||||
m_scale.Z = z;
|
||||
}
|
||||
|
||||
void CSprite::SetColour(float * colour)
|
||||
{
|
||||
m_colour[0] = colour[0];
|
||||
m_colour[1] = colour[1];
|
||||
m_colour[2] = colour[2];
|
||||
m_colour[3] = colour[3];
|
||||
}
|
||||
|
||||
// should be called before any other gl calls
|
||||
void CSprite::BeginBillboard()
|
||||
{
|
||||
float newMatrix[16] = { 1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f };
|
||||
float currentMatrix[16];
|
||||
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, currentMatrix);
|
||||
newMatrix[0] = currentMatrix[0];
|
||||
newMatrix[1] = currentMatrix[4];
|
||||
newMatrix[2] = currentMatrix[8];
|
||||
newMatrix[4] = currentMatrix[1];
|
||||
newMatrix[5] = currentMatrix[5];
|
||||
newMatrix[6] = currentMatrix[9];
|
||||
newMatrix[8] = currentMatrix[2];
|
||||
newMatrix[9] = currentMatrix[6];
|
||||
newMatrix[10] = currentMatrix[10];
|
||||
|
||||
glPushMatrix();
|
||||
glMultMatrixf(newMatrix);
|
||||
}
|
||||
|
||||
void CSprite::EndBillboard()
|
||||
{
|
||||
glPopMatrix();
|
||||
}
|
86
source/ape/ext/Sprite.h
Executable file
86
source/ape/ext/Sprite.h
Executable file
@ -0,0 +1,86 @@
|
||||
/*==================================================================
|
||||
|
|
||||
| Name: Sprite.h
|
||||
|
|
||||
|===================================================================
|
||||
|
|
||||
| Author: Ben Vinegar
|
||||
| Contact: benvinegar () hotmail ! com
|
||||
|
|
||||
|
|
||||
| Last Modified: 03/08/04
|
||||
|
|
||||
| Overview: Billboarding sprite class - always faces the camera. It
|
||||
| does this by getting the current model view matrix state.
|
||||
|
|
||||
|
|
||||
| Usage: The functions speak for themselves. Instantiate, then be
|
||||
| sure to pass a loaded (using tex_load()) texture before
|
||||
| calling Render().
|
||||
|
|
||||
| To do: TBA
|
||||
|
|
||||
| More Information: TBA
|
||||
|
|
||||
==================================================================*/
|
||||
|
||||
#ifndef SPRITE_H
|
||||
#define SPRITE_H
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Includes / Compiler directives
|
||||
//--------------------------------------------------------
|
||||
|
||||
#include "Vector3D.h"
|
||||
#include <GL/gl.h>
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
class CSprite
|
||||
{
|
||||
public:
|
||||
CSprite();
|
||||
~CSprite();
|
||||
|
||||
void Render();
|
||||
|
||||
int SetTexture(GLuint tex);
|
||||
|
||||
void SetSize(float width, float height);
|
||||
|
||||
float GetWidth();
|
||||
void SetWidth(float width);
|
||||
|
||||
float GetHeight();
|
||||
void SetHeight(float height);
|
||||
|
||||
CVector3D GetTranslation();
|
||||
void SetTranslation(CVector3D pos);
|
||||
void SetTranslation(float x, float y, float z);
|
||||
|
||||
CVector3D GetScale();
|
||||
void SetScale(CVector3D scale);
|
||||
void SetScale(float x, float y, float z);
|
||||
|
||||
void SetColour(float * colour);
|
||||
void SetColour(float r, float g, float b, float a = 1.0f);
|
||||
private:
|
||||
void BeginBillboard();
|
||||
void EndBillboard();
|
||||
|
||||
GLuint m_texture;
|
||||
|
||||
CVector3D m_coords[4];
|
||||
|
||||
float m_width;
|
||||
float m_height;
|
||||
|
||||
CVector3D m_translation;
|
||||
CVector3D m_scale;
|
||||
|
||||
float m_colour[4];
|
||||
};
|
||||
|
||||
#endif // SPRITE_H
|
62
source/ape/ext/Types.h
Executable file
62
source/ape/ext/Types.h
Executable file
@ -0,0 +1,62 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Types.h
|
||||
// Last Update: 25/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: The basic types used by the engine
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef TYPES_H
|
||||
#define TYPES_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
//color structures
|
||||
struct SColor4ub
|
||||
{
|
||||
unsigned char R;
|
||||
unsigned char G;
|
||||
unsigned char B;
|
||||
unsigned char A;
|
||||
};
|
||||
|
||||
struct SColor4f
|
||||
{
|
||||
float R;
|
||||
float G;
|
||||
float B;
|
||||
float A;
|
||||
};
|
||||
|
||||
//all the major classes:
|
||||
|
||||
class CCamera;
|
||||
|
||||
class CEngine;
|
||||
class CEntity;
|
||||
|
||||
class CFrustum;
|
||||
|
||||
class CMatrix3D;
|
||||
class CMesh;
|
||||
class CMeshPoly;
|
||||
class CShadyMesh;
|
||||
class CShadyMeshPoly;
|
||||
|
||||
class CNode;
|
||||
|
||||
class CPatch;
|
||||
class CPlane;
|
||||
|
||||
class CRenderer;
|
||||
|
||||
class CTerrain;
|
||||
|
||||
class CVector3D;
|
||||
|
||||
class CWorld;
|
||||
|
||||
|
||||
#endif
|
192
source/ape/ext/Vector3D.cpp
Executable file
192
source/ape/ext/Vector3D.cpp
Executable file
@ -0,0 +1,192 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Vector3D.Cpp
|
||||
// Last Update: 28/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: Provides an interface for a vector in R3 and
|
||||
// allows vector and scalar operations on it
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#include "Vector3D.h"
|
||||
|
||||
CVector3D::CVector3D ()
|
||||
{
|
||||
X = Y = Z = 0.0f;
|
||||
}
|
||||
|
||||
CVector3D::CVector3D (float x, float y, float z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
int CVector3D::operator == (const CVector3D &vector) const
|
||||
{
|
||||
if (X != vector.X ||
|
||||
Y != vector.Y ||
|
||||
Z != vector.Z)
|
||||
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CVector3D::operator != (const CVector3D &vector) const
|
||||
{
|
||||
if (X != vector.X ||
|
||||
Y != vector.Y ||
|
||||
Z != vector.Z)
|
||||
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CVector3D::operator ! () const
|
||||
{
|
||||
if (X != 0.0f ||
|
||||
Y != 0.0f ||
|
||||
Z != 0.0f)
|
||||
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//vector addition
|
||||
CVector3D CVector3D::operator + (const CVector3D &vector) const
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = X + vector.X;
|
||||
Temp.Y = Y + vector.Y;
|
||||
Temp.Z = Z + vector.Z;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//vector addition/assignment
|
||||
CVector3D &CVector3D::operator += (const CVector3D &vector)
|
||||
{
|
||||
X += vector.X;
|
||||
Y += vector.Y;
|
||||
Z += vector.Z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//vector subtraction
|
||||
CVector3D CVector3D::operator - (const CVector3D &vector) const
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = X - vector.X;
|
||||
Temp.Y = Y - vector.Y;
|
||||
Temp.Z = Z - vector.Z;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//vector negation
|
||||
CVector3D CVector3D::operator-() const
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = -X;
|
||||
Temp.Y = -Y;
|
||||
Temp.Z = -Z;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
//vector subtrcation/assignment
|
||||
CVector3D &CVector3D::operator -= (const CVector3D &vector)
|
||||
{
|
||||
X -= vector.X;
|
||||
Y -= vector.Y;
|
||||
Z -= vector.Z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//scalar multiplication
|
||||
CVector3D CVector3D::operator * (float value) const
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = X * value;
|
||||
Temp.Y = Y * value;
|
||||
Temp.Z = Z * value;
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
//scalar multiplication/assignment
|
||||
CVector3D& CVector3D::operator *= (float value)
|
||||
{
|
||||
X *= value;
|
||||
Y *= value;
|
||||
Z *= value;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void CVector3D::Set (float x, float y, float z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
void CVector3D::Clear ()
|
||||
{
|
||||
X = Y = Z = 0.0f;
|
||||
}
|
||||
|
||||
//Dot product
|
||||
float CVector3D::Dot (const CVector3D &vector) const
|
||||
{
|
||||
return ( X * vector.X +
|
||||
Y * vector.Y +
|
||||
Z * vector.Z );
|
||||
}
|
||||
|
||||
//Cross product
|
||||
CVector3D CVector3D::Cross (const CVector3D &vector) const
|
||||
{
|
||||
CVector3D Temp;
|
||||
|
||||
Temp.X = (Y * vector.Z) - (Z * vector.Y);
|
||||
Temp.Y = (Z * vector.X) - (X * vector.Z);
|
||||
Temp.Z = (X * vector.Y) - (Y * vector.X);
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
float CVector3D::GetLength () const
|
||||
{
|
||||
return sqrtf ( SQR(X) + SQR(Y) + SQR(Z) );
|
||||
}
|
||||
|
||||
void CVector3D::Normalize ()
|
||||
{
|
||||
float scale = 1.0f/GetLength ();
|
||||
|
||||
X *= scale;
|
||||
Y *= scale;
|
||||
Z *= scale;
|
||||
}
|
||||
|
||||
SColor4ub CVector3D::ConvertToColor (float alpha_factor) const
|
||||
{
|
||||
SColor4ub color;
|
||||
|
||||
color.R = (unsigned char)(127.0f * X + 128.0f);
|
||||
color.G = (unsigned char)(127.0f * Y + 128.0f);
|
||||
color.B = (unsigned char)(127.0f * Z + 128.0f);
|
||||
color.A = (unsigned char)(255.0f * alpha_factor);
|
||||
|
||||
return color;
|
||||
}
|
71
source/ape/ext/Vector3D.h
Executable file
71
source/ape/ext/Vector3D.h
Executable file
@ -0,0 +1,71 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Vector3D.H
|
||||
// Last Update: 28/1/02
|
||||
// Author: Poya Manouchehri
|
||||
//
|
||||
// Description: Provides an interface for a vector in R3 and
|
||||
// allows vector and scalar operations on it
|
||||
//
|
||||
//***********************************************************
|
||||
|
||||
#ifndef VECTOR3D_H
|
||||
#define VECTOR3D_H
|
||||
|
||||
#include <math.h>
|
||||
#include "MathUtil.h"
|
||||
#include "Types.h"
|
||||
|
||||
class CVector3D
|
||||
{
|
||||
public:
|
||||
float X, Y, Z;
|
||||
|
||||
public:
|
||||
CVector3D ();
|
||||
CVector3D (float x, float y, float z);
|
||||
|
||||
int operator == (const CVector3D &vector) const ;
|
||||
int operator != (const CVector3D &vector) const ;
|
||||
int operator ! () const ;
|
||||
|
||||
float& operator[](int index) { return *((&X)+index); }
|
||||
const float& operator[](int index) const { return *((&X)+index); }
|
||||
|
||||
//vector addition
|
||||
CVector3D operator + (const CVector3D &vector) const ;
|
||||
//vector addition/assignment
|
||||
CVector3D &operator += (const CVector3D &vector);
|
||||
|
||||
//vector subtraction
|
||||
CVector3D operator - (const CVector3D &vector) const ;
|
||||
//vector subtraction/assignment
|
||||
CVector3D &operator -= (const CVector3D &vector);
|
||||
|
||||
//scalar multiplication
|
||||
CVector3D operator * (float value) const ;
|
||||
//scalar multiplication/assignment
|
||||
CVector3D& operator *= (float value);
|
||||
|
||||
// negation
|
||||
CVector3D operator-() const;
|
||||
|
||||
public:
|
||||
void Set (float x, float y, float z);
|
||||
void Clear ();
|
||||
|
||||
//Dot product
|
||||
float Dot (const CVector3D &vector) const;
|
||||
//Cross product
|
||||
CVector3D Cross (const CVector3D &vector) const;
|
||||
|
||||
//Returns length of the vector
|
||||
float GetLength () const;
|
||||
void Normalize ();
|
||||
|
||||
//Returns a color which describes the vector
|
||||
SColor4ub ConvertToColor (float alpha_factor) const;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
61
source/ape/ext/tex_.cpp
Executable file
61
source/ape/ext/tex_.cpp
Executable file
@ -0,0 +1,61 @@
|
||||
#include "tex_.h"
|
||||
#include <GL/glaux.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
AUX_RGBImageRec * LoadBMP(char * filename);
|
||||
|
||||
int tex_load(char * filename, unsigned int *texture) // Load Bitmaps And Convert To Textures
|
||||
{
|
||||
int Status=FALSE; // Status Indicator
|
||||
|
||||
AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture
|
||||
|
||||
memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL
|
||||
|
||||
// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
|
||||
if (TextureImage[0]=LoadBMP(filename))
|
||||
{
|
||||
Status=TRUE; // Set The Status To TRUE
|
||||
|
||||
glGenTextures(1, texture); // Create The Texture
|
||||
|
||||
// Typical Texture Generation Using Data From The Bitmap
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
||||
}
|
||||
|
||||
if (TextureImage[0]) // If Texture Exists
|
||||
{
|
||||
if (TextureImage[0]->data) // If Texture Image Exists
|
||||
{
|
||||
free(TextureImage[0]->data); // Free The Texture Image Memory
|
||||
}
|
||||
|
||||
free(TextureImage[0]); // Free The Image Structure
|
||||
}
|
||||
|
||||
return Status; // Return The Status
|
||||
}
|
||||
|
||||
AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image
|
||||
{
|
||||
FILE *File=NULL; // File Handle
|
||||
|
||||
if (!Filename) // Make Sure A Filename Was Given
|
||||
{
|
||||
return NULL; // If Not Return NULL
|
||||
}
|
||||
|
||||
File=fopen(Filename,"r"); // Check To See If The File Exists
|
||||
|
||||
if (File) // Does The File Exist?
|
||||
{
|
||||
fclose(File); // Close The Handle
|
||||
return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer
|
||||
}
|
||||
|
||||
return NULL; // If Load Failed Return NULL
|
||||
}
|
8
source/ape/ext/tex_.h
Executable file
8
source/ape/ext/tex_.h
Executable file
@ -0,0 +1,8 @@
|
||||
#ifndef __TEX_H__
|
||||
#define __TEX_H__
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
int tex_load(char *filename, unsigned int *id);
|
||||
|
||||
#endif // __TEX_H__
|
9
source/ape/ext/timer_.cpp
Executable file
9
source/ape/ext/timer_.cpp
Executable file
@ -0,0 +1,9 @@
|
||||
#include "timer_.h"
|
||||
#include <time.h>
|
||||
|
||||
double timeStart;
|
||||
|
||||
double get_time()
|
||||
{
|
||||
return (double)clock() / 1000;
|
||||
}
|
6
source/ape/ext/timer_.h
Executable file
6
source/ape/ext/timer_.h
Executable file
@ -0,0 +1,6 @@
|
||||
#ifndef __TIMER_H__
|
||||
#define __TIMER_H__
|
||||
|
||||
double get_time();
|
||||
|
||||
#endif // __TIMER_H__
|
Loading…
Reference in New Issue
Block a user