Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2012, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file camera.h
  35. * @brief Defines the aiCamera data structure
  36. */
  37. #ifndef AI_CAMERA_H_INC
  38. #define AI_CAMERA_H_INC
  39. #include "types.h"
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. // ---------------------------------------------------------------------------
  44. /** Helper structure to describe a virtual camera.
  45. *
  46. * Cameras have a representation in the node graph and can be animated.
  47. * An important aspect is that the camera itself is also part of the
  48. * scenegraph. This means, any values such as the look-at vector are not
  49. * *absolute*, they're <b>relative</b> to the coordinate system defined
  50. * by the node which corresponds to the camera. This allows for camera
  51. * animations. For static cameras parameters like the 'look-at' or 'up' vectors
  52. * are usually specified directly in aiCamera, but beware, they could also
  53. * be encoded in the node transformation. The following (pseudo)code sample
  54. * shows how to do it: <br><br>
  55. * @code
  56. * // Get the camera matrix for a camera at a specific time
  57. * // if the node hierarchy for the camera does not contain
  58. * // at least one animated node this is a static computation
  59. * get-camera-matrix (node sceneRoot, camera cam) : matrix
  60. * {
  61. * node cnd = find-node-for-camera(cam)
  62. * matrix cmt = identity()
  63. *
  64. * // as usual - get the absolute camera transformation for this frame
  65. * for each node nd in hierarchy from sceneRoot to cnd
  66. * matrix cur
  67. * if (is-animated(nd))
  68. * cur = eval-animation(nd)
  69. * else cur = nd->mTransformation;
  70. * cmt = mult-matrices( cmt, cur )
  71. * end for
  72. *
  73. * // now multiply with the camera's own local transform
  74. * cam = mult-matrices (cam, get-camera-matrix(cmt) )
  75. * }
  76. * @endcode
  77. *
  78. * @note some file formats (such as 3DS, ASE) export a "target point" -
  79. * the point the camera is looking at (it can even be animated). Assimp
  80. * writes the target point as a subnode of the camera's main node,
  81. * called "<camName>.Target". However this is just additional information
  82. * then the transformation tracks of the camera main node make the
  83. * camera already look in the right direction.
  84. *
  85. */
  86. struct aiCamera
  87. {
  88. /** The name of the camera.
  89. *
  90. * There must be a node in the scenegraph with the same name.
  91. * This node specifies the position of the camera in the scene
  92. * hierarchy and can be animated.
  93. */
  94. C_STRUCT aiString mName;
  95. /** Position of the camera relative to the coordinate space
  96. * defined by the corresponding node.
  97. *
  98. * The default value is 0|0|0.
  99. */
  100. C_STRUCT aiVector3D mPosition;
  101. /** 'Up' - vector of the camera coordinate system relative to
  102. * the coordinate space defined by the corresponding node.
  103. *
  104. * The 'right' vector of the camera coordinate system is
  105. * the cross product of the up and lookAt vectors.
  106. * The default value is 0|1|0. The vector
  107. * may be normalized, but it needn't.
  108. */
  109. C_STRUCT aiVector3D mUp;
  110. /** 'LookAt' - vector of the camera coordinate system relative to
  111. * the coordinate space defined by the corresponding node.
  112. *
  113. * This is the viewing direction of the user.
  114. * The default value is 0|0|1. The vector
  115. * may be normalized, but it needn't.
  116. */
  117. C_STRUCT aiVector3D mLookAt;
  118. /** Half horizontal field of view angle, in radians.
  119. *
  120. * The field of view angle is the angle between the center
  121. * line of the screen and the left or right border.
  122. * The default value is 1/4PI.
  123. */
  124. float mHorizontalFOV;
  125. /** Distance of the near clipping plane from the camera.
  126. *
  127. * The value may not be 0.f (for arithmetic reasons to prevent
  128. * a division through zero). The default value is 0.1f.
  129. */
  130. float mClipPlaneNear;
  131. /** Distance of the far clipping plane from the camera.
  132. *
  133. * The far clipping plane must, of course, be further away than the
  134. * near clipping plane. The default value is 1000.f. The ratio
  135. * between the near and the far plane should not be too
  136. * large (between 1000-10000 should be ok) to avoid floating-point
  137. * inaccuracies which could lead to z-fighting.
  138. */
  139. float mClipPlaneFar;
  140. /** Screen aspect ratio.
  141. *
  142. * This is the ration between the width and the height of the
  143. * screen. Typical values are 4/3, 1/2 or 1/1. This value is
  144. * 0 if the aspect ratio is not defined in the source file.
  145. * 0 is also the default value.
  146. */
  147. float mAspect;
  148. #ifdef __cplusplus
  149. aiCamera()
  150. : mUp (0.f,1.f,0.f)
  151. , mLookAt (0.f,0.f,1.f)
  152. , mHorizontalFOV (0.25f * (float)AI_MATH_PI)
  153. , mClipPlaneNear (0.1f)
  154. , mClipPlaneFar (1000.f)
  155. , mAspect (0.f)
  156. {}
  157. /** @brief Get a *right-handed* camera matrix from me
  158. * @param out Camera matrix to be filled
  159. */
  160. void GetCameraMatrix (aiMatrix4x4& out) const
  161. {
  162. /** todo: test ... should work, but i'm not absolutely sure */
  163. /** We don't know whether these vectors are already normalized ...*/
  164. aiVector3D zaxis = mLookAt; zaxis.Normalize();
  165. aiVector3D yaxis = mUp; yaxis.Normalize();
  166. aiVector3D xaxis = mUp^mLookAt; xaxis.Normalize();
  167. out.a4 = -(xaxis * mPosition);
  168. out.b4 = -(yaxis * mPosition);
  169. out.c4 = -(zaxis * mPosition);
  170. out.a1 = xaxis.x;
  171. out.a2 = xaxis.y;
  172. out.a3 = xaxis.z;
  173. out.b1 = yaxis.x;
  174. out.b2 = yaxis.y;
  175. out.b3 = yaxis.z;
  176. out.c1 = zaxis.x;
  177. out.c2 = zaxis.y;
  178. out.c3 = zaxis.z;
  179. out.d1 = out.d2 = out.d3 = 0.f;
  180. out.d4 = 1.f;
  181. }
  182. #endif
  183. };
  184. #ifdef __cplusplus
  185. }
  186. #endif
  187. #endif // AI_CAMERA_H_INC