In my update loop I run everything in this order:
Code: Select all
irrDriver->beginScene(true, true, SColor(255,0,0,0));
physicsTick(); //tick the reactphysics3d physics engine
updateAllObjects(); //set the position of all the node objects to whatever the physics engine says they should be
cameraChase(); //whatever camera following code i'm currently testing
irrsmgr->drawAll();//scene manager
guienv->drawAll();//IGUIEnvironment
irrDriver->endScene();//IVideoDriver
I know about the updateAbsolutePosition() function but i'm not sure if its broken or if im not using it right. The following code performs exactly the same regardless of if the lines containing updateAbsolutePosition() are commented out or not.
Code: Select all
core::vector3df forward = thingToChase->getNode()->getRotation().rotationToDirection();
core::vector3df up = thingToChase->getNode()->getRotation().rotationToDirection(core::vector3df(0,1,0));
core::vector3df thingPosition = thingToChase->getNode()->getPosition();
thingToChase->getParentThing()->getNode()->updateAbsolutePosition();
thingToChase->getNode()->updateAbsolutePosition();
theCamera->updateAbsolutePosition();
theCamera->setPosition(thingPosition - forward);
theCamera->updateAbsolutePosition();
theCamera->setTarget(thingPosition + forward);
theCamera->setUpVector(up);
Code: Select all
thingToChase->getParentThing()->getNode()->updateAbsolutePosition();
thingToChase->getNode()->updateAbsolutePosition();
core::vector3df forward = thingToChase->getNode()->getRotation().rotationToDirection();
core::vector3df up = thingToChase->getNode()->getRotation().rotationToDirection(core::vector3df(0,1,0));
core::vector3df thingPosition = thingToChase->getNode()->getPosition();
theCamera->setPosition(thingPosition - forward);
theCamera->setTarget(thingPosition + forward);
theCamera->setUpVector(up);
Code: Select all
core::vector3df forward = thingToChase->getNode()->getRotation().rotationToDirection();
core::vector3df up = thingToChase->getNode()->getRotation().rotationToDirection(core::vector3df(0,1,0));
core::vector3df shipPosition = thingToChase->getNode()->getPosition();
theCamera->setPosition(shipPosition + (forward * -64.0f) + (up * 10.0f));
theCamera->setTarget(shipPosition);
Edit: well, darn. calculating velocities and moving the camera to where it should be 1 frame from "now" can't work if the parent object is rotating and the child object is moving because of the way pivoting changes the position. That's some really complicated math.