miniassimp

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