Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

RandomLogic

Sort of a beam weapon

This topic is 5735 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve asked this before and maybe my intent wasn''t clear, somebody MUST have pulled this off. What I want to do is to render a quad so that it stretches between 2 arbitrary points in space so that it''s flat side faces the camera. The effect is of a beam weapon, laser shot, a straight trail attached to a back of a ship etc. you get the picture. I''ve tried using the conventional way of setting up particles using the up and right vectors of the view matrix (added to the quad''s vertices) and adding to that a 3rd vector representing the quads ''heading'' in space. This messed up the orientation... I got the quad but it didn''t always face the camera. I have another way in mind which involves creating a lookAt matrix per quad per frame and transforming each quad seperately, which would be very expensive. Any ideas? Thanks, RL

Share this post


Link to post
Share on other sites
Advertisement
so you will have to make sure that the planes normal will always intersect your line of view.
fw=planes forward/normal vector
cp=camera position
up=planes up vector (you have that.. end-starting point)
right=planes right vector
bp=beam position

fw=cp-bp;
right=fw x up;
fw=right x up;



Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hrm...I think my answer was to take the cross product of beam''s direction and the viewing direction, then normalize then scale it to the beam size, which gives the offset from the center of the edge.

Or maybe that''s what you tried and I misread.

Share this post


Link to post
Share on other sites
Trienco,

I get what you say, one thing still escapes me... When I set up particles quad I just add/sub the (normalized) up/right from the particle''s position, and get four vertices forming a square that faces the camera. I can''t try this out till tonight but I tried similar stuff and when I use scaled vectors (which I have to in this case) it screws the rotation up.

Example of what I mean:

vPos = beam''s center position.
right, fw = right and forward (as calculated your way).

//this is not nessecarily the order the veritces are set up.
vert1 = vPos - up;
vert2 = vPos - right;
vert3 = vPos + up;
vert4 = vPos + right;

The above works for standard particles. If I say for example that I want the beam quad to be 5.0 X 1.0 in size then intuitvely I''d scale the up vector X 2.5 and the right X 0.5. Is this the way you meant to do this? I''ll mess around with it tonight anyways, but if my line of thought is wrong please say.

Anonymous... If I get what your saying you''d need at least 2 vectors as the beam has both width and height. Do I understand you?

Share this post


Link to post
Share on other sites
theres probably an easier way, but the above is what i used for pretty much the same thing (laserbeams).

but i had some problems to get my sun aligned the right way in my landscape yesterday (a great combination of copy/pasting a wrong cross product, mixing up indices and getting headaches from trying to imagine the current location of it all just by staring at numbers).

if your 3 vectors for the beam are correct there shouldnt be a problem. one reason why particle stuff wont work: a particle is supposed to fully face the cam, but this is not possible for a laserbeam. the 3 vectors have to be orthonormal and obviously it cant face the cam and be in the right direction at the same time (except your cam happens to be at the right place). instead it has to face your line of sight.

the difference is that for particles you know one vector (the forward vector for the particle facing your cam) while for a beam you know another vector (its up vector in the direction its supposed to point). in both cases you just pick a good vector to get the right second vector (here using cam.pos-beam.pos will make sure the right vector is chosen in a way that makes the full breadth of the beam face the cam). if you draw the beam yourself anyway you wont even need the second cross product, as a normalized up and right is enough.

but i think the vertices should look more like this:

vert1 = vPos -right +up;
vert2 = vPos -right -up;
vert3 = vPos +right -up;
vert4 = vPos +right +up;

Share this post


Link to post
Share on other sites
I know exactly what you mean about the headaches
That''s what happens when you stare at code all day at work then do some intense staring at home

What you propose sounds so simple I can''t believe I didn''t think of it that way. I''ll try it tonight.

Thanks a bunch,
RL

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Same AP as above here...

This is more or less the code I use (checked it since the other post):

vDirection=vBeamEnd-vBeamStart;
vRight=(0.5f*fBeamWidth)*Normalize(Cross(vLook,vDirection));

v[0]=vBeamStart+vRight;
v[1]=vBeamStart-vRight;
v[2]=vBeamEnd+vRight;
v[3]=vBeamEnd-vRight;

Vertex order is probably screwed up, and vRight may need to be negated, but hopefully this gives you the idea.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Two arbitrary points aren''t necessarily going to face the camera. When one point is closer to the camera than the other, then the quad will not face the camera. If the laser bolt shoots from the camera straight ahead, no quad orientation will face the camera if it contains these points; they''ll all be edge-on.

Share this post


Link to post
Share on other sites
Anonymous,

By vLook you mean vQuadsPos - CameraPos (and not camera lookAt) right?

I tried it last night Trienco''s way (which was actually almost exactly what I was doing in the first place, but I screwed it up somewhere). It worked great. Sometime before I tried what you say but couldn''t get it to work either. will try it tonight.

As for the edge on problem... I thought about it I think it can be solved by using an additional quad that will be perpendicular to the beam''s quad and attached to the start and end points. possibly even the same quad at BOTH points so if part of the beam clips you won''t loose the effect. I haven''t tried this yet but it seems it should work.

Cheers,
RL

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!