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