mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-21 17:09:19 +02:00
view range factor implementation
This commit is contained in:
@@ -53,7 +53,7 @@ void TCamera::OnCursorMove(double x, double y)
|
||||
Yaw += 2 * M_PI;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
1
EU07.cpp
1
EU07.cpp
@@ -93,6 +93,7 @@ void window_resize_callback(GLFWwindow *window, int w, int h)
|
||||
{
|
||||
Global::ScreenWidth = w;
|
||||
Global::ScreenHeight = h;
|
||||
Global::fDistanceFactor = h / 768.0f; // not sure if this is really something we want to use
|
||||
glViewport(0, 0, w, h);
|
||||
}
|
||||
|
||||
|
||||
10
Globals.cpp
10
Globals.cpp
@@ -120,7 +120,7 @@ int Global::iHiddenEvents = 1; // czy łączyć eventy z torami poprzez nazwę t
|
||||
int Global::Keys[MaxKeys];
|
||||
int Global::iWindowWidth = 800;
|
||||
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::iFeedbackPort = 0; // dodatkowy adres dla informacji zwrotnych
|
||||
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
|
||||
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
|
||||
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::iModifyTGA = 7; // czy korygować pliki TGA dla szybszego wczytywania
|
||||
// bool Global::bTerrainCompact=true; //czy zapisać teren w pliku
|
||||
@@ -620,6 +621,11 @@ void Global::ConfigParse(cParser &Parser)
|
||||
// tworzenie plików binarnych
|
||||
Parser.getTokens(1, false);
|
||||
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")
|
||||
{
|
||||
|
||||
43
Model3d.cpp
43
Model3d.cpp
@@ -74,7 +74,7 @@ void TSubModel::FirstInit()
|
||||
// Hits=NULL;
|
||||
// CollisionPts=NULL;
|
||||
// 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;
|
||||
fWireSize = 0;
|
||||
fNearAttenStart = 40;
|
||||
@@ -376,13 +376,10 @@ int TSubModel::Load(cParser &parser, TModel3d *Model, int Pos, bool dynamic)
|
||||
TextureID = GfxRenderer.GetTextureId( texture, szTexturePath );
|
||||
// TexAlpha=TTexturesManager::GetAlpha(TextureID);
|
||||
// iFlags|=TexAlpha?0x20:0x10; //0x10-nieprzezroczysta, 0x20-przezroczysta
|
||||
if (Opacity < 1.0) // przezroczystość z tekstury brana tylko dla Opacity
|
||||
// 0!
|
||||
iFlags |= GfxRenderer.Texture(TextureID).has_alpha ?
|
||||
0x20 :
|
||||
0x10; // 0x10-nieprzezroczysta, 0x20-przezroczysta
|
||||
else
|
||||
iFlags |= 0x10; // normalnie nieprzezroczyste
|
||||
iFlags |=
|
||||
( GfxRenderer.Texture(TextureID).has_alpha ?
|
||||
0x20 :
|
||||
0x10 ); // 0x10-nieprzezroczysta, 0x20-przezroczysta
|
||||
// renderowanie w cyklu przezroczystych tylko jeśli:
|
||||
// 1. Opacity=0 (przejściowo <1, czy tam <100) oraz
|
||||
// 2. tekstura ma przezroczystość
|
||||
@@ -391,19 +388,19 @@ int TSubModel::Load(cParser &parser, TModel3d *Model, int Pos, bool dynamic)
|
||||
else
|
||||
iFlags |= 0x10;
|
||||
|
||||
// visibility range
|
||||
std::string discard;
|
||||
parser.getTokens(5, false);
|
||||
parser >> discard >> fSquareMaxDist >> discard >> fSquareMinDist >> discard;
|
||||
|
||||
if (fSquareMaxDist >= 0.0)
|
||||
{
|
||||
fSquareMaxDist *= fSquareMaxDist;
|
||||
}
|
||||
else
|
||||
{
|
||||
fSquareMaxDist = 15000 * 15000;
|
||||
} // 15km to więcej, niż się obecnie wyświetla
|
||||
if( fSquareMaxDist <= 0.0 ) {
|
||||
// 15km to więcej, niż się obecnie wyświetla
|
||||
fSquareMaxDist = 15000.0;
|
||||
}
|
||||
fSquareMaxDist *= fSquareMaxDist;
|
||||
fSquareMinDist *= fSquareMinDist;
|
||||
|
||||
// transformation matrix
|
||||
fMatrix = new float4x4();
|
||||
readMatrix(parser, *fMatrix); // wczytanie transform
|
||||
if (!fMatrix->IdentityIs())
|
||||
@@ -688,7 +685,7 @@ void TSubModel::DisplayLists()
|
||||
glColorMaterial(GL_FRONT, GL_EMISSION);
|
||||
glDisable(GL_LIGHTING); // Tolaris-030603: bo mu punkty swiecace sie blendowaly
|
||||
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();
|
||||
glEnable(GL_LIGHTING);
|
||||
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
|
||||
@@ -1484,7 +1481,7 @@ void TSubModel::AdjustDist()
|
||||
if (fSquareMaxDist > 0.0)
|
||||
fSquareMaxDist *= Global::fDistanceFactor;
|
||||
if (fSquareMinDist > 0.0)
|
||||
fSquareMinDist *= Global::fDistanceFactor;
|
||||
fSquareMinDist /= Global::fDistanceFactor;
|
||||
// if (fNearAttenStart>0.0) fNearAttenStart*=Global::fDistanceFactor;
|
||||
// if (fNearAttenEnd>0.0) fNearAttenEnd*=Global::fDistanceFactor;
|
||||
if (Child)
|
||||
@@ -2015,12 +2012,10 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, float8 *v,
|
||||
if (pTexture.find_last_of("/\\") == std::string::npos)
|
||||
pTexture.insert(0, Global::asCurrentTexturePath);
|
||||
TextureID = GfxRenderer.GetTextureId(pTexture, szTexturePath);
|
||||
if( Opacity < 1.0 ) // przezroczystość z tekstury brana tylko dla Opacity 0!
|
||||
iFlags |= GfxRenderer.Texture( TextureID ).has_alpha ?
|
||||
0x20 :
|
||||
0x10; // 0x10-nieprzezroczysta, 0x20-przezroczysta
|
||||
else
|
||||
iFlags |= 0x10; // normalnie nieprzezroczyste
|
||||
iFlags |=
|
||||
( GfxRenderer.Texture( TextureID ).has_alpha ?
|
||||
0x20 :
|
||||
0x10 ); // 0x10-nieprzezroczysta, 0x20-przezroczysta
|
||||
}
|
||||
else
|
||||
TextureID = iTexture;
|
||||
|
||||
@@ -19,6 +19,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
//#include "math.h"
|
||||
#include "Timer.h"
|
||||
#include "mczapkie/mctools.h"
|
||||
#include "usefull.h"
|
||||
|
||||
TRealSound::TRealSound(std::string const &SoundName, double SoundAttenuation, double X, double Y, double Z, bool Dynamic,
|
||||
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
|
||||
{
|
||||
float df, Vlist;
|
||||
if ((Global::bSoundEnabled) && (AM != 0))
|
||||
if ((Global::bSoundEnabled) && (AM != 0) && (pSound != nullptr))
|
||||
{
|
||||
if (dt > 0)
|
||||
// efekt Dopplera
|
||||
@@ -190,9 +191,7 @@ void TRealSound::AdjFreq(double Freq, double dt) // McZapkie TODO: dorobic tu ef
|
||||
if (Timer::GetSoundTimer())
|
||||
{
|
||||
df = fFrequency * df; // TODO - brac czestotliwosc probkowania z wav
|
||||
pSound->SetFrequency((df < DSBFREQUENCY_MIN ?
|
||||
DSBFREQUENCY_MIN :
|
||||
(df > DSBFREQUENCY_MAX ? DSBFREQUENCY_MAX : df)));
|
||||
pSound->SetFrequency( clamp( df, static_cast<float>(DSBFREQUENCY_MIN), static_cast<float>(DSBFREQUENCY_MAX) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,6 +275,12 @@ opengl_texture::load_DDS() {
|
||||
--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
|
||||
data.resize( datasize );
|
||||
if( offset != 0 ) {
|
||||
|
||||
27
skydome.cpp
27
skydome.cpp
@@ -2,6 +2,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "skydome.h"
|
||||
#include "color.h"
|
||||
#include "usefull.h"
|
||||
|
||||
// sky gradient based on "A practical analytic model for daylight"
|
||||
// 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) :
|
||||
m_tesselation( Tesselation ) {
|
||||
|
||||
@@ -121,8 +107,6 @@ void CSkyDome::Generate() {
|
||||
}
|
||||
}
|
||||
|
||||
//******************************************************************************//
|
||||
|
||||
void CSkyDome::Update( Math3D::vector3 const &Sun ) {
|
||||
|
||||
if( true == SetSunPosition( Sun ) ) {
|
||||
@@ -166,8 +150,6 @@ void CSkyDome::Render() {
|
||||
::glDisableClientState( GL_VERTEX_ARRAY );
|
||||
}
|
||||
|
||||
//******************************************************************************//
|
||||
|
||||
bool CSkyDome::SetSunPosition( Math3D::vector3 const &Direction ) {
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
//******************************************************************************//
|
||||
|
||||
void CSkyDome::GetPerez( float *Perez, float Distribution[ 5 ][ 2 ], const float Turbidity ) {
|
||||
|
||||
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 ) {
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
//******************************************************************************//
|
||||
void CSkyDome::RebuildColors() {
|
||||
|
||||
// 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
|
||||
// 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 );
|
||||
// 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 );
|
||||
|
||||
41
usefull.h
41
usefull.h
@@ -9,17 +9,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#pragma once
|
||||
|
||||
//#define B1(t) (t*t*t)
|
||||
//#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
|
||||
#include "stdafx.h"
|
||||
|
||||
#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 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 asSceneryPath std::string("scenery\\")
|
||||
//#define asTexturePath AnsiString("textures\\")
|
||||
//#define asTextureExt AnsiString(".bmp")
|
||||
#define szSceneryPath "scenery\\"
|
||||
#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))
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user