17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 09:49:19 +02:00
Files
maszyna/rendering/openglcamera.cppm
maj00r b8f040e6fd propagate template headers transitively, import Console where used
AnimModel.cpp reaches cParser through the simulation core, not a direct
import, so the previous pass missed it; the propagation now follows the
whole import closure. Train.cpp, drivermode.cpp and Globals.cpp call
Console:: inside _WIN32 guards without importing eu07.console - invisible
on Linux, where those blocks are skipped.
2026-09-10 01:41:24 +02:00

103 lines
2.8 KiB
C++

module;
#include <array>
#include <chrono>
#include <cstddef>
#include <deque>
#include <limits>
#include <mutex>
#include <ostream>
#include <sstream>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <vector>
export module eu07.rendering.openglcamera;
import eu07.glm;
import eu07.simcore;
import eu07.rendering.frustum;
export {
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
// simple camera object. paired with 'virtual camera' in the scene
class opengl_camera {
public:
// constructors
opengl_camera() = default;
// methods:
inline
void
update_frustum() { update_frustum( m_projection, m_modelview ); }
inline
void
update_frustum(glm::mat4 frustumtest_proj) {
update_frustum(frustumtest_proj, m_modelview); }
void
update_frustum( glm::mat4 const &Projection, glm::mat4 const &Modelview );
bool
visible( scene::bounding_area const &Area ) const;
bool
visible( TDynamicObject const *Dynamic ) const;
inline
glm::dvec3 const &
position() const { return m_position; }
inline
glm::dvec3 &
position() { return m_position; }
inline
glm::mat4 const &
projection() const { return m_projection; }
inline
glm::mat4 &
projection() { return m_projection; }
inline
glm::mat4 const &
modelview() const { return m_modelview; }
inline
glm::mat4 &
modelview() { return m_modelview; }
inline
std::vector<glm::vec4> &
frustum_points() { return m_frustumpoints; }
// transforms provided set of clip space points to world space
template <class Iterator_>
void
transform_to_world( Iterator_ First, Iterator_ Last ) const {
std::for_each(
First, Last,
[this]( glm::vec4 &point ) {
// transform each point using the cached matrix...
point = this->m_inversetransformation * point;
// ...and scale by transformed w
point = glm::vec4{ glm::vec3{ point } / point.w, 1.f }; } ); }
// debug helper, draws shape of frustum in world space
void
draw( glm::vec3 const &Offset ) const;
private:
// members:
cFrustum m_frustum;
std::vector<glm::vec4> m_frustumpoints; // visualization helper; corners of defined frustum, in world space
glm::dvec3 m_position;
glm::mat4 m_projection;
glm::mat4 m_modelview;
glm::mat4 m_inversetransformation; // cached transformation to world space
};
//---------------------------------------------------------------------------
} // export