0

I am attempting to cast a ray from the center of the screen and check for collisions with objects.

When rendering, I use these calls to set up the camera:

GL11.glRotated(mPitch, 1, 0, 0);
GL11.glRotated(mYaw, 0, 1, 0);
GL11.glTranslated(mPositionX, mPositionY, mPositionZ);

I am having trouble creating the ray, however. This is the code I have so far:

ray.origin = new Vector(mPositionX, mPositionY, mPositionZ);
ray.direction = new Vector(?, ?, ?);

My question is: what should I put in the question mark spots? I.e. how can I create the ray direction from the pitch and roll?

Olivier Moindrot
  • 27,908
  • 11
  • 92
  • 91
Isaac Waller
  • 32,709
  • 29
  • 96
  • 107

1 Answers1

0

I answered a question not unlike your's just recently. So I suggest you read this: 3d coordinate from point and angles

This applies to your question as well, only that you don't want just a point, but a ray. Well, remember that a point can be assumed a displacement-from-origin vector and that a ray is defined as

 r(t) = v*t + s

In your case, s is the camera position, and v would be a point relative to the camera's position. You figure the rest (or ask, if things are still unclear).

Community
  • 1
  • 1
datenwolf
  • 159,371
  • 13
  • 185
  • 298