In ICameraSceneNode.h you have to add
Code: Select all
//! Sets if target is relative to parent
/** */
virtual void setIsTargetRelative( bool targetRelative )
{
IsTargetRelative = targetRelative;
}
//! Returns if target is relative to parent
/** */
virtual bool isTargetRelative()
{
return IsTargetRelative;
}
private:
bool IsTargetRelative;
Code: Select all
//! prerender
void CCameraSceneNode::OnRegisterSceneNode()
{
// if upvector and vector to the target are the same, we have a
// problem. so solve this problem:
core::vector3df pos = getAbsolutePosition();
core::vector3df target = Target;
if (isTargetRelative())
{
core::matrix4 targetTransformation;
targetTransformation.setTranslation(target);
targetTransformation =
Parent->getAbsoluteTransformation() * targetTransformation;
target = targetTransformation.getTranslation();
}
core::vector3df tgtv = target - pos;
tgtv.normalize();
core::vector3df up = UpVector;
up.normalize();
f32 dp = tgtv.dotProduct(up);
if ( core::equals ( fabs ( dp ), 1.f ) )
{
up.X += 0.5f;
}
ViewArea.Matrices [ video::ETS_VIEW ].buildCameraLookAtMatrixLH(pos, target, up);
ViewArea.setTransformState ( video::ETS_VIEW );
recalculateViewArea();
if ( SceneManager->getActiveCamera () == this )
SceneManager->registerNodeForRendering(this, ESNRP_CAMERA);
if (IsVisible)
ISceneNode::OnRegisterSceneNode();
}
But there is one problem using a Maya camera. The feature only works correct if a fix in animate() is deactivated which is
Code: Select all
// jox: fixed bug: jitter when rotating to the top and bottom of y
UpVector.set(0,1,0);
UpVector.rotateXYBy(-nRotY, core::vector3df(0,0,0));
UpVector.rotateXZBy(-nRotX+180.f, core::vector3df(0,0,0));
Maybe someone could help me to find a way to combine this feature an the jitter bugfix.