Jump to content
  • Advertisement
Sign in to follow this  
calidev234

Laser Scope

This topic is 4802 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

Does anyone know how to create a laser scope (line of site) for a 3rd person shoot 'em game. Line when you are walking around with a gun, to have laser scope following your line of site (from your camera position). I've been trying to mess around with Vertex gtest[] = { { g_vCameraPos.x, g_vCameraPos.y, g_vCameraPos.z, 0xffff0000 }, // red = +x Axis { g_vLook.x, g_vLook.y, g_vLook.z, 0xffff0000 } }; g_pVertexBuffer->Lock( 0, sizeof(gtest), (void**)&pVertices, 0 ); memcpy( pVertices, gtest, sizeof(gtest) ); g_pVertexBuffer->Unlock(); in the rendering loop, but I cannot get this to work. Is this even possible? Thank you

Share this post


Link to post
Share on other sites
Advertisement
Yes, it's perfectly possible. What do you mean it "doesn't work"? You should be using a dynamic VB for this, not static, otherwise you'll get a fairly large performance penalty.

Share this post


Link to post
Share on other sites
It doesn't work because the laser is not going from camera view to look view. I can see it and it's moving, but it doesn't start from the camera view and it doesn't end in the look view. It's off in the distance moving around. Also, how could I make this dynamic vb and not static?

Thank you for responding.

Share this post


Link to post
Share on other sites
Quote:

Also, how could I make this dynamic vb and not static?

When you call CreateVertexBuffer(), specify D3DUSAGE_DYNAMIC for the usage parameter. Dynamic buffers should also be created in D3DPOOL_DEFAULT. Also, when you lock the vb, you have to specify D3DLOCK_DISCARD and D3DLOCK_NOOVERWRITE.

Remember, since the VB is now created in the default pool, you have to release and re-create it when the device is reset.

Share this post


Link to post
Share on other sites
Quote:
Original post by calidev234
It doesn't work because the laser is not going from camera view to look view. I can see it and it's moving, but it doesn't start from the camera view and it doesn't end in the look view. It's off in the distance moving around.
You'll need to set your world matrix accordingly. If you're using your view vectors, I think you can set the world matrix to the identity matrix, and it'll work.
Also, if g_vLook is normalized, you'll need to extend it to be long enough (as long as the distance between the near and far clip planes), which is simple with D3DXVECTOR3: D3DXVECTOR3 vLook = g_vLook*(fFarClip-fNearClip); Where fFarClip and fNearClip are obviously the values for your near and far clip planes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!