## particle with tail and billboarding

### particle with tail and billboarding

Particle is located in point P0.
It's tail (trace) is located in points: P1, P2, P3, etc...
Camera is located in point C.

I want to draw "line" from P0 to P1, then from P1 to P2, then from P2 to P3,
etc...
However, it can't be just GL_LINES, because its thickness should differ when
particle is far or close to camera.
So I need to construct set of rectangles, based on P0 and P1, then P1 and P2,
then P2 and P3, etc... And draw them with positive alpha inside and alpha=0 on
edges.

The problem is how to do it correctly, so rectangles will be faced directly to
rotating objects, but about generating points around "lines", to make
rectangles.

example:

this is part of tail:

P0--------P1

this is rectangle:

A--------B
|      |
P0--------P1
|      |
D--------C

It's obvious that AD and BC are perpendicular to P0P1.
There is infinite set of vectors which are perp. to P0P1, but only one (?)
which is faced directly to camera.

How to calculate it? :-)

PS. CP0 x P0P1 == AD ?

--
Free Software - find interesting programs and change them
NetHack - meet interesting creatures, kill them and eat their bodies
Usenet - meet interesting people from all over the world and flame them
Decopter - unrealistic helicopter simulator, get it from http://decopter.sf.net

### particle with tail and billboarding

if your camera is at C and you want to draw
a rectangle starting at P1 facing the camera, you need
a vector which is perpendicular to the line C - P1 and, preferably,
also to the line P2 - P1, right ? the cross product of two vectors
does just that, it gives you a vector that is perpendicular
to the two input-vectors and has the magnitude of
the area of the parallelogram formed by the two input-vectors.
so, to get a offset-vector from your first linesegment P1 - > P2,
take the cross-product V = ( C - P1 ) x ( P2 - P1 ) this will point
'up' from the linesegment, perpedicular to both the line of sight
and the first linesegment. Then normalize, ie divide V by it's own
length, scale it to the appropriate height for the rectangle,
and you're ready to construct a billboarded rectangle like

glVertex    P1 + V
glVertex    P2 + V
glVertex    P2 - V
glVertex    P1 - V
glEnd()

; )

J

--
reply to J at dynamica dot org
"The first principle is that you must
not fool yourself - and you are the
easiest person to fool" -- R.Feynman

Quote:> Particle is located in point P0.
> It's tail (trace) is located in points: P1, P2, P3, etc...
> Camera is located in point C.

> I want to draw "line" from P0 to P1, then from P1 to P2, then from P2 to
P3,
> etc...
> However, it can't be just GL_LINES, because its thickness should differ
when
> particle is far or close to camera.
> So I need to construct set of rectangles, based on P0 and P1, then P1 and
P2,
> then P2 and P3, etc... And draw them with positive alpha inside and
alpha=0 on
> edges.

> The problem is how to do it correctly, so rectangles will be faced
directly to
> rotating objects, but about generating points around "lines", to make
> rectangles.

> example:

> this is part of tail:

> P0--------P1

> this is rectangle:

>  A--------B
>   |      |
> P0--------P1
>   |      |
>  D--------C

> It's obvious that AD and BC are perpendicular to P0P1.
> There is infinite set of vectors which are perp. to P0P1, but only one (?)
> which is faced directly to camera.

> How to calculate it? :-)

> PS. CP0 x P0P1 == AD ?

> --
> Free Software - find interesting programs and change them
> NetHack - meet interesting creatures, kill them and eat their bodies
> Usenet - meet interesting people from all over the world and flame them
> Decopter - unrealistic helicopter simulator, get it from

http://decopter.sf.net

I sent it on cga.opengl, but now I realized it's probably better place...

Particle is located in point P0.
Its tail (trace) is located in points: P1, P2, P3, etc...
Camera is located in point C.

I want to draw "line" from P0 to P1, then from P1 to P2, then from P2 to P3,
etc...
However, it can't be just GL_LINES, because its thickness should differ when
particle is far or close to camera.
So I need to construct set of rectangles, based on P0 and P1, then P1 and P2,
then P2 and P3, etc... And draw them with positive alpha inside and alpha=0 on
edges.

The problem is how to do it correctly, so rectangles will be faced directly to
rotating objects, but about generating points around "lines", to make
rectangles.

example:

this is part of tail:

P0--------P1

this is rectangle:

A--------B
|      |
P0--------P1
|      |
D--------C

It's obvious that AD and BC are perpendicular to P0P1.
There is infinite set of vectors which are perp. to P0P1, but only one (?)
which is faced directly to camera.

How to calculate it? :-)

PS. CP0 x P0P1 == AD ?

--
Free Software - find interesting programs and change them
NetHack - meet interesting creatures, kill them and eat their bodies
Usenet - meet interesting people from all over the world and flame them
Decopter - unrealistic helicopter simulator, get it from http://decopter.sf.net