1. ## Drawing phasers!

Ok, for a while i have this problem with rendering scifi-like phasers for my game, the thing is, i have to use a proper texture for the ray, and it has to be aligned to always face the screen, something like a "billboard line".

Here is my miserable attempt.. using GLplane, i cannot figure out how to make this thing orient at the camera:

I am looking for any sort of advice on how to do this properly, any help will be greatly appreciated. also i'm using glscene for object management so if you can figure out something that i can use from glscene it would just.. rock.

2. ## Re: Drawing phasers!

Okay... looks like a math problem. I try to explain what i would do. No guarantees that it will work though.

We have a line in 3d space between vector A and B. Our camera location is given by vector C. V1, V2, V3, V4 are the four vertices that form the quad we will use to render our beam texture to (These four vectors need to be calculated).

Imagine we defined a plane that ran through the line AB and camera position C. The normal vector of this plane would be:

N = Cross_Product( A - B, A - C ).

This normal vector will always be perpendicular to the line when looking through our camera. Like this:

Code:
```N
|
|__________________
A         B```
Now we want our quad vertices to be like this:

Code:
```V1         V3
|         |
|__________________|
A|         |B
|         |
V2         V4```
This is easy:

V1 = A + N
V2 = A - N
V3 = B + N
V4 = B - N

Now you have your four vertices. Just draw a textured quad using these and you'll be all set, unless i'm missing something ofcourse. It might be desirable to Normalize N and multiply it with a certian number to change the line's "thickness", but that's up to you.

Hope this helped.

3. ## Re: Drawing phasers!

Could i somehow calculate a matrix for that normal so i could use it with glscene? basically, set the object at beam origin, apply this matrix and the visual child object would be properly oriented along the beam direction and normal?

4. ## Re: Drawing phasers!

What kind of matrix? A rotation matrix? Does GLScene have some sort of utility functions to convert axis-angle, quaternions or euler angles to a matrix?

5. ## Re: Drawing phasers!

Originally Posted by JSoftware
What kind of matrix? A rotation matrix? Does GLScene have some sort of utility functions to convert axis-angle, quaternions or euler angles to a matrix?
I meant ordinary 4*4 transformation matrix (the rotation part mostly).
and yeah it has routines to handle quaternions and euler angles

6. ## Re: Drawing phasers!

Hi there. I'm still trying to work out why it has to face the camera all the time. Wouldn't that just make it appear 2D like a sprite

Wouldn't say your attempt was pathetic , You could use a gldisc at the "base" of the laser which always faces the camera to give it a sort of glare and then draw the plane as you have. You could also use a couple of glshaders to give it a glow effect.

7. ## Re: Drawing phasers!

Originally Posted by ize
Hi there. I'm still trying to work out why it has to face the camera all the time. Wouldn't that just make it appear 2D like a sprite

Wouldn't say your attempt was pathetic , You could use a gldisc at the "base" of the laser which always faces the camera to give it a sort of glare and then draw the plane as you have. You could also use a couple of glshaders to give it a glow effect.
Because it's a engine remake, and i need to use existing texture that look like this:

These are then colored to match specified phaser emitter color by the engine.

Well actually, the game i'm rebuilding is even more complex (size was intentionally exaggerated to make the shape and complexity more obvious).

But i'll be happy if i can draw a quad facing the camera for now, when that works i can work on more complex shapes.

The project is opensource, and has a sourceforge project here: http://sourceforge.net/projects/st-sc

No releases yet, but i can get you a working demo if anyone is interested.

Right now my game renders these phasers with TGLPipe in a solid color, but the pipes don't have any uv mapping and cannot draw quad lines, so they are unsuitable for this use.

This is how they look with Tglpipe:

8. ## Re: Drawing phasers!

Ah, that makes thing a bit clearer for me now. I wrote a track editor some time ago which basically used splines to generate the "path" of the track, then generated and saved it as a 3ds object. i don't know how useful that would be to you if the phasers are in constant need of updating. What performance-hit are you getting using pipes? There may be some tweaking there that incorporates uv mapping.

I'm sure the source for my track-ed is on one of my drives somewhere. If i find it, or figure out anything else i'll post it.

Those screenies look great btw :thumbsup:

9. ## Re: Drawing phasers!

1 solution is also to draw 2 quads instead of 1 so that they a form + sign if looked in front. I mean, if beam is directed in Z-axis, make textured quads on YZ and XZ planes... It should look ok from every angle assuming you can smooth/hide the beam ends.

Looks something like this

10. ## Re: Drawing phasers!

Originally Posted by User137
1 solution is also to draw 2 quads instead of 1 so that they a form + sign if looked in front. I mean, if beam is directed in Z-axis, make textured quads on YZ and XZ planes... It should look ok from every angle assuming you can smooth/hide the beam ends.

Looks something like this

That will probably be what i will have to use, unless i can make it look just like the original game (see screenshots)

Ize: generating geometry along path isn't hard, the hard part is getting it facing the camera.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•