Archived

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

first 3D fps game problem

This topic is 5042 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 am trying to write my first FPS game and have run into a problem. I am using a 2D sprite as a crosshair to aim at the targets. The targets exist in the 3D game world. My problem is that I want to be able to shoot at the targets and when crosshair is directly over the target, the target should take damage. How do I get my program to calculate the 2D position of the target?? I know that I have to project the target onto the 2D plane but how is this accomplished?? I am using directX9 and C++. Thanks in advance

Share this post


Link to post
Share on other sites
See "D3DXVec3Project" in the SDK, for starters.
The procedure is essentially the same that the hardware uses to transform geometry into screen space.

-Nik

EDIT: Do consider unprojecting the view vector also, so that you could test for collisions in world space! I use this technique, for precision and flexibility.


[edited by - Nik02 on February 20, 2004 2:55:52 PM]

Share this post


Link to post
Share on other sites
I have managed to get D3DXVec3Project working, but I still having problems with trying to find out if the enemy is within the line of fire.

Which transformations/calculations should I apply to the vector returned by "D3DXVec3Project"??

thanks in advance

Share this post


Link to post
Share on other sites
METACODE:

Let "enemy" be the enemy''s projected position.
Let "crosshair" be the crosshair''s screen-space position.

if distance between enemy and crosshair is below the crosshair size (ie. some tolerance value) then the crosshair is over an enemy.

END METACODE

Remember to take the z distance from enemy into account, to scale the treshold value.
I find it easier to unproject the ray extending from the view position, and then testing for ray-bbox intersections in the world space. This way, you don''t have to worry about scaling explicitly, and the test is as precise as the world itself.
For more info, see the SDK "pick" example.

-Nik

Share this post


Link to post
Share on other sites