16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 16:19:19 +02:00

view range factor implementation

This commit is contained in:
tmj-fstate
2017-03-08 01:25:09 +01:00
parent 2f3e916d9e
commit 6526620364
8 changed files with 56 additions and 81 deletions

View File

@@ -53,7 +53,7 @@ void TCamera::OnCursorMove(double x, double y)
Yaw += 2 * M_PI; Yaw += 2 * M_PI;
if (Type == tp_Follow) // jeżeli jazda z pojazdem if (Type == tp_Follow) // jeżeli jazda z pojazdem
{ {
Fix(Pitch, -M_PI_4, M_PI_4); // ograniczenie kąta spoglądania w dół i w górę clamp(Pitch, -M_PI_4, M_PI_4); // ograniczenie kąta spoglądania w dół i w górę
// Fix(Yaw,-M_PI,M_PI); // Fix(Yaw,-M_PI,M_PI);
} }
} }

View File

@@ -93,6 +93,7 @@ void window_resize_callback(GLFWwindow *window, int w, int h)
{ {
Global::ScreenWidth = w; Global::ScreenWidth = w;
Global::ScreenHeight = h; Global::ScreenHeight = h;
Global::fDistanceFactor = h / 768.0f; // not sure if this is really something we want to use
glViewport(0, 0, w, h); glViewport(0, 0, w, h);
} }

View File

@@ -120,7 +120,7 @@ int Global::iHiddenEvents = 1; // czy łączyć eventy z torami poprzez nazwę t
int Global::Keys[MaxKeys]; int Global::Keys[MaxKeys];
int Global::iWindowWidth = 800; int Global::iWindowWidth = 800;
int Global::iWindowHeight = 600; int Global::iWindowHeight = 600;
float Global::fDistanceFactor = 768.0; // baza do przeliczania odległości dla LoD float Global::fDistanceFactor = Global::ScreenHeight / 768.0; // baza do przeliczania odległości dla LoD
int Global::iFeedbackMode = 1; // tryb pracy informacji zwrotnej int Global::iFeedbackMode = 1; // tryb pracy informacji zwrotnej
int Global::iFeedbackPort = 0; // dodatkowy adres dla informacji zwrotnych int Global::iFeedbackPort = 0; // dodatkowy adres dla informacji zwrotnych
bool Global::bFreeFly = false; bool Global::bFreeFly = false;
@@ -154,7 +154,8 @@ bool Global::bSmoothTraction = false; // wygładzanie drutów starym sposobem
std::string Global::szDefaultExt = Global::szTexturesDDS; // domyślnie od DDS std::string Global::szDefaultExt = Global::szTexturesDDS; // domyślnie od DDS
int Global::iMultisampling = 2; // tryb antyaliasingu: 0=brak,1=2px,2=4px,3=8px,4=16px int Global::iMultisampling = 2; // tryb antyaliasingu: 0=brak,1=2px,2=4px,3=8px,4=16px
bool Global::bGlutFont = false; // czy tekst generowany przez GLUT32.DLL bool Global::bGlutFont = false; // czy tekst generowany przez GLUT32.DLL
int Global::iConvertModels = 7; // tworzenie plików binarnych, +2-optymalizacja transformów //int Global::iConvertModels = 7; // tworzenie plików binarnych, +2-optymalizacja transformów
int Global::iConvertModels{ 0 }; // temporary override, to prevent generation of .e3d not compatible with old exe
int Global::iSlowMotionMask = -1; // maska wyłączanych właściwości dla zwiększenia FPS int Global::iSlowMotionMask = -1; // maska wyłączanych właściwości dla zwiększenia FPS
int Global::iModifyTGA = 7; // czy korygować pliki TGA dla szybszego wczytywania int Global::iModifyTGA = 7; // czy korygować pliki TGA dla szybszego wczytywania
// bool Global::bTerrainCompact=true; //czy zapisać teren w pliku // bool Global::bTerrainCompact=true; //czy zapisać teren w pliku
@@ -620,6 +621,11 @@ void Global::ConfigParse(cParser &Parser)
// tworzenie plików binarnych // tworzenie plików binarnych
Parser.getTokens(1, false); Parser.getTokens(1, false);
Parser >> Global::iConvertModels; Parser >> Global::iConvertModels;
// temporary override, to prevent generation of .e3d not compatible with old exe
Global::iConvertModels =
( Global::iConvertModels > 128 ?
Global::iConvertModels - 128 :
0 );
} }
else if (token == "inactivepause") else if (token == "inactivepause")
{ {

View File

@@ -74,7 +74,7 @@ void TSubModel::FirstInit()
// Hits=NULL; // Hits=NULL;
// CollisionPts=NULL; // CollisionPts=NULL;
// CollisionPtsCount=0; // CollisionPtsCount=0;
Opacity = 1.0; // przy wczytywaniu modeli było dzielone przez 100... Opacity = 0.0f; // przy wczytywaniu modeli było dzielone przez 100...
bWire = false; bWire = false;
fWireSize = 0; fWireSize = 0;
fNearAttenStart = 40; fNearAttenStart = 40;
@@ -376,13 +376,10 @@ int TSubModel::Load(cParser &parser, TModel3d *Model, int Pos, bool dynamic)
TextureID = GfxRenderer.GetTextureId( texture, szTexturePath ); TextureID = GfxRenderer.GetTextureId( texture, szTexturePath );
// TexAlpha=TTexturesManager::GetAlpha(TextureID); // TexAlpha=TTexturesManager::GetAlpha(TextureID);
// iFlags|=TexAlpha?0x20:0x10; //0x10-nieprzezroczysta, 0x20-przezroczysta // iFlags|=TexAlpha?0x20:0x10; //0x10-nieprzezroczysta, 0x20-przezroczysta
if (Opacity < 1.0) // przezroczystość z tekstury brana tylko dla Opacity iFlags |=
// 0! ( GfxRenderer.Texture(TextureID).has_alpha ?
iFlags |= GfxRenderer.Texture(TextureID).has_alpha ? 0x20 :
0x20 : 0x10 ); // 0x10-nieprzezroczysta, 0x20-przezroczysta
0x10; // 0x10-nieprzezroczysta, 0x20-przezroczysta
else
iFlags |= 0x10; // normalnie nieprzezroczyste
// renderowanie w cyklu przezroczystych tylko jeśli: // renderowanie w cyklu przezroczystych tylko jeśli:
// 1. Opacity=0 (przejściowo <1, czy tam <100) oraz // 1. Opacity=0 (przejściowo <1, czy tam <100) oraz
// 2. tekstura ma przezroczystość // 2. tekstura ma przezroczystość
@@ -391,19 +388,19 @@ int TSubModel::Load(cParser &parser, TModel3d *Model, int Pos, bool dynamic)
else else
iFlags |= 0x10; iFlags |= 0x10;
// visibility range
std::string discard; std::string discard;
parser.getTokens(5, false); parser.getTokens(5, false);
parser >> discard >> fSquareMaxDist >> discard >> fSquareMinDist >> discard; parser >> discard >> fSquareMaxDist >> discard >> fSquareMinDist >> discard;
if (fSquareMaxDist >= 0.0) if( fSquareMaxDist <= 0.0 ) {
{ // 15km to więcej, niż się obecnie wyświetla
fSquareMaxDist *= fSquareMaxDist; fSquareMaxDist = 15000.0;
} }
else fSquareMaxDist *= fSquareMaxDist;
{
fSquareMaxDist = 15000 * 15000;
} // 15km to więcej, niż się obecnie wyświetla
fSquareMinDist *= fSquareMinDist; fSquareMinDist *= fSquareMinDist;
// transformation matrix
fMatrix = new float4x4(); fMatrix = new float4x4();
readMatrix(parser, *fMatrix); // wczytanie transform readMatrix(parser, *fMatrix); // wczytanie transform
if (!fMatrix->IdentityIs()) if (!fMatrix->IdentityIs())
@@ -688,7 +685,7 @@ void TSubModel::DisplayLists()
glColorMaterial(GL_FRONT, GL_EMISSION); glColorMaterial(GL_FRONT, GL_EMISSION);
glDisable(GL_LIGHTING); // Tolaris-030603: bo mu punkty swiecace sie blendowaly glDisable(GL_LIGHTING); // Tolaris-030603: bo mu punkty swiecace sie blendowaly
glBegin(GL_POINTS); glBegin(GL_POINTS);
glVertex3f( 0.0f, 0.0f, -0.025f ); // shift point towards the viewer, to avoid z-fighting with the light polygons glVertex3f( 0.0f, 0.0f, -0.05f ); // shift point towards the viewer, to avoid z-fighting with the light polygons
glEnd(); glEnd();
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
@@ -1484,7 +1481,7 @@ void TSubModel::AdjustDist()
if (fSquareMaxDist > 0.0) if (fSquareMaxDist > 0.0)
fSquareMaxDist *= Global::fDistanceFactor; fSquareMaxDist *= Global::fDistanceFactor;
if (fSquareMinDist > 0.0) if (fSquareMinDist > 0.0)
fSquareMinDist *= Global::fDistanceFactor; fSquareMinDist /= Global::fDistanceFactor;
// if (fNearAttenStart>0.0) fNearAttenStart*=Global::fDistanceFactor; // if (fNearAttenStart>0.0) fNearAttenStart*=Global::fDistanceFactor;
// if (fNearAttenEnd>0.0) fNearAttenEnd*=Global::fDistanceFactor; // if (fNearAttenEnd>0.0) fNearAttenEnd*=Global::fDistanceFactor;
if (Child) if (Child)
@@ -2015,12 +2012,10 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, float8 *v,
if (pTexture.find_last_of("/\\") == std::string::npos) if (pTexture.find_last_of("/\\") == std::string::npos)
pTexture.insert(0, Global::asCurrentTexturePath); pTexture.insert(0, Global::asCurrentTexturePath);
TextureID = GfxRenderer.GetTextureId(pTexture, szTexturePath); TextureID = GfxRenderer.GetTextureId(pTexture, szTexturePath);
if( Opacity < 1.0 ) // przezroczystość z tekstury brana tylko dla Opacity 0! iFlags |=
iFlags |= GfxRenderer.Texture( TextureID ).has_alpha ? ( GfxRenderer.Texture( TextureID ).has_alpha ?
0x20 : 0x20 :
0x10; // 0x10-nieprzezroczysta, 0x20-przezroczysta 0x10 ); // 0x10-nieprzezroczysta, 0x20-przezroczysta
else
iFlags |= 0x10; // normalnie nieprzezroczyste
} }
else else
TextureID = iTexture; TextureID = iTexture;

View File

@@ -19,6 +19,7 @@ http://mozilla.org/MPL/2.0/.
//#include "math.h" //#include "math.h"
#include "Timer.h" #include "Timer.h"
#include "mczapkie/mctools.h" #include "mczapkie/mctools.h"
#include "usefull.h"
TRealSound::TRealSound(std::string const &SoundName, double SoundAttenuation, double X, double Y, double Z, bool Dynamic, TRealSound::TRealSound(std::string const &SoundName, double SoundAttenuation, double X, double Y, double Z, bool Dynamic,
bool freqmod, double rmin) bool freqmod, double rmin)
@@ -177,7 +178,7 @@ void TRealSound::AdjFreq(double Freq, double dt) // McZapkie TODO: dorobic tu ef
// Freq moze byc liczba dodatnia mniejsza od 1 lub wieksza od 1 // Freq moze byc liczba dodatnia mniejsza od 1 lub wieksza od 1
{ {
float df, Vlist; float df, Vlist;
if ((Global::bSoundEnabled) && (AM != 0)) if ((Global::bSoundEnabled) && (AM != 0) && (pSound != nullptr))
{ {
if (dt > 0) if (dt > 0)
// efekt Dopplera // efekt Dopplera
@@ -190,9 +191,7 @@ void TRealSound::AdjFreq(double Freq, double dt) // McZapkie TODO: dorobic tu ef
if (Timer::GetSoundTimer()) if (Timer::GetSoundTimer())
{ {
df = fFrequency * df; // TODO - brac czestotliwosc probkowania z wav df = fFrequency * df; // TODO - brac czestotliwosc probkowania z wav
pSound->SetFrequency((df < DSBFREQUENCY_MIN ? pSound->SetFrequency( clamp( df, static_cast<float>(DSBFREQUENCY_MIN), static_cast<float>(DSBFREQUENCY_MAX) ) );
DSBFREQUENCY_MIN :
(df > DSBFREQUENCY_MAX ? DSBFREQUENCY_MAX : df)));
} }
} }
} }

View File

@@ -275,6 +275,12 @@ opengl_texture::load_DDS() {
--mapcount; --mapcount;
} }
*/ */
if( datasize == 0 ) {
// catch malformed .dds files
WriteLog( "File \"" + name + "\" is malformed and holds no texture data." );
data_state = resource_state::failed;
return;
}
// reserve space and load texture data // reserve space and load texture data
data.resize( datasize ); data.resize( datasize );
if( offset != 0 ) { if( offset != 0 ) {

View File

@@ -2,6 +2,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "skydome.h" #include "skydome.h"
#include "color.h" #include "color.h"
#include "usefull.h"
// sky gradient based on "A practical analytic model for daylight" // sky gradient based on "A practical analytic model for daylight"
// by A. J. Preetham Peter Shirley Brian Smits (University of Utah) // by A. J. Preetham Peter Shirley Brian Smits (University of Utah)
@@ -41,21 +42,6 @@ float CSkyDome::m_zenithymatrix[ 3 ][ 4 ] = {
//******************************************************************************// //******************************************************************************//
float clamp( float const Value, float const Min, float const Max ) {
float value = Value;
if( value < Min ) { value = Min; }
if( value > Max ) { value = Max; }
return value;
}
float interpolate( float const First, float const Second, float const Factor ) {
return ( First * ( 1.0f - Factor ) ) + ( Second * Factor );
}
//******************************************************************************//
CSkyDome::CSkyDome (int const Tesselation) : CSkyDome::CSkyDome (int const Tesselation) :
m_tesselation( Tesselation ) { m_tesselation( Tesselation ) {
@@ -121,8 +107,6 @@ void CSkyDome::Generate() {
} }
} }
//******************************************************************************//
void CSkyDome::Update( Math3D::vector3 const &Sun ) { void CSkyDome::Update( Math3D::vector3 const &Sun ) {
if( true == SetSunPosition( Sun ) ) { if( true == SetSunPosition( Sun ) ) {
@@ -166,8 +150,6 @@ void CSkyDome::Render() {
::glDisableClientState( GL_VERTEX_ARRAY ); ::glDisableClientState( GL_VERTEX_ARRAY );
} }
//******************************************************************************//
bool CSkyDome::SetSunPosition( Math3D::vector3 const &Direction ) { bool CSkyDome::SetSunPosition( Math3D::vector3 const &Direction ) {
auto sundirection = SafeNormalize( float3( Direction.x, Direction.y, Direction.z) ); auto sundirection = SafeNormalize( float3( Direction.x, Direction.y, Direction.z) );
@@ -205,8 +187,6 @@ void CSkyDome::SetOvercastFactor( float const Overcast ) {
m_overcast = clamp( Overcast, 0.0f, 1.0f ); m_overcast = clamp( Overcast, 0.0f, 1.0f );
} }
//******************************************************************************//
void CSkyDome::GetPerez( float *Perez, float Distribution[ 5 ][ 2 ], const float Turbidity ) { void CSkyDome::GetPerez( float *Perez, float Distribution[ 5 ][ 2 ], const float Turbidity ) {
Perez[ 0 ] = Distribution[ 0 ][ 0 ] * Turbidity + Distribution[ 0 ][ 1 ]; Perez[ 0 ] = Distribution[ 0 ][ 0 ] * Turbidity + Distribution[ 0 ][ 1 ];
@@ -227,8 +207,6 @@ float CSkyDome::GetZenith( float Zenithmatrix[ 3 ][ 4 ], const float Theta, cons
} }
//******************************************************************************//
float CSkyDome::PerezFunctionO1( float Perezcoeffs[ 5 ], const float Thetasun, const float Zenithval ) { float CSkyDome::PerezFunctionO1( float Perezcoeffs[ 5 ], const float Thetasun, const float Zenithval ) {
const float val = ( 1.0f + Perezcoeffs[ 0 ] * std::exp( Perezcoeffs[ 1 ] ) ) * const float val = ( 1.0f + Perezcoeffs[ 0 ] * std::exp( Perezcoeffs[ 1 ] ) ) *
@@ -244,7 +222,6 @@ float CSkyDome::PerezFunctionO2( float Perezcoeffs[ 5 ], const float Icostheta,
( 1.0f + Perezcoeffs[ 2 ] * std::exp( Perezcoeffs[ 3 ] * Gamma ) + Perezcoeffs[ 4 ] * Cosgamma2 ); ( 1.0f + Perezcoeffs[ 2 ] * std::exp( Perezcoeffs[ 3 ] * Gamma ) + Perezcoeffs[ 4 ] * Cosgamma2 );
} }
//******************************************************************************//
void CSkyDome::RebuildColors() { void CSkyDome::RebuildColors() {
// get zenith luminance // get zenith luminance
@@ -320,7 +297,7 @@ void CSkyDome::RebuildColors() {
// override the hue, based on sun height above the horizon. crude way to deal with model shortcomings // override the hue, based on sun height above the horizon. crude way to deal with model shortcomings
// correction begins when the sun is higher than 10 degrees above the horizon, and fully in effect at 10+15 degrees // correction begins when the sun is higher than 10 degrees above the horizon, and fully in effect at 10+15 degrees
auto const degreesabovehorizon = 90.0f - m_thetasun * ( 180.0f / M_PI ); float const degreesabovehorizon = 90.0f - m_thetasun * ( 180.0f / M_PI );
auto const sunbasedphase = clamp( (1.0f / 15.0f) * ( degreesabovehorizon - 10.0f ), 0.0f, 1.0f ); auto const sunbasedphase = clamp( (1.0f / 15.0f) * ( degreesabovehorizon - 10.0f ), 0.0f, 1.0f );
// correction is applied in linear manner from the bottom, becomes fully in effect for vertices with y = 0.50 // correction is applied in linear manner from the bottom, becomes fully in effect for vertices with y = 0.50
auto const heightbasedphase = clamp( vertex.y * 2.0f, 0.0f, 1.0f ); auto const heightbasedphase = clamp( vertex.y * 2.0f, 0.0f, 1.0f );

View File

@@ -9,17 +9,7 @@ http://mozilla.org/MPL/2.0/.
#pragma once #pragma once
//#define B1(t) (t*t*t) #include "stdafx.h"
//#define B2(t) (3*t*t*(1-t))
//#define B3(t) (3*t*(1-t)*(1-t))
//#define B4(t) ((1-t)*(1-t)*(1-t))
// Ra: to jest mocno nieoptymalne: 10+3*4=22 mnożenia, 6 odejmowań, 3*3=9 dodawań
// Ra: po przeliczeniu współczynników mamy: 3*3=9 mnożeń i 3*3=9 dodawań
//#define Interpolate(t,p1,cp1,cp2,p2) (B4(t)*p1+B3(t)*cp1+B2(t)*cp2+B1(t)*p2)
// Ra: "delete NULL" nic nie zrobi, więc "if (a!=NULL)" jest zbędne
//#define SafeFree(a) if (a!=NULL) free(a)
//#define M_PI = 3.141592653589793
#define SafeDelete(a) \ #define SafeDelete(a) \
{ \ { \
@@ -37,25 +27,26 @@ http://mozilla.org/MPL/2.0/.
#define DegToRad(a) ((M_PI / 180.0) * (a)) //(a) w nawiasie, bo może być dodawaniem #define DegToRad(a) ((M_PI / 180.0) * (a)) //(a) w nawiasie, bo może być dodawaniem
#define RadToDeg(r) ((180.0 / M_PI) * (r)) #define RadToDeg(r) ((180.0 / M_PI) * (r))
#define Fix(a, b, c) \
{ \
if (a < b) \
a = b; \
if (a > c) \
a = c; \
}
#define asModelsPath std::string("models\\") #define asModelsPath std::string("models\\")
#define asSceneryPath std::string("scenery\\") #define asSceneryPath std::string("scenery\\")
//#define asTexturePath AnsiString("textures\\")
//#define asTextureExt AnsiString(".bmp")
#define szSceneryPath "scenery\\" #define szSceneryPath "scenery\\"
#define szTexturePath "textures\\" #define szTexturePath "textures\\"
//#define szDefaultTextureExt ".dds"
//#define DevelopTime //FIXME
//#define EditorMode
#define MAKE_ID4(a,b,c,d) (((std::uint32_t)(d)<<24)|((std::uint32_t)(c)<<16)|((std::uint32_t)(b)<<8)|(std::uint32_t)(a)) #define MAKE_ID4(a,b,c,d) (((std::uint32_t)(d)<<24)|((std::uint32_t)(c)<<16)|((std::uint32_t)(b)<<8)|(std::uint32_t)(a))
template <typename _Type>
_Type clamp( _Type const Value, _Type const Min, _Type const Max ) {
_Type value = Value;
if( value < Min ) { value = Min; }
if( value > Max ) { value = Max; }
return value;
}
template <typename _Type>
_Type interpolate( _Type const First, _Type const Second, float const Factor ) {
return ( First * ( 1.0f - Factor ) ) + ( Second * Factor );
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------