Advertisement

Particle engine

Started by June 17, 2004 04:35 AM
6 comments, last by DMINATOR 20 years, 5 months ago
I am working on my Particle engine , and the only problem ,that is bothering me , is how can i make my Triangles face the screen ? Here is an example
I guess you know where your camera is and what it's looking at (i usually have a vector and a quaternion for my camera). So you can compute a "right" and an "up" vector for your camera, right ?
If your particles are far enough from your camera, you can use those 2 vectors to draw the triangles for each particle (and they will face the camera for sure).
If the particles are too close you may have to correct the vectors using cross products (but it's likely you can ignore this problem).

Hope it helps.
SaM3d!, a cross-platform API for 3d based on SDL and OpenGL.The trouble is that things never get better, they just stay the same, only more so. -- (Terry Pratchett, Eric)
Advertisement
have you tryied glLoadIdentity?
Aquellos que crean que algo es imposible no deben ponerse en el camino de los que estan dispuestos a intentarlo.MEGANUKE
Actually i wan't my particles to be independed from camera position
I know that gluUnProject can transform screen 2d coordinates to openGL 3d coords , but is there a way to use it contrary ?

yes i tried glLoadIdentity() , maybe i just don't understand how i can use it in this case.
Quote: Original post by DMINATOR
Actually i wan't my particles to be independed from camera position


Maybe I was not clear... Particles don't depend on the camera, but the way I render them does.
For each particle, I store the position, size, color... When rendering a particle, I generate a couple triangles for the particle. Those 2 triangles are defined using the particle's position and size and the camera's "up" and "right" vector. This helps me make sure the triangles will face the camera.

Hope it's clearer...
SaM3d!, a cross-platform API for 3d based on SDL and OpenGL.The trouble is that things never get better, they just stay the same, only more so. -- (Terry Pratchett, Eric)
You should indeed be doing what rodzilla is saying. If you want tutorials, go to google and search for "billboarding" (be sure to include words such as OpenGL in your search as well).

Some tutorials from said search:
Billboarding Method 1
Billboarding Method 2 (the way rodzilla spoke of)

I'm sure there are other ways to do it, but these two work well. I use a method similar to the first method I linked to above, but my method doesn't work in all situations.
- [email=atronic@gamebox.net]Alex Broadwin[/email]- Adroit Creations- My Journal- The All-Knowing One
Advertisement
Not sure it will help you, but here's part of the rendering code I use (billboards are rotated, that's why the code is a bit more complicated than necessary) :

Vector3 up = Camera::current()->po.up();Vector3 right = Camera::current()->po.right();Vector3 d1 = cos(m_rotate)*right+sin(m_rotate)*up;Vector3 d2 = -sin(m_rotate)*right+cos(m_rotate)*up;m_ps->m_texture.bind();glEnable(GL_BLEND);glDepthMask(GL_FALSE);glBlendFunc(m_ps->m_src_blend, m_ps->m_dst_blend);glBegin(GL_QUADS);for (i = 0; i < m_ps->m_nb_particles; ++i) {	particle_t& p = m_particles[m_order];	float x = p.position.x;	float y = p.position.y;	float z = p.position.z;	float time = p.time;	int aspect_index;	for (aspect_index = 0; m_ps->m_aspect[aspect_index].time <= time; ++aspect_index);	aspect_t& a = m_ps->m_aspect[aspect_index];	float size = a.size_a*time+a.size_b;	glColor4f(a.red_a*time+a.red_b,		  a.green_a*time+a.green_b,		  a.blue_a*time+a.blue_b,		  a.alpha_a*time+a.alpha_b);	glTexCoord2f(0, 0);	glVertex3f(x-d1.x*size, y-d1.y*size, z-d1.z*size);	glTexCoord2f(1, 0);	glVertex3f(x-d2.x*size, y-d2.y*size, z-d2.z*size);	glTexCoord2f(1, 1);	glVertex3f(x+d1.x*size, y+d1.y*size, z+d1.z*size);	glTexCoord2f(0, 1);	glVertex3f(x+d2.x*size, y+d2.y*size, z+d2.z*size);}glEnd();glDisable(GL_BLEND);glDepthMask(GL_TRUE);
SaM3d!, a cross-platform API for 3d based on SDL and OpenGL.The trouble is that things never get better, they just stay the same, only more so. -- (Terry Pratchett, Eric)
Thank's for the help , i would look it more closely

This topic is closed to new replies.

Advertisement