vrshoot
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/assimp/camera.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,223 @@ 1.4 +/* 1.5 +--------------------------------------------------------------------------- 1.6 +Open Asset Import Library (assimp) 1.7 +--------------------------------------------------------------------------- 1.8 + 1.9 +Copyright (c) 2006-2012, assimp team 1.10 + 1.11 +All rights reserved. 1.12 + 1.13 +Redistribution and use of this software in source and binary forms, 1.14 +with or without modification, are permitted provided that the following 1.15 +conditions are met: 1.16 + 1.17 +* Redistributions of source code must retain the above 1.18 + copyright notice, this list of conditions and the 1.19 + following disclaimer. 1.20 + 1.21 +* Redistributions in binary form must reproduce the above 1.22 + copyright notice, this list of conditions and the 1.23 + following disclaimer in the documentation and/or other 1.24 + materials provided with the distribution. 1.25 + 1.26 +* Neither the name of the assimp team, nor the names of its 1.27 + contributors may be used to endorse or promote products 1.28 + derived from this software without specific prior 1.29 + written permission of the assimp team. 1.30 + 1.31 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.32 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.33 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.34 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.35 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.36 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.37 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.38 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.39 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.40 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.41 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.42 +--------------------------------------------------------------------------- 1.43 +*/ 1.44 + 1.45 +/** @file camera.h 1.46 + * @brief Defines the aiCamera data structure 1.47 + */ 1.48 + 1.49 +#ifndef AI_CAMERA_H_INC 1.50 +#define AI_CAMERA_H_INC 1.51 + 1.52 +#include "types.h" 1.53 + 1.54 +#ifdef __cplusplus 1.55 +extern "C" { 1.56 +#endif 1.57 + 1.58 +// --------------------------------------------------------------------------- 1.59 +/** Helper structure to describe a virtual camera. 1.60 + * 1.61 + * Cameras have a representation in the node graph and can be animated. 1.62 + * An important aspect is that the camera itself is also part of the 1.63 + * scenegraph. This means, any values such as the look-at vector are not 1.64 + * *absolute*, they're <b>relative</b> to the coordinate system defined 1.65 + * by the node which corresponds to the camera. This allows for camera 1.66 + * animations. For static cameras parameters like the 'look-at' or 'up' vectors 1.67 + * are usually specified directly in aiCamera, but beware, they could also 1.68 + * be encoded in the node transformation. The following (pseudo)code sample 1.69 + * shows how to do it: <br><br> 1.70 + * @code 1.71 + * // Get the camera matrix for a camera at a specific time 1.72 + * // if the node hierarchy for the camera does not contain 1.73 + * // at least one animated node this is a static computation 1.74 + * get-camera-matrix (node sceneRoot, camera cam) : matrix 1.75 + * { 1.76 + * node cnd = find-node-for-camera(cam) 1.77 + * matrix cmt = identity() 1.78 + * 1.79 + * // as usual - get the absolute camera transformation for this frame 1.80 + * for each node nd in hierarchy from sceneRoot to cnd 1.81 + * matrix cur 1.82 + * if (is-animated(nd)) 1.83 + * cur = eval-animation(nd) 1.84 + * else cur = nd->mTransformation; 1.85 + * cmt = mult-matrices( cmt, cur ) 1.86 + * end for 1.87 + * 1.88 + * // now multiply with the camera's own local transform 1.89 + * cam = mult-matrices (cam, get-camera-matrix(cmt) ) 1.90 + * } 1.91 + * @endcode 1.92 + * 1.93 + * @note some file formats (such as 3DS, ASE) export a "target point" - 1.94 + * the point the camera is looking at (it can even be animated). Assimp 1.95 + * writes the target point as a subnode of the camera's main node, 1.96 + * called "<camName>.Target". However this is just additional information 1.97 + * then the transformation tracks of the camera main node make the 1.98 + * camera already look in the right direction. 1.99 + * 1.100 +*/ 1.101 +struct aiCamera 1.102 +{ 1.103 + /** The name of the camera. 1.104 + * 1.105 + * There must be a node in the scenegraph with the same name. 1.106 + * This node specifies the position of the camera in the scene 1.107 + * hierarchy and can be animated. 1.108 + */ 1.109 + C_STRUCT aiString mName; 1.110 + 1.111 + /** Position of the camera relative to the coordinate space 1.112 + * defined by the corresponding node. 1.113 + * 1.114 + * The default value is 0|0|0. 1.115 + */ 1.116 + C_STRUCT aiVector3D mPosition; 1.117 + 1.118 + 1.119 + /** 'Up' - vector of the camera coordinate system relative to 1.120 + * the coordinate space defined by the corresponding node. 1.121 + * 1.122 + * The 'right' vector of the camera coordinate system is 1.123 + * the cross product of the up and lookAt vectors. 1.124 + * The default value is 0|1|0. The vector 1.125 + * may be normalized, but it needn't. 1.126 + */ 1.127 + C_STRUCT aiVector3D mUp; 1.128 + 1.129 + 1.130 + /** 'LookAt' - vector of the camera coordinate system relative to 1.131 + * the coordinate space defined by the corresponding node. 1.132 + * 1.133 + * This is the viewing direction of the user. 1.134 + * The default value is 0|0|1. The vector 1.135 + * may be normalized, but it needn't. 1.136 + */ 1.137 + C_STRUCT aiVector3D mLookAt; 1.138 + 1.139 + 1.140 + /** Half horizontal field of view angle, in radians. 1.141 + * 1.142 + * The field of view angle is the angle between the center 1.143 + * line of the screen and the left or right border. 1.144 + * The default value is 1/4PI. 1.145 + */ 1.146 + float mHorizontalFOV; 1.147 + 1.148 + /** Distance of the near clipping plane from the camera. 1.149 + * 1.150 + * The value may not be 0.f (for arithmetic reasons to prevent 1.151 + * a division through zero). The default value is 0.1f. 1.152 + */ 1.153 + float mClipPlaneNear; 1.154 + 1.155 + /** Distance of the far clipping plane from the camera. 1.156 + * 1.157 + * The far clipping plane must, of course, be further away than the 1.158 + * near clipping plane. The default value is 1000.f. The ratio 1.159 + * between the near and the far plane should not be too 1.160 + * large (between 1000-10000 should be ok) to avoid floating-point 1.161 + * inaccuracies which could lead to z-fighting. 1.162 + */ 1.163 + float mClipPlaneFar; 1.164 + 1.165 + 1.166 + /** Screen aspect ratio. 1.167 + * 1.168 + * This is the ration between the width and the height of the 1.169 + * screen. Typical values are 4/3, 1/2 or 1/1. This value is 1.170 + * 0 if the aspect ratio is not defined in the source file. 1.171 + * 0 is also the default value. 1.172 + */ 1.173 + float mAspect; 1.174 + 1.175 +#ifdef __cplusplus 1.176 + 1.177 + aiCamera() 1.178 + : mUp (0.f,1.f,0.f) 1.179 + , mLookAt (0.f,0.f,1.f) 1.180 + , mHorizontalFOV (0.25f * (float)AI_MATH_PI) 1.181 + , mClipPlaneNear (0.1f) 1.182 + , mClipPlaneFar (1000.f) 1.183 + , mAspect (0.f) 1.184 + {} 1.185 + 1.186 + /** @brief Get a *right-handed* camera matrix from me 1.187 + * @param out Camera matrix to be filled 1.188 + */ 1.189 + void GetCameraMatrix (aiMatrix4x4& out) const 1.190 + { 1.191 + /** todo: test ... should work, but i'm not absolutely sure */ 1.192 + 1.193 + /** We don't know whether these vectors are already normalized ...*/ 1.194 + aiVector3D zaxis = mLookAt; zaxis.Normalize(); 1.195 + aiVector3D yaxis = mUp; yaxis.Normalize(); 1.196 + aiVector3D xaxis = mUp^mLookAt; xaxis.Normalize(); 1.197 + 1.198 + out.a4 = -(xaxis * mPosition); 1.199 + out.b4 = -(yaxis * mPosition); 1.200 + out.c4 = -(zaxis * mPosition); 1.201 + 1.202 + out.a1 = xaxis.x; 1.203 + out.a2 = xaxis.y; 1.204 + out.a3 = xaxis.z; 1.205 + 1.206 + out.b1 = yaxis.x; 1.207 + out.b2 = yaxis.y; 1.208 + out.b3 = yaxis.z; 1.209 + 1.210 + out.c1 = zaxis.x; 1.211 + out.c2 = zaxis.y; 1.212 + out.c3 = zaxis.z; 1.213 + 1.214 + out.d1 = out.d2 = out.d3 = 0.f; 1.215 + out.d4 = 1.f; 1.216 + } 1.217 + 1.218 +#endif 1.219 +}; 1.220 + 1.221 + 1.222 +#ifdef __cplusplus 1.223 +} 1.224 +#endif 1.225 + 1.226 +#endif // AI_CAMERA_H_INC