Jump to content
  • Advertisement

Archived

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

CondiS

newbie drawing question!

This topic is 6012 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to draw particles in my 3d game, but the problem i''m having is that i use the camera tutorial from www.gametutorials.com for my camera, and i want my particles to be in their own X, Y, Z for rotating and stuff, how should i do this? i tried glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glTranslatef(); but it didn''t work, the particles followed the camera not the "world" =( any suggestions?

Share this post


Link to post
Share on other sites
Advertisement
don''t do any of that stuff.
simple draw them at their world coordinates. You might need to do some fancy stuff to keep them facing the camera, but it isn''t that hard.

Share this post


Link to post
Share on other sites
but if i just draw them at their position and then wants to rotate them they rotate around the 0,0,0.. I want them to rotate at their own x,y,z position!

[edited by - CondiS on June 2, 2002 12:02:23 PM]

Share this post


Link to post
Share on other sites
Simply

glPushMatrix()
glTranslatef();
glRotatef()
Display_Your_Particle();
glPopMatrix();

========================
Leyder Dylan
http://ibelgique.ifrance.com/Slug-Production/

Share this post


Link to post
Share on other sites
Now i really feel lika newbie =/
i still can't get it to work.

particle.h

      
#ifndef _PARTICLE_H_
#define _PARTICLE_H_

#include "include.h"
#include "vector.h"
#include "timing.h"


#define MAX_PARTICLES 50
#define P_SMOKE 0
#define P_FIRE 1
#define P_EXPLOSION 2


struct SParticle {
CVector Org_Position;
CVector Position;
CVector Direction;

float life;

};

class CParticle {
public:

CParticle(float x, float y, float z, int N_Type, int N_Time);
CParticle(CVector &N_Position, int N_Type, int N_Time);

void Calculate_Direction();
void Draw(void);
void ReLoad(void);

CVector Position;

float rot;

SParticle Par[MAX_PARTICLES];

bool Alive; //if Alive == 1, it's alive else it's dead

int Type; //holds the type number ( P_SMOKE, P_FIRE, P_EXPLOSION )

int Time; //how many ms the particle type will last

int Time_Passed;

ticker_t CTimer;
unsigned int Texture; //holds the particle texture infotmation


};



#endif



particle.cpp

  

#ifndef _PARTICLE_CPP_
#define _PARTICLE_CPP_

#include "particle.h"
#include "engine.h"
#include "texture.h"
#include "camera.h"


extern CEngine engine;
extern CTexture texture;
extern CCamera camera;

CParticle::CParticle(float x, float y, float z, int N_Type, int N_Time) {
CVector temp;
temp.x = x;
temp.y = y;
temp.z = z;

for(int a=0; a<MAX_PARTICLES; a++) {
Par[a].Org_Position = temp;
Par[a].Position = temp;
}

Calculate_Direction();
CTimer.Init();

Texture = texture.BMP("data/texture/brkrun.bmp");

}

void CParticle::Draw(void) {

glBindTexture(GL_TEXTURE_2D, Texture); // TextureId

glEnable(GL_TEXTURE_2D);

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
glDepthMask(GL_FALSE);

glColor3f(0.5, 0.0, 0.0);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();


glTranslatef(Position.x, Position.y, Position.z);
glRotatef(rot,0,1,0);
rot += 0.1;

for(int a=1; a<MAX_PARTICLES; a++) {

glBegin(GL_TRIANGLE_STRIP);
glTexCoord2d(1,1); glVertex3f(Par[a].Position.x+0.5f, Par[a].Position.y+0.5f, Par[a].Position.z);
glTexCoord2d(0,1); glVertex3f(Par[a].Position.x-0.5f, Par[a].Position.y+0.5f, Par[a].Position.z);
glTexCoord2d(1,0); glVertex3f(Par[a].Position.x+0.5f, Par[a].Position.y-0.5f, Par[a].Position.z);
glTexCoord2d(0,0); glVertex3f(Par[a].Position.x-0.5f, Par[a].Position.y-0.5f, Par[a].Position.z);
glEnd();

}

glPopMatrix();


for(a=0; a<MAX_PARTICLES; a++) {
Par[a].Position.x += Par[a].Direction.x * engine.last_frame_time;
Par[a].Position.y += Par[a].Direction.y * engine.last_frame_time;
Par[a].Position.z += Par[a].Direction.z * engine.last_frame_time;
}

//Calculate_Direction();


glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_ONE);

glDisable(GL_TEXTURE_2D);

}
void CParticle::ReLoad() {

for(int a=0; a<MAX_PARTICLES; a++) {
Par[a].Position = Par[a].Org_Position;
}

CTimer.Update();

}

/************************ PARTICLE ENGINE *************************/

void CParticle::Calculate_Direction() {

srand(GetTickCount()); //seed the randomizer

if(Type == P_SMOKE) { //if type is smoke


for(int a=0; a<MAX_PARTICLES; a++) {
Par[a].Direction.x = ((rand()%100-50) / 1000000.0f);
Par[a].Direction.y = ((rand()%100+50) / 1000000.0f); //from 1 - 3 / 1000, 0,003 * 1000 = 0 - 3 units/s

Par[a].Direction.z = ((rand()%100-50) / 1000000.0f);
}
}
else if(Type == P_FIRE) {



}


}
#endif



but they still rotate around the 0,0,0, not the position the particle class is in =(
i get really mad soon...

[edited by - CondiS on June 3, 2002 11:55:01 AM]

[edited by - CondiS on June 3, 2002 11:55:48 AM]

Share this post


Link to post
Share on other sites
lol! sounds like the same prob i had trying to rotate some boxes.

pushMatrix
Translate
rotate
draw
pop matrix

just like someone said above. It works trust me.

Share this post


Link to post
Share on other sites
first if yoy look in the code above I do EXACTLY that, nad it doesn''t work.

and what matrix should i push.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!