Altered to better comply with coding standards.
This was SVN commit r188.
This commit is contained in:
parent
23e35513d3
commit
16c7c585ee
@ -1,12 +1,28 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Particle.cpp
|
||||
// Last Update: 03/04/04
|
||||
// Author: Ben Vinegar
|
||||
//
|
||||
// Description: Particle class implementation
|
||||
//
|
||||
//***********************************************************
|
||||
/*==================================================================
|
||||
|
|
||||
| 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 "time.h"
|
||||
@ -18,29 +34,34 @@ CParticle::CParticle() :
|
||||
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();
|
||||
m_gravity(0.0f, 0.0f, 0.0f)
|
||||
{
|
||||
m_timeOfLastFrame = get_time();
|
||||
|
||||
// default white colour
|
||||
m_colour[0] = m_colour[1] = m_colour[2] = m_colour[3] = 1.0f;
|
||||
}
|
||||
|
||||
CParticle::~CParticle() {
|
||||
CParticle::~CParticle()
|
||||
{
|
||||
}
|
||||
|
||||
void CParticle::Init() {
|
||||
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() {
|
||||
void CParticle::Frame()
|
||||
{
|
||||
Update();
|
||||
Render();
|
||||
}
|
||||
|
||||
void CParticle::Render() {
|
||||
void CParticle::Render()
|
||||
{
|
||||
assert(m_sprite);
|
||||
|
||||
m_sprite->SetColour(m_colour);
|
||||
@ -48,7 +69,8 @@ void CParticle::Render() {
|
||||
m_sprite->Render();
|
||||
}
|
||||
|
||||
void CParticle::Update() {
|
||||
void CParticle::Update()
|
||||
{
|
||||
float timeElapsed = float(get_time() - m_timeOfLastFrame);
|
||||
|
||||
m_velocity += m_gravity * timeElapsed;
|
||||
|
@ -1,45 +1,70 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Particle.h
|
||||
// Last Update: 03/04/04
|
||||
// Author: Ben Vinegar
|
||||
//
|
||||
// Description: Particle class header
|
||||
//
|
||||
//***********************************************************
|
||||
/*==================================================================
|
||||
|
|
||||
| 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"
|
||||
|
||||
class CParticle {
|
||||
public:
|
||||
CParticle();
|
||||
~CParticle();
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
// necessary pre-processing immediately before first update call
|
||||
void Init();
|
||||
class CParticle
|
||||
{
|
||||
public:
|
||||
CParticle();
|
||||
~CParticle();
|
||||
|
||||
void Frame();
|
||||
void Update();
|
||||
void Render();
|
||||
// necessary pre-processing immediately before first update call
|
||||
void Init();
|
||||
|
||||
void SetColour(float r, float g, float b, float a);
|
||||
void Frame();
|
||||
void Update();
|
||||
void Render();
|
||||
|
||||
CSprite * m_sprite;
|
||||
void SetColour(float r, float g, float b, float a);
|
||||
|
||||
float m_duration;
|
||||
double m_timeOfLastFrame;
|
||||
double m_timeElapsedTotal;
|
||||
CSprite * m_sprite;
|
||||
|
||||
CVector3D m_position;
|
||||
CVector3D m_velocity;
|
||||
CVector3D m_gravity;
|
||||
float m_duration;
|
||||
double m_timeOfLastFrame;
|
||||
double m_timeElapsedTotal;
|
||||
|
||||
float m_colour[4];
|
||||
float m_colourInc[3];
|
||||
CVector3D m_position;
|
||||
CVector3D m_velocity;
|
||||
CVector3D m_gravity;
|
||||
|
||||
float m_colour[4];
|
||||
float m_colourInc[3];
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,16 +1,30 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: ParticleEmitter.cpp
|
||||
// Last Update: 03/02/04
|
||||
// Author: Ben Vinegar
|
||||
//
|
||||
// Description: Particle class header
|
||||
//
|
||||
//
|
||||
// To-do: - estimate particles to release / second
|
||||
// - randomness, range still needs to be implemented
|
||||
// - colour issues
|
||||
//***********************************************************
|
||||
/*==================================================================
|
||||
|
|
||||
| Name: ParticleEmitter.cpp
|
||||
|
|
||||
|===================================================================
|
||||
|
|
||||
| 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
|
||||
|
|
||||
==================================================================*/
|
||||
|
||||
#include "ParticleEmitter.h"
|
||||
#include "time.h"
|
||||
@ -30,19 +44,23 @@ CParticleEmitter::CParticleEmitter() :
|
||||
m_maxLifetime(0),
|
||||
m_minLifetime(0),
|
||||
m_timeOfLastFrame(0.0f),
|
||||
m_timeSinceLastEmit(0.0f) {
|
||||
m_particles.clear();
|
||||
m_timeSinceLastEmit(0.0f)
|
||||
{
|
||||
m_particles.clear();
|
||||
}
|
||||
|
||||
CParticleEmitter::~CParticleEmitter() {
|
||||
CParticleEmitter::~CParticleEmitter()
|
||||
{
|
||||
}
|
||||
|
||||
void CParticleEmitter::Frame() {
|
||||
void CParticleEmitter::Frame()
|
||||
{
|
||||
Update();
|
||||
Render();
|
||||
}
|
||||
|
||||
void CParticleEmitter::Render() {
|
||||
void CParticleEmitter::Render()
|
||||
{
|
||||
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
@ -52,7 +70,8 @@ void CParticleEmitter::Render() {
|
||||
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
|
||||
|
||||
vector<CParticle *>::iterator itor = m_particles.begin();
|
||||
while (itor != m_particles.end()) {
|
||||
while (itor != m_particles.end())
|
||||
{
|
||||
CParticle * curParticle = (*itor);
|
||||
|
||||
curParticle->Frame();
|
||||
@ -63,18 +82,21 @@ void CParticleEmitter::Render() {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
void CParticleEmitter::Update() {
|
||||
void CParticleEmitter::Update()
|
||||
{
|
||||
float timeElapsed = get_time() - m_timeOfLastFrame;
|
||||
|
||||
// update existing particles
|
||||
vector<CParticle *>::iterator itor = m_particles.begin();
|
||||
while (itor != m_particles.end()) {
|
||||
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) {
|
||||
if (curParticle->m_timeElapsedTotal >= curParticle->m_duration)
|
||||
{
|
||||
m_particles.erase(itor);
|
||||
delete curParticle;
|
||||
--m_numParticles;
|
||||
@ -85,7 +107,8 @@ void CParticleEmitter::Update() {
|
||||
|
||||
float secondsPerEmit = 1 / (m_minParticles / m_minLifetime);
|
||||
|
||||
if (m_timeSinceLastEmit > secondsPerEmit) {
|
||||
if (m_timeSinceLastEmit > secondsPerEmit)
|
||||
{
|
||||
|
||||
int duration;
|
||||
CVector3D position, velocity;
|
||||
@ -134,7 +157,8 @@ void CParticleEmitter::Update() {
|
||||
m_particles.push_back(newParticle);
|
||||
|
||||
timeElapsed -= secondsPerEmit;
|
||||
if (timeElapsed < secondsPerEmit) {
|
||||
if (timeElapsed < secondsPerEmit)
|
||||
{
|
||||
moreParticlesToEmit = false;
|
||||
}
|
||||
|
||||
@ -149,88 +173,105 @@ void CParticleEmitter::Update() {
|
||||
m_timeOfLastFrame = get_time();
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetSprite(CSprite * sprite) {
|
||||
void CParticleEmitter::SetSprite(CSprite * sprite)
|
||||
{
|
||||
m_sprite = sprite;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetOrigin(CVector3D origin) {
|
||||
void CParticleEmitter::SetOrigin(CVector3D origin)
|
||||
{
|
||||
m_origin = origin;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetOrigin(float x, float y, float z) {
|
||||
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) {
|
||||
void CParticleEmitter::SetOriginSpread(CVector3D spread)
|
||||
{
|
||||
m_originSpread = spread;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetOriginSpread(float x, float y, float z) {
|
||||
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) {
|
||||
void CParticleEmitter::SetGravity(CVector3D gravity)
|
||||
{
|
||||
m_gravity = gravity;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetGravity(float x, float y, float z) {
|
||||
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) {
|
||||
void CParticleEmitter::SetVelocity(CVector3D velocity)
|
||||
{
|
||||
m_velocity = velocity;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetVelocity(float x, float y, float z) {
|
||||
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) {
|
||||
void CParticleEmitter::SetVelocitySpread(CVector3D spread)
|
||||
{
|
||||
m_velocitySpread = spread;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetVelocitySpread(float x, float y, float z) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
void CParticleEmitter::SetMaxLifetime(double maxLife)
|
||||
{
|
||||
m_maxLifetime = maxLife;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetMinLifetime(double minLife) {
|
||||
void CParticleEmitter::SetMinLifetime(double minLife)
|
||||
{
|
||||
m_minLifetime = minLife;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetMaxParticles(int maxParticles) {
|
||||
void CParticleEmitter::SetMaxParticles(int maxParticles)
|
||||
{
|
||||
m_maxParticles = maxParticles;
|
||||
}
|
||||
|
||||
void CParticleEmitter::SetMinParticles(int minParticles) {
|
||||
void CParticleEmitter::SetMinParticles(int minParticles)
|
||||
{
|
||||
m_minParticles = minParticles;
|
||||
}
|
||||
|
@ -1,92 +1,119 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: ParticleEmitter.h
|
||||
// Last Update: 03/01/04
|
||||
// Author: Ben Vinegar
|
||||
//
|
||||
// Description: Particle class header
|
||||
//
|
||||
//***********************************************************
|
||||
/*==================================================================
|
||||
|
|
||||
| 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 "Sprite.h"
|
||||
#include "Vector3D.h"
|
||||
#include <vector>
|
||||
|
||||
class CParticleEmitter {
|
||||
public:
|
||||
CParticleEmitter();
|
||||
~CParticleEmitter();
|
||||
|
||||
// must be performed before first frame/render/update call
|
||||
bool Init();
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
// renders and updates particles
|
||||
void Frame();
|
||||
class CParticleEmitter
|
||||
{
|
||||
public:
|
||||
CParticleEmitter();
|
||||
~CParticleEmitter();
|
||||
|
||||
// renders without updating particles
|
||||
void Render();
|
||||
// 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();
|
||||
void Update();
|
||||
|
||||
void SetSprite(CSprite * sprite);
|
||||
void SetSprite(CSprite * sprite);
|
||||
|
||||
void SetOrigin(CVector3D origin);
|
||||
void SetOrigin(float x, float y, float z);
|
||||
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 SetOriginSpread(CVector3D spread);
|
||||
void SetOriginSpread(float x, float y, float z);
|
||||
|
||||
void SetGravity(CVector3D gravity);
|
||||
void SetGravity(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 SetVelocity(CVector3D direction);
|
||||
void SetVelocity(float x, float y, float z);
|
||||
|
||||
void SetVelocitySpread(CVector3D spread);
|
||||
void SetVelocitySpread(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);
|
||||
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 SetMaxLifetime(double maxLife);
|
||||
|
||||
// in milliseconds
|
||||
void SetMinLifetime(double minLife);
|
||||
// in milliseconds
|
||||
void SetMinLifetime(double minLife);
|
||||
|
||||
void SetMaxParticles(int maxParticles);
|
||||
void SetMaxParticles(int maxParticles);
|
||||
void SetMinParticles(int minParticles);
|
||||
|
||||
void SetMinParticles(int minParticles);
|
||||
private:
|
||||
CSprite * m_sprite;
|
||||
|
||||
private:
|
||||
CSprite * m_sprite;
|
||||
std::vector<CParticle *> m_particles;
|
||||
|
||||
CVector3D m_origin;
|
||||
CVector3D m_originSpread;
|
||||
|
||||
std::vector<CParticle *> m_particles;
|
||||
CVector3D m_velocity;
|
||||
CVector3D m_velocitySpread;
|
||||
|
||||
CVector3D m_origin;
|
||||
CVector3D m_originSpread;
|
||||
CVector3D m_gravity;
|
||||
|
||||
CVector3D m_velocity;
|
||||
CVector3D m_velocitySpread;
|
||||
float m_startColour[4];
|
||||
float m_endColour[4];
|
||||
|
||||
CVector3D m_gravity;
|
||||
int m_maxParticles;
|
||||
int m_minParticles;
|
||||
int m_numParticles;
|
||||
|
||||
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_maxLifetime;
|
||||
double m_minLifetime;
|
||||
|
||||
double m_timeOfLastFrame;
|
||||
float m_timeSinceLastEmit;
|
||||
double m_timeOfLastFrame;
|
||||
float m_timeSinceLastEmit;
|
||||
};
|
||||
|
||||
#endif // PARTICLE_EMITTER_H
|
||||
|
@ -1,21 +1,36 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Sprite.cpp
|
||||
// Last Update: 26/02/04
|
||||
// Author: Ben Vinegar
|
||||
//
|
||||
// Description: 3D Sprite class implementation.
|
||||
//
|
||||
// To-do:
|
||||
//
|
||||
//***********************************************************
|
||||
/*==================================================================
|
||||
|
|
||||
| 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 "ogl.h"
|
||||
#include "tex.h"
|
||||
|
||||
CSprite::CSprite() :
|
||||
m_texture(NULL) {
|
||||
m_texture(NULL)
|
||||
{
|
||||
|
||||
// default scale 1:1
|
||||
m_scale.X = m_scale.Y = m_scale.Z = 1.0f;
|
||||
@ -30,10 +45,12 @@ CSprite::CSprite() :
|
||||
m_colour[0] = m_colour[1] = m_colour[2] = m_colour[3] = 1.0f;
|
||||
}
|
||||
|
||||
CSprite::~CSprite() {
|
||||
CSprite::~CSprite()
|
||||
{
|
||||
}
|
||||
|
||||
void CSprite::Render() {
|
||||
void CSprite::Render()
|
||||
{
|
||||
BeginBillboard();
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
@ -68,14 +85,16 @@ void CSprite::Render() {
|
||||
EndBillboard();
|
||||
}
|
||||
|
||||
int CSprite::SetTexture(CTexture *texture) {
|
||||
int CSprite::SetTexture(CTexture *texture)
|
||||
{
|
||||
if (texture == NULL) return -1;
|
||||
|
||||
m_texture = texture;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CSprite::SetSize(float width, float height) {
|
||||
void CSprite::SetSize(float width, float height)
|
||||
{
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
|
||||
@ -103,51 +122,62 @@ void CSprite::SetSize(float width, float height) {
|
||||
m_coords[3].Z = 0.0f;
|
||||
}
|
||||
|
||||
float CSprite::GetWidth() {
|
||||
float CSprite::GetWidth()
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
void CSprite::SetWidth(float width) {
|
||||
void CSprite::SetWidth(float width)
|
||||
{
|
||||
SetSize(width, m_height);
|
||||
}
|
||||
|
||||
float CSprite::GetHeight() {
|
||||
float CSprite::GetHeight()
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
void CSprite::SetHeight(float height) {
|
||||
void CSprite::SetHeight(float height)
|
||||
{
|
||||
SetSize(m_width, height);
|
||||
}
|
||||
|
||||
CVector3D CSprite::GetTranslation() {
|
||||
CVector3D CSprite::GetTranslation()
|
||||
{
|
||||
return m_translation;
|
||||
}
|
||||
|
||||
void CSprite::SetTranslation(CVector3D trans) {
|
||||
void CSprite::SetTranslation(CVector3D trans)
|
||||
{
|
||||
m_translation = trans;
|
||||
}
|
||||
|
||||
void CSprite::SetTranslation(float x, float y, float z) {
|
||||
void CSprite::SetTranslation(float x, float y, float z)
|
||||
{
|
||||
m_translation.X = x;
|
||||
m_translation.Y = y;
|
||||
m_translation.Z = z;
|
||||
}
|
||||
|
||||
CVector3D CSprite::GetScale() {
|
||||
CVector3D CSprite::GetScale()
|
||||
{
|
||||
return m_scale;
|
||||
}
|
||||
|
||||
void CSprite::SetScale(CVector3D scale) {
|
||||
void CSprite::SetScale(CVector3D scale)
|
||||
{
|
||||
m_scale = scale;
|
||||
}
|
||||
|
||||
void CSprite::SetScale(float x, float y, float z) {
|
||||
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) {
|
||||
void CSprite::SetColour(float * colour)
|
||||
{
|
||||
m_colour[0] = colour[0];
|
||||
m_colour[1] = colour[1];
|
||||
m_colour[2] = colour[2];
|
||||
@ -155,7 +185,8 @@ void CSprite::SetColour(float * colour) {
|
||||
}
|
||||
|
||||
// should be called before any other gl calls
|
||||
void CSprite::BeginBillboard() {
|
||||
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,
|
||||
@ -177,6 +208,7 @@ void CSprite::BeginBillboard() {
|
||||
glMultMatrixf(newMatrix);
|
||||
}
|
||||
|
||||
void CSprite::EndBillboard() {
|
||||
void CSprite::EndBillboard()
|
||||
{
|
||||
glPopMatrix();
|
||||
}
|
||||
|
@ -1,63 +1,86 @@
|
||||
//***********************************************************
|
||||
//
|
||||
// Name: Sprite.h
|
||||
// Last Update: 22/02/04
|
||||
// Author: Ben Vinegar
|
||||
//
|
||||
// Description: 3D Sprite class header.
|
||||
//
|
||||
//***********************************************************
|
||||
/*==================================================================
|
||||
|
|
||||
| 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 "Texture.h"
|
||||
|
||||
class CSprite {
|
||||
public:
|
||||
CSprite();
|
||||
~CSprite();
|
||||
//--------------------------------------------------------
|
||||
// Declarations
|
||||
//--------------------------------------------------------
|
||||
|
||||
void Render();
|
||||
class CSprite
|
||||
{
|
||||
public:
|
||||
CSprite();
|
||||
~CSprite();
|
||||
|
||||
int SetTexture(CTexture *texture);
|
||||
void Render();
|
||||
|
||||
void SetSize(float width, float height);
|
||||
int SetTexture(CTexture *texture);
|
||||
|
||||
float GetWidth();
|
||||
void SetWidth(float width);
|
||||
void SetSize(float width, float height);
|
||||
|
||||
float GetHeight();
|
||||
void SetHeight(float height);
|
||||
float GetWidth();
|
||||
void SetWidth(float width);
|
||||
|
||||
CVector3D GetTranslation();
|
||||
void SetTranslation(CVector3D pos);
|
||||
void SetTranslation(float x, float y, float z);
|
||||
float GetHeight();
|
||||
void SetHeight(float height);
|
||||
|
||||
CVector3D GetScale();
|
||||
void SetScale(CVector3D scale);
|
||||
void SetScale(float x, float y, float z);
|
||||
CVector3D GetTranslation();
|
||||
void SetTranslation(CVector3D pos);
|
||||
void SetTranslation(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();
|
||||
CVector3D GetScale();
|
||||
void SetScale(CVector3D scale);
|
||||
void SetScale(float x, float y, float z);
|
||||
|
||||
CTexture *m_texture;
|
||||
void SetColour(float * colour);
|
||||
void SetColour(float r, float g, float b, float a = 1.0f);
|
||||
private:
|
||||
void BeginBillboard();
|
||||
void EndBillboard();
|
||||
|
||||
CVector3D m_coords[4];
|
||||
CTexture *m_texture;
|
||||
|
||||
float m_width;
|
||||
float m_height;
|
||||
CVector3D m_coords[4];
|
||||
|
||||
CVector3D m_translation;
|
||||
CVector3D m_scale;
|
||||
float m_width;
|
||||
float m_height;
|
||||
|
||||
float m_colour[4];
|
||||
CVector3D m_translation;
|
||||
CVector3D m_scale;
|
||||
|
||||
float m_colour[4];
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // SPRITE_H
|
Loading…
Reference in New Issue
Block a user