qtk/src/camera3d.cpp

54 lines
2.0 KiB
C++
Raw Normal View History

2021-09-03 16:56:57 +00:00
/*##############################################################################
## Author: Shaun Reed ##
2022-03-06 16:54:05 +00:00
## Legal: All Content (c) 2022 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>
using namespace Qtk;
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);
/*******************************************************************************
* Accessors
******************************************************************************/
// Produces worldToView matrix
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) {
2021-09-03 16:56:57 +00:00
out << transform.transform();
return out;
}
2022-11-24 22:26:53 +00:00
QDataStream & operator>>(QDataStream & in, Camera3D & transform) {
2021-09-03 16:56:57 +00:00
in >> transform.transform();
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";
dbg << "Position: <" << transform.translation().x() << ", "
2022-11-24 22:26:53 +00:00
<< transform.translation().y() << ", " << transform.translation().z()
<< ">\n";
2021-09-03 16:56:57 +00:00
dbg << "Rotation: <" << transform.rotation().x() << ", "
2022-11-24 22:26:53 +00:00
<< transform.rotation().y() << ", " << transform.rotation().z() << " | "
2021-09-03 16:56:57 +00:00
<< transform.rotation().scalar() << ">\n}";
return dbg;
}