miniassimp

view include/miniassimp/camera.h @ 0:879c81d94345

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