- Home /
How do I use TRS matrices in the GL class in loops without it being reset?
I'm trying to create a particle system using the GL class. The only problem I'm having is adding rotation to the mix.
The particles are being displayed properly one-by-one, but when having to display multiple particles; it resets to the newest one.
public void Draw()
{
Matrix4x4 matrix;
GL.PushMatrix();
GL.Begin(GL.QUADS);
for (int i = 0; i < particleList.Count; i++)
{
Particle particle = particleList[i];
if (particle.IsVisible)
{
matrix = Matrix4x4.TRS(particle.position, Quaternion.Euler(0, 45, 0), particle.scale);
particle.material.SetPass(0);
GL.MultMatrix(matrix);
GL.Color(particle.color);
DrawQuad();
}
}
GL.End();
GL.PopMatrix();
}
private void DrawQuad()
{
GL.Vertex3(-.5f, 0, -.5f);
GL.Vertex3(.5f, 0, -.5f);
GL.Vertex3(.5f, 0, .5f);
GL.Vertex3(-.5f, 0, .5f);
}
If I put PushMatrix/PopMatrix within the Begin/End methods; then the particles will not display properly.
I have tested placing Push/PopMatrix at different places in the code, but nothing gives me the result I want, so I'm pretty much out of ideas.
I have looked through a ton of information on how to use the GL class, but I have realized that I'm in a kinda unique position here.
If needed, here is a link to the entire file: Pastebin
Any help is greatly appreciated!
-MankeyX
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613125600im_/https://answers.unity.com/themes/thub/images/avi.jpg)