nuclear@0: /* nuclear@0: --------------------------------------------------------------------------- nuclear@0: Open Asset Import Library (assimp) nuclear@0: --------------------------------------------------------------------------- nuclear@0: nuclear@0: Copyright (c) 2006-2018, assimp team nuclear@0: nuclear@0: nuclear@0: nuclear@0: All rights reserved. nuclear@0: nuclear@0: Redistribution and use of this software in source and binary forms, nuclear@0: with or without modification, are permitted provided that the following nuclear@0: conditions are met: nuclear@0: nuclear@0: * Redistributions of source code must retain the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer. nuclear@0: nuclear@0: * Redistributions in binary form must reproduce the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer in the documentation and/or other nuclear@0: materials provided with the distribution. nuclear@0: nuclear@0: * Neither the name of the assimp team, nor the names of its nuclear@0: contributors may be used to endorse or promote products nuclear@0: derived from this software without specific prior nuclear@0: written permission of the assimp team. nuclear@0: nuclear@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS nuclear@0: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT nuclear@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR nuclear@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT nuclear@0: OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, nuclear@0: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT nuclear@0: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, nuclear@0: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY nuclear@0: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT nuclear@0: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE nuclear@0: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. nuclear@0: --------------------------------------------------------------------------- nuclear@0: */ nuclear@0: nuclear@0: /** @file camera.h nuclear@0: * @brief Defines the aiCamera data structure nuclear@0: */ nuclear@0: nuclear@0: #pragma once nuclear@0: #ifndef AI_CAMERA_H_INC nuclear@0: #define AI_CAMERA_H_INC nuclear@0: nuclear@0: #include "types.h" nuclear@0: nuclear@0: #ifdef __cplusplus nuclear@0: extern "C" { nuclear@0: #endif nuclear@0: nuclear@0: // --------------------------------------------------------------------------- nuclear@0: /** Helper structure to describe a virtual camera. nuclear@0: * nuclear@0: * Cameras have a representation in the node graph and can be animated. nuclear@0: * An important aspect is that the camera itself is also part of the nuclear@0: * scenegraph. This means, any values such as the look-at vector are not nuclear@0: * *absolute*, they're relative to the coordinate system defined nuclear@0: * by the node which corresponds to the camera. This allows for camera nuclear@0: * animations. For static cameras parameters like the 'look-at' or 'up' vectors nuclear@0: * are usually specified directly in aiCamera, but beware, they could also nuclear@0: * be encoded in the node transformation. The following (pseudo)code sample nuclear@0: * shows how to do it:

nuclear@0: * @code nuclear@0: * // Get the camera matrix for a camera at a specific time nuclear@0: * // if the node hierarchy for the camera does not contain nuclear@0: * // at least one animated node this is a static computation nuclear@0: * get-camera-matrix (node sceneRoot, camera cam) : matrix nuclear@0: * { nuclear@0: * node cnd = find-node-for-camera(cam) nuclear@0: * matrix cmt = identity() nuclear@0: * nuclear@0: * // as usual - get the absolute camera transformation for this frame nuclear@0: * for each node nd in hierarchy from sceneRoot to cnd nuclear@0: * matrix cur nuclear@0: * if (is-animated(nd)) nuclear@0: * cur = eval-animation(nd) nuclear@0: * else cur = nd->mTransformation; nuclear@0: * cmt = mult-matrices( cmt, cur ) nuclear@0: * end for nuclear@0: * nuclear@0: * // now multiply with the camera's own local transform nuclear@0: * cam = mult-matrices (cam, get-camera-matrix(cmt) ) nuclear@0: * } nuclear@0: * @endcode nuclear@0: * nuclear@0: * @note some file formats (such as 3DS, ASE) export a "target point" - nuclear@0: * the point the camera is looking at (it can even be animated). Assimp nuclear@0: * writes the target point as a subnode of the camera's main node, nuclear@0: * called ".Target". However this is just additional information nuclear@0: * then the transformation tracks of the camera main node make the nuclear@0: * camera already look in the right direction. nuclear@0: * nuclear@0: */ nuclear@0: struct aiCamera nuclear@0: { nuclear@0: /** The name of the camera. nuclear@0: * nuclear@0: * There must be a node in the scenegraph with the same name. nuclear@0: * This node specifies the position of the camera in the scene nuclear@0: * hierarchy and can be animated. nuclear@0: */ nuclear@0: C_STRUCT aiString mName; nuclear@0: nuclear@0: /** Position of the camera relative to the coordinate space nuclear@0: * defined by the corresponding node. nuclear@0: * nuclear@0: * The default value is 0|0|0. nuclear@0: */ nuclear@0: C_STRUCT aiVector3D mPosition; nuclear@0: nuclear@0: nuclear@0: /** 'Up' - vector of the camera coordinate system relative to nuclear@0: * the coordinate space defined by the corresponding node. nuclear@0: * nuclear@0: * The 'right' vector of the camera coordinate system is nuclear@0: * the cross product of the up and lookAt vectors. nuclear@0: * The default value is 0|1|0. The vector nuclear@0: * may be normalized, but it needn't. nuclear@0: */ nuclear@0: C_STRUCT aiVector3D mUp; nuclear@0: nuclear@0: nuclear@0: /** 'LookAt' - vector of the camera coordinate system relative to nuclear@0: * the coordinate space defined by the corresponding node. nuclear@0: * nuclear@0: * This is the viewing direction of the user. nuclear@0: * The default value is 0|0|1. The vector nuclear@0: * may be normalized, but it needn't. nuclear@0: */ nuclear@0: C_STRUCT aiVector3D mLookAt; nuclear@0: nuclear@0: nuclear@0: /** Half horizontal field of view angle, in radians. nuclear@0: * nuclear@0: * The field of view angle is the angle between the center nuclear@0: * line of the screen and the left or right border. nuclear@0: * The default value is 1/4PI. nuclear@0: */ nuclear@0: float mHorizontalFOV; nuclear@0: nuclear@0: /** Distance of the near clipping plane from the camera. nuclear@0: * nuclear@0: * The value may not be 0.f (for arithmetic reasons to prevent nuclear@0: * a division through zero). The default value is 0.1f. nuclear@0: */ nuclear@0: float mClipPlaneNear; nuclear@0: nuclear@0: /** Distance of the far clipping plane from the camera. nuclear@0: * nuclear@0: * The far clipping plane must, of course, be further away than the nuclear@0: * near clipping plane. The default value is 1000.f. The ratio nuclear@0: * between the near and the far plane should not be too nuclear@0: * large (between 1000-10000 should be ok) to avoid floating-point nuclear@0: * inaccuracies which could lead to z-fighting. nuclear@0: */ nuclear@0: float mClipPlaneFar; nuclear@0: nuclear@0: nuclear@0: /** Screen aspect ratio. nuclear@0: * nuclear@0: * This is the ration between the width and the height of the nuclear@0: * screen. Typical values are 4/3, 1/2 or 1/1. This value is nuclear@0: * 0 if the aspect ratio is not defined in the source file. nuclear@0: * 0 is also the default value. nuclear@0: */ nuclear@0: float mAspect; nuclear@0: nuclear@0: #ifdef __cplusplus nuclear@0: nuclear@0: aiCamera() AI_NO_EXCEPT nuclear@0: : mUp (0.f,1.f,0.f) nuclear@0: , mLookAt (0.f,0.f,1.f) nuclear@0: , mHorizontalFOV (0.25f * (float)AI_MATH_PI) nuclear@0: , mClipPlaneNear (0.1f) nuclear@0: , mClipPlaneFar (1000.f) nuclear@0: , mAspect (0.f) nuclear@0: {} nuclear@0: nuclear@0: /** @brief Get a *right-handed* camera matrix from me nuclear@0: * @param out Camera matrix to be filled nuclear@0: */ nuclear@0: void GetCameraMatrix (aiMatrix4x4& out) const nuclear@0: { nuclear@0: /** todo: test ... should work, but i'm not absolutely sure */ nuclear@0: nuclear@0: /** We don't know whether these vectors are already normalized ...*/ nuclear@0: aiVector3D zaxis = mLookAt; zaxis.Normalize(); nuclear@0: aiVector3D yaxis = mUp; yaxis.Normalize(); nuclear@0: aiVector3D xaxis = mUp^mLookAt; xaxis.Normalize(); nuclear@0: nuclear@0: out.a4 = -(xaxis * mPosition); nuclear@0: out.b4 = -(yaxis * mPosition); nuclear@0: out.c4 = -(zaxis * mPosition); nuclear@0: nuclear@0: out.a1 = xaxis.x; nuclear@0: out.a2 = xaxis.y; nuclear@0: out.a3 = xaxis.z; nuclear@0: nuclear@0: out.b1 = yaxis.x; nuclear@0: out.b2 = yaxis.y; nuclear@0: out.b3 = yaxis.z; nuclear@0: nuclear@0: out.c1 = zaxis.x; nuclear@0: out.c2 = zaxis.y; nuclear@0: out.c3 = zaxis.z; nuclear@0: nuclear@0: out.d1 = out.d2 = out.d3 = 0.f; nuclear@0: out.d4 = 1.f; nuclear@0: } nuclear@0: nuclear@0: #endif nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: #ifdef __cplusplus nuclear@0: } nuclear@0: #endif nuclear@0: nuclear@0: #endif // AI_CAMERA_H_INC