mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-20 09:09:19 +02:00
Merge pull request #97 from docentYT/migrate-from-dumb3d-to-glm
Migrate from dumb3d to glm
This commit is contained in:
@@ -10,7 +10,6 @@ http://mozilla.org/MPL/2.0/.
|
||||
#pragma once
|
||||
|
||||
#include "utilities/Float3d.h"
|
||||
#include "utilities/dumb3d.h"
|
||||
|
||||
inline std::vector<glm::vec4> const ndcfrustumshapepoints //
|
||||
{
|
||||
@@ -47,9 +46,6 @@ public:
|
||||
inline
|
||||
bool
|
||||
point_inside( float3 const &Point ) const { return point_inside( Point.x, Point.y, Point.z ); }
|
||||
inline
|
||||
bool
|
||||
point_inside( Math3D::vector3 const &Point ) const { return point_inside( static_cast<float>( Point.x ), static_cast<float>( Point.y ), static_cast<float>( Point.z ) ); }
|
||||
bool
|
||||
point_inside( float const X, float const Y, float const Z ) const;
|
||||
// tests if the sphere is in frustum, returns the distance between origin and sphere centre
|
||||
@@ -62,9 +58,6 @@ public:
|
||||
inline
|
||||
float
|
||||
sphere_inside( float3 const &Center, float const Radius ) const { return sphere_inside( Center.x, Center.y, Center.z, Radius ); }
|
||||
inline
|
||||
float
|
||||
sphere_inside( Math3D::vector3 const &Center, float const Radius ) const { return sphere_inside( static_cast<float>( Center.x ), static_cast<float>( Center.y ), static_cast<float>( Center.z ), Radius ); }
|
||||
float
|
||||
sphere_inside( float const X, float const Y, float const Z, float const Radius ) const;
|
||||
// returns true if specified cube is inside of the frustum. Size = half of the length
|
||||
@@ -74,9 +67,6 @@ public:
|
||||
inline
|
||||
bool
|
||||
cube_inside( float3 const &Center, float const Size ) const { return cube_inside( Center.x, Center.y, Center.z, Size ); }
|
||||
inline
|
||||
bool
|
||||
cube_inside( Math3D::vector3 const &Center, float const Size ) const { return cube_inside( static_cast<float>( Center.x ), static_cast<float>( Center.y ), static_cast<float>( Center.z ), Size ); }
|
||||
bool
|
||||
cube_inside( float const X, float const Y, float const Z, float const Size ) const;
|
||||
|
||||
|
||||
@@ -46,12 +46,12 @@ light_array::update() {
|
||||
if( light.index == end::front ) {
|
||||
// front light set
|
||||
light.position = light.owner->GetPosition() + ( light.owner->VectorFront() * ( std::max( 0.0, light.owner->GetLength() * 0.5 - 2.0 ) ) );// +( light.owner->VectorUp() * 0.25 );
|
||||
light.direction = glm::make_vec3( light.owner->VectorFront().getArray() );
|
||||
light.direction = glm::make_vec3( glm::value_ptr(light.owner->VectorFront()) ); // TODO: It is needed to get value_ptr and then make_vec3?
|
||||
}
|
||||
else {
|
||||
// rear light set
|
||||
light.position = light.owner->GetPosition() - ( light.owner->VectorFront() * ( std::max( 0.0, light.owner->GetLength() * 0.5 - 2.0 ) ) );// +( light.owner->VectorUp() * 0.25 );
|
||||
light.direction = glm::make_vec3( light.owner->VectorFront().getArray() );
|
||||
light.direction = glm::make_vec3( glm::value_ptr(light.owner->VectorFront()) ); // TODO: It is needed to get value_ptr and then make_vec3?
|
||||
light.direction.x = -light.direction.x;
|
||||
light.direction.z = -light.direction.z;
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
//#define EU07_DEBUG_OPENGL
|
||||
|
||||
int const EU07_PICKBUFFERSIZE{ 1024 }; // size of (square) textures bound with the pick framebuffer
|
||||
int const EU07_REFLECTIONFIDELITYOFFSET { 250 }; // artificial increase of range for reflection pass detail reduction
|
||||
int constexpr EU07_PICKBUFFERSIZE{ 1024 }; // size of (square) textures bound with the pick framebuffer
|
||||
int constexpr EU07_REFLECTIONFIDELITYOFFSET { 250 }; // artificial increase of range for reflection pass detail reduction
|
||||
|
||||
void GLAPIENTRY
|
||||
ErrorCallback( GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam ) {
|
||||
@@ -1275,7 +1275,7 @@ bool opengl33_renderer::Render_lowpoly( TDynamicObject *Dynamic, float const Squ
|
||||
|
||||
::glPushMatrix();
|
||||
::glTranslated( originoffset.x, originoffset.y, originoffset.z );
|
||||
::glMultMatrixd( Dynamic->mMatrix.readArray() );
|
||||
::glMultMatrixd( glm::value_ptr(Dynamic->mMatrix) );
|
||||
}
|
||||
// HACK: reduce light level for vehicle interior if there's strong global lighting source
|
||||
if( false == Alpha ) {
|
||||
@@ -1338,7 +1338,7 @@ bool opengl33_renderer::Render_coupler_adapter( TDynamicObject *Dynamic, float c
|
||||
|
||||
if( Dynamic->m_coupleradapters[ End ] == nullptr ) { return false; }
|
||||
|
||||
auto const position { Math3D::vector3 {
|
||||
auto const position { glm::dvec3 {
|
||||
0.f,
|
||||
Dynamic->MoverParameters->Couplers[ End ].adapter_height,
|
||||
( Dynamic->MoverParameters->Couplers[ End ].adapter_length + Dynamic->MoverParameters->Dim.L * 0.5 ) * ( End == end::front ? 1 : -1 ) } };
|
||||
@@ -1365,7 +1365,8 @@ bool opengl33_renderer::Render_reflections(viewport_config &vp)
|
||||
|
||||
auto const timestamp{ Timer::GetRenderTime() };
|
||||
if( ( timestamp - m_environmentupdatetime < Global.reflectiontune.update_interval )
|
||||
&& ( glm::length( m_renderpass.pass_camera.position() - m_environmentupdatelocation ) < 1000.0 ) ) {
|
||||
&& ( glm::length2( m_renderpass.pass_camera.position() - m_environmentupdatelocation ) < sq(1000.0)) ) // length2 is better than length for comparing because it does not require sqrt function
|
||||
{
|
||||
// run update every 5+ mins of simulation time, or at least 1km from the last location
|
||||
return false;
|
||||
}
|
||||
@@ -2753,7 +2754,7 @@ void opengl33_renderer::Render(scene::shape_node const &Shape, bool const Ignore
|
||||
case rendermode::shadows:
|
||||
{
|
||||
// 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees
|
||||
distancesquared = Math3D::SquareMagnitude((data.area.center - m_renderpass.viewport_camera.position()) / (double)Global.ZoomFactor) / Global.fDistanceFactor;
|
||||
distancesquared = glm::length2((data.area.center - m_renderpass.viewport_camera.position()) / (double)Global.ZoomFactor) / Global.fDistanceFactor;
|
||||
break;
|
||||
}
|
||||
case rendermode::reflections:
|
||||
@@ -2761,7 +2762,7 @@ void opengl33_renderer::Render(scene::shape_node const &Shape, bool const Ignore
|
||||
// reflection mode draws simplified version of the shapes, by artificially increasing view range
|
||||
distancesquared =
|
||||
// TBD, TODO: bind offset value with setting variable?
|
||||
( EU07_REFLECTIONFIDELITYOFFSET * EU07_REFLECTIONFIDELITYOFFSET )
|
||||
sq(EU07_REFLECTIONFIDELITYOFFSET)
|
||||
+ glm::length2( ( data.area.center - m_renderpass.pass_camera.position() ) );
|
||||
/*
|
||||
// TBD: take into account distance multipliers?
|
||||
@@ -2835,7 +2836,7 @@ void opengl33_renderer::Render(TAnimModel *Instance)
|
||||
return;
|
||||
}
|
||||
// TBD, TODO: bind offset value with setting variable?
|
||||
distancesquared += ( EU07_REFLECTIONFIDELITYOFFSET * EU07_REFLECTIONFIDELITYOFFSET );
|
||||
distancesquared += sq(EU07_REFLECTIONFIDELITYOFFSET);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -2850,7 +2851,7 @@ void opengl33_renderer::Render(TAnimModel *Instance)
|
||||
}
|
||||
// crude way to reject early items too far to affect the output (mostly relevant for shadow passes)
|
||||
auto const drawdistancethreshold{ m_renderpass.draw_range + 250 };
|
||||
if( distancesquared > drawdistancethreshold * drawdistancethreshold ) {
|
||||
if( distancesquared > sq(drawdistancethreshold) ) {
|
||||
return;
|
||||
}
|
||||
// second stage visibility cull, reject modelstoo far away to be noticeable
|
||||
@@ -2928,7 +2929,7 @@ bool opengl33_renderer::Render(TDynamicObject *Dynamic)
|
||||
}
|
||||
// TBD, TODO: bind offset value with setting variable?
|
||||
// NOTE: combined 'squared' distance doesn't equal actual squared (distance + offset) but, eh
|
||||
squaredistance += ( EU07_REFLECTIONFIDELITYOFFSET * EU07_REFLECTIONFIDELITYOFFSET );
|
||||
squaredistance += sq(EU07_REFLECTIONFIDELITYOFFSET);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -2940,7 +2941,7 @@ bool opengl33_renderer::Render(TDynamicObject *Dynamic)
|
||||
}
|
||||
// crude way to reject early items too far to affect the output (mostly relevant for shadow and reflection passes)
|
||||
auto const drawdistancethreshold{ m_renderpass.draw_range + 250 };
|
||||
if( squaredistance > drawdistancethreshold * drawdistancethreshold ) {
|
||||
if( squaredistance > sq(drawdistancethreshold) ) {
|
||||
return false;
|
||||
}
|
||||
// second stage visibility cull, reject vehicles too far away to be noticeable
|
||||
@@ -2962,7 +2963,7 @@ bool opengl33_renderer::Render(TDynamicObject *Dynamic)
|
||||
|
||||
::glPushMatrix();
|
||||
::glTranslated(originoffset.x, originoffset.y, originoffset.z);
|
||||
::glMultMatrixd(Dynamic->mMatrix.getArray());
|
||||
::glMultMatrixd(glm::value_ptr(Dynamic->mMatrix));
|
||||
|
||||
switch (m_renderpass.draw_mode)
|
||||
{
|
||||
@@ -3084,7 +3085,7 @@ bool opengl33_renderer::Render_cab(TDynamicObject const *Dynamic, float const Li
|
||||
|
||||
auto const originoffset = Dynamic->GetPosition() - m_renderpass.pass_camera.position();
|
||||
::glTranslated(originoffset.x, originoffset.y, originoffset.z);
|
||||
::glMultMatrixd(Dynamic->mMatrix.readArray());
|
||||
::glMultMatrixd(glm::value_ptr(Dynamic->mMatrix));
|
||||
|
||||
switch (m_renderpass.draw_mode)
|
||||
{
|
||||
@@ -3177,17 +3178,16 @@ bool opengl33_renderer::Render(TModel3d *Model, material_data const *Material, f
|
||||
return true;
|
||||
}
|
||||
|
||||
bool opengl33_renderer::Render(TModel3d *Model, material_data const *Material, float const Squaredistance, Math3D::vector3 const &Position, glm::vec3 const &A)
|
||||
bool opengl33_renderer::Render(TModel3d *Model, material_data const *Material, float const Squaredistance, glm::dvec3 const &Position, glm::vec3 const &Angle)
|
||||
{
|
||||
Math3D::vector3 Angle(A);
|
||||
::glPushMatrix();
|
||||
::glTranslated(Position.x, Position.y, Position.z);
|
||||
if (Angle.y != 0.0)
|
||||
::glRotated(Angle.y, 0.0, 1.0, 0.0);
|
||||
::glRotated(Angle.y, 0.f, 1.f, 0.f);
|
||||
if (Angle.x != 0.0)
|
||||
::glRotated(Angle.x, 1.0, 0.0, 0.0);
|
||||
::glRotated(Angle.x, 1.f, 0.f, 0.f);
|
||||
if (Angle.z != 0.0)
|
||||
::glRotated(Angle.z, 0.0, 0.0, 1.0);
|
||||
::glRotated(Angle.z, 0.f, 0.f, 1.f);
|
||||
|
||||
auto const result = Render(Model, Material, Squaredistance);
|
||||
|
||||
@@ -3851,7 +3851,7 @@ void opengl33_renderer::Render_Alpha(TAnimModel *Instance)
|
||||
}
|
||||
// crude way to reject early items too far to affect the output (mostly relevant for shadow passes)
|
||||
auto const drawdistancethreshold{ m_renderpass.draw_range + 250 };
|
||||
if( distancesquared > drawdistancethreshold * drawdistancethreshold ) {
|
||||
if( distancesquared > sq(drawdistancethreshold) ) {
|
||||
return;
|
||||
}
|
||||
// second stage visibility cull, reject modelstoo far away to be noticeable
|
||||
@@ -3980,7 +3980,7 @@ bool opengl33_renderer::Render_Alpha(TDynamicObject *Dynamic)
|
||||
::glPushMatrix();
|
||||
|
||||
::glTranslated(originoffset.x, originoffset.y, originoffset.z);
|
||||
::glMultMatrixd(Dynamic->mMatrix.getArray());
|
||||
::glMultMatrixd(glm::value_ptr(Dynamic->mMatrix));
|
||||
|
||||
if (Dynamic->fShade > 0.0f)
|
||||
{
|
||||
@@ -4052,17 +4052,16 @@ bool opengl33_renderer::Render_Alpha(TModel3d *Model, material_data const *Mater
|
||||
return true;
|
||||
}
|
||||
|
||||
bool opengl33_renderer::Render_Alpha(TModel3d *Model, material_data const *Material, float const Squaredistance, Math3D::vector3 const &Position, glm::vec3 const &A)
|
||||
bool opengl33_renderer::Render_Alpha(TModel3d *Model, material_data const *Material, float const Squaredistance, glm::dvec3 const &Position, glm::vec3 const &Angle)
|
||||
{
|
||||
Math3D::vector3 Angle(A);
|
||||
::glPushMatrix();
|
||||
::glTranslated(Position.x, Position.y, Position.z);
|
||||
if (Angle.y != 0.0)
|
||||
::glRotated(Angle.y, 0.0, 1.0, 0.0);
|
||||
::glRotated(Angle.y, 0.f, 1.f, 0.f);
|
||||
if (Angle.x != 0.0)
|
||||
::glRotated(Angle.x, 1.0, 0.0, 0.0);
|
||||
::glRotated(Angle.x, 1.f, 0.f, 0.f);
|
||||
if (Angle.z != 0.0)
|
||||
::glRotated(Angle.z, 0.0, 0.0, 1.0);
|
||||
::glRotated(Angle.z, 0.f, 0.f, 1.f);
|
||||
|
||||
auto const result = Render_Alpha(Model, Material, Squaredistance); // position is effectively camera offset
|
||||
|
||||
@@ -4692,7 +4691,7 @@ void opengl33_renderer::Update_Lights(light_array &Lights)
|
||||
break;
|
||||
}
|
||||
auto const lightoffset = glm::vec3{scenelight.position - camera};
|
||||
if (glm::length(lightoffset) > 1000.f) {
|
||||
if (glm::length2(lightoffset) > sq(1000.f)) {
|
||||
// we don't care about lights past arbitrary limit of 1 km.
|
||||
// but there could still be weaker lights which are closer, so keep looking
|
||||
continue;
|
||||
@@ -4737,7 +4736,7 @@ void opengl33_renderer::Update_Lights(light_array &Lights)
|
||||
auto const offset{ 75.f * ( 5.f / cone ) };
|
||||
headlights.position() =
|
||||
scenelight.owner->GetPosition()
|
||||
- scenelight.direction * offset
|
||||
- glm::dvec3(scenelight.direction * offset)
|
||||
+ up * ( size * 0.5 );
|
||||
/*
|
||||
headlights.projection() = ortho_projection(
|
||||
|
||||
@@ -267,7 +267,7 @@ class opengl33_renderer : public gfx_renderer {
|
||||
void Render(scene::shape_node const &Shape, bool const Ignorerange);
|
||||
void Render(TAnimModel *Instance);
|
||||
bool Render(TDynamicObject *Dynamic);
|
||||
bool Render(TModel3d *Model, material_data const *Material, float const Squaredistance, Math3D::vector3 const &Position, glm::vec3 const &Angle);
|
||||
bool Render(TModel3d *Model, material_data const *Material, float const Squaredistance, glm::dvec3 const &Position, glm::vec3 const &Angle);
|
||||
bool Render(TModel3d *Model, material_data const *Material, float const Squaredistance);
|
||||
void Render(TSubModel *Submodel);
|
||||
void Render(TTrack *Track);
|
||||
@@ -286,7 +286,7 @@ class opengl33_renderer : public gfx_renderer {
|
||||
void Render_Alpha(TTraction *Traction);
|
||||
void Render_Alpha(scene::lines_node const &Lines);
|
||||
bool Render_Alpha(TDynamicObject *Dynamic);
|
||||
bool Render_Alpha(TModel3d *Model, material_data const *Material, float const Squaredistance, Math3D::vector3 const &Position, glm::vec3 const &Angle);
|
||||
bool Render_Alpha(TModel3d *Model, material_data const *Material, float const Squaredistance, glm::dvec3 const &Position, glm::vec3 const &Angle);
|
||||
bool Render_Alpha(TModel3d *Model, material_data const *Material, float const Squaredistance);
|
||||
void Render_Alpha(TSubModel *Submodel);
|
||||
void Update_Lights(light_array &Lights);
|
||||
|
||||
@@ -28,9 +28,9 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "rendering/screenshot.h"
|
||||
#include <imgui/imgui_impl_opengl2.h>
|
||||
|
||||
int const EU07_PICKBUFFERSIZE { 1024 }; // size of (square) textures bound with the pick framebuffer
|
||||
int const EU07_ENVIRONMENTBUFFERSIZE { 256 }; // size of (square) environmental cube map texture
|
||||
int const EU07_REFLECTIONFIDELITYOFFSET { 250 }; // artificial increase of range for reflection pass detail reduction
|
||||
int constexpr EU07_PICKBUFFERSIZE { 1024 }; // size of (square) textures bound with the pick framebuffer
|
||||
int constexpr EU07_ENVIRONMENTBUFFERSIZE { 256 }; // size of (square) environmental cube map texture
|
||||
int constexpr EU07_REFLECTIONFIDELITYOFFSET { 250 }; // artificial increase of range for reflection pass detail reduction
|
||||
|
||||
float const EU07_OPACITYDEFAULT { 0.5f };
|
||||
|
||||
@@ -806,7 +806,7 @@ bool opengl_renderer::Render_lowpoly( TDynamicObject *Dynamic, float const Squar
|
||||
::glPushMatrix();
|
||||
|
||||
::glTranslated( originoffset.x, originoffset.y, originoffset.z );
|
||||
::glMultMatrixd( Dynamic->mMatrix.getArray() );
|
||||
::glMultMatrixd( glm::value_ptr(Dynamic->mMatrix) );
|
||||
|
||||
m_renderspecular = true; // vehicles are rendered with specular component. static models without, at least for the time being
|
||||
}
|
||||
@@ -867,7 +867,7 @@ bool opengl_renderer::Render_coupler_adapter( TDynamicObject *Dynamic, float con
|
||||
|
||||
if( Dynamic->m_coupleradapters[ End ] == nullptr ) { return false; }
|
||||
|
||||
auto const position { Math3D::vector3 {
|
||||
auto const position { glm::dvec3 {
|
||||
0.f,
|
||||
Dynamic->MoverParameters->Couplers[ End ].adapter_height,
|
||||
( Dynamic->MoverParameters->Couplers[ End ].adapter_length + Dynamic->MoverParameters->Dim.L * 0.5 ) * ( End == end::front ? 1 : -1 ) } };
|
||||
@@ -892,7 +892,7 @@ opengl_renderer::Render_reflections() {
|
||||
|
||||
auto const timestamp { Timer::GetRenderTime() };
|
||||
if( ( timestamp - m_environmentupdatetime < Global.reflectiontune.update_interval )
|
||||
&& ( glm::length( m_renderpass.camera.position() - m_environmentupdatelocation ) < 1000.0 ) ) {
|
||||
&& ( glm::length2( m_renderpass.camera.position() - m_environmentupdatelocation ) < sq(1000.0)) ) {
|
||||
// run update every 5+ mins of simulation time, or at least 1km from the last location
|
||||
return false;
|
||||
}
|
||||
@@ -1041,8 +1041,8 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f
|
||||
camera.position() = Global.pCamera.Pos - glm::dvec3 { lightvector };
|
||||
viewmatrix *= glm::lookAt(
|
||||
camera.position(),
|
||||
glm::dvec3 { Global.pCamera.Pos },
|
||||
glm::dvec3 { 0.f, 1.f, 0.f } );
|
||||
Global.pCamera.Pos,
|
||||
glm::dvec3 { 0, 1, 0 } );
|
||||
// projection
|
||||
auto const maphalfsize { std::min( 10.f, Config.draw_range * 0.5f ) };
|
||||
camera.projection() *=
|
||||
@@ -2277,14 +2277,14 @@ opengl_renderer::Render( scene::shape_node const &Shape, bool const Ignorerange
|
||||
case rendermode::shadows:
|
||||
case rendermode::cabshadows: {
|
||||
// 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees
|
||||
distancesquared = Math3D::SquareMagnitude( ( data.area.center - Global.pCamera.Pos ) / Global.ZoomFactor ) / Global.fDistanceFactor;
|
||||
distancesquared = glm::length2( ( data.area.center - Global.pCamera.Pos ) / (double)Global.ZoomFactor ) / Global.fDistanceFactor;
|
||||
break;
|
||||
}
|
||||
case rendermode::reflections: {
|
||||
// reflection mode draws simplified version of the shapes, by artificially increasing view range
|
||||
distancesquared =
|
||||
// TBD, TODO: bind offset value with setting variable?
|
||||
( EU07_REFLECTIONFIDELITYOFFSET * EU07_REFLECTIONFIDELITYOFFSET )
|
||||
sq(EU07_REFLECTIONFIDELITYOFFSET)
|
||||
// TBD: take into account distance multipliers?
|
||||
+ glm::length2( ( data.area.center - m_renderpass.camera.position() ) ) /* / Global.fDistanceFactor */;
|
||||
break;
|
||||
@@ -2360,7 +2360,7 @@ opengl_renderer::Render( TAnimModel *Instance ) {
|
||||
return;
|
||||
}
|
||||
// TBD, TODO: bind offset value with setting variable?
|
||||
distancesquared += ( EU07_REFLECTIONFIDELITYOFFSET * EU07_REFLECTIONFIDELITYOFFSET );
|
||||
distancesquared += sq(EU07_REFLECTIONFIDELITYOFFSET);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -2374,7 +2374,7 @@ opengl_renderer::Render( TAnimModel *Instance ) {
|
||||
}
|
||||
// crude way to reject early items too far to affect the output (mostly relevant for shadow passes)
|
||||
auto const drawdistancethreshold{ m_renderpass.draw_range + 250 };
|
||||
if( distancesquared > drawdistancethreshold * drawdistancethreshold ) {
|
||||
if( distancesquared > sq(drawdistancethreshold) ) {
|
||||
return;
|
||||
}
|
||||
// second stage visibility cull, reject modelstoo far away to be noticeable
|
||||
@@ -2426,14 +2426,14 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) {
|
||||
squaredistance = glm::length2( glm::vec3{ glm::dvec3{ Dynamic->vPosition - Global.pCamera.Pos } } / Global.ZoomFactor );
|
||||
if( false == FreeFlyModeFlag ) {
|
||||
// filter out small details if we're in vehicle cab
|
||||
squaredistance = std::max( 100.f * 100.f, squaredistance );
|
||||
squaredistance = std::max( sq(100.f), squaredistance );
|
||||
}
|
||||
break;
|
||||
}
|
||||
case rendermode::cabshadows: {
|
||||
squaredistance = glm::length2( glm::vec3{ glm::dvec3{ Dynamic->vPosition - Global.pCamera.Pos } } / Global.ZoomFactor );
|
||||
// filter out small details
|
||||
squaredistance = std::max( 100.f * 100.f, squaredistance );
|
||||
squaredistance = std::max( sq(100.f), squaredistance );
|
||||
break;
|
||||
}
|
||||
case rendermode::reflections: {
|
||||
@@ -2441,7 +2441,7 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) {
|
||||
// it also ignores zoom settings and distance multipliers
|
||||
squaredistance =
|
||||
std::max(
|
||||
100.f * 100.f,
|
||||
sq(100.f),
|
||||
// TBD: take into account distance multipliers?
|
||||
glm::length2( glm::vec3{ originoffset } ) /* / Global.fDistanceFactor */ );
|
||||
// NOTE: arbitrary draw range limit
|
||||
@@ -2450,7 +2450,7 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) {
|
||||
}
|
||||
// TBD, TODO: bind offset value with setting variable?
|
||||
// NOTE: combined 'squared' distance doesn't equal actual squared (distance + offset) but, eh
|
||||
squaredistance += ( EU07_REFLECTIONFIDELITYOFFSET * EU07_REFLECTIONFIDELITYOFFSET );
|
||||
squaredistance += sq(EU07_REFLECTIONFIDELITYOFFSET);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -2461,7 +2461,7 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) {
|
||||
}
|
||||
// crude way to reject early items too far to affect the output (mostly relevant for shadow and reflection passes)
|
||||
auto const drawdistancethreshold{ m_renderpass.draw_range + 250 };
|
||||
if( squaredistance > drawdistancethreshold * drawdistancethreshold ) {
|
||||
if( squaredistance > sq(drawdistancethreshold) ) {
|
||||
return false;
|
||||
}
|
||||
// second stage visibility cull, reject vehicles too far away to be noticeable
|
||||
@@ -2480,7 +2480,7 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) {
|
||||
::glPushMatrix();
|
||||
|
||||
::glTranslated( originoffset.x, originoffset.y, originoffset.z );
|
||||
::glMultMatrixd( Dynamic->mMatrix.getArray() );
|
||||
::glMultMatrixd( glm::value_ptr(Dynamic->mMatrix) );
|
||||
|
||||
switch( m_renderpass.draw_mode ) {
|
||||
|
||||
@@ -2593,7 +2593,7 @@ opengl_renderer::Render_cab( TDynamicObject const *Dynamic, float const Lightlev
|
||||
|
||||
auto const originoffset = Dynamic->GetPosition() - m_renderpass.camera.position();
|
||||
::glTranslated( originoffset.x, originoffset.y, originoffset.z );
|
||||
::glMultMatrixd( Dynamic->mMatrix.readArray() );
|
||||
::glMultMatrixd( glm::value_ptr(Dynamic->mMatrix) );
|
||||
|
||||
switch( m_renderpass.draw_mode ) {
|
||||
case rendermode::color: {
|
||||
@@ -2696,7 +2696,7 @@ opengl_renderer::Render( TModel3d *Model, material_data const *Material, float c
|
||||
}
|
||||
|
||||
bool
|
||||
opengl_renderer::Render( TModel3d *Model, material_data const *Material, float const Squaredistance, Math3D::vector3 const &Position, glm::vec3 const &Angle ) {
|
||||
opengl_renderer::Render( TModel3d *Model, material_data const *Material, float const Squaredistance, glm::dvec3 const &Position, glm::vec3 const &Angle ) {
|
||||
|
||||
::glPushMatrix();
|
||||
::glTranslated( Position.x, Position.y, Position.z );
|
||||
@@ -3505,7 +3505,7 @@ opengl_renderer::Render_Alpha( TAnimModel *Instance ) {
|
||||
switch( m_renderpass.draw_mode ) {
|
||||
case rendermode::shadows: {
|
||||
// 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees
|
||||
distancesquared = Math3D::SquareMagnitude( ( Instance->location() - Global.pCamera.Pos ) / Global.ZoomFactor ) / Global.fDistanceFactor;
|
||||
distancesquared = glm::length2( ( Instance->location() - Global.pCamera.Pos ) / (double)Global.ZoomFactor ) / Global.fDistanceFactor;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -3519,7 +3519,7 @@ opengl_renderer::Render_Alpha( TAnimModel *Instance ) {
|
||||
}
|
||||
// crude way to reject early items too far to affect the output (mostly relevant for shadow passes)
|
||||
auto const drawdistancethreshold{ m_renderpass.draw_range + 250 };
|
||||
if( distancesquared > drawdistancethreshold * drawdistancethreshold ) {
|
||||
if( distancesquared > sq(drawdistancethreshold) ) {
|
||||
return;
|
||||
}
|
||||
// second stage visibility cull, reject modelstoo far away to be noticeable
|
||||
@@ -3549,7 +3549,7 @@ opengl_renderer::Render_Alpha( TTraction *Traction ) {
|
||||
switch( m_renderpass.draw_mode ) {
|
||||
case rendermode::shadows: {
|
||||
// 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees
|
||||
distancesquared = Math3D::SquareMagnitude( ( Traction->location() - Global.pCamera.Pos ) / Global.ZoomFactor ) / Global.fDistanceFactor;
|
||||
distancesquared = glm::length2( ( Traction->location() - Global.pCamera.Pos ) / Global.ZoomFactor ) / Global.fDistanceFactor;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -3613,7 +3613,7 @@ opengl_renderer::Render_Alpha( scene::lines_node const &Lines ) {
|
||||
switch( m_renderpass.draw_mode ) {
|
||||
case rendermode::shadows: {
|
||||
// 'camera' for the light pass is the light source, but we need to draw what the 'real' camera sees
|
||||
distancesquared = Math3D::SquareMagnitude( ( data.area.center - Global.pCamera.Pos ) / Global.ZoomFactor ) / Global.fDistanceFactor;
|
||||
distancesquared = glm::length2( ( data.area.center - Global.pCamera.Pos ) / Global.ZoomFactor ) / Global.fDistanceFactor;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -3675,7 +3675,7 @@ opengl_renderer::Render_Alpha( TDynamicObject *Dynamic ) {
|
||||
::glPushMatrix();
|
||||
|
||||
::glTranslated( originoffset.x, originoffset.y, originoffset.z );
|
||||
::glMultMatrixd( Dynamic->mMatrix.getArray() );
|
||||
::glMultMatrixd( glm::value_ptr(Dynamic->mMatrix) );
|
||||
|
||||
if( Dynamic->fShade > 0.0f ) {
|
||||
// change light level based on light level of the occupied track
|
||||
@@ -3769,7 +3769,7 @@ opengl_renderer::Render_Alpha( TModel3d *Model, material_data const *Material, f
|
||||
}
|
||||
|
||||
bool
|
||||
opengl_renderer::Render_Alpha( TModel3d *Model, material_data const *Material, float const Squaredistance, Math3D::vector3 const &Position, glm::vec3 const &Angle ) {
|
||||
opengl_renderer::Render_Alpha( TModel3d *Model, material_data const *Material, float const Squaredistance, glm::dvec3 const &Position, glm::vec3 const &Angle ) {
|
||||
|
||||
::glPushMatrix();
|
||||
::glTranslated( Position.x, Position.y, Position.z );
|
||||
@@ -4341,7 +4341,8 @@ opengl_renderer::Update_Lights( light_array &Lights ) {
|
||||
break;
|
||||
}
|
||||
auto const lightoffset = glm::vec3{ scenelight.position - camera };
|
||||
if( glm::length( lightoffset ) > 1000.f ) {
|
||||
// length2 is better than length for comparing because it does not require sqrt function
|
||||
if( glm::length2( lightoffset ) > sq(1000.f)) {
|
||||
// we don't care about lights past arbitrary limit of 1 km.
|
||||
// but there could still be weaker lights which are closer, so keep looking
|
||||
continue;
|
||||
|
||||
@@ -223,7 +223,7 @@ private:
|
||||
bool
|
||||
Render( TDynamicObject *Dynamic );
|
||||
bool
|
||||
Render( TModel3d *Model, material_data const *Material, float const Squaredistance, Math3D::vector3 const &Position, glm::vec3 const &Angle );
|
||||
Render( TModel3d *Model, material_data const *Material, float const Squaredistance, glm::dvec3 const &Position, glm::vec3 const &Angle );
|
||||
bool
|
||||
Render( TModel3d *Model, material_data const *Material, float const Squaredistance );
|
||||
void
|
||||
@@ -259,7 +259,7 @@ private:
|
||||
bool
|
||||
Render_Alpha( TDynamicObject *Dynamic );
|
||||
bool
|
||||
Render_Alpha( TModel3d *Model, material_data const *Material, float const Squaredistance, Math3D::vector3 const &Position, glm::vec3 const &Angle );
|
||||
Render_Alpha( TModel3d *Model, material_data const *Material, float const Squaredistance, glm::dvec3 const &Position, glm::vec3 const &Angle );
|
||||
bool
|
||||
Render_Alpha( TModel3d *Model, material_data const *Material, float const Squaredistance );
|
||||
void
|
||||
|
||||
@@ -302,7 +302,7 @@ smoke_source::location() const {
|
||||
m_offset.x * m_owner.vehicle->VectorLeft()
|
||||
+ m_offset.y * m_owner.vehicle->VectorUp()
|
||||
+ m_offset.z * m_owner.vehicle->VectorFront() };
|
||||
location += glm::dvec3{ m_owner.vehicle->GetPosition() };
|
||||
location += m_owner.vehicle->GetPosition();
|
||||
break;
|
||||
}
|
||||
case owner_type::node: {
|
||||
|
||||
@@ -70,7 +70,9 @@ basic_precipitation::update() {
|
||||
cameramove = glm::dvec3{ 0.0 };
|
||||
}
|
||||
// ... from camera jump to another location
|
||||
if( glm::length( cameramove ) > 100.0 ) {
|
||||
// length2 is better than length for comparing because it does not require sqrt function
|
||||
if( glm::length2( cameramove ) > sq(100.0) )
|
||||
{
|
||||
cameramove = glm::dvec3{ 0.0 };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user