#include "SceneContext.h"
#include "SceneCache.h"
#include "SetCamera.h"
#include "DrawScene.h"
#include "DrawText.h"
#include "targa.h"
#include "../Common/Common.h"
namespace
{
const char * SAMPLE_FILENAME = "humanoid.fbx";
const int LEFT_BUTTON = 0;
const int MIDDLE_BUTTON = 1;
const int RIGHT_BUTTON = 2;
const int BUTTON_DOWN = 0;
const int BUTTON_UP = 1;
void FillCameraArrayRecursive(FbxNode* pNode, FbxArray<FbxNode*>& pCameraArray)
{
if (pNode)
{
if (pNode->GetNodeAttribute())
{
if (pNode->GetNodeAttribute()->GetAttributeType() == FbxNodeAttribute::eCamera)
{
pCameraArray.Add(pNode);
}
}
const int lCount = pNode->GetChildCount();
for (int i = 0; i < lCount; i++)
{
FillCameraArrayRecursive(pNode->GetChild(i), pCameraArray);
}
}
}
void FillCameraArray(FbxScene* pScene, FbxArray<FbxNode*>& pCameraArray)
{
pCameraArray.Clear();
FillCameraArrayRecursive(pScene->GetRootNode(), pCameraArray);
}
void FillPoseArray(FbxScene* pScene, FbxArray<FbxPose*>& pPoseArray)
{
const int lPoseCount = pScene->GetPoseCount();
for (int i=0; i < lPoseCount; ++i)
{
pPoseArray.Add(pScene->GetPose(i));
}
}
void PreparePointCacheData(FbxScene* pScene, FbxTime &pCache_Start, FbxTime &pCache_Stop)
{
const int lNodeCount = pScene->GetSrcObjectCount<FbxNode>();
FbxStatus lStatus;
for (int lIndex=0; lIndex<lNodeCount; lIndex++)
{
FbxNode* lNode = pScene->GetSrcObject<FbxNode>(lIndex);
if (lNode->GetGeometry())
{
int i, lVertexCacheDeformerCount = lNode->GetGeometry()->GetDeformerCount(FbxDeformer::eVertexCache);
lVertexCacheDeformerCount = lVertexCacheDeformerCount > 0 ? 1 : 0;
for (i=0; i<lVertexCacheDeformerCount; ++i )
{
FbxVertexCacheDeformer* lDeformer = static_cast<FbxVertexCacheDeformer*>(lNode->GetGeometry()->GetDeformer(i, FbxDeformer::eVertexCache));
if( !lDeformer ) continue;
FbxCache* lCache = lDeformer->GetCache();
if( !lCache ) continue;
if (lDeformer->IsActive())
{
if (lCache->GetCacheFileFormat() == FbxCache::eMaxPointCacheV2)
{
#if 0
if (!lCache->ConvertFromPC2ToMC(FbxCache::eMCOneFile,
FbxTime::GetFrameRate(pScene->GetGlobalTimeSettings().GetTimeMode())))
{
FbxString lTheErrorIs = lCache->GetStaus().GetErrorString();
}
#endif
}
else if (lCache->GetCacheFileFormat() == FbxCache::eMayaCache)
{
if (!lCache->ConvertFromMCToPC2(FbxTime::GetFrameRate(pScene->GetGlobalSettings().GetTimeMode()), 0, &lStatus))
{
FbxString lTheErrorIs = lStatus.GetErrorString();
}
}
if (!lCache->OpenFileForRead(&lStatus))
{
FbxString lTheErrorIs = lStatus.GetErrorString();
lDeformer->SetActive(false);
}
else
{
int lChannelCount = lCache->GetChannelCount();
for (int iChannelNo=0; iChannelNo < lChannelCount; iChannelNo++)
{
FbxTime lChannel_Start;
FbxTime lChannel_Stop;
if(lCache->GetAnimationRange(iChannelNo, lChannel_Start, lChannel_Stop))
{
if(lChannel_Start < pCache_Start) pCache_Start = lChannel_Start;
if(lChannel_Stop > pCache_Stop) pCache_Stop = lChannel_Stop;
}
}
}
}
}
}
}
}
bool LoadTextureFromFile(const FbxString & pFilePath, unsigned int & pTextureObject)
{
if (pFilePath.Right(3).Upper() == "TGA")
{
tga_image lTGAImage;
if (tga_read(&lTGAImage, pFilePath.Buffer()) == TGA_NOERR)
{
if (tga_is_right_to_left(&lTGAImage))
tga_flip_horiz(&lTGAImage);
if (tga_is_top_to_bottom(&lTGAImage))
tga_flip_vert(&lTGAImage);
tga_convert_depth(&lTGAImage, 24);
glGenTextures(1, &pTextureObject);
glBindTexture(GL_TEXTURE_2D, pTextureObject);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexImage2D(GL_TEXTURE_2D, 0, 3, lTGAImage.width, lTGAImage.height, 0, GL_BGR,
GL_UNSIGNED_BYTE, lTGAImage.image_data);
glBindTexture(GL_TEXTURE_2D, 0);
tga_free_buffers(&lTGAImage);
return true;
}
}
return false;
}
void LoadCacheRecursive(FbxNode * pNode, FbxAnimLayer * pAnimLayer, bool pSupportVBO)
{
const int lMaterialCount = pNode->GetMaterialCount();
for (int lMaterialIndex = 0; lMaterialIndex < lMaterialCount; ++lMaterialIndex)
{
FbxSurfaceMaterial * lMaterial = pNode->GetMaterial(lMaterialIndex);
if (lMaterial && !lMaterial->GetUserDataPtr())
{
FbxAutoPtr<MaterialCache> lMaterialCache(new MaterialCache);
if (lMaterialCache->Initialize(lMaterial))
{
lMaterial->SetUserDataPtr(lMaterialCache.Release());
}
}
}
FbxNodeAttribute* lNodeAttribute = pNode->GetNodeAttribute();
if (lNodeAttribute)
{
if (lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eMesh)
{
FbxMesh * lMesh = pNode->GetMesh();
if (pSupportVBO && lMesh && !lMesh->GetUserDataPtr())
{
FbxAutoPtr<VBOMesh> lMeshCache(new VBOMesh);
if (lMeshCache->Initialize(lMesh))
{
lMesh->SetUserDataPtr(lMeshCache.Release());
}
}
}
else if (lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eLight)
{
FbxLight * lLight = pNode->GetLight();
if (lLight && !lLight->GetUserDataPtr())
{
FbxAutoPtr<LightCache> lLightCache(new LightCache);
if (lLightCache->Initialize(lLight, pAnimLayer))
{
lLight->SetUserDataPtr(lLightCache.Release());
}
}
}
}
const int lChildCount = pNode->GetChildCount();
for (int lChildIndex = 0; lChildIndex < lChildCount; ++lChildIndex)
{
LoadCacheRecursive(pNode->GetChild(lChildIndex), pAnimLayer, pSupportVBO);
}
}
void UnloadCacheRecursive(FbxNode * pNode)
{
const int lMaterialCount = pNode->GetMaterialCount();
for (int lMaterialIndex = 0; lMaterialIndex < lMaterialCount; ++lMaterialIndex)
{
FbxSurfaceMaterial * lMaterial = pNode->GetMaterial(lMaterialIndex);
if (lMaterial && lMaterial->GetUserDataPtr())
{
MaterialCache * lMaterialCache = static_cast<MaterialCache *>(lMaterial->GetUserDataPtr());
lMaterial->SetUserDataPtr(NULL);
delete lMaterialCache;
}
}
FbxNodeAttribute* lNodeAttribute = pNode->GetNodeAttribute();
if (lNodeAttribute)
{
if (lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eMesh)
{
FbxMesh * lMesh = pNode->GetMesh();
if (lMesh && lMesh->GetUserDataPtr())
{
VBOMesh * lMeshCache = static_cast<VBOMesh *>(lMesh->GetUserDataPtr());
lMesh->SetUserDataPtr(NULL);
delete lMeshCache;
}
}
else if (lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eLight)
{
FbxLight * lLight = pNode->GetLight();
if (lLight && lLight->GetUserDataPtr())
{
LightCache * lLightCache = static_cast<LightCache *>(lLight->GetUserDataPtr());
lLight->SetUserDataPtr(NULL);
delete lLightCache;
}
}
}
const int lChildCount = pNode->GetChildCount();
for (int lChildIndex = 0; lChildIndex < lChildCount; ++lChildIndex)
{
UnloadCacheRecursive(pNode->GetChild(lChildIndex));
}
}
void LoadCacheRecursive(FbxScene * pScene, FbxAnimLayer * pAnimLayer, const char * pFbxFileName, bool pSupportVBO)
{
const int lTextureCount = pScene->GetTextureCount();
for (int lTextureIndex = 0; lTextureIndex < lTextureCount; ++lTextureIndex)
{
FbxTexture * lTexture = pScene->GetTexture(lTextureIndex);
FbxFileTexture * lFileTexture = FbxCast<FbxFileTexture>(lTexture);
if (lFileTexture && !lFileTexture->GetUserDataPtr())
{
const FbxString lFileName = lFileTexture->GetFileName();
if (lFileName.Right(3).Upper() != "TGA")
{
FBXSDK_printf("Only TGA textures are supported now: %s\n", lFileName.Buffer());
continue;
}
GLuint lTextureObject = 0;
bool lStatus = LoadTextureFromFile(lFileName, lTextureObject);
const FbxString lAbsFbxFileName = FbxPathUtils::Resolve(pFbxFileName);
const FbxString lAbsFolderName = FbxPathUtils::GetFolderName(lAbsFbxFileName);
if (!lStatus)
{
const FbxString lResolvedFileName = FbxPathUtils::Bind(lAbsFolderName, lFileTexture->GetRelativeFileName());
lStatus = LoadTextureFromFile(lResolvedFileName, lTextureObject);
}
if (!lStatus)
{
const FbxString lTextureFileName = FbxPathUtils::GetFileName(lFileName);
const FbxString lResolvedFileName = FbxPathUtils::Bind(lAbsFolderName, lTextureFileName);
lStatus = LoadTextureFromFile(lResolvedFileName, lTextureObject);
}
if (!lStatus)
{
FBXSDK_printf("Failed to load texture file: %s\n", lFileName.Buffer());
continue;
}
if (lStatus)
{
GLuint * lTextureName = new GLuint(lTextureObject);
lFileTexture->SetUserDataPtr(lTextureName);
}
}
}
LoadCacheRecursive(pScene->GetRootNode(), pAnimLayer, pSupportVBO);
}
void UnloadCacheRecursive(FbxScene * pScene)
{
const int lTextureCount = pScene->GetTextureCount();
for (int lTextureIndex = 0; lTextureIndex < lTextureCount; ++lTextureIndex)
{
FbxTexture * lTexture = pScene->GetTexture(lTextureIndex);
FbxFileTexture * lFileTexture = FbxCast<FbxFileTexture>(lTexture);
if (lFileTexture && lFileTexture->GetUserDataPtr())
{
GLuint * lTextureName = static_cast<GLuint *>(lFileTexture->GetUserDataPtr());
lFileTexture->SetUserDataPtr(NULL);
glDeleteTextures(1, lTextureName);
delete lTextureName;
}
}
UnloadCacheRecursive(pScene->GetRootNode());
}
}
bool InitializeOpenGL()
{
GLenum lError = glewInit();
if (lError != GLEW_OK)
{
FBXSDK_printf("GLEW Error: %s\n", glewGetErrorString(lError));
return false;
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glClearColor(0.0, 0.0, 0.0, 0.0);
if (!GLEW_VERSION_1_5)
{
FBXSDK_printf("The OpenGL version should be at least 1.5 to display shaded scene!\n");
return false;
}
return true;
}
SceneContext::SceneContext(const char * pFileName, int pWindowWidth, int pWindowHeight, bool pSupportVBO)
: mFileName(pFileName), mStatus(UNLOADED),
mSdkManager(NULL), mScene(NULL), mImporter(NULL), mCurrentAnimLayer(NULL), mSelectedNode(NULL),
mPoseIndex(-1), mCameraStatus(CAMERA_NOTHING), mPause(false), mShadingMode(SHADING_MODE_SHADED),
mSupportVBO(pSupportVBO), mCameraZoomMode(ZOOM_FOCAL_LENGTH),
mWindowWidth(pWindowWidth), mWindowHeight(pWindowHeight), mDrawText(new DrawText)
{
if (mFileName == NULL)
mFileName = SAMPLE_FILENAME;
mCache_Start = FBXSDK_TIME_INFINITE;
mCache_Stop = FBXSDK_TIME_MINUS_INFINITE;
InitializeSdkObjects(mSdkManager, mScene);
if (mSdkManager)
{
int lFileFormat = -1;
mImporter = FbxImporter::Create(mSdkManager,"");
if (!mSdkManager->GetIOPluginRegistry()->DetectReaderFileFormat(mFileName, lFileFormat) )
{
lFileFormat = mSdkManager->GetIOPluginRegistry()->FindReaderIDByDescription( "FBX binary (*.fbx)" );;
}
if(mImporter->Initialize(mFileName, lFileFormat) == true)
{
mWindowMessage = "Importing file ";
mWindowMessage += mFileName;
mWindowMessage += "\nPlease wait!";
mStatus = MUST_BE_LOADED;
}
else
{
mWindowMessage = "Unable to open file ";
mWindowMessage += mFileName;
mWindowMessage += "\nError reported: ";
mWindowMessage += mImporter->GetStatus().GetErrorString();
mWindowMessage += "\nEsc to exit";
}
}
else
{
mWindowMessage = "Unable to create the FBX SDK manager";
mWindowMessage += "\nEsc to exit";
}
}
SceneContext::~SceneContext()
{
FbxArrayDelete(mAnimStackNameArray);
delete mDrawText;
if (mScene)
{
UnloadCacheRecursive(mScene);
}
DestroySdkObjects(mSdkManager, true);
}
bool SceneContext::LoadFile()
{
bool lResult = false;
if (mStatus == MUST_BE_LOADED)
{
if (mImporter->Import(mScene) == true)
{
mStatus = MUST_BE_REFRESHED;
FbxAxisSystem SceneAxisSystem = mScene->GetGlobalSettings().GetAxisSystem();
FbxAxisSystem OurAxisSystem(FbxAxisSystem::eYAxis, FbxAxisSystem::eParityOdd, FbxAxisSystem::eRightHanded);
if( SceneAxisSystem != OurAxisSystem )
{
OurAxisSystem.ConvertScene(mScene);
}
FbxSystemUnit SceneSystemUnit = mScene->GetGlobalSettings().GetSystemUnit();
if( SceneSystemUnit.GetScaleFactor() != 1.0 )
{
FbxSystemUnit::cm.ConvertScene( mScene);
}
mScene->FillAnimStackNameArray(mAnimStackNameArray);
FillCameraArray(mScene, mCameraArray);
FbxGeometryConverter lGeomConverter(mSdkManager);
lGeomConverter.Triangulate(mScene, true);
lGeomConverter.SplitMeshesPerMaterial(mScene, true);
LoadCacheRecursive(mScene, mCurrentAnimLayer, mFileName, mSupportVBO);
PreparePointCacheData(mScene, mCache_Start, mCache_Stop);
FillPoseArray(mScene, mPoseArray);
mWindowMessage = "File ";
mWindowMessage += mFileName;
mWindowMessage += "\nClick on the right mouse button to enter menu.";
mWindowMessage += "\nEsc to exit.";
mFrameTime.SetTime(0, 0, 0, 1, 0, mScene->GetGlobalSettings().GetTimeMode());
FBXSDK_printf("Play/Pause Animation: Space Bar.\n");
FBXSDK_printf("Camera Rotate: Left Mouse Button.\n");
FBXSDK_printf("Camera Pan: Left Mouse Button + Middle Mouse Button.\n");
FBXSDK_printf("Camera Zoom: Middle Mouse Button.\n");
lResult = true;
}
else
{
mStatus = UNLOADED;
mWindowMessage = "Unable to import file ";
mWindowMessage += mFileName;
mWindowMessage += "\nError reported: ";
mWindowMessage += mImporter->GetStatus().GetErrorString();
}
mImporter->Destroy();
mImporter = NULL;
}
return lResult;
}
bool SceneContext::SetCurrentAnimStack(int pIndex)
{
const int lAnimStackCount = mAnimStackNameArray.GetCount();
if (!lAnimStackCount || pIndex >= lAnimStackCount)
{
return false;
}
FbxAnimStack * lCurrentAnimationStack = mScene->FindMember<FbxAnimStack>(mAnimStackNameArray[pIndex]->Buffer());
if (lCurrentAnimationStack == NULL)
{
return false;
}
mCurrentAnimLayer = lCurrentAnimationStack->GetMember<FbxAnimLayer>();
mScene->GetEvaluator()->SetContext(lCurrentAnimationStack);
FbxTakeInfo* lCurrentTakeInfo = mScene->GetTakeInfo(*(mAnimStackNameArray[pIndex]));
if (lCurrentTakeInfo)
{
mStart = lCurrentTakeInfo->mLocalTimeSpan.GetStart();
mStop = lCurrentTakeInfo->mLocalTimeSpan.GetStop();
}
else
{
FbxTimeSpan lTimeLineTimeSpan;
mScene->GetGlobalSettings().GetTimelineDefaultTimeSpan(lTimeLineTimeSpan);
mStart = lTimeLineTimeSpan.GetStart();
mStop = lTimeLineTimeSpan.GetStop();
}
if(mCache_Start < mStart)
mStart = mCache_Start;
if(mCache_Stop > mStop)
mStop = mCache_Stop;
mCurrentTime = mStart;
mStatus = MUST_BE_REFRESHED;
return true;
}
bool SceneContext::SetCurrentCamera(const char * pCameraName)
{
if (!pCameraName)
{
return false;
}
FbxGlobalSettings& lGlobalCameraSettings = mScene->GetGlobalSettings();
lGlobalCameraSettings.SetDefaultCamera(pCameraName);
mStatus = MUST_BE_REFRESHED;
return true;
}
bool SceneContext::SetCurrentPoseIndex(int pPoseIndex)
{
mPoseIndex = pPoseIndex;
mStatus = MUST_BE_REFRESHED;
return true;
}
void SceneContext::OnTimerClick() const
{
if (mStop > mStart && !mPause)
{
mStatus = MUST_BE_REFRESHED;
mCurrentTime += mFrameTime;
if (mCurrentTime > mStop)
{
mCurrentTime = mStart;
}
}
else
{
mStatus = REFRESHED;
}
}
bool SceneContext::OnDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (mStatus != UNLOADED && mStatus != MUST_BE_LOADED)
{
glPushAttrib(GL_ENABLE_BIT);
glPushAttrib(GL_LIGHTING_BIT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
SetCamera(mScene, mCurrentTime, mCurrentAnimLayer, mCameraArray,
mWindowWidth, mWindowHeight);
FbxPose * lPose = NULL;
if (mPoseIndex != -1)
{
lPose = mScene->GetPose(mPoseIndex);
}
FbxAMatrix lDummyGlobalPosition;
if (mSelectedNode)
{
InitializeLights(mScene, mCurrentTime, lPose);
DrawNodeRecursive(mSelectedNode, mCurrentTime, mCurrentAnimLayer, lDummyGlobalPosition, lPose, mShadingMode);
DisplayGrid(lDummyGlobalPosition);
}
else
{
InitializeLights(mScene, mCurrentTime, lPose);
DrawNodeRecursive(mScene->GetRootNode(), mCurrentTime, mCurrentAnimLayer, lDummyGlobalPosition, lPose, mShadingMode);
DisplayGrid(lDummyGlobalPosition);
}
glPopAttrib();
glPopAttrib();
}
DisplayWindowMessage();
return true;
}
void SceneContext::OnReshape(int pWidth, int pHeight)
{
glViewport(0, 0, (GLsizei)pWidth, (GLsizei)pHeight);
mWindowWidth = pWidth;
mWindowHeight = pHeight;
}
void SceneContext::OnKeyboard(unsigned char pKey)
{
if (pKey == 43 || pKey == 61)
{
FbxCamera* lCamera = GetCurrentCamera(mScene);
if(lCamera)
{
CameraZoom(mScene, 10, mCameraZoomMode);
mStatus = MUST_BE_REFRESHED;
}
}
if (pKey == 45 || pKey == 95)
{
FbxCamera* lCamera = GetCurrentCamera(mScene);
if(lCamera)
{
CameraZoom(mScene, 0 - 10, mCameraZoomMode);
mStatus = MUST_BE_REFRESHED;
}
}
if (pKey == 'N' || pKey == 'n')
{
}
if (pKey == ' ')
{
SetPause(!GetPause());
}
}
void SceneContext::OnMouse(int pButton, int pState, int pX, int pY)
{
FbxCamera* lCamera = GetCurrentCamera(mScene);
if (lCamera)
{
mCamPosition = lCamera->Position.Get();
mCamCenter = lCamera->InterestPosition.Get();
mRoll = lCamera->Roll.Get();
}
mLastX = pX;
mLastY = pY;
switch (pButton)
{
case LEFT_BUTTON:
switch (pState)
{
case BUTTON_DOWN:
if (mCameraStatus == CAMERA_ZOOM)
{
mCameraStatus = CAMERA_PAN;
}
else
{
mCameraStatus = CAMERA_ORBIT;
}
break;
default:
if (mCameraStatus == CAMERA_PAN)
{
mCameraStatus = CAMERA_ZOOM;
}
else
{
mCameraStatus = CAMERA_NOTHING;
}
break;
}
break;
case MIDDLE_BUTTON:
switch (pState)
{
case BUTTON_DOWN:
if (mCameraStatus == CAMERA_ORBIT)
{
mCameraStatus = CAMERA_PAN;
}
else
{
mCameraStatus = CAMERA_ZOOM;
}
break;
default:
if (mCameraStatus == CAMERA_PAN)
{
mCameraStatus = CAMERA_ORBIT;
}
else
{
mCameraStatus = CAMERA_NOTHING;
}
break;
}
break;
}
}
void SceneContext::OnMouseMotion(int pX, int pY)
{
int motion;
switch (mCameraStatus)
{
case CAMERA_ORBIT:
CameraOrbit(mScene, mCamPosition, mRoll, pX-mLastX, mLastY-pY);
mStatus = MUST_BE_REFRESHED;
break;
case CAMERA_ZOOM:
motion = mLastY-pY;
CameraZoom(mScene, motion, mCameraZoomMode);
mLastY = pY;
mStatus = MUST_BE_REFRESHED;
break;
case CAMERA_PAN:
CameraPan(mScene, mCamPosition, mCamCenter, mRoll, pX-mLastX, mLastY-pY);
mStatus = MUST_BE_REFRESHED;
break;
}
}
void SceneContext::SetSelectedNode(FbxNode * pSelectedNode)
{
mSelectedNode = pSelectedNode;
mStatus = MUST_BE_REFRESHED;
}
void SceneContext::SetShadingMode(ShadingMode pMode)
{
mShadingMode = pMode;
mStatus = MUST_BE_REFRESHED;
}
void SceneContext::DisplayWindowMessage()
{
glColor3f(1.0, 1.0, 1.0);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, mWindowWidth, 0, mWindowHeight);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
const float lX = 5;
const float lY = static_cast<float>(mWindowHeight) - 20;
glTranslatef(lX, lY, 0);
mDrawText->SetPointSize(15.f);
mDrawText->Display(mWindowMessage.Buffer());
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}
void SceneContext::DisplayGrid(const FbxAMatrix & pTransform)
{
glPushMatrix();
glMultMatrixd(pTransform);
glColor3f(0.3f, 0.3f, 0.3f);
glLineWidth(1.0);
const int hw = 500;
const int step = 20;
const int bigstep = 100;
int i;
for (i = -hw; i <= hw; i+=step) {
if (i % bigstep == 0) {
glLineWidth(2.0);
} else {
glLineWidth(1.0);
}
glBegin(GL_LINES);
glVertex3i(i,0,-hw);
glVertex3i(i,0,hw);
glEnd();
glBegin(GL_LINES);
glVertex3i(-hw,0,i);
glVertex3i(hw,0,i);
glEnd();
}
const GLfloat zoffset = -2.f;
const GLfloat xoffset = 1.f;
mDrawText->SetPointSize(4.f);
for (i = -hw; i <= hw; i+=bigstep)
{
FbxString scoord;
int lCount;
if (i == 0) {
scoord = "0";
lCount = (int)scoord.GetLen();
glPushMatrix();
glVertex3f(i+xoffset,0,zoffset);
glRotatef(-90,1,0,0);
mDrawText->Display(scoord.Buffer());
glPopMatrix();
continue;
}
scoord = "X: ";
scoord += i;
lCount = (int)scoord.GetLen();
glPushMatrix();
glTranslatef(i+xoffset,0,zoffset);
glRotatef(-90,1,0,0);
mDrawText->Display(scoord.Buffer());
glPopMatrix();
scoord = "Z: ";
scoord += i;
lCount = (int)scoord.GetLen();
glPushMatrix();
glTranslatef(xoffset,0,i+zoffset);
glRotatef(-90,1,0,0);
mDrawText->Display(scoord.Buffer());
glPopMatrix();
}
glPopMatrix();
}
void SceneContext::SetZoomMode( CameraZoomMode pZoomMode)
{
if( pZoomMode == ZOOM_POSITION)
{
mCameraZoomMode = ZOOM_POSITION;
}
else
{
mCameraZoomMode = ZOOM_FOCAL_LENGTH;
}
}