qtk/src/qtk/camera3d.h

113 lines
3.7 KiB
C
Raw Normal View History

2021-09-03 16:56:57 +00:00
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
2021-09-03 16:56:57 +00:00
## About: Fly camera class from tutorials followed at trentreed.net ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################*/
#ifndef QTK_CAMERA3D_H
#define QTK_CAMERA3D_H
#include <QDebug>
#include "qtkapi.h"
#include "transform3D.h"
2021-09-03 16:56:57 +00:00
namespace Qtk {
class QTKAPI Camera3D {
2022-11-24 22:26:53 +00:00
public:
2022-11-26 18:24:38 +00:00
/*************************************************************************
* Static Public Constants
2022-11-26 18:24:38 +00:00
************************************************************************/
2022-11-24 22:26:53 +00:00
static const QVector3D LocalForward;
static const QVector3D LocalUp;
static const QVector3D LocalRight;
2022-11-26 18:24:38 +00:00
/*************************************************************************
* Accessors
************************************************************************/
/**
* @return Transform3D associated with this camera.
*/
2022-11-26 18:24:38 +00:00
inline Transform3D & getTransform() { return mTransform; }
2022-11-24 22:26:53 +00:00
/**
* @return Current translation of the camera as a QVector3D.
*/
2022-11-26 18:24:38 +00:00
[[nodiscard]] inline const QVector3D & getTranslation() const {
2022-11-24 22:26:53 +00:00
return mTransform.getTranslation();
}
/**
* @return Current rotation of this camera as a QQuaternion.
*/
2022-11-26 18:24:38 +00:00
[[nodiscard]] inline const QQuaternion & getRotation() const {
2022-11-24 22:26:53 +00:00
return mTransform.getRotation();
}
/**
* @return QVector3D for the forward vector of the camera.
*/
[[nodiscard]] inline QVector3D getForward() const {
2022-11-24 22:26:53 +00:00
return mTransform.getRotation().rotatedVector(LocalForward);
}
/**
* @return QVector3D for the right vector of the camera.
*/
[[nodiscard]] inline QVector3D getRight() const {
2022-11-24 22:26:53 +00:00
return mTransform.getRotation().rotatedVector(LocalRight);
}
/**
* @return QVector3D for the up vector of the camera.
*/
[[nodiscard]] inline QVector3D getUp() const {
2022-11-24 22:26:53 +00:00
return mTransform.getRotation().rotatedVector(LocalUp);
}
2022-11-26 18:24:38 +00:00
/*************************************************************************
* Public Methods
2022-11-26 18:24:38 +00:00
************************************************************************/
/**
* @return World To View matrix for this camera.
*/
const QMatrix4x4 & toMatrix();
2021-09-03 16:56:57 +00:00
private:
2022-11-26 18:24:38 +00:00
/*************************************************************************
* Private Methods
************************************************************************/
2021-09-03 16:56:57 +00:00
#ifndef QT_NO_DATASTREAM
2022-11-24 22:26:53 +00:00
friend QDataStream & operator<<(QDataStream & out, Camera3D & transform);
friend QDataStream & operator>>(QDataStream & in, Camera3D & transform);
2021-09-03 16:56:57 +00:00
#endif
/*************************************************************************
* Private Members
************************************************************************/
Transform3D mTransform;
QMatrix4x4 mWorld;
};
2021-09-03 16:56:57 +00:00
// Qt Streams
#ifndef QT_NO_DATASTREAM
QDataStream & operator<<(QDataStream & out, const Camera3D & transform);
QDataStream & operator>>(QDataStream & in, Camera3D & transform);
2021-09-03 16:56:57 +00:00
#endif
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const Camera3D & transform);
2021-09-03 16:56:57 +00:00
#endif
2022-11-24 22:26:53 +00:00
} // namespace Qtk
Q_DECLARE_TYPEINFO(Qtk::Camera3D, Q_MOVABLE_TYPE);
2021-09-03 16:56:57 +00:00
2022-11-24 22:26:53 +00:00
#endif // QTK_CAMERA3D_H