Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.70 KB | None | 0 0
  1. /*
  2. Copyright 2011-2017 Daniel S. Buckstein
  3.  
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7.  
  8. http://www.apache.org/licenses/LICENSE-2.0
  9.  
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. */
  16.  
  17. /*
  18. animal3D SDK: Minimal 3D Animation Framework
  19. By Daniel S. Buckstein
  20.  
  21. a3_DemoState.h
  22. Demo state interface and programmer function declarations.
  23.  
  24. ********************************************
  25. *** THIS IS YOUR DEMO'S MAIN HEADER FILE ***
  26. ********************************************
  27. */
  28.  
  29. #ifndef __ANIMAL3D_DEMOSTATE_H
  30. #define __ANIMAL3D_DEMOSTATE_H
  31.  
  32.  
  33. //-----------------------------------------------------------------------------
  34. // animal3D framework includes
  35.  
  36. #include "animal3D/animal3D.h"
  37.  
  38.  
  39. //-----------------------------------------------------------------------------
  40. // other demo includes
  41.  
  42. #include "_utilities/a3_DemoSceneObject.h"
  43. #include "_utilities/a3_RayPicking.h"
  44. #include "_utilities/a3_Quaternion.h"
  45. #include "_utilities/a3_HierarchyState.h"
  46. #include "_utilities/a3_Kinematics.h"
  47.  
  48.  
  49. //-----------------------------------------------------------------------------
  50.  
  51. #ifdef __cplusplus
  52. extern "C"
  53. {
  54. #else // !__cplusplus
  55. typedef struct a3_DemoState a3_DemoState;
  56. typedef struct a3_DemoStateShaderProgram a3_DemoStateShaderProgram;
  57. #endif // __cplusplus
  58.  
  59.  
  60. //-----------------------------------------------------------------------------
  61.  
  62. // object maximum counts for easy array storage
  63. // good idea to make these numbers greater than what you actually need
  64. // and if you end up needing more just increase the count... there's
  65. // more than enough memory to hold extra objects
  66. enum a3_DemoStateObjectMaxCounts
  67. {
  68. demoStateMaxCount_sceneObject = 4,
  69. demoStateMaxCount_camera = 1,
  70. demoStateMaxCount_timer = 1,
  71. demoStateMaxCount_texture = 4,
  72. demoStateMaxCount_drawDataBuffer = 1,
  73. demoStateMaxCount_vertexArray = 4,
  74. demoStateMaxCount_drawable = 16,
  75. demoStateMaxCount_shaderProgram = 8,
  76. demoStateMaxCount_shaderProgramUniform = 16,
  77. };
  78.  
  79.  
  80. //-----------------------------------------------------------------------------
  81.  
  82. // structure to help with shader program and uniform management
  83. struct a3_DemoStateShaderProgram
  84. {
  85. a3_ShaderProgram program[1];
  86. union {
  87. int uniformLocation[demoStateMaxCount_shaderProgramUniform];
  88. struct {
  89. int
  90. // common vertex shader uniforms
  91. uMVP, // model-view-projection transform
  92. uLocal, // local-space transform (pre-model)
  93. uLightPos_obj, // light position in object-space
  94. uEyePos_obj, // eye position in object-space
  95.  
  96. // geometry shader uniforms
  97. uWaypoints, // all waypoint data for curve drawing
  98. uWaypointHandles, // all waypoint handle data for Hermite curves
  99. uWaypointCount, // number of path waypoints
  100. uWaypointIndex, // index of current path waypoint
  101. uLineColor, // line segment color
  102. uCurveColor, // curve segment color
  103.  
  104. // common fragment shader uniforms
  105. uColor, // uniform color
  106. uTex_dm, // diffuse texture sampler
  107. uTex_sm; // specular texture sampler
  108. };
  109. };
  110. };
  111.  
  112.  
  113.  
  114. //-----------------------------------------------------------------------------
  115.  
  116. // persistent demo state data structure
  117. struct a3_DemoState
  118. {
  119. //---------------------------------------------------------------------
  120. // general variables pertinent to the state
  121.  
  122. // terminate key pressed
  123. int exitFlag;
  124.  
  125. // global vertical axis: Z = 0, Y = 1
  126. int verticalAxis;
  127.  
  128. // asset streaming between loads enabled (careful!)
  129. int streaming;
  130.  
  131. // window and full-frame dimensions
  132. unsigned int windowWidth, windowHeight;
  133. unsigned int frameWidth, frameHeight;
  134. int frameBorder;
  135.  
  136.  
  137. //---------------------------------------------------------------------
  138. // objects that have known or fixed instance count in the whole demo
  139.  
  140. // text renderer
  141. int textInit, showText;
  142. a3_TextRenderer text[1];
  143.  
  144. // input
  145. a3_MouseInput mouse[1];
  146. a3_KeyboardInput keyboard[1];
  147. a3_XboxControllerInput xcontrol[4];
  148.  
  149. // pointer to fast trig table
  150. float trigTable[4096 * 4];
  151.  
  152.  
  153. //---------------------------------------------------------------------
  154. // animation variables and objects
  155.  
  156. // update and display modes
  157. int kinematicsMode;
  158. int displayBoneAxes;
  159.  
  160. // skeleton hierarchies and fixed state information
  161. a3_Hierarchy skeleton[1];
  162. a3_HierarchyPoseSet skeletonPoses[1];
  163.  
  164. // ****TODO: delete this
  165. //p3vec3 skeletonBaseOffsets[64];
  166.  
  167. // hierarchy states for different modes
  168. a3_HierarchyState skeletonState_procFK[1];
  169. a3_HierarchyState skeletonState_ctrlFK[1];
  170. a3_HierarchyState skeletonState_keyPoses[1];
  171.  
  172. // procedural animation values
  173. float cycleTime, cycleDuration;
  174.  
  175. // controlled FK values
  176. p3vec3 skeletonEulers[64];
  177. unsigned int skeletonControlIndex;
  178.  
  179. // select index (pose to pose)
  180. unsigned int selectKeyPoseIndex;
  181.  
  182.  
  183. //---------------------------------------------------------------------
  184. // object arrays: organized as anonymous unions for two reasons:
  185. // 1. easy to manage entire sets of the same type of object using the
  186. // array component
  187. // 2. at the same time, variables are named pointers
  188.  
  189. // scene objects
  190. union {
  191. a3_DemoSceneObject sceneObject[demoStateMaxCount_sceneObject];
  192. struct {
  193. a3_DemoSceneObject
  194. cameraObject[1], // transform for camera
  195. lightObject[1], // transform for light
  196. skeletonObject[1]; // skeletal animation object
  197. };
  198. };
  199.  
  200. // cameras
  201. union {
  202. a3_DemoCamera camera[demoStateMaxCount_camera];
  203. struct {
  204. a3_DemoCamera
  205. sceneCamera[1]; // scene viewing camera
  206. };
  207. };
  208.  
  209. // timers
  210. union {
  211. a3_Timer timer[demoStateMaxCount_timer];
  212. struct {
  213. a3_Timer
  214. renderTimer[1]; // render FPS timer
  215. };
  216. };
  217.  
  218.  
  219. // textures
  220. union {
  221. a3_Texture texture[demoStateMaxCount_texture];
  222. struct {
  223. a3_Texture
  224. tex_checker[1], // checkered texture
  225. tex_earth_dm[1], // earth diffuse texture
  226. tex_earth_sm[1]; // earth specular texture
  227. };
  228. };
  229.  
  230.  
  231. // draw data buffers
  232. union {
  233. a3_VertexBuffer drawDataBuffer[demoStateMaxCount_drawDataBuffer];
  234. struct {
  235. a3_VertexBuffer
  236. vbo_staticSceneObjectDrawBuffer[1]; // buffer to hold all data for static scene objects (e.g. grid)
  237. };
  238. };
  239.  
  240. // vertex array objects
  241. union {
  242. a3_VertexArrayDescriptor vertexArray[demoStateMaxCount_vertexArray];
  243. struct {
  244. a3_VertexArrayDescriptor
  245. vao_position[1], // VAO for vertex format with only position
  246. vao_position_color[1], // VAO for vertex format with position and color
  247. vao_position_texcoords[1], // VAO for vertex format with position and UVs
  248. vao_tangentBasis[1]; // VAO for vertex format with full tangent basis, inclusing position and UVs
  249. };
  250. };
  251.  
  252. // drawables
  253. union {
  254. a3_VertexDrawable drawable[demoStateMaxCount_drawable];
  255. struct {
  256. a3_VertexDrawable
  257. draw_grid[1], // wireframe ground plane to emphasize scaling
  258. draw_axes[1], // coordinate axes at the center of the world
  259. draw_curve[1], // single-vertex shape used for drawing curve segments
  260. draw_node[1], // small round shape for a node or waypoint
  261. draw_gimbal[1], // gimbal background
  262. draw_ring[1], // gimbal ring (torus or ring)
  263. draw_bone[1], // skeletal bone shape (spike)
  264. draw_joint[1], // joint shape
  265. draw_sphere[1], // procedural sphere
  266. draw_teapot[1]; // loaded teapot model
  267. };
  268. };
  269.  
  270.  
  271. // shader programs and uniforms
  272. union {
  273. a3_DemoStateShaderProgram shaderProgram[demoStateMaxCount_shaderProgram];
  274. struct {
  275. a3_DemoStateShaderProgram
  276. prog_drawColor[1], // draw color attribute
  277. prog_drawColorInstanced[1], // draw color attribute instanced
  278. prog_drawColorUnif[1], // draw uniform color
  279. prog_drawColorUnifInstanced[1], // draw uniform color instanced
  280. prog_drawTexture[1], // draw texture sample
  281. prog_drawPhong_obj[1], // draw object-space Phong shading
  282. prog_drawLine[1], // draw line segment
  283. prog_drawCurve[1]; // draw curve segment
  284. };
  285. };
  286.  
  287.  
  288. //---------------------------------------------------------------------
  289. };
  290.  
  291.  
  292. //-----------------------------------------------------------------------------
  293.  
  294. // demo-related functions
  295.  
  296. void a3demo_setDefaultGraphicsState();
  297.  
  298. void a3demo_loadTextures(a3_DemoState *demoState);
  299. void a3demo_loadGeometry(a3_DemoState *demoState);
  300. void a3demo_loadShaders(a3_DemoState *demoState);
  301.  
  302. void a3demo_unloadTextures(a3_DemoState *demoState);
  303. void a3demo_unloadGeometry(a3_DemoState *demoState);
  304. void a3demo_unloadShaders(a3_DemoState *demoState);
  305.  
  306. void a3demo_loadAnimation(a3_DemoState *demoState);
  307. void a3demo_unloadAnimation(a3_DemoState *demoState);
  308.  
  309. void a3demo_initScene(a3_DemoState *demoState);
  310.  
  311. void a3demo_validateUnload(const a3_DemoState *demoState);
  312.  
  313. void a3demo_refresh(a3_DemoState *demoState);
  314. void a3demo_update(a3_DemoState *demoState, double dt);
  315. void a3demo_render(a3_DemoState *demoState);
  316.  
  317.  
  318. //-----------------------------------------------------------------------------
  319.  
  320.  
  321. #ifdef __cplusplus
  322. }
  323. #endif // __cplusplus
  324.  
  325.  
  326. #endif // !__ANIMAL3D_DEMOSTATE_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement