#include <math.h>
struct particle
{
Vector3 pos;
Vector3 targ;
int age;
//float speed;
};
struct emitter
{
private:
Vector3 pos;
vector<particle> array;
int num_part;
int lifetime;
float speed;
float grav;
float x_spread;
float y_spread;
public:
emitter();
~emitter();
void Position(float x, float y, float z);
void Spread(float x_ang, float y_ang);
void Speed(float sp);
void Particles(int num);
void InitEmitter();
void InitParticle(int num);
void Update();
void Render();
};
emitter::emitter()
{
pos.x = 0; pos.y = 0; pos.z = 0;
num_part = 1;
array.resize(num_part);
lifetime = 1;
speed = 1;
grav = 0.01f;
x_spread = 45;
y_spread = 45;
}
emitter::~emitter()
{}
void emitter::Position(float x, float y, float z)
{
pos.x = x;
pos.y = y;
pos.z = z;
}
void emitter::Speed(float sp)
{ speed = sp;}
void emitter::Spread(float x_ang, float y_ang)
{
x_spread = x_ang;
y_spread = y_ang;
}
void emitter::Particles(int num)
{
num_part = num;
array.resize(num_part);
}
void emitter::InitEmitter()
{
for(int x = 0; x < num_part; x++)
InitParticle(x);
}
void emitter::InitParticle(int num)
{
int x_ang, y_ang;
array[num].age = 0;
array[num].pos.x = pos.x;
array[num].pos.y = pos.y;
array[num].pos.z = pos.z;
x_ang = (rand() / x_spread) - (x_spread / 2);
y_ang = (rand() / y_spread) - (y_spread / 2);
array[num].targ.x = cos(x_ang);
array[num].targ.y = sin(y_ang);
array[num].targ.z = sin(x_ang);
array[num].targ = Normalize(array[num].targ);
}
void emitter::Update()
{
for(int x = 0; x < num_part; x++)
{
if(array[x].age == lifetime)
InitParticle(x);
array[x].targ.y = array[x].targ.y - grav;
array[x].pos.x = array[x].pos.x + (speed * array[x].targ.x);
array[x].pos.y = array[x].pos.y + (speed * array[x].targ.y);
array[x].pos.z = array[x].pos.z +(speed * array[x].targ.z);
}
}
void emitter::Render()
{
for(int x = 0; x < num_part; x++)
{
glBegin(GL_POINTS);
glVertex3f(array[x].pos.x,
array[x].pos.y,
array[x].pos.z);
glEnd();
}
}
thanks ahead of time
[edited by - adam17 on January 7, 2004 1:48:11 AM]
Ever seen this error?
C:\Adam\Software\Visual C++\VC98\INCLUDE\xutility(39) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'const struct particle' (or there is no acceptable conversion)
i have no idea what could be going on in this error. this xutility error has driven me nuts so far that i have rewritten my particle system code FIVE TIMES!!! grrrr. any ideas of what i can do? i checked the '=' thing and i cant find anything. just in case someone does here is my code:
What does your Vector3 class look like? It''s possible it''s preventing a default assignement operator from being generated for your particle class.
Is array.targ of type const struct particle?
This line is the only thing I can see that could be wrong.
array[num].targ = Normalize(array[num].targ);
This line is the only thing I can see that could be wrong.
array[num].targ = Normalize(array[num].targ);
I could be wrong, I only quickly glanced at your code, but...
perhaps it''s the resize method you call from vector. I''m not quite familiar with that method. In any case, if you overload the = operator for the partical class, it might remove your error. STL containers, at least certain ones, use various operators( including =, <, > ) operator for sorting and other operations. And, you will recieve an error within various template files while the compiler is trying to sort out templetes.
Also, I suggest you use iterators for traversing stl containers, and not just your own index count.
perhaps it''s the resize method you call from vector. I''m not quite familiar with that method. In any case, if you overload the = operator for the partical class, it might remove your error. STL containers, at least certain ones, use various operators( including =, <, > ) operator for sorting and other operations. And, you will recieve an error within various template files while the compiler is trying to sort out templetes.
Also, I suggest you use iterators for traversing stl containers, and not just your own index count.
here is my vector.h file
struct Vector3{ Vector3() {} Vector3(float X, float Y, float Z) { x = X; y = Y; z = Z;} Vector3 operator-(Vector3 vector) { return Vector3( x - vector.x, y - vector.y, z - vector.z);} Vector3 operator+(Vector3 vector) { return Vector3( x + vector.x, y + vector.y, z + vector.z);} Vector3 operator*(Vector3 vector) { return Vector3( x * vector.x, y * vector.y, z * vector.z);} Vector3 operator=(Vector3 vector) { return Vector3( x = vector.x, y = vector.y, z = vector.z);} /*Vector3 operator/(Vector3 vector, float num) { return Vector3( vector.x/3, vector.y/3, vector.z/3);}*/ float x, y, z;};Vector3 Cross(Vector3 vector1, Vector3 vector2){ Vector3 temp_vector; temp_vector.x = (vector1.z * vector2.y) - (vector1.y * vector2.z); temp_vector.y = (vector1.x * vector2.z) - (vector1.z * vector2.x); temp_vector.z = (vector1.y * vector2.x) - (vector1.x * vector2.y); return temp_vector;}float Dot3(Vector3 vector1, Vector3 vector2){ float decimal; decimal = sqrt(vector1.x * vector2.x + vector1.y * vector2.y + vector1.z * vector2.z); return decimal;}float Magnitude(Vector3 vector){ return sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z);}Vector3 Normalize(Vector3 vector){ float len = Magnitude(vector); vector.x /= len; vector.y /= len; vector.z /= len; return vector;}Vector3 Mul(Vector3 vector, float multiplier){ vector.x *= multiplier; vector.y *= multiplier; vector.z *= multiplier; return vector;}/*//vector1 is the normal, vector2 is the test vertex//if return > 0 => vector2 is in front of plane//if return = 0 => vector2 is on the plane//if return < 0 => vector2 is behind the planeVector3 Plane_Equ(Vector3 vector1, Vector3 vector2){ Vector3 temp_vector; temp_vector.x = vector1.x * vector2.x; temp_vector.y = vector1.y * vector2.y; temp_vector.z = vector1.z * vector2.z; temp_vector = Magnitude(vector2) + temp_vector; return temp_vector;}*/
MSVC 6 gets pissy about assignment operators that aren''t defined exactly how it wants them to be defined. Your Vector3 operator=() doesn''t match it''s preferred signature. Try changing it to
Vector3 & Vector3::operator=(const Vector3 & vector) { x = vector.x; y = vector.y; z = vector.z; return *this;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement