Skip to main content
GameDev.net gamedev.net
🔒 Locked

newbie drawing question!

Started by CondiS May 31, 2002 at 7:28 PM 11 replies 950+ views
Original Post
CondiS
CondiS
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?
RipTorn
RipTorn
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.
CondiS
CondiS
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]
Leyder Dylan
Leyder Dylan
Simply

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

========================
Leyder Dylan
http://ibelgique.ifrance.com/Slug-Production/
========================Leyder Dylan (dylan.leyder@slug-production.be.tf http://users.skynet.be/fa550206/Slug-Production/Index.htm/
CondiS
CondiS
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]
CondiS
CondiS
yes, no different, the problem remains. =(
_Titan_
_Titan_
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.
CondiS
CondiS
first if yoy look in the code above I do EXACTLY that, nad it doesn''t work.

and what matrix should i push.
LockePick
LockePick
Hmmm... you are translating to the particles position, shouldn''t you draw the particle right there , instead of moving it away again (which is what the positions in the glVertex3f calls will do).

------------
http://aud.vze.com <-- Newbie alert, look at your own risk. Can induce severe laughing fits and other variations of hysterical outburst.
CaptainJester
CaptainJester
quote:
Original post by CondiS
glTranslatef(Position.x, Position.y, Position.z);


Either remove this line.
quote:
Original post by CondiS

glBegin(GL_TRIANGLE_STRIP);
glTexCoord2d(1,1); glVertex3f(ParLink
  
glTexCoord2d(1,1); glVertex3f(0.5f,0.5f,0.0f);
glTexCoord2d(0,1); glVertex3f(-0.5f,0.5f,0.0f);
glTexCoord2d(1,0); glVertex3f(0.5f,-0.5f,0.0f);
glTexCoord2d(0,0); glVertex3f(-0.5f,-0.5f,0.0f);


See if that works.

---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
CondiS
CondiS
how stupid of me, argh.
well thnx anyway =/

[edited by - CondiS on June 3, 2002 4:11:05 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.