mirror of https://github.com/mosra/magnum.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
151 lines
5.5 KiB
151 lines
5.5 KiB
|
14 years ago
|
#ifndef Magnum_SceneGraph_Camera3D_h
|
||
|
|
#define Magnum_SceneGraph_Camera3D_h
|
||
|
|
/*
|
||
|
|
This file is part of Magnum.
|
||
|
|
|
||
|
13 years ago
|
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
|
||
|
|
|
||
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||
|
|
copy of this software and associated documentation files (the "Software"),
|
||
|
|
to deal in the Software without restriction, including without limitation
|
||
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
||
|
|
Software is furnished to do so, subject to the following conditions:
|
||
|
|
|
||
|
|
The above copyright notice and this permission notice shall be included
|
||
|
|
in all copies or substantial portions of the Software.
|
||
|
|
|
||
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||
|
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||
|
|
DEALINGS IN THE SOFTWARE.
|
||
|
14 years ago
|
*/
|
||
|
|
|
||
|
|
/** @file
|
||
|
13 years ago
|
* @brief Class @ref Magnum::SceneGraph::BasicCamera3D, typedef @ref Magnum::SceneGraph::Camera3D
|
||
|
14 years ago
|
*/
|
||
|
|
|
||
|
|
#include "AbstractCamera.h"
|
||
|
|
|
||
|
13 years ago
|
#ifdef CORRADE_TARGET_WINDOWS /* I so HATE windef.h */
|
||
|
13 years ago
|
#undef near
|
||
|
|
#undef far
|
||
|
|
#endif
|
||
|
|
|
||
|
14 years ago
|
namespace Magnum { namespace SceneGraph {
|
||
|
|
|
||
|
|
/**
|
||
|
|
@brief Camera for three-dimensional scenes
|
||
|
|
|
||
|
14 years ago
|
See Drawable documentation for introduction. The camera by default displays
|
||
|
|
OpenGL unit cube `[(-1, -1, -1); (1, 1, 1)]` with orthographic projection and
|
||
|
|
doesn't do any aspect ratio correction. Common setup example:
|
||
|
|
@code
|
||
|
13 years ago
|
SceneGraph::Camera3D camera(&cameraObject);
|
||
|
|
camera.setPerspective({}, 0.001f, 100.0f)
|
||
|
|
.setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::Extend);
|
||
|
14 years ago
|
@endcode
|
||
|
14 years ago
|
|
||
|
|
@section Camera3D-explicit-specializations Explicit template specializations
|
||
|
|
|
||
|
13 years ago
|
The following specialization are explicitly compiled into @ref SceneGraph
|
||
|
|
library. For other specializations (e.g. using @ref Double type) you have to
|
||
|
|
use @ref Camera3D.hpp implementation file to avoid linker errors. See also
|
||
|
|
relevant section in @ref AbstractCamera-explicit-specializations "AbstractCamera"
|
||
|
|
class documentation or @ref compilation-speedup-hpp for more information.
|
||
|
14 years ago
|
|
||
|
13 years ago
|
- @ref Camera3D
|
||
|
14 years ago
|
|
||
|
13 years ago
|
@see @ref scenegraph, @ref Camera3D, @ref BasicCamera2D, @ref Drawable,
|
||
|
|
@ref DrawableGroup
|
||
|
14 years ago
|
*/
|
||
|
13 years ago
|
template<class T> class BasicCamera3D: public AbstractCamera<3, T> {
|
||
|
14 years ago
|
public:
|
||
|
|
/**
|
||
|
|
* @brief Constructor
|
||
|
|
* @param object %Object holding this feature
|
||
|
|
*/
|
||
|
13 years ago
|
explicit BasicCamera3D(AbstractObject<3, T>& object);
|
||
|
|
|
||
|
|
#ifndef DOXYGEN_GENERATING_OUTPUT
|
||
|
|
/* This is here to avoid ambiguity with deleted copy constructor when
|
||
|
|
passing `*this` from class subclassing both BasicCamera3D and
|
||
|
|
AbstractObject */
|
||
|
13 years ago
|
template<class U, class = typename std::enable_if<std::is_base_of<AbstractObject<3, T>, U>::value>::type> BasicCamera3D(U& object):
|
||
|
|
#ifndef CORRADE_GCC46_COMPATIBILITY
|
||
|
|
BasicCamera3D(static_cast<AbstractObject<3, T>&>(object)) {}
|
||
|
|
#else
|
||
|
|
AbstractCamera<3, T>(static_cast<AbstractObject<3, T>&>(object)) {}
|
||
|
|
#endif
|
||
|
13 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
|
/**
|
||
|
|
* @brief Set orthographic projection
|
||
|
14 years ago
|
* @param size Size of the view
|
||
|
|
* @param near Near clipping plane
|
||
|
|
* @param far Far clipping plane
|
||
|
13 years ago
|
* @return Reference to self (for method chaining)
|
||
|
14 years ago
|
*
|
||
|
13 years ago
|
* @see @ref setPerspective(), @ref Matrix4::orthographicProjection()
|
||
|
14 years ago
|
*/
|
||
|
13 years ago
|
BasicCamera3D<T>& setOrthographic(const Math::Vector2<T>& size, T near, T far);
|
||
|
14 years ago
|
|
||
|
|
/**
|
||
|
|
* @brief Set perspective projection
|
||
|
14 years ago
|
* @param size Size of near clipping plane
|
||
|
|
* @param near Near clipping plane
|
||
|
|
* @param far Far clipping plane
|
||
|
13 years ago
|
* @return Reference to self (for method chaining)
|
||
|
14 years ago
|
*
|
||
|
13 years ago
|
* @see @ref setOrthographic(), @ref Matrix4::perspectiveProjection()
|
||
|
14 years ago
|
*/
|
||
|
13 years ago
|
BasicCamera3D<T>& setPerspective(const Math::Vector2<T>& size, T near, T far);
|
||
|
14 years ago
|
|
||
|
|
/**
|
||
|
|
* @brief Set perspective projection
|
||
|
13 years ago
|
* @param fov Field of view angle (horizontal)
|
||
|
14 years ago
|
* @param aspectRatio Aspect ratio
|
||
|
|
* @param near Near clipping plane
|
||
|
|
* @param far Far clipping plane
|
||
|
13 years ago
|
* @return Reference to self (for method chaining)
|
||
|
14 years ago
|
*
|
||
|
13 years ago
|
* @see @ref setOrthographic(), @ref Matrix4::perspectiveProjection()
|
||
|
14 years ago
|
*/
|
||
|
13 years ago
|
BasicCamera3D<T>& setPerspective(Math::Rad<T> fov, T aspectRatio, T near, T far);
|
||
|
14 years ago
|
|
||
|
|
/** @brief Near clipping plane */
|
||
|
13 years ago
|
T near() const { return _near; }
|
||
|
14 years ago
|
|
||
|
|
/** @brief Far clipping plane */
|
||
|
13 years ago
|
T far() const { return _far; }
|
||
|
14 years ago
|
|
||
|
|
/* Overloads to remove WTF-factor from method chaining order */
|
||
|
|
#ifndef DOXYGEN_GENERATING_OUTPUT
|
||
|
13 years ago
|
BasicCamera3D<T>& setAspectRatioPolicy(AspectRatioPolicy policy) {
|
||
|
13 years ago
|
AbstractCamera<3, T>::setAspectRatioPolicy(policy);
|
||
|
13 years ago
|
return *this;
|
||
|
14 years ago
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
private:
|
||
|
|
T _near, _far;
|
||
|
|
};
|
||
|
|
|
||
|
13 years ago
|
/**
|
||
|
|
@brief Camera for three-dimensional float scenes
|
||
|
|
|
||
|
|
@see @ref Camera2D
|
||
|
|
*/
|
||
|
|
typedef BasicCamera3D<Float> Camera3D;
|
||
|
|
|
||
|
13 years ago
|
#ifdef CORRADE_TARGET_WINDOWS
|
||
|
13 years ago
|
extern template class MAGNUM_SCENEGRAPH_EXPORT BasicCamera3D<Float>;
|
||
|
|
#endif
|
||
|
|
|
||
|
14 years ago
|
}}
|
||
|
|
|
||
|
|
#endif
|