XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

2D Crosshair in a 3D world?

Last post 7/26/2009 4:09 PM by Steve Hazen. 5 replies.
  • 7/26/2009 7:40 AM

    2D Crosshair in a 3D world?

    Hi, This is a sort of 3rd person game, how do I convert my 2D crosshair position into a 3D position?

    I imagine that i set the "gun look at" position 10000 quants or so infront of the camera inline with the 2D crosshair,
    but I can't think of a good way to find the in-to-the-screen depth relative to the camera
    Does anyone have any idea how I should do this?

    basically "how do I convert my 2D crosshair position into a 3D position?"
    Any help would be most appreciated,
    Thank you,
    Luke.

    Edit:
    See below, thank you.
  • 7/26/2009 7:59 AM In reply to

    Re: 2D Crosshair in a 3D world?

    Answer
    Reply Quote
    Hi Dunham,

    You're looking for Viewport.Unproject. Make sure to read the remarks.

    Cheers!
    Jeromy Walsh
  • 7/26/2009 10:03 AM In reply to

    Re: 2D Crosshair in a 3D world?

    Hi Jeromy,
    Thanks that look like just what I need maybe it's not as complicated as I though.^_^

    When I asked this question I though I knew how to point my cannon object towards a Vector3,
    but it turns out that I don't ^_^ (I assume this is 3d basics so I don't mean to be a noob but)

    I investigated how the camera LookAt works.
    I've found most people do this "Vector2 direc = new Vector2((float)Math.Sin(cannon.rotation.Y), (float)-Math.Cos(cannon.rotation.X));" to point direction
    But I'm sure that's only for 2D angle calculation.

    Should I be using a Matrix or working out the angle with trigonometry?

    Thank you,
    Luke.

  • 7/26/2009 10:14 AM In reply to

    Re: 2D Crosshair in a 3D world?

    Answer
    Reply Quote
    Hi

    Are you looking for a ray projected from the weapon? If so you could use the transformation matrix you most likely have for your weapon already. If your weapon in object space is aligned along the z-axis you would just set the rays object space direction to be unit z.

    Hope that helps
  • 7/26/2009 2:23 PM In reply to

    Re: 2D Crosshair in a 3D world? Lock on?

    Hi thanks that make sense, I understand now thanks! ^_^

    I'd rather not spam by opening a new topic about a related subject, (I have been looking but I think im missing a keyword or something)
    but all I need to do is debug my lock-on system where the cannon needs to keeps looking at another object(enemy)

    How do I make an object face anouther object? is it simple?

    That's something I'll use a lot in my game, if anyone knows it would really help. ^_^
    Sorry to be a bother, Thank you,
    Luke.
  • 7/26/2009 4:09 PM In reply to

    Re: 2D Crosshair in a 3D world? Lock on?

    Answer
    Reply Quote
    DunhamBrosGames:
    How do I make an object face anouther object? is it simple?
    here is the standard thread for this question
    Unlock The *I don't use 3 angles in a Vector3 for rotations anymore* Achievement Here
Page 1 of 1 (6 items) Previous Next