// Get the animated parameters of a camera contained in the scene // and store them in the associated member variables contained in // the camera. void Scene::getCameraAnimatedParameters(KFbxNode* pNode, KTime time) { KFbxCamera* lCamera = (KFbxCamera*) pNode->GetNodeAttribute(); lCamera->Position.Set(getGlobalPosition(pNode, time).GetT()); KFbxAnimCurve* fc = lCamera->Roll.GetCurve<KFbxAnimCurve>(currentAnimationLayer); if (fc) lCamera->Roll.Set(fc->Evaluate(time)); if (lCamera->GetApertureMode() == KFbxCamera::eHORIZONTAL || lCamera->GetApertureMode() == KFbxCamera::eVERTICAL) { fc = lCamera->FieldOfView.GetCurve<KFbxAnimCurve>(currentAnimationLayer); if (fc) lCamera->FieldOfView.Set(fc->Evaluate(time)); } else if (lCamera->GetApertureMode() == KFbxCamera::eHORIZONTAL_AND_VERTICAL) { // In this aperture mode, the squeeze ratio is not relevant // because the fields of view in X and Y are independent. // It's value is set to retrieve the proper aspect in function SetCamera(). // // if: // // aspect = field of view X / field of view Y = aperture width * squeeze ratio / aperture height // // then: // // squeeze ratio = (field of view X * aperture height) / (field of view Y * aperture width) // double lFieldOfViewX = lCamera->FieldOfViewX.Get(); double lFieldOfViewY = lCamera->FieldOfViewY.Get(); fc = lCamera->FieldOfViewX.GetCurve<KFbxAnimCurve>(currentAnimationLayer); if (fc) lFieldOfViewX = fc->Evaluate(time); fc = lCamera->FieldOfViewY.GetCurve<KFbxAnimCurve>(currentAnimationLayer); if (fc) lFieldOfViewY = fc->Evaluate(time); double lSqueezeRatio = (lFieldOfViewX * lCamera->GetApertureHeight()) / (lFieldOfViewY * lCamera->GetApertureWidth()); lCamera->FieldOfViewX.Set(lFieldOfViewX); lCamera->FieldOfViewY.Set(lFieldOfViewY); lCamera->SetSqueezeRatio(lSqueezeRatio); } else if (lCamera->GetApertureMode() == KFbxCamera::eFOCAL_LENGTH) { double lFocalLength = lCamera->FocalLength.Get(); fc = lCamera->FocalLength.GetCurve<KFbxAnimCurve>(currentAnimationLayer); if (fc && fc ->Evaluate(time)) lCamera->FocalLength.Set(lFocalLength); } }
void GetCameraAnimatedParameters(KFbxNode* pNode, KTime& pTime) { KFbxCamera* lCamera = (KFbxCamera*) pNode->GetNodeAttribute(); lCamera->Position.Set(GetGlobalPosition(pNode, pTime).GetT()); KFbxAnimCurve* fc = lCamera->Roll.GetCurve<KFbxAnimCurve>(gCurrentAnimationLayer); if (fc) lCamera->Roll.Set(fc->Evaluate(pTime)); if (lCamera->GetApertureMode() == KFbxCamera::eHORIZONTAL || lCamera->GetApertureMode() == KFbxCamera::eVERTICAL) { fc = lCamera->FieldOfView.GetCurve<KFbxAnimCurve>(gCurrentAnimationLayer); if (fc) lCamera->FieldOfView.Set(fc->Evaluate(pTime)); } else if (lCamera->GetApertureMode() == KFbxCamera::eHORIZONTAL_AND_VERTICAL) { double lFieldOfViewX = lCamera->FieldOfViewX.Get(); double lFieldOfViewY = lCamera->FieldOfViewY.Get(); fc = lCamera->FieldOfViewX.GetCurve<KFbxAnimCurve>(gCurrentAnimationLayer); if (fc) lFieldOfViewX = fc->Evaluate(pTime); fc = lCamera->FieldOfViewY.GetCurve<KFbxAnimCurve>(gCurrentAnimationLayer); if (fc) lFieldOfViewY = fc->Evaluate(pTime); double lSqueezeRatio = (lFieldOfViewX * lCamera->GetApertureHeight()) / (lFieldOfViewY * lCamera->GetApertureWidth()); lCamera->FieldOfViewX.Set(lFieldOfViewX); lCamera->FieldOfViewY.Set(lFieldOfViewY); lCamera->SetSqueezeRatio(lSqueezeRatio); } else if (lCamera->GetApertureMode() == KFbxCamera::eFOCAL_LENGTH) { double lFocalLength = lCamera->FocalLength.Get(); fc = lCamera->FocalLength.GetCurve<KFbxAnimCurve>(gCurrentAnimationLayer); if (fc && fc ->Evaluate(pTime)) lCamera->FocalLength.Set(lFocalLength); } }
void CameraZoomOut(KFbxScene* pScene, int dY) { KFbxCamera* lCamera = GetCurrentCamera(pScene); if (lCamera) { if (lCamera->ProjectionType.Get() == KFbxCamera::ePERSPECTIVE) { double lOriginalAperture = sqrt(lCamera->GetApertureWidth()); double lApertureTransform = lOriginalAperture+dY/400.0; if (lApertureTransform <0.25) { lApertureTransform =0.25; } if (lApertureTransform*lApertureTransform >179) { lApertureTransform = sqrt(179.0); } double lApertureH = lApertureTransform/lOriginalAperture*sqrt(lCamera->GetApertureHeight()); double lApertureWidthOrig = lCamera->GetApertureWidth(); double lApertureHeightOrig = lCamera->GetApertureHeight(); if (lCamera->GetApertureMode() == KFbxCamera::eFOCAL_LENGTH) { double lFLOrig = lCamera->FocalLength.Get(); double lFOVOrig = lCamera->ComputeFieldOfView(lFLOrig); // recompute to be sure. lCamera->SetApertureWidth(lApertureTransform * lApertureTransform); lCamera->SetApertureHeight(lApertureH * lApertureH); double lFLNew = lCamera->ComputeFocalLength(lFOVOrig); double lFOVNew = lCamera->ComputeFieldOfView(lFLNew); lCamera->FocalLength.Set(lFLNew); lCamera->FieldOfView.Set(lFOVNew); } else if (lCamera->GetApertureMode() == KFbxCamera::eVERTICAL || lCamera->GetApertureMode() == KFbxCamera::eHORIZONTAL) { double lFOVOrig = lCamera->FieldOfView.Get(); double lFLOrig = lCamera->ComputeFocalLength(lFOVOrig); // recompute to be sure. lCamera->SetApertureWidth(lApertureTransform * lApertureTransform); lCamera->SetApertureHeight(lApertureH * lApertureH); double lFOVNew = lCamera->ComputeFieldOfView(lFLOrig); double lFLNew = lCamera->ComputeFocalLength(lFOVNew); lCamera->FieldOfView.Set(lFOVNew); lCamera->FocalLength.Set(lFLNew); } else if (lCamera->GetApertureMode() == KFbxCamera::eHORIZONTAL_AND_VERTICAL) { double lFOVOrig = lCamera->FieldOfViewY.Get(); double lFLOrig = lCamera->ComputeFocalLength(lFOVOrig); // recompute to be sure. lCamera->SetApertureWidth(lApertureTransform * lApertureTransform); lCamera->SetApertureHeight(lApertureH * lApertureH); double lFOVNew = lCamera->ComputeFieldOfView(lFLOrig); double lFLNew = lCamera->ComputeFocalLength(lFOVNew); lCamera->FieldOfViewY.Set(lFOVNew); lCamera->FocalLength.Set(lFLNew); } lCamera->SetApertureWidth(lApertureWidthOrig); lCamera->SetApertureHeight(lApertureHeightOrig); } else { gsOrthoCameraScale *= 1.25; } } }
// Set the view to the current camera settings. void SetCamera(KFbxScene* pScene, KTime& pTime, KFbxAnimLayer* pAnimLayer, KArrayTemplate<KFbxNode*>& pCameraArray) { KFbxCamera* lCamera = GetCurrentCamera(pScene, pTime, pCameraArray); KFbxNode* lCameraNode = lCamera ? lCamera->GetNode() : NULL; KFbxVector4 lEye(0,0,1); KFbxVector4 lCenter(0,0,0); KFbxVector4 lUp(0,1,0); KFbxVector4 lForward, lRight; if (lCamera) { lEye = lCamera->Position.Get(); lUp = lCamera->UpVector.Get(); } if (lCameraNode && lCameraNode->GetTarget()) { lCenter = GetGlobalPosition(lCameraNode->GetTarget(), pTime).GetT(); } else { if (!lCameraNode || IsProducerCamera(pScene, lCamera)) { if (lCamera) lCenter = lCamera->InterestPosition.Get(); } else { KFbxXMatrix lGlobalRotation; KFbxVector4 lRotationVector(GetGlobalPosition(lCameraNode, pTime).GetR()); lGlobalRotation.SetR(lRotationVector); KFbxVector4 lInterestPosition(lCamera->InterestPosition.Get()); KFbxVector4 lCameraGlobalPosition(GetGlobalPosition(lCameraNode, pTime).GetT()); double lLength = (KFbxVector4(lInterestPosition - lCameraGlobalPosition).Length()); lRotationVector = KFbxVector4(1.0,0,0); lCenter = lGlobalRotation.MultT(lRotationVector); lCenter *= lLength; lCenter += lEye; lRotationVector = KFbxVector4(0,1.0,0); lUp = lGlobalRotation.MultT(lRotationVector); } } lForward = lCenter - lEye; lForward.Normalize(); lRight = lForward.CrossProduct(lUp); lRight.Normalize(); lUp = lRight.CrossProduct(lForward); lUp.Normalize(); double lRadians = 0; if (lCamera) lRadians = 3.1416 * lCamera->Roll.Get() / 180.0; lUp *= cos(lRadians); lRight *= sin(lRadians); lUp = lUp + lRight; double lNearPlane = 0.01; if (lCamera) lNearPlane = lCamera->GetNearPlane(); double lFarPlane = 1000.0; if (lCamera) lFarPlane = lCamera->GetFarPlane(); if (lCamera && lCamera->ProjectionType.Get() == KFbxCamera::ePERSPECTIVE) { double lFieldOfViewY=0.0; double lAspect = lCamera->GetApertureWidth() * lCamera->GetSqueezeRatio() / lCamera->GetApertureHeight(); if (lCamera->GetApertureMode() == KFbxCamera::eHORIZONTAL || lCamera->GetApertureMode() == KFbxCamera::eVERTICAL) { lFieldOfViewY = lCamera->FieldOfView.Get(); if (lCamera->GetApertureMode() == KFbxCamera::eHORIZONTAL) lFieldOfViewY /= lAspect; } else if (lCamera->GetApertureMode() == KFbxCamera::eFOCAL_LENGTH) { lFieldOfViewY = lCamera->ComputeFieldOfView(lCamera->FocalLength.Get()); lFieldOfViewY /= lAspect; } else if (lCamera->GetApertureMode() == KFbxCamera::eHORIZONTAL_AND_VERTICAL) { lFieldOfViewY = lCamera->FieldOfViewY.Get(); } GlSetCameraPerspective(lFieldOfViewY, lAspect, lNearPlane, lFarPlane, lEye, lCenter, lUp); } else { double lPixelRatio = 1.0; if (lCamera) lPixelRatio = lCamera->GetPixelRatio(); int lWidth, lHeight; double lLeftPlane, lRightPlane, lBottomPlane, lTopPlane; GlGetWindowSize(lWidth, lHeight); if(lWidth < lHeight) { lLeftPlane = -gsOrthoCameraScale * lPixelRatio; lRightPlane = gsOrthoCameraScale * lPixelRatio; lBottomPlane = -gsOrthoCameraScale * lHeight / lWidth; lTopPlane = gsOrthoCameraScale * lHeight / lWidth; } else { lWidth *= (int) lPixelRatio; lLeftPlane = -gsOrthoCameraScale * lWidth / lHeight; lRightPlane = gsOrthoCameraScale * lWidth / lHeight; lBottomPlane = -gsOrthoCameraScale; lTopPlane = gsOrthoCameraScale; } GlSetCameraOrthogonal(lLeftPlane, lRightPlane, lBottomPlane, lTopPlane, lNearPlane, lFarPlane, lEye, lCenter, lUp); } }