Retrieving a point where the camera is facing
Posted: Sun Dec 30, 2007 8:30 pm
So I'm trying to find a vector3df that's placed ANYWHERE on the line projecting from the center of my current camera. This is all during initialization btw, so there have been no calls to createScene() or any such thing.
Basically what I'm trying to achieve is a camera class that calls lookAt() on a target ISceneNode every frame, and I just move that scene node around to have the camera look elsewhere. That all works fine, and what I'm trying to do now is initialize it properly. Right now, I just hard-coded a location for the scene node to start, and as such, the camera will always start facing that point. I want the camera to start facing an arbitrary direction (and thus, point), so I need a way to calculate where to put my scene node the camera will be lookAt()ing at when my camera is first created.
My first few lines of code for this were put immediately after :
But what I noticed at this point was that the line3df returned isn't correct.
line.start is giving me the camera's world position, which is fine, but line.end is always giving me vector3df(0.0f, 0.0f, 1.0f) and I have no idea why. If I put that same code into my createScene(), the first call will give me the same thing, but the later calls will be okay. Why might that be? Is there some updating that needs to be done internally in the engine after I create an ICameraSceneNode with a lookAt position, before it's ACTUALLY looking at that position?
Basically what I'm trying to achieve is a camera class that calls lookAt() on a target ISceneNode every frame, and I just move that scene node around to have the camera look elsewhere. That all works fine, and what I'm trying to do now is initialize it properly. Right now, I just hard-coded a location for the scene node to start, and as such, the camera will always start facing that point. I want the camera to start facing an arbitrary direction (and thus, point), so I need a way to calculate where to put my scene node the camera will be lookAt()ing at when my camera is first created.
My first few lines of code for this were put immediately after :
Code: Select all
position2d<s32> screenCenter = position2d<s32>(400, 300);
line3df line = mDevice->getSceneManager()->getSceneCollisionManager()->getRayFromScreenCoordinates(screenCenter);
line.start is giving me the camera's world position, which is fine, but line.end is always giving me vector3df(0.0f, 0.0f, 1.0f) and I have no idea why. If I put that same code into my createScene(), the first call will give me the same thing, but the later calls will be okay. Why might that be? Is there some updating that needs to be done internally in the engine after I create an ICameraSceneNode with a lookAt position, before it's ACTUALLY looking at that position?