Archived

This topic is now archived and is closed to further replies.

okouya

particles system pascal and c coders

Recommended Posts

due to the fact that i''m a opp coders i need some explanation see the code above that i don''t understand is the "m_color[4]" i guess that he was talking about a table but what table it is where did he declare it and if i guess right is someone can explain me how to do it in pascal. " ****************************************************************************/ #ifndef __PARTICLES_H_INCLUDED__ #define __PARTICLES_H_INCLUDED__ /********************************* Includes *********************************/ #include <iostream.h> #include <windows.h> #include <GL/gl.h> #include <GL/glu.h> #include "vector.h" //using namespace std; /***************************** Data structures ******************************/ class CParticleSystem; struct particle_t { CVector m_pos; // current position of the particle CVector m_prevPos; // last position of the particle CVector m_velocity; // direction and speed CVector m_acceleration; // acceleration float m_energy; // determines how long the particle is alive float m_size; // size of particle float m_sizeDelta; // amount to change the size over time float m_weight; // determines how gravity affects the particle float m_weightDelta; // change over time float m_color[4]; // current color of the particle float m_colorDelta[4]; // how the color changes with time }; class CParticleSystem { public: CParticleSystem(int maxParticles, CVector origin); // abstract functions virtual void Update(float elapsedTime) = 0; virtual void Render() = 0; virtual int Emit(int numParticles); virtual void InitializeSystem(); virtual void KillSystem(); protected: virtual void InitializeParticle(int index) = 0; particle_t *m_particleList; // particles for this emitter int m_maxParticles; // maximum number of particles in total int m_numParticles; // indicies of all free particles CVector m_origin; // center of the particle system float m_accumulatedTime; // used to track how long since the last particle was emitted CVector m_force; // force (gravity, wind, etc.) acting on the particle system }; #endif // __PARTICLES_H_INCLUDED if you want to understand all i''m doing i''m trying to understand how to make a particles systeme this the ccp if you know how to do it in pascal too don''t stop your explanation // abstract functions virtual void Update(float elapsedTime) = 0; virtual void Render() = 0; **************************************************************************** Particles.cpp Author : Dave Astle Date : 2/1/2001 Written for OpenGL Game Programming *****************************************************************************/ #include "Particles.h" /***************************************************************************** CParticleSystem::Constructor Store initialization values and set defaults. *****************************************************************************/ CParticleSystem::CParticleSystem(int maxParticles, CVector origin) { m_maxParticles = maxParticles; m_origin = origin; m_particleList = NULL; } // end CParticleSystem::Constructor /***************************************************************************** CParticleSystem::Emit() Creates the number of new particles specified by the parameter, using the general particle system values with some random element. Note that only initial values will be randomized. Final values will not. This may be changed in the future. *****************************************************************************/ int CParticleSystem::Emit(int numParticles) { // create numParticles new particles (if there''s room) while (numParticles && (m_numParticles < m_maxParticles)) { // initialize the current particle and increase the count InitializeParticle(m_numParticles++); --numParticles; } return numParticles; } // end CParticleSystem::Emit /***************************************************************************** CParticleSystem::InitializeSystem() Allocate memory for the maximum number of particles in the system *****************************************************************************/ void CParticleSystem::InitializeSystem() { // if this is just a reset, free the memory if (m_particleList) { delete[] m_particleList; m_particleList = NULL; } // allocate the maximum number of particles m_particleList = new particle_t[m_maxParticles]; // reset the number of particles and accumulated time m_numParticles = 0; m_accumulatedTime = 0.0f; } // end CParticleSystem::InitializeSystem /***************************************************************************** CParticleSystem::KillSystem() Tells the emitter to stop emitting. If the parameter is true, all live particles are killed as well. Otherwise, they are allowed to die off on their own. *****************************************************************************/ void CParticleSystem::KillSystem() { if (m_particleList) { delete[] m_particleList; m_particleList = NULL; } m_numParticles = 0; } // end CParticleSystem::KillSystem love and peace

Share this post


Link to post
Share on other sites
In a declaration,
float m_color[4];
would be:
m_color: array [4] of float;
(or possibly m_color: array [0..3] of single)

When used as:
m_color[4]
it doesn''t change, it''s still:
m_color[4]
in pascal.

Hope that helps,

John B

Share this post


Link to post
Share on other sites
yes thanks i understand but what about that can you give me explanation and traduction


// abstract functions
virtual void Update(float elapsedTime) = 0;
virtual void Render() = 0;





class CParticleSystem
{
public:
CParticleSystem(int maxParticles, CVector origin);

// abstract functions
virtual void Update(float elapsedTime) = 0;
virtual void Render() = 0;

virtual int Emit(int numParticles);

virtual void InitializeSystem();
virtual void KillSystem();

protected:
virtual void InitializeParticle(int index) = 0;
particle_t *m_particleList; // particles for this emitter
int m_maxParticles; // maximum number of particles in total
int m_numParticles; // indicies of all free particles
CVector m_origin; // center of the particle system

float m_accumulatedTime; // used to track how long since the last particle was emitted

CVector m_force; // force (gravity, wind, etc.) acting on the particle system
};


#endif // __PARTICLES_H_INCLUDE


and waht about that too


int CParticleSystem::Emit(int numParticles)
{
// create numParticles new particles (if there''s room)
while (numParticles && (m_numParticles < m_maxParticles))
{
// initialize the current particle and increase the count
InitializeParticle(m_numParticles++);
--numParticles;
}
return numParticles;
} // end CParticleSystem::Emit

this
InitializeParticle(m_numParticles++);
--numParticles;



and to finish this



how can you dothis in pascal


void CParticleSystem::InitializeSystem()
{
// if this is just a reset, free the memory
if (m_particleList)
{
delete[] m_particleList;
m_particleList = NULL;
}

// allocate the maximum number of particles
m_particleList = new particle_t[m_maxParticles];







love and peace

Share this post


Link to post
Share on other sites