0

Hi :) I have been searching for weeks and can't find a solution. Can sum1 please tell me how to implement ray picking when using a first person camera. Where exactly in the formula are you suppossed to include the camera's direction?? If anyone has any solution or working coding of this please comment

Thank you very much

Olivier Moindrot
  • 27,908
  • 11
  • 92
  • 91
user614573
  • 21
  • 5

1 Answers1

0

This site is going to explain it a lot better then I could

http://www.toymaker.info/Games/html/picking.html

Is a really good site.

thecoshman
  • 8,394
  • 8
  • 55
  • 77
  • that site does not help tho because in that example it is a staionary (for lack of a better word) camera and position. But thank you – user614573 Feb 12 '11 at 21:59
  • Erm... you what? No. It takes a vector for the direction the camera is facing, and then checks it for intersection with all objects, and sorts them by distance, return the closet hit. It's the same function for a moving or stationary camera. Just how are you storing your cameras position and direction? – thecoshman Feb 12 '11 at 22:03
  • Sorry my mistake. I am using the DXUTCamera class because most of my program is based off the XACTGame from the DirectX SDK. Where exactly here -> http://www.toymaker.info/Games/html/picking.html does it take the vector for the camera direction? Thank you once again :) – user614573 Feb 12 '11 at 22:14
  • Ahh, I see your problem here. When I used this I was using my own camera class. I am no expert on XACT, but I am sure that one way or another you will be able to read a vector for the camera direction from it. Also bare in mind that the linked tutorial is on about letting you move the mouse around on screen with out moving the camera, so you can click on something in the corner of the screen, so if you have an FPS style camera controlled with a mouse, you can skip the first few little bits of that guide. – thecoshman Feb 12 '11 at 23:30
  • I have found the function which returns the direction of the camera, but the only thing is I'm not sure exactly what it is that I need to modify. As you said I can skip the first few bits, but I'm not sure exactly what I'm suppossed to change/edit. Any suggestions? thnx again :) – user614573 Feb 12 '11 at 23:53
  • You basically want to look at the ray-mesh intersection. DirectX has some functions built in that let you check if a Ray intersects a mesh. I think this guide does funny things like keep the ray in a static space, and move the screen around it backwards... if you get what I mean. Basically, your model data is stored in local co-ords, as is you ray, so you need to get them both translated into world space co-ords so you can collision check them. – thecoshman Feb 13 '11 at 00:18
  • well thnk u, but will I not still have 2 create a ray? That is the part I still not do understand fully. I think I can do the collision correctly, but I still don't rele know how to construct the ray – user614573 Feb 13 '11 at 00:26
  • oh, well, the 'ray' is a a point in space [ray origin] (where your camera is) and a direction [ ray direction] (which way is it pointing). So it's just two vectors. DirectX doesn't actually use a specific ray class, you just pass it in the two vectors. – thecoshman Feb 13 '11 at 00:29
  • Well my problem rele has been just basically figuring out which numbers I need to plug in, to get those two vectors. Like, how do I alter this -> http://www.toymaker.info/Games/html/picking.html . I have been trying for a couple weeks but can't seem to get it. Im not sure exactly what I need to change to make it work for me. I know that for the mouse coord it is just the height and width /2 to get the centre. I also know the position of the camera in the world, but from there I'm not rele sure what to change – user614573 Feb 13 '11 at 00:38