qtk/src/qtk/camera3d.cpp

57 lines
2.2 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 ##
##############################################################################*/
#include "camera3d.h"
2021-09-03 16:56:57 +00:00
using namespace Qtk;
2021-09-03 16:56:57 +00:00
/*******************************************************************************
* Static Public Constants
******************************************************************************/
2021-09-03 16:56:57 +00:00
const QVector3D Camera3D::LocalForward(0.0f, 0.0f, -1.0f);
const QVector3D Camera3D::LocalUp(0.0f, 1.0f, 0.0f);
const QVector3D Camera3D::LocalRight(1.0f, 0.0f, 0.0f);
/*******************************************************************************
* Public Methods
2021-09-03 16:56:57 +00:00
******************************************************************************/
2022-11-24 22:26:53 +00:00
const QMatrix4x4 & Camera3D::toMatrix() {
2021-09-03 16:56:57 +00:00
mWorld.setToIdentity();
2022-03-06 16:54:05 +00:00
// Qt6 renamed QMatrix4x4::conjugate() to conjugated()
2022-11-24 22:26:53 +00:00
mWorld.rotate(mTransform.getRotation().conjugated());
mWorld.translate(-mTransform.getTranslation());
2021-09-03 16:56:57 +00:00
return mWorld;
}
/*******************************************************************************
* Qt Streams
******************************************************************************/
2022-11-24 22:26:53 +00:00
QDataStream & operator<<(QDataStream & out, Camera3D & transform) {
2022-11-26 18:24:38 +00:00
out << transform.getTransform();
2021-09-03 16:56:57 +00:00
return out;
}
2022-11-24 22:26:53 +00:00
QDataStream & operator>>(QDataStream & in, Camera3D & transform) {
2022-11-26 18:24:38 +00:00
in >> transform.getTransform();
2021-09-03 16:56:57 +00:00
return in;
}
2022-11-24 22:26:53 +00:00
QDebug operator<<(QDebug dbg, const Camera3D & transform) {
2021-09-03 16:56:57 +00:00
dbg << "Camera3D\n{\n";
2022-11-26 18:24:38 +00:00
dbg << "Position: <" << transform.getTranslation().x() << ", "
<< transform.getTranslation().y() << ", "
<< transform.getTranslation().z() << ">\n";
dbg << "Rotation: <" << transform.getRotation().x() << ", "
<< transform.getRotation().y() << ", " << transform.getRotation().z()
<< " | " << transform.getRotation().scalar() << ">\n}";
2021-09-03 16:56:57 +00:00
return dbg;
}