Archived

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

helix

"Beam" weapon question

Recommended Posts

helix    301
I''m doing a FPS style demo and I want to have a laser beam looking weapon effect. I am creating a ID3DXMesh using the function D3DXCreateCylinder. First of all, does this sound reasonable so far? Second, I''m wondering how to do the positioning. How do you position the start and end points for a beam like this that you want to travel in the direction the camera is aiming so it looks good from the player''s point of view? Currently, it looks pretty bad. Here''s what I am doing for the start and end point: D3DXVECTOR3 pos = m_pCamera->GetPos(); D3DXVECTOR3 end = pos + (m_pCamera->GetDir() * INFINITY); Basically, the camera''s position for the start and the camera''s direction scaled to "infinity" (a large number so the beam will be longer than the room) added to the start position. Sound good? I guess I''m just curious if anyone has moved the ray down and over a few units or something like that to make it look better.

Share this post


Link to post
Share on other sites
Madgap    122
Might want to move it down like you said. Right now it might look like it''s coming out of your own eyes like superman''s heat vision.

Share this post


Link to post
Share on other sites
helix    301
Yeah, my only concern is that collisions along that beam may not appear to be accurate if I move the starting position for the effect away from the real starting pos.

Share this post


Link to post
Share on other sites
Waverider    169
I think if you move the beam down just enough so it doesn''t screw up the view, it won''t look so far off in the distance where it is striking objects, so it shouldn''t matter.

You might only need to move it a few inches by scale, which doesn''t make a lot of difference when you are firing at objects 40 feet away.

Give it a try, see how it turns out, and tweak it.

Share this post


Link to post
Share on other sites
helix    301
I moved it down slightly and yeah, it does look a lot better. I''ll know if it''s going to work once I fix a few bugs. :D

Share this post


Link to post
Share on other sites
helix    301
Well, I have one big bug to fix before it''s presentable. I''ll post a link or I can email you the url when it''s done.

I''m proud of it because I didn''t know anything about directx before I started.

Share this post


Link to post
Share on other sites
helix    301
Well, I have to work on a specific demo to send to a prospective employer so I won''t be able to finish this one as soon as I had hoped. So I''ll post what I have for now for those who are interested.

http://www.users.qwest.net/~beoch/demo-2.4.zip

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
You linked with the debug libs (d3dx8d.lib) so it wouldn''t run. Something to keep in mind, not everyone has the debug version installed.

But you did include the source so I recompiled.

Problems I found:
If you flip upside down, the left and right get reversed...
also firing up or down the beam is messed up...I think it''s cause you just move the starting point down and don''t rotate that point with the view...Didn''t look at the code to confirm this.
Looks like you tried to make a swirl effect around the beam, but it doesn''t follow it, don''t know how to explain it...looks like it''s coming out of your eyes sometimes.

Good job for one of your first DX apps.

My specs in case you want to know..
P4 @ 1.9ghz
Windows XP pro
512 megs of ram
Geforce3


Share this post


Link to post
Share on other sites
helix    301
hmm, that''s wierd about the debug lib, I thought I had the release version installed. That would explain some things... Thanks for pointing that out.

I plan on limiting your movement so you can''t flip over. And the weapon is the unfinished part of my demo. I haven''t gotten that working quite right yet... Thanks for the comments.

Share this post


Link to post
Share on other sites
NitroSR    122
Just as a suggestion, you may want to rethink how you are representing the objects in your universe. It seems to me as if you do not have a player OBJECT but rather the view matrix is directly determining the player''s perspective. Perhaps you could start off by considering the ''player'' just one of the objects in the game universe, and add a function that allows you to ''attach'' the camera view to the player as if it too were an object. This would allow you to shoot your laser from whatever place relative to your player object you wish, and it''s collision would be accurate.

I assume you are generating a model matrix for your objects by concatonating rotation and translation matrices. You can obtain an object''s ''view'' of the world by getting the inverse of it''s model matrix and setting this as the View Matrix. If you have the camera is an object attached to the player, and the weapon as an object attached to another point on the player, then your problem should begin to lessen. The beam should also be it''s own object just using the weapon''s position in world space as a starting point.

In a word, Object Heirarchy.

Share this post


Link to post
Share on other sites