vrshoot

view libs/assimp/assimp/camera.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
6 Copyright (c) 2006-2012, assimp team
8 All rights reserved.
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:
14 * Redistributions of source code must retain the above
15 copyright notice, this list of conditions and the
16 following disclaimer.
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.
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.
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 */
42 /** @file camera.h
43 * @brief Defines the aiCamera data structure
44 */
46 #ifndef AI_CAMERA_H_INC
47 #define AI_CAMERA_H_INC
49 #include "types.h"
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
55 // ---------------------------------------------------------------------------
56 /** Helper structure to describe a virtual camera.
57 *
58 * Cameras have a representation in the node graph and can be animated.
59 * An important aspect is that the camera itself is also part of the
60 * scenegraph. This means, any values such as the look-at vector are not
61 * *absolute*, they're <b>relative</b> to the coordinate system defined
62 * by the node which corresponds to the camera. This allows for camera
63 * animations. For static cameras parameters like the 'look-at' or 'up' vectors
64 * are usually specified directly in aiCamera, but beware, they could also
65 * be encoded in the node transformation. The following (pseudo)code sample
66 * shows how to do it: <br><br>
67 * @code
68 * // Get the camera matrix for a camera at a specific time
69 * // if the node hierarchy for the camera does not contain
70 * // at least one animated node this is a static computation
71 * get-camera-matrix (node sceneRoot, camera cam) : matrix
72 * {
73 * node cnd = find-node-for-camera(cam)
74 * matrix cmt = identity()
75 *
76 * // as usual - get the absolute camera transformation for this frame
77 * for each node nd in hierarchy from sceneRoot to cnd
78 * matrix cur
79 * if (is-animated(nd))
80 * cur = eval-animation(nd)
81 * else cur = nd->mTransformation;
82 * cmt = mult-matrices( cmt, cur )
83 * end for
84 *
85 * // now multiply with the camera's own local transform
86 * cam = mult-matrices (cam, get-camera-matrix(cmt) )
87 * }
88 * @endcode
89 *
90 * @note some file formats (such as 3DS, ASE) export a "target point" -
91 * the point the camera is looking at (it can even be animated). Assimp
92 * writes the target point as a subnode of the camera's main node,
93 * called "<camName>.Target". However this is just additional information
94 * then the transformation tracks of the camera main node make the
95 * camera already look in the right direction.
96 *
97 */
98 struct aiCamera
99 {
100 /** The name of the camera.
101 *
102 * There must be a node in the scenegraph with the same name.
103 * This node specifies the position of the camera in the scene
104 * hierarchy and can be animated.
105 */
106 C_STRUCT aiString mName;
108 /** Position of the camera relative to the coordinate space
109 * defined by the corresponding node.
110 *
111 * The default value is 0|0|0.
112 */
113 C_STRUCT aiVector3D mPosition;
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;
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;
137 /** Half horizontal field of view angle, in radians.
138 *
139 * The field of view angle is the angle between the center
140 * line of the screen and the left or right border.
141 * The default value is 1/4PI.
142 */
143 float mHorizontalFOV;
145 /** Distance of the near clipping plane from the camera.
146 *
147 * The value may not be 0.f (for arithmetic reasons to prevent
148 * a division through zero). The default value is 0.1f.
149 */
150 float mClipPlaneNear;
152 /** Distance of the far clipping plane from the camera.
153 *
154 * The far clipping plane must, of course, be further away than the
155 * near clipping plane. The default value is 1000.f. The ratio
156 * between the near and the far plane should not be too
157 * large (between 1000-10000 should be ok) to avoid floating-point
158 * inaccuracies which could lead to z-fighting.
159 */
160 float mClipPlaneFar;
163 /** Screen aspect ratio.
164 *
165 * This is the ration between the width and the height of the
166 * screen. Typical values are 4/3, 1/2 or 1/1. This value is
167 * 0 if the aspect ratio is not defined in the source file.
168 * 0 is also the default value.
169 */
170 float mAspect;
172 #ifdef __cplusplus
174 aiCamera()
175 : mUp (0.f,1.f,0.f)
176 , mLookAt (0.f,0.f,1.f)
177 , mHorizontalFOV (0.25f * (float)AI_MATH_PI)
178 , mClipPlaneNear (0.1f)
179 , mClipPlaneFar (1000.f)
180 , mAspect (0.f)
181 {}
183 /** @brief Get a *right-handed* camera matrix from me
184 * @param out Camera matrix to be filled
185 */
186 void GetCameraMatrix (aiMatrix4x4& out) const
187 {
188 /** todo: test ... should work, but i'm not absolutely sure */
190 /** We don't know whether these vectors are already normalized ...*/
191 aiVector3D zaxis = mLookAt; zaxis.Normalize();
192 aiVector3D yaxis = mUp; yaxis.Normalize();
193 aiVector3D xaxis = mUp^mLookAt; xaxis.Normalize();
195 out.a4 = -(xaxis * mPosition);
196 out.b4 = -(yaxis * mPosition);
197 out.c4 = -(zaxis * mPosition);
199 out.a1 = xaxis.x;
200 out.a2 = xaxis.y;
201 out.a3 = xaxis.z;
203 out.b1 = yaxis.x;
204 out.b2 = yaxis.y;
205 out.b3 = yaxis.z;
207 out.c1 = zaxis.x;
208 out.c2 = zaxis.y;
209 out.c3 = zaxis.z;
211 out.d1 = out.d2 = out.d3 = 0.f;
212 out.d4 = 1.f;
213 }
215 #endif
216 };
219 #ifdef __cplusplus
220 }
221 #endif
223 #endif // AI_CAMERA_H_INC