I want pointsprites always face to me

Started by
2 comments, last by DarkKiller 21 years, 9 months ago
How can I do that? I created a particlesystem with pointsprites and now I want them to face into my direction I move them with glTranslate but I use gluLookAt before to set my cam. any ideas? [edited by - DarkKiller on June 28, 2002 6:49:14 AM]
DarkMcNugget next time... ;)
Advertisement
easy.

this is how I go about it...


Matrix m;
m.rotate(Vector3(0,0,-PI/4));

spriteAngle[0]=Vector3(1,0,0)*m*Vector3(1,window->aspect,0)*matrix;
spriteAngle[1]=Vector3(0,1,0)*m*Vector3(1,window->aspect,0)*matrix;


where matrix is the untranslated modelview matrix''s transpose.
spriteAngle is a 2 part vector.
the first matrix (m) is to rotate the final values, so they appear square on screen instead of dimond shaped..


then,
it''s a matter of settings the verticies of the quad:

setup the verticies like:

vert 1: position-spriteAngle[1]*size;
vert 2: position+spriteAngle[0]*size;
vert 3: position+spriteAngle[1]*size;
vert 4: position-spriteAngle[0]*size;

where position and size should be blindingly obvious.

then a matter of drawing..


static const BYTE index[4]={0,1,2,3};
glDrawElements(GL_QUADS,4,GL_UNSIGNED_BYTE,index);

where the pointers to the vertex data are setup prior to this call (obviously)

simple.
note that the spriteAngle vectors only need recalculation every time the view point changes (ie, each frame)
As you may have seen I have a little fear about vectors but maybe you can take this fear....

I''ve never worked with matrixes before, so its absolutly new for me.

I still try to understand you example. I do not really understand these lines:
Matrix m;
m.rotate(Vector3(0,0,-PI/4));

spriteAngle[0]=Vector3(1,0,0)*m*Vector3(1,window->aspect,0)*matrix;
spriteAngle[1]=Vector3(0,1,0)*m*Vector3(1,window->aspect,0)*matrix;

What you do is to rotate Z by -PI/4, right? 45 degrees.
then, you fill this array spriteAngle[0] with a matrix-multiplication: A Vector(1,0,0), our matrix ''m'', another Vector(1,window->aspect,0) and the matrix.

ok ...

"(where matrix is the untranslated modelview matrix''s transpose)"
so you meen glLoadIdentity() ... (?) dunno.
DarkMcNugget next time... ;)
as I said,
without:

Matrix m;
m.rotate(Vector3(0,0,-PI/4));

and the:

Vector3(1,0,0)*m

the sprites come out dimond shaped on screen.. multiplying them by this simple rotation matrix rotates them to a square shape...

Vector3(1,0,0) is the horizontal verticies of the sprite, while Vector3(0,1,0) is the verticle component... hence the reason they come out as a dimond..

this part:
*Vector3(1,window->aspect,0)

scales the vectors, so the sprites appear correct to the aspect ratio. otherwise they appear very tall...

as for loading the model view matrix:

an easy way:

float matrix[4][4];

glGetFloatv(GL_MODELVIEW_MATRIX,matrix);

(since you probably will set this yourself, it's best not to bother and use the matrix you load in)

a transpose matrix is such that:

matrix[1][2] = matrix[2][1];
matrix[0][3] = matrix[3][0];
etc... for all 16 elements..

transpose is a cheap way to invert an UNSCALED rotation matrix. since we want this matrix to be used only for rotation, you can ignore the 4th row/column (ie, it becomes 3x3) and this will remove any translation data stored.

I personally use a 16 float array, not 4 4 float arrays... so, Vector-matrix multiplication for me, looks like this:


      	return Vector3(				x*m[0]+				y*m[4]+				z*m[8]				,								x*m[1]+				y*m[5]+				z*m[9]				,				x*m[2]+				y*m[6]+				z*m[10]);      


where m is the matrix data, in the form float[16]...

[edited by - RipTorn on June 28, 2002 8:00:28 AM]

[edited by - RipTorn on June 28, 2002 8:01:55 AM]

This topic is closed to new replies.

Advertisement