-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSceneContext.h
156 lines (124 loc) · 5.02 KB
/
SceneContext.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/****************************************************************************************
Copyright (C) 2013 Autodesk, Inc.
Edited 2013 by Emre Tanirgan
All rights reserved.
Use of this software is subject to the terms of the Autodesk license agreement
provided at the time of installation or download, or which otherwise accompanies
this software in either electronic or hard copy form.
****************************************************************************************/
#ifndef _SCENE_CONTEXT_H
#define _SCENE_CONTEXT_H
#include "GlFunctions.h"
#include "Motion.h"
#include "Frame.h"
class DrawText;
// This class is responsive for loading files and recording current status as
// a bridge between window system such as GLUT or Qt and a specific FBX scene.
class SceneContext
{
public:
enum Status
{
UNLOADED, // Unload file or load failure;
MUST_BE_LOADED, // Ready for loading file;
MUST_BE_REFRESHED, // Something changed and redraw needed;
REFRESHED // No redraw needed.
};
Status GetStatus() const { return mStatus; }
// Initialize with a .FBX, .DAE or .OBJ file name and current window size.
SceneContext(const char * pFileName, int pWindowWidth, int pWindowHeight, bool pSupportVBO);
~SceneContext();
// Return the FBX scene for more informations.
const FbxScene * GetScene() const { return mScene; }
// Load the FBX or COLLADA file into memory.
bool LoadFile();
// The time period for one frame.
const FbxTime GetFrameTime() const { return mFrameTime; }
// Call this method when redraw is needed.
bool OnDisplay();
// Call this method when window size is changed.
void OnReshape(int pWidth, int pHeight);
// Call this method when keyboard input occurs.
void OnKeyboard(unsigned char pKey);
// Call this method when mouse buttons are pushed or released.
void OnMouse(int pButton, int pState, int pX, int pY);
// Call this method when mouse is moved.
void OnMouseMotion(int pX, int pY);
// Call this method when timer is finished, for animation display.
void OnTimerClick() const;
// Methods for creating menus.
// Get all the cameras in current scene, including producer cameras.
const FbxArray<FbxNode *> & GetCameraArray() const { return mCameraArray; }
// Get all the animation stack names in current scene.
const FbxArray<FbxString *> & GetAnimStackNameArray() const { return mAnimStackNameArray; }
// Get all the pose in current scene.
const FbxArray<FbxPose *> & GetPoseArray() const { return mPoseArray; }
// The input index is corresponding to the array returned from GetAnimStackNameArray.
bool SetCurrentAnimStack(int pIndex);
// Set the current camera with its name.
bool SetCurrentCamera(const char * pCameraName);
// The input index is corresponding to the array returned from GetPoseArray.
bool SetCurrentPoseIndex(int pPoseIndex);
// Set the currently selected node from external window system.
void SetSelectedNode(FbxNode * pSelectedNode);
// Set the shading mode, wire-frame or shaded.
void SetShadingMode(ShadingMode pMode);
// Pause the animation.
void SetPause(bool pPause) { mPause = pPause; }
// Check whether the animation is paused.
bool GetPause() const { return mPause; }
void convertToSkeleton();
void setRotationValue(Joint* joint, Frame* frame, FbxTime myTime);
enum CameraZoomMode
{
ZOOM_FOCAL_LENGTH,
ZOOM_POSITION
};
CameraZoomMode GetZoomMode() { return mCameraZoomMode; }
void SetZoomMode( CameraZoomMode pZoomMode);
private:
// Display information about current status in the left-up corner of the window.
void DisplayWindowMessage();
// Display a X-Z grid.
void DisplayGrid(const FbxAMatrix & pTransform);
enum CameraStatus
{
CAMERA_NOTHING,
CAMERA_ORBIT,
CAMERA_ZOOM,
CAMERA_PAN
};
const char * mFileName;
mutable Status mStatus;
mutable FbxString mWindowMessage;
FbxManager * mSdkManager;
FbxScene * mScene;
FbxImporter * mImporter;
FbxAnimLayer * mCurrentAnimLayer;
FbxNode * mSelectedNode;
int mPoseIndex;
FbxArray<FbxString*> mAnimStackNameArray;
FbxArray<FbxNode*> mCameraArray;
FbxArray<FbxPose*> mPoseArray;
mutable FbxTime mFrameTime, mStart, mStop, mCurrentTime;
mutable FbxTime mCache_Start, mCache_Stop;
// Data for camera manipulation
mutable int mLastX, mLastY;
mutable FbxVector4 mCamPosition, mCamCenter;
mutable double mRoll;
mutable CameraStatus mCameraStatus;
bool mPause;
ShadingMode mShadingMode;
bool mSupportVBO;
//camera zoom mode
CameraZoomMode mCameraZoomMode;
int mWindowWidth, mWindowHeight;
// Utility class for draw text in OpenGL.
DrawText * mDrawText;
Motion* motion;
bool setAnim;
Skeleton* skeleton;
};
// Initialize GLEW, must be called after the window is created.
bool InitializeOpenGL();
#endif // _SCENE_CONTEXT_H