Sort of.
What I have is a class that looks (simplified) like this:
Code: Select all
class camFree: public camCamera {
public:
camFree(ICameraSceneNode *camera);
~camFree();
void update();
private:
ICameraSceneNode *mCamera;
ISceneNode *mTarget;
};
roughly. - - Every frame, the update() function is called, and all it really does is the following:
Code: Select all
void camFree::update() {
mCamera->setTarget(mTarget->getPosition());
}
What this allows me to do is move the camera or the target, and the camera will always be looking at the target.
To elaborate more on what I'm trying to achieve, here's the constructor for the class:
Code: Select all
camFree::camFree(ICameraSceneNode *camera): mCamera(camera) {
mTarget = ISceneManager::addSceneNode();
//Figure out where mCamera is looking, and put mTarget there, so when update() is called, it all looks smooth
// ---- HOW? ----
}
The line that's creating the class is this:
Code: Select all
ICameraSceneNode *camNode = ISceneManager::addCameraSceneNode(0, vector3df(0, -30, -9), vector3df(9, -30, 9),
camCamera *camera = new camFree(camNode);
So as you can see, I'm specifying the camera's starting position and looking position when I create the ICameraSceneNode, and since my camera is being repositioned every frame to be looking at it's internal target ISceneNode, what I want to do is initially set that target ISceneNode to a position directly in front of the camera, where's it looking when I create the camFree class with that camera.
To put this in simple terms using code that doesn't exist in the Irrlicht Engine, I want to do this:
Code: Select all
mTarget->setPosition(mCamera->getTargetPosition());
But since obviously the camera's target is not a 3d point in space, but rather a ray, this is not possible;; So I've put together a couple of lines of code in the constructor to start figuring that out, but I'm not getting expected results back from ISceneCollisionManager::getRayFromSceneCoordinates()..
When I change the constructor to look like this:
Code: Select all
camFree::camFree(ICameraSceneNode *camera): mCamera(camera) {
mTarget = ISceneManager::addSceneNode();
//Figure out where mCamera is looking, and put mTarget there, so when update() is called, it all looks smooth
position2d<s32> screenCenter = position2d<s32>(400, 300);
line3df line = ISceneCollisionManager::getRayFromScreenCoordinates(screenCenter);
}
and I examine the line variable after the call to getRayFromScreenCoordinates(), it gives me the correct numbers in line.start, which is the camera's position, but the numbers in line.end are way out to lunch at vector3df(0, 0, 1)... that makes no sense, since the camera's obviously not looking at that point- looking at the code tells us that it's actually looking down the Z axis. If the camera was looking at that point, it would be looking almost straight up! (along the Y axis)