Laser Weapon

E05263ec846eb85da803f56e2917962d
0
Noor 101 Jan 31, 2003 at 23:28

I am trying to make a laser weapon for a space game, and I am wondering about the technique used. I would like to use one texture. As you may know, billboardeding will not work. But I want it to look like 3D, any ideas?

17 Replies

Please log in or register to post a reply.

6ad5f8c742f1e8ec61000e2b0900fc76
0
davepermen 101 Feb 02, 2003 at 12:33

hm.. one method is to do it 3d (an extruded triangle, a prisma.. something like that)

the other idea could be some sort of billboard around an axis, or so.. i’ve once seen a page explaining it.. but i don’t remember the link, sorry..

D046712cf3efd2c2d7840c4c51d28669
0
Yau 101 Feb 04, 2003 at 04:42

Just wondering.. why won’t billboarding work?? I think lots of games use billboarding to do their lasers.

Fdbdc4176840d77fe6a8deca457595ab
0
dk 158 Feb 04, 2003 at 04:46

spherical billboarding won’t work. However, you can use cylindrical billboarding.

D046712cf3efd2c2d7840c4c51d28669
0
Yau 101 Feb 04, 2003 at 10:04

Well if a laser is a true cylinder then if u were to only see a portion of the cyclinder flashing past ur eyes all u would see is a rectangle?? So u can use billboards to represent a laser but u don’t rotate ur billboard so it always faces the viewers camera.

So if u consider a laser with 2 points, point A where is originates from (probably a gun), point B it’s destination or current position. Then u draw a rectangle with a height equal to the diameter of the laser with one end at point A and the other end at point B. U can rotate the rectangle by the vector AB so that the viewer can see the maximum surface area of the rectangle.

Should the laser fire directly at the viewer then draw a circle using a billboard to create the effect.

If u use billboard u can create the 3D effects if u have really cool textures.

opps…. I said the hieght of rectangle should be the radius of the laser beam, in fact it should be the diameter.

C24eb7e6aaefba78b94c831ddc7b4d0b
0
donBerto 101 Feb 04, 2003 at 13:00

agreed :yes:

if you want, you can use 2 [or more, maybe just 2] rectangles, have 2 different textures and have some kind of ‘animation’ going on. this will do nicely with yau’s implementation. of course, there are other ways but i would do what yau said.

…just a thought.

590e8bdac8129bd87b188df15e62d0e5
0
CyraX 101 Feb 05, 2003 at 14:55

What about using views based systems?

__________________________________________________

|__________________________________________________| <- Side B and Side A

From the side a laser is JUST a rectangle. Using clever texture mapping, create a texture that is pretty bright @ the center and pitch dark @ the edges.
Now when you have the Side A and B, these should be modelled in “circular” forms. Thus create a texture (or resuse the textre) and using alpha blending, just chop off the corners.
I guess this is te best way of doing this.
Any better way I would love to know.

6ad5f8c742f1e8ec61000e2b0900fc76
0
davepermen 101 Feb 05, 2003 at 15:49

and you have to orient the flat rectangle around the laserbeam axis facing the camera.. haven’t i mentoyed this above yet? a quad rotating around the laserbeam direction, billboarding you? billboards don’t mean always be facing the cam in all directions. it can mean as well that its a board that rotates around some axis to always try to face the camera. and thats what i would use for laserbeams.. or prismas.. dunno..

C24eb7e6aaefba78b94c831ddc7b4d0b
0
donBerto 101 Feb 05, 2003 at 15:49

going off of Cyrax’s “clever texture mapping”

let’s use a vector for the path of the laser. starting point is at the barrel of the weapon and the terminal point is the opponent ship. . using the magnitude/length of the vector as the ‘length’ of the laser’s path. make a rectangle based on the length and then texture. theoretically, no matter what viewpoint you’re at, you’ll see a relative laser shot. well, maybe all points of view except directly where it will be just a point.

any more ideas?

0684f9d33f52fa189aad7ac9e8c87510
0
baldurk 101 Feb 05, 2003 at 19:21

I’d draw a triangular prism (a triangle at each end and a quad for each side) and then do some fancy texture mapping and particle effects to make it look better. With the right texturing and lighting you could make it look pretty smooth.

D046712cf3efd2c2d7840c4c51d28669
0
Yau 101 Feb 06, 2003 at 01:03

The only problem with a triangular prism is that u have ta render 6 times more triangles than just using a rectangle oriengated nicely to face the camera.

With just a rectangle u could create a texture where in the middle of the beam is bright and towards the edge of the beem the color becomes slightly dull and transparent. This is very difficult to accomplish with a prism.

C24eb7e6aaefba78b94c831ddc7b4d0b
0
donBerto 101 Feb 06, 2003 at 01:03

with baldurk’s implementation, I’d make the ‘prism’ spin/rotate.

i like his idea but in my personal opinion, unless you make it dynamic [make it move or add some really cool things like baldurk said, lighting in itself may work against it, making it look kind of … different :huh:

what i’m getting at is, it’s like a big ‘triangular piece of “metal” ‘ will go from the weapon to the target. cool funny effect, maybe not so ‘realistic’. open to interpretation. :lol:

E05263ec846eb85da803f56e2917962d
0
Noor 101 Feb 06, 2003 at 01:50

@Yau

Well if a laser is a true cylinder then if u were to only see a portion of the cyclinder flashing past ur eyes all u would see is a rectangle?? So u can use billboards to represent a laser but u don’t rotate ur billboard so it always faces the viewers camera.

So if u consider a laser with 2 points, point A where is originates from (probably a gun), point B it’s destination or current position. Then u draw a rectangle with a height equal to the diameter of the laser with one end at point A and the other end at point B. U can rotate the rectangle by the vector AB so that the viewer can see the maximum surface area of the rectangle.

Should the laser fire directly at the viewer then draw a circle using a billboard to create the effect.

If u use billboard u can create the 3D effects if u have really cool textures.

opps…. I said the hieght of rectangle should be the radius of the laser beam, in fact it should be the diameter.

Yau, could you please post some details of how to accomplish your idea of having one rectangle (which is exactly what i want)? Maybe some code will help. I think the most important thing here is the math behind it which is what i’m mosly looking for.

Or if you have a website, that would also help.

Thanks

D046712cf3efd2c2d7840c4c51d28669
0
Yau 101 Feb 06, 2003 at 06:52

OKay here u go… but this code is kinda untested.

void drawLaser(float origin[3],   // position where the laser originates
                         float dest[3],     // position where the laser ends
                         float camera_pos[3], // position of the camera
                         float radius // radius of laser
                         ) 
{
   float vector1[3];
   float vector2[3];

   // vector1 is the vector from origin to the camera
   vector1[0] = camera_pos[0] - origin[0];
   vector1[1] = camera_pos[1] - origin[1];
   vector1[2] = camera_pos[2] - origin[2];

   // vector2 is the vector from the origin to the destination
   vector2[0] = dest[0] - origin[0];
   vector2[1] = dest[1] - origin[1];
   vector2[2] = dest[2] - origin[2];

   float normal[3];
   
   // get the normal or cross product between vector1 and vector 2
   // we will use this vector to create a rectangle which runs along vector 2
   // and as facing a direction that give maximum surface area to the camera.

   normal[0] = vector1[1] * vector2[2] - vector1[2] * vector2[1];
   normal[1] = vector1[2] * vector2[0] - vector1[0] * vector2[2];
   normal[2] = vector1[0] * vector2[1] - vector1[1] * vector2[0];

   float magnitude;

   magnitude = sqrt(SQR(normal[0]) + SQR(normal[1]) + SQR(normal[2]));

   // normalize the normal, so the magnitude of normal is 1
   normal[0] = normal[0]/magnitude;
   normal[1] = normal[1]/magnitude;
   normal[2] = normal[2]/magnitude;

   // now create the corners for the rectangle
   float corners[4][3];

   // first corner
   corners[0][0] = origin[0] - (radius * normal[0]);
   corners[0][1] = origin[1] - (radius * normal[1]);
   corners[0][2] = origin[2] - (radius * normal[2]);

   // second corner
   corners[1][0] = origin[0] + (radius * normal[0]);
   corners[1][1] = origin[1] + (radius * normal[1]);
   corners[1][2] = origin[2] + (radius * normal[2]);

   // third corner
   corners[2][0] = dest[0] + (radius * normal[0]);
   corners[2][1] = dest[1] + (radius * normal[1]);
   corners[2][2] = dest[2] + (radius * normal[2]);

   // forth corner
   corners[3][0] = dest[0] - (radius * normal[0]);
   corners[3][1] = dest[1] - (radius * normal[1]);
   corners[3][2] = dest[2] - (radius * normal[2]);

   // now draw the rectangle

   // you can add material, colours or texture commands here to make ur laser look more funky
   glBegin(GL_QUADS);
      // remember add a texture coordinate infront of each glVertex3fv for funkier looking lasers

      glVertex3fv(corners[0]);
      glVertex3fv(corners[1]);
      glVertex3fv(corners[2]);
      glVertex3fv(corners[3]);
   glEnd();

}

And finished.

B4 i mentioned that we should rotated the rectangle to allow maximum surface area to face the camera. You may notice that there r no OpenGL rotate commands here, but by using the normal between the vector from the start of the laser to the camera and the vector from the start of the laser to the end to generate the rectangle we esentially created a rectangle rotated to face the camera nicely.

I hope this code works because I kinda fudged it on the spot.

0684f9d33f52fa189aad7ac9e8c87510
0
baldurk 101 Feb 06, 2003 at 18:29

aah. So you resize the rectangle dynamically so that it’s the right size? that’s really good, I didn’t think of that. Nice one!

7627adb236c5fce1dd7466ccbc062f5b
0
banandgia 101 Feb 25, 2003 at 06:42

see “Game Programming Gems”, i can’t remember exactly it’s vol 1 or 2, but there must be a topic talking exactly on this approah, and it discusses texture mapping of this technique as well

D046712cf3efd2c2d7840c4c51d28669
0
Yau 101 Feb 25, 2003 at 10:14

Well having a quick glance at vol 2, I didn’t find anything on lasers so it must be on vol. 1.

7627adb236c5fce1dd7466ccbc062f5b
0
banandgia 101 Feb 25, 2003 at 10:58

or let me reborrow it from the library and post the ideas here