vrshoot

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