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