Laser Weapon

17 replies to this topic

#1Noor

Senior Member

• Members
• 503 posts

Posted 31 January 2003 - 11:28 PM

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?
"What ever happened to happily ever after?"

#2davepermen

Senior Member

• Members
• 1306 posts

Posted 02 February 2003 - 12:33 PM

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..
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....

#3Yau

New Member

• Members
• 26 posts

Posted 04 February 2003 - 04:42 AM

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

#4Dia

DevMaster Staff

• 1120 posts

Posted 04 February 2003 - 04:46 AM

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

#5Yau

New Member

• Members
• 26 posts

Posted 04 February 2003 - 10:04 AM

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.

#6donBerto

Senior Member

• Members
• 369 posts

Posted 04 February 2003 - 01:00 PM

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.
Imagine.

#7CyraX

Valued Member

• Members
• 144 posts

Posted 05 February 2003 - 02:55 PM

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.

#8davepermen

Senior Member

• Members
• 1306 posts

Posted 05 February 2003 - 03:49 PM

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..
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....

#9donBerto

Senior Member

• Members
• 369 posts

Posted 05 February 2003 - 03:49 PM

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. [i just want to cover all grounds, bare with me]. 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?
Imagine.

#10baldurk

Senior Member

• Members
• 1057 posts

Posted 05 February 2003 - 07:21 PM

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.
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.

#11Yau

New Member

• Members
• 26 posts

Posted 06 February 2003 - 01:03 AM

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.

#12donBerto

Senior Member

• Members
• 369 posts

Posted 06 February 2003 - 01:03 AM

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:
Imagine.

#13Noor

Senior Member

• Members
• 503 posts

Posted 06 February 2003 - 01:50 AM

Yau said:

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
"What ever happened to happily ever after?"

#14Yau

New Member

• Members
• 26 posts

Posted 06 February 2003 - 06:52 AM

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 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

// 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.

#15baldurk

Senior Member

• Members
• 1057 posts

Posted 06 February 2003 - 06:29 PM

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!
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.

#16banandgia

New Member

• Members
• 3 posts

Posted 25 February 2003 - 06:42 AM

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

#17Yau

New Member

• Members
• 26 posts

Posted 25 February 2003 - 10:14 AM

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

#18banandgia

New Member

• Members
• 3 posts

Posted 25 February 2003 - 10:58 AM

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

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users