mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-23 00:29:19 +02:00
light wrapper object
This commit is contained in:
69
DynObj.cpp
69
DynObj.cpp
@@ -3771,6 +3771,8 @@ void TDynamicObject::Render()
|
||||
glTranslated(vPosition.x, vPosition.y,
|
||||
vPosition.z); // standardowe przesunięcie względem początku scenerii
|
||||
glMultMatrixd(mMatrix.getArray());
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
// TODO: re-implement this
|
||||
if (fShade > 0.0)
|
||||
{ // Ra: zmiana oswietlenia w tunelu, wykopie
|
||||
GLfloat ambientLight[4] = {0.5f, 0.5f, 0.5f, 1.0f};
|
||||
@@ -3787,6 +3789,7 @@ void TDynamicObject::Render()
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
|
||||
}
|
||||
#endif
|
||||
if (Global::bUseVBO)
|
||||
{ // wersja VBO
|
||||
if (mdLowPolyInt)
|
||||
@@ -3819,6 +3822,8 @@ void TDynamicObject::Render()
|
||||
// ma byc wyswietlana
|
||||
// ABu: tylko w trybie FreeFly, zwykly tryb w world.cpp
|
||||
// Ra: świetła są ustawione dla zewnętrza danego pojazdu
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
// TODO: re-mplement this
|
||||
// oswietlenie kabiny
|
||||
GLfloat ambientCabLight[4] = {0.5f, 0.5f, 0.5f, 1.0f};
|
||||
GLfloat diffuseCabLight[4] = {0.5f, 0.5f, 0.5f, 1.0f};
|
||||
@@ -3854,20 +3859,25 @@ void TDynamicObject::Render()
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientCabLight);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseCabLight);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, specularCabLight);
|
||||
#endif
|
||||
if (Global::bUseVBO)
|
||||
mdKabina->RaRender(ObjSqrDist, 0);
|
||||
else
|
||||
mdKabina->Render(ObjSqrDist, 0);
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, Global::ambientDayLight);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, Global::diffuseDayLight);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, Global::specularDayLight);
|
||||
#endif
|
||||
}
|
||||
if (fShade != 0.0) // tylko jeśli było zmieniane
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
if( fShade != 0.0 ) // tylko jeśli było zmieniane
|
||||
{ // przywrócenie standardowego oświetlenia
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, Global::ambientDayLight);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, Global::diffuseDayLight);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, Global::specularDayLight);
|
||||
}
|
||||
#endif
|
||||
glPopMatrix();
|
||||
if (btnOn)
|
||||
TurnOff(); // przywrócenie domyślnych pozycji submodeli
|
||||
@@ -4265,6 +4275,8 @@ void TDynamicObject::RenderAlpha()
|
||||
glTranslated(vPosition.x, vPosition.y,
|
||||
vPosition.z); // standardowe przesunięcie względem początku scenerii
|
||||
glMultMatrixd(mMatrix.getArray());
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
// TODO: re-implement this
|
||||
if (fShade > 0.0)
|
||||
{ // Ra: zmiana oswietlenia w tunelu, wykopie
|
||||
GLfloat ambientLight[4] = {0.5f, 0.5f, 0.5f, 1.0f};
|
||||
@@ -4281,6 +4293,7 @@ void TDynamicObject::RenderAlpha()
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
|
||||
}
|
||||
#endif
|
||||
if (Global::bUseVBO)
|
||||
{ // wersja VBO
|
||||
if (mdLowPolyInt)
|
||||
@@ -4303,63 +4316,15 @@ void TDynamicObject::RenderAlpha()
|
||||
// if (mdPrzedsionek) //Ra: przedsionków tu wcześniej nie było - włączyć?
|
||||
// mdPrzedsionek->RenderAlpha(ObjSqrDist,ReplacableSkinID,iAlpha);
|
||||
}
|
||||
/* skoro false to można wyciąc
|
||||
//ABu: Tylko w trybie freefly
|
||||
if (false)//((mdKabina!=mdModel) && bDisplayCab && FreeFlyModeFlag)
|
||||
{
|
||||
//oswietlenie kabiny
|
||||
GLfloat ambientCabLight[4]= { 0.5f, 0.5f, 0.5f, 1.0f };
|
||||
GLfloat diffuseCabLight[4]= { 0.5f, 0.5f, 0.5f, 1.0f };
|
||||
GLfloat specularCabLight[4]= { 0.5f, 0.5f, 0.5f, 1.0f };
|
||||
for (int li=0; li<3; li++)
|
||||
{
|
||||
ambientCabLight[li]= Global::ambientDayLight[li]*0.9;
|
||||
diffuseCabLight[li]= Global::diffuseDayLight[li]*0.5;
|
||||
specularCabLight[li]= Global::specularDayLight[li]*0.5;
|
||||
}
|
||||
switch (MyTrack->eEnvironment)
|
||||
{
|
||||
case e_canyon:
|
||||
{
|
||||
for (int li=0; li<3; li++)
|
||||
{
|
||||
diffuseCabLight[li]*= 0.6;
|
||||
specularCabLight[li]*= 0.8;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case e_tunnel:
|
||||
{
|
||||
for (int li=0; li<3; li++)
|
||||
{
|
||||
ambientCabLight[li]*= 0.3;
|
||||
diffuseCabLight[li]*= 0.1;
|
||||
specularCabLight[li]*= 0.2;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
// dorobic swiatlo od drugiej strony szyby
|
||||
|
||||
glLightfv(GL_LIGHT0,GL_AMBIENT,ambientCabLight);
|
||||
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseCabLight);
|
||||
glLightfv(GL_LIGHT0,GL_SPECULAR,specularCabLight);
|
||||
|
||||
mdKabina->RenderAlpha(ObjSqrDist,0);
|
||||
//smierdzi
|
||||
// mdModel->RenderAlpha(SquareMagnitude(Global::pCameraPosition-pos),0);
|
||||
|
||||
glLightfv(GL_LIGHT0,GL_AMBIENT,Global::ambientDayLight);
|
||||
glLightfv(GL_LIGHT0,GL_DIFFUSE,Global::diffuseDayLight);
|
||||
glLightfv(GL_LIGHT0,GL_SPECULAR,Global::specularDayLight);
|
||||
}
|
||||
*/
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
// TODO: re-implement this
|
||||
if (fShade != 0.0) // tylko jeśli było zmieniane
|
||||
{ // przywrócenie standardowego oświetlenia
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, Global::ambientDayLight);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, Global::diffuseDayLight);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, Global::specularDayLight);
|
||||
}
|
||||
#endif
|
||||
glPopMatrix();
|
||||
if (btnOn)
|
||||
TurnOff(); // przywrócenie domyślnych pozycji submodeli
|
||||
|
||||
@@ -90,12 +90,16 @@ double Global::fFogEnd = 2000;
|
||||
float Global::Background[3] = {0.2, 0.4, 0.33};
|
||||
GLfloat Global::AtmoColor[] = {0.423f, 0.702f, 1.0f};
|
||||
GLfloat Global::FogColor[] = {0.6f, 0.7f, 0.8f};
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
GLfloat Global::ambientDayLight[] = {0.40f, 0.40f, 0.45f, 1.0f}; // robocze
|
||||
GLfloat Global::diffuseDayLight[] = {0.55f, 0.54f, 0.50f, 1.0f};
|
||||
GLfloat Global::specularDayLight[] = {0.95f, 0.94f, 0.90f, 1.0f};
|
||||
GLfloat Global::ambientLight[] = {0.80f, 0.80f, 0.85f, 1.0f}; // stałe
|
||||
GLfloat Global::diffuseLight[] = {0.85f, 0.85f, 0.80f, 1.0f};
|
||||
GLfloat Global::specularLight[] = {0.95f, 0.94f, 0.90f, 1.0f};
|
||||
#else
|
||||
opengl_light Global::DayLight;
|
||||
#endif
|
||||
GLfloat Global::whiteLight[] = {1.00f, 1.00f, 1.00f, 1.0f};
|
||||
GLfloat Global::noLight[] = {0.00f, 0.00f, 0.00f, 1.0f};
|
||||
GLfloat Global::darkLight[] = {0.03f, 0.03f, 0.03f, 1.0f}; //śladowe
|
||||
|
||||
53
Globals.h
53
Globals.h
@@ -120,6 +120,53 @@ class cParser; // nowy (powolny!) parser
|
||||
class TEvent;
|
||||
class TTextSound;
|
||||
|
||||
// bare-bones render controller, in lack of anything better yet
|
||||
struct opengl_renderer {
|
||||
|
||||
GLenum static const sunlight{ GL_LIGHT0 };
|
||||
GLenum static const ambientlight{ GL_LIGHT1 };
|
||||
|
||||
enum class rendermode {
|
||||
color
|
||||
};
|
||||
|
||||
rendermode renderpass{ rendermode::color };
|
||||
};
|
||||
|
||||
struct opengl_light {
|
||||
|
||||
GLuint id{ -1 };
|
||||
Math3D::vector3 direction;
|
||||
GLfloat position[ 4 ]; // 4th parameter specifies directional(0) or omni-directional(1) light source
|
||||
GLfloat ambient[ 4 ];
|
||||
GLfloat diffuse[ 4 ];
|
||||
GLfloat specular[ 4 ];
|
||||
|
||||
opengl_light() {
|
||||
position[ 0 ] = position[ 1 ] = position[ 2 ] = 0.0f; position[ 3 ] = 1.0f;
|
||||
ambient[ 0 ] = ambient[ 1 ] = ambient[ 2 ] = ambient[ 3 ] = 1.0f;
|
||||
diffuse[ 0 ] = diffuse[ 1 ] = diffuse[ 2 ] = diffuse[ 3 ] = 1.0f;
|
||||
specular[ 0 ] = specular[ 1 ] = specular[ 2 ] = specular[ 3 ] = 1.0f;
|
||||
}
|
||||
|
||||
inline
|
||||
void apply_intensity() {
|
||||
|
||||
glLightfv( id, GL_AMBIENT, ambient );
|
||||
glLightfv( id, GL_DIFFUSE, diffuse );
|
||||
glLightfv( id, GL_SPECULAR, specular );
|
||||
}
|
||||
inline
|
||||
void apply_angle() {
|
||||
|
||||
glLightfv( id, GL_POSITION, position );
|
||||
if( position[ 3 ] == 1.0f ) {
|
||||
GLfloat directionarray[] = { direction.x, direction.y, direction.z };
|
||||
glLightfv( id, GL_SPOT_DIRECTION, directionarray );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class TTranscript
|
||||
{ // klasa obsługująca linijkę napisu do dźwięku
|
||||
public:
|
||||
@@ -220,12 +267,18 @@ class Global
|
||||
static GLfloat AtmoColor[];
|
||||
static GLfloat FogColor[];
|
||||
// static bool bTimeChange;
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
static opengl_light AmbientLight;
|
||||
|
||||
static GLfloat ambientDayLight[];
|
||||
static GLfloat diffuseDayLight[];
|
||||
static GLfloat specularDayLight[];
|
||||
static GLfloat ambientLight[];
|
||||
static GLfloat diffuseLight[];
|
||||
static GLfloat specularLight[];
|
||||
#else
|
||||
static opengl_light DayLight;
|
||||
#endif
|
||||
static GLfloat whiteLight[];
|
||||
static GLfloat noLight[];
|
||||
static GLfloat darkLight[];
|
||||
|
||||
112
Ground.cpp
112
Ground.cpp
@@ -327,9 +327,15 @@ void TGroundNode::RenderVBO()
|
||||
if (linealpha > 255)
|
||||
linealpha = 255;
|
||||
float r, g, b;
|
||||
r = floor(Diffuse[0] * Global::ambientDayLight[0]); // w zaleznosci od koloru swiatla
|
||||
g = floor(Diffuse[1] * Global::ambientDayLight[1]);
|
||||
b = floor(Diffuse[2] * Global::ambientDayLight[2]);
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
r = floor( Diffuse[ 0 ] * Global::ambientDayLight[ 0 ] ); // w zaleznosci od koloru swiatla
|
||||
g = floor( Diffuse[ 1 ] * Global::ambientDayLight[ 1 ] );
|
||||
b = floor( Diffuse[ 2 ] * Global::ambientDayLight[ 2 ] );
|
||||
#else
|
||||
r = floor( Diffuse[ 0 ] * Global::DayLight.ambient[ 0 ] ); // w zaleznosci od koloru swiatla
|
||||
g = floor( Diffuse[ 1 ] * Global::DayLight.ambient[ 1 ] );
|
||||
b = floor( Diffuse[ 2 ] * Global::DayLight.ambient[ 2 ] );
|
||||
#endif
|
||||
glColor4ub(r, g, b, linealpha); // przezroczystosc dalekiej linii
|
||||
// glDisable(GL_LIGHTING); //nie powinny świecić
|
||||
glDrawArrays(iType, iVboPtr, iNumPts); // rysowanie linii
|
||||
@@ -388,9 +394,15 @@ void TGroundNode::RenderAlphaVBO()
|
||||
float linealpha = 255000 * fLineThickness / (mgn + 1.0);
|
||||
if (linealpha > 255)
|
||||
linealpha = 255;
|
||||
r = Diffuse[0] * Global::ambientDayLight[0]; // w zaleznosci od koloru swiatla
|
||||
g = Diffuse[1] * Global::ambientDayLight[1];
|
||||
b = Diffuse[2] * Global::ambientDayLight[2];
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
r = Diffuse[ 0 ] * Global::ambientDayLight[ 0 ]; // w zaleznosci od koloru swiatla
|
||||
g = Diffuse[ 1 ] * Global::ambientDayLight[ 1 ];
|
||||
b = Diffuse[ 2 ] * Global::ambientDayLight[ 2 ];
|
||||
#else
|
||||
r = Diffuse[ 0 ] * Global::DayLight.ambient[ 0 ]; // w zaleznosci od koloru swiatla
|
||||
g = Diffuse[ 1 ] * Global::DayLight.ambient[ 1 ];
|
||||
b = Diffuse[ 2 ] * Global::DayLight.ambient[ 2 ];
|
||||
#endif
|
||||
glColor4ub(r, g, b, linealpha); // przezroczystosc dalekiej linii
|
||||
// glDisable(GL_LIGHTING); //nie powinny świecić
|
||||
glDrawArrays(iType, iVboPtr, iNumPts); // rysowanie linii
|
||||
@@ -583,9 +595,15 @@ void TGroundNode::RenderDL()
|
||||
// if (iNumPts)
|
||||
{ // wszelkie linie są rysowane na samym końcu
|
||||
float r, g, b;
|
||||
r = Diffuse[0] * Global::ambientDayLight[0]; // w zaleznosci od koloru swiatla
|
||||
g = Diffuse[1] * Global::ambientDayLight[1];
|
||||
b = Diffuse[2] * Global::ambientDayLight[2];
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
r = Diffuse[ 0 ] * Global::ambientDayLight[ 0 ]; // w zaleznosci od koloru swiatla
|
||||
g = Diffuse[ 1 ] * Global::ambientDayLight[ 1 ];
|
||||
b = Diffuse[ 2 ] * Global::ambientDayLight[ 2 ];
|
||||
#else
|
||||
r = Diffuse[ 0 ] * Global::DayLight.ambient[ 0 ]; // w zaleznosci od koloru swiatla
|
||||
g = Diffuse[ 1 ] * Global::DayLight.ambient[ 1 ];
|
||||
b = Diffuse[ 2 ] * Global::DayLight.ambient[ 2 ];
|
||||
#endif
|
||||
glColor4ub(r, g, b, 1.0);
|
||||
glCallList(DisplayListID);
|
||||
// glColor4fv(Diffuse); //przywrócenie koloru
|
||||
@@ -659,9 +677,15 @@ void TGroundNode::RenderAlphaDL()
|
||||
float linealpha = 255000 * fLineThickness / (mgn + 1.0);
|
||||
if (linealpha > 255)
|
||||
linealpha = 255;
|
||||
r = Diffuse[0] * Global::ambientDayLight[0]; // w zaleznosci od koloru swiatla
|
||||
g = Diffuse[1] * Global::ambientDayLight[1];
|
||||
b = Diffuse[2] * Global::ambientDayLight[2];
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
r = Diffuse[ 0 ] * Global::ambientDayLight[ 0 ]; // w zaleznosci od koloru swiatla
|
||||
g = Diffuse[ 1 ] * Global::ambientDayLight[ 1 ];
|
||||
b = Diffuse[ 2 ] * Global::ambientDayLight[ 2 ];
|
||||
#else
|
||||
r = Diffuse[ 0 ] * Global::DayLight.ambient[ 0 ]; // w zaleznosci od koloru swiatla
|
||||
g = Diffuse[ 1 ] * Global::DayLight.ambient[ 1 ];
|
||||
b = Diffuse[ 2 ] * Global::DayLight.ambient[ 2 ];
|
||||
#endif
|
||||
glColor4ub(r, g, b, linealpha); // przezroczystosc dalekiej linii
|
||||
glCallList(DisplayListID);
|
||||
}
|
||||
@@ -2454,15 +2478,20 @@ void TGround::FirstInit()
|
||||
else
|
||||
glDisable(GL_FOG);
|
||||
glDisable(GL_LIGHTING);
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
// TODO, TBD: re-implement this
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, Global::lightPos); // daylight position
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, Global::ambientDayLight); // kolor wszechobceny
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, Global::diffuseDayLight); // kolor padający
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, Global::specularDayLight); // kolor odbity
|
||||
// musi być tutaj, bo wcześniej nie mieliśmy wartości światła
|
||||
#endif
|
||||
/*
|
||||
if (Global::fMoveLight >= 0.0) // albo tak, albo niech ustala minimum ciemności w nocy
|
||||
{
|
||||
*/
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
// TODO, TBD: re-implement this
|
||||
Global::fLuminance = // obliczenie luminacji "światła w ciemności"
|
||||
+0.150 * Global::ambientDayLight[0] // R
|
||||
+ 0.295 * Global::ambientDayLight[1] // G
|
||||
@@ -2472,6 +2501,7 @@ void TGround::FirstInit()
|
||||
Global::ambientDayLight[i] *=
|
||||
0.1 / Global::fLuminance; // ograniczenie jasności w nocy
|
||||
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, Global::ambientDayLight);
|
||||
#endif
|
||||
/*
|
||||
}
|
||||
else if (Global::bDoubleAmbient) // Ra: wcześniej było ambient dawane na obydwa światła
|
||||
@@ -2837,6 +2867,7 @@ bool TGround::Init(std::string asFile, HDC hDC)
|
||||
else if (str == "light")
|
||||
{ // Ra: ustawianie światła przeniesione do FirstInit
|
||||
WriteLog("Scenery light definition");
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
vector3 lp;
|
||||
parser.getTokens();
|
||||
parser >> lp.x;
|
||||
@@ -2848,27 +2879,44 @@ bool TGround::Init(std::string asFile, HDC hDC)
|
||||
Global::lightPos[0] = lp.x; // daylight position
|
||||
Global::lightPos[1] = lp.y;
|
||||
Global::lightPos[2] = lp.z;
|
||||
parser.getTokens();
|
||||
parser >> Global::ambientDayLight[0]; // kolor wszechobceny
|
||||
parser.getTokens();
|
||||
parser >> Global::ambientDayLight[1];
|
||||
parser.getTokens();
|
||||
parser >> Global::ambientDayLight[2];
|
||||
|
||||
parser.getTokens();
|
||||
parser >> Global::diffuseDayLight[0]; // kolor padający
|
||||
parser.getTokens();
|
||||
parser >> Global::diffuseDayLight[1];
|
||||
parser.getTokens();
|
||||
parser >> Global::diffuseDayLight[2];
|
||||
|
||||
parser.getTokens();
|
||||
parser >> Global::specularDayLight[0]; // kolor odbity
|
||||
parser.getTokens();
|
||||
parser >> Global::specularDayLight[1];
|
||||
parser.getTokens();
|
||||
parser >> Global::specularDayLight[2];
|
||||
#else
|
||||
parser.getTokens(3, false);
|
||||
parser
|
||||
>> Global::DayLight.direction.x
|
||||
>> Global::DayLight.direction.y
|
||||
>> Global::DayLight.direction.z;;
|
||||
Global::DayLight.direction.Normalize();
|
||||
#endif
|
||||
parser.getTokens(9, false);
|
||||
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
parser
|
||||
>> Global::ambientDayLight[ 0 ]
|
||||
>> Global::ambientDayLight[ 1 ]
|
||||
>> Global::ambientDayLight[ 2 ]
|
||||
>> Global::diffuseDayLight[ 0 ]
|
||||
>> Global::diffuseDayLight[ 1 ]
|
||||
>> Global::diffuseDayLight[ 2 ]
|
||||
>> Global::specularDayLight[ 0 ]
|
||||
>> Global::specularDayLight[ 1 ]
|
||||
>> Global::specularDayLight[ 2 ];
|
||||
#else
|
||||
/*
|
||||
parser
|
||||
// kolor wszechobceny
|
||||
>> Global::DayLight.ambient[0]
|
||||
>> Global::DayLight.ambient[1]
|
||||
>> Global::DayLight.ambient[2]
|
||||
// kolor padający
|
||||
>> Global::DayLight.diffuse[0]
|
||||
>> Global::DayLight.diffuse[1]
|
||||
>> Global::DayLight.diffuse[2]
|
||||
// kolor odbity
|
||||
>> Global::DayLight.specular[0]
|
||||
>> Global::DayLight.specular[1]
|
||||
>> Global::DayLight.specular[2];
|
||||
*/
|
||||
#endif
|
||||
do
|
||||
{
|
||||
parser.getTokens();
|
||||
|
||||
@@ -2583,6 +2583,8 @@ void TTrack::RaRenderVBO(int iPtr)
|
||||
void TTrack::EnvironmentSet()
|
||||
{ // ustawienie zmienionego światła
|
||||
glColor3f(1.0f, 1.0f, 1.0f); // Ra: potrzebne to?
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
// TODO: re-implement this
|
||||
if (eEnvironment)
|
||||
{ // McZapkie-310702: zmiana oswietlenia w tunelu, wykopie
|
||||
GLfloat ambientLight[4] = {0.5f, 0.5f, 0.5f, 1.0f};
|
||||
@@ -2614,10 +2616,13 @@ void TTrack::EnvironmentSet()
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
void TTrack::EnvironmentReset()
|
||||
{ // przywrócenie domyślnego światła
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
// TODO: re-implement this
|
||||
switch (eEnvironment)
|
||||
{ // przywrócenie globalnych ustawień światła, o ile było zmienione
|
||||
case e_canyon: // wykop
|
||||
@@ -2626,6 +2631,7 @@ void TTrack::EnvironmentReset()
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, Global::diffuseDayLight);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, Global::specularDayLight);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
void TTrack::RenderDyn()
|
||||
|
||||
24
Traction.cpp
24
Traction.cpp
@@ -323,9 +323,15 @@ void TTraction::RenderDL(float mgn) // McZapkie: mgn to odleglosc od obserwatora
|
||||
g *= 0.6;
|
||||
b *= 0.6;
|
||||
}
|
||||
r *= Global::ambientDayLight[0]; // w zaleźności od koloru swiatła
|
||||
g *= Global::ambientDayLight[1];
|
||||
b *= Global::ambientDayLight[2];
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
r *= Global::ambientDayLight[ 0 ]; // w zaleźności od koloru swiatła
|
||||
g *= Global::ambientDayLight[ 1 ];
|
||||
b *= Global::ambientDayLight[ 2 ];
|
||||
#else
|
||||
r *= Global::DayLight.ambient[ 0 ]; // w zaleźności od koloru swiatła
|
||||
g *= Global::DayLight.ambient[ 1 ];
|
||||
b *= Global::DayLight.ambient[2];
|
||||
#endif
|
||||
if (linealpha > 1.0)
|
||||
linealpha = 1.0; // trzeba ograniczyć do <=1
|
||||
glColor4f(r, g, b, linealpha);
|
||||
@@ -527,9 +533,15 @@ void TTraction::RenderVBO(float mgn, int iPtr)
|
||||
b = 0.0;
|
||||
break; //żółte z podłączonym zasilaniem z obu stron
|
||||
}
|
||||
r = r * Global::ambientDayLight[0]; // w zaleznosci od koloru swiatla
|
||||
g = g * Global::ambientDayLight[1];
|
||||
b = b * Global::ambientDayLight[2];
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
r *= Global::ambientDayLight[ 0 ]; // w zaleźności od koloru swiatła
|
||||
g *= Global::ambientDayLight[ 1 ];
|
||||
b *= Global::ambientDayLight[ 2 ];
|
||||
#else
|
||||
r *= Global::DayLight.ambient[ 0 ]; // w zaleźności od koloru swiatła
|
||||
g *= Global::DayLight.ambient[ 1 ];
|
||||
b *= Global::DayLight.ambient[ 2 ];
|
||||
#endif
|
||||
if (linealpha > 1.0)
|
||||
linealpha = 1.0; // trzeba ograniczyć do <=1
|
||||
glColor4f(r, g, b, linealpha);
|
||||
|
||||
93
World.cpp
93
World.cpp
@@ -347,7 +347,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
|
||||
// glLineWidth(2.0f);
|
||||
WriteLog("glPointSize(2.0f);");
|
||||
glPointSize(2.0f);
|
||||
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
// ----------- LIGHTING SETUP -----------
|
||||
// Light values and coordinates
|
||||
|
||||
@@ -359,7 +359,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
|
||||
Global::lightPos[3] = 0.0f;
|
||||
|
||||
// Ra: światła by sensowniej było ustawiać po wczytaniu scenerii
|
||||
|
||||
// TODO: re-implement this
|
||||
// Ra: szczątkowe światło rozproszone - żeby było cokolwiek widać w ciemności
|
||||
WriteLog("glLightModelfv(GL_LIGHT_MODEL_AMBIENT,darkLight);");
|
||||
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, Global::darkLight);
|
||||
@@ -375,7 +375,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, Global::lightPos);
|
||||
WriteLog("glEnable(GL_LIGHT0);");
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
#endif
|
||||
// glColor() ma zmieniać kolor wybrany w glColorMaterial()
|
||||
WriteLog("glEnable(GL_COLOR_MATERIAL);");
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
@@ -470,13 +470,22 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
|
||||
SetForegroundWindow(hWnd);
|
||||
WriteLog("Sound Init");
|
||||
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
glDisable( GL_DEPTH_TEST ); // Disables depth testing
|
||||
#ifndef EU07_USE_OLD_LIGHTING_MODEL
|
||||
glEnable( GL_LIGHTING );
|
||||
glEnable( GL_LIGHT0 );
|
||||
#endif
|
||||
|
||||
glLoadIdentity();
|
||||
// glColor4f(0.3f,0.0f,0.0f,0.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glTranslatef(0.0f, 0.0f, -0.50f);
|
||||
// glRasterPos2f(-0.25f, -0.10f);
|
||||
glDisable(GL_DEPTH_TEST); // Disables depth testing
|
||||
glColor3f(3.0f, 3.0f, 3.0f);
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
glColor3f( 3.0f, 3.0f, 3.0f );
|
||||
#else
|
||||
glColor3f( 1.0f, 1.0f, 1.0f );
|
||||
#endif
|
||||
|
||||
auto logo = TextureManager.GetTextureId( "logo", szTexturePath, 6 );
|
||||
TextureManager.Bind(logo); // Select our texture
|
||||
@@ -492,7 +501,7 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
|
||||
glVertex3f(-0.28f, 0.22f, 0.0f); // top left of the texture and quad
|
||||
glEnd();
|
||||
//~logo; Ra: to jest bez sensu zapis
|
||||
glColor3f(0.0f, 0.0f, 100.0f);
|
||||
glColor3f(0.0f, 0.0f, 1.0f);
|
||||
if (Global::detonatoryOK)
|
||||
{
|
||||
glRasterPos2f(-0.25f, -0.09f);
|
||||
@@ -502,7 +511,6 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
|
||||
}
|
||||
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
/*-----------------------Sound Initialization-----------------------*/
|
||||
TSoundsManager::Init(hWnd);
|
||||
// TSoundsManager::LoadSounds( "" );
|
||||
@@ -562,8 +570,26 @@ bool TWorld::Init(HWND NhWnd, HDC hDC)
|
||||
}
|
||||
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
|
||||
|
||||
#ifndef EU07_USE_OLD_LIGHTING_MODEL
|
||||
// setup lighting
|
||||
// GLfloat ambient[] = { 0.65f, 0.65f, 0.65f, 0.5f };
|
||||
GLfloat ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
::glLightModelfv( GL_LIGHT_MODEL_AMBIENT, ambient );
|
||||
|
||||
Global::DayLight.id = opengl_renderer::sunlight;
|
||||
// directional light
|
||||
// TODO, TBD: test omni-directional variant
|
||||
Global::DayLight.position[ 3 ] = 1.0f;
|
||||
::glLightf( opengl_renderer::sunlight, GL_SPOT_CUTOFF, 90.0 );
|
||||
// rgb value for 5780 kelvin
|
||||
Global::DayLight.diffuse[ 0 ] = 255.0 / 255.0;
|
||||
Global::DayLight.diffuse[ 1 ] = 242.0 / 255.0;
|
||||
Global::DayLight.diffuse[ 2 ] = 231.0 / 255.0;
|
||||
#endif
|
||||
|
||||
Ground.Init(Global::SceneryFile, hDC);
|
||||
// Global::tSinceStart= 0;
|
||||
Sun.init();
|
||||
Clouds.Init();
|
||||
WriteLog("Ground init OK");
|
||||
if (Global::detonatoryOK)
|
||||
@@ -1401,6 +1427,7 @@ void TWorld::Update_Lights() {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
// double a=Global::fTimeAngleDeg/180.0*M_PI-M_PI; //kąt godzinny w radianach
|
||||
double a = fmod( Global::fTimeAngleDeg, 360.0 ) / 180.0 * M_PI -
|
||||
M_PI; // kąt godzinny w radianach
|
||||
@@ -1478,6 +1505,31 @@ void TWorld::Update_Lights() {
|
||||
+0.150 * ( Global::diffuseDayLight[ 0 ] + Global::ambientDayLight[ 0 ] ) // R
|
||||
+ 0.295 * ( Global::diffuseDayLight[ 1 ] + Global::ambientDayLight[ 1 ] ) // G
|
||||
+ 0.055 * ( Global::diffuseDayLight[ 2 ] + Global::ambientDayLight[ 2 ] ); // B
|
||||
#else
|
||||
Sun.update();
|
||||
auto const position = Sun.getPosition();
|
||||
Global::DayLight.position[0] = position.x;
|
||||
Global::DayLight.position[1] = position.y;
|
||||
Global::DayLight.position[2] = position.z;
|
||||
auto const direction = -1.0 * Sun.getDirection();
|
||||
Global::DayLight.direction = direction;
|
||||
auto const intensity = std::min( 2.0f * Sun.getIntensity(), 1.0f );
|
||||
|
||||
Global::DayLight.diffuse[ 0 ] = 255.0 / 255.0 * intensity;
|
||||
Global::DayLight.diffuse[ 1 ] = 242.0 / 255.0 * intensity;
|
||||
Global::DayLight.diffuse[ 2 ] = 231.0 / 255.0 * intensity;
|
||||
// Global::DayLight.diffuse[ 3 ] = 1.0f;// std::min( 0.15f + intensity, 1.0f );
|
||||
Global::DayLight.ambient[ 0 ] = 205.0 / 255.0 * intensity * 0.75f;
|
||||
Global::DayLight.ambient[ 1 ] = 217.0 / 255.0 * intensity * 0.75f;
|
||||
Global::DayLight.ambient[ 2 ] = 231.0 / 255.0 * intensity * 0.75f;
|
||||
// Global::DayLight.ambient[ 3 ] = 1.0f;
|
||||
/*
|
||||
// Global::DayLight.ambient[ 3 ] = intensity;
|
||||
GLfloat ambient[] = { 0.1f + 0.5f * intensity, 0.1f + 0.5f * intensity, 0.1f + 0.5f * intensity, 0.5f };
|
||||
::glLightModelfv( GL_LIGHT_MODEL_AMBIENT, ambient );
|
||||
*/
|
||||
Global::fLuminance = intensity;
|
||||
#endif
|
||||
|
||||
vector3 sky = vector3( Global::AtmoColor[ 0 ], Global::AtmoColor[ 1 ], Global::AtmoColor[ 2 ] );
|
||||
if( Global::fLuminance < 0.25 ) { // przyspieszenie zachodu/wschodu
|
||||
@@ -1503,14 +1555,20 @@ bool TWorld::Render()
|
||||
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
|
||||
glLoadIdentity();
|
||||
Camera.SetMatrix(); // ustawienie macierzy kamery względem początku scenerii
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, Global::lightPos);
|
||||
|
||||
if (!Global::bWireFrame)
|
||||
{ // bez nieba w trybie rysowania linii
|
||||
glDisable(GL_FOG);
|
||||
if( !Global::bWireFrame ) { // bez nieba w trybie rysowania linii
|
||||
glDisable( GL_FOG );
|
||||
Clouds.Render();
|
||||
glEnable(GL_FOG);
|
||||
glEnable( GL_FOG );
|
||||
}
|
||||
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, Global::lightPos);
|
||||
#else
|
||||
Sun.render( Camera.Pos );
|
||||
Global::DayLight.apply_angle();
|
||||
Global::DayLight.apply_intensity();
|
||||
#endif
|
||||
if (Global::bUseVBO)
|
||||
{ // renderowanie przez VBO
|
||||
if (!Ground.RenderVBO(Camera.Pos))
|
||||
@@ -1693,7 +1751,10 @@ TWorld::Render_Cab() {
|
||||
glEnable( GL_LIGHTING ); // po renderowaniu drutów może być to wyłączone
|
||||
|
||||
if( dynamic->mdKabina ) // bo mogła zniknąć przy przechodzeniu do innego pojazdu
|
||||
{ // oswietlenie kabiny
|
||||
{
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
// TODO: re-implement this
|
||||
// oswietlenie kabiny
|
||||
GLfloat ambientCabLight[ 4 ] = { 0.5f, 0.5f, 0.5f, 1.0f };
|
||||
GLfloat diffuseCabLight[ 4 ] = { 0.5f, 0.5f, 0.5f, 1.0f };
|
||||
GLfloat specularCabLight[ 4 ] = { 0.5f, 0.5f, 0.5f, 1.0f };
|
||||
@@ -1773,6 +1834,7 @@ TWorld::Render_Cab() {
|
||||
glLightfv( GL_LIGHT0, GL_AMBIENT, ambientCabLight );
|
||||
glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuseCabLight );
|
||||
glLightfv( GL_LIGHT0, GL_SPECULAR, specularCabLight );
|
||||
#endif
|
||||
if( Global::bUseVBO ) { // renderowanie z użyciem VBO
|
||||
dynamic->mdKabina->RaRender( 0.0, dynamic->ReplacableSkinID, dynamic->iAlpha );
|
||||
dynamic->mdKabina->RaRenderAlpha( 0.0, dynamic->ReplacableSkinID, dynamic->iAlpha );
|
||||
@@ -1781,10 +1843,13 @@ TWorld::Render_Cab() {
|
||||
dynamic->mdKabina->Render( 0.0, dynamic->ReplacableSkinID, dynamic->iAlpha );
|
||||
dynamic->mdKabina->RenderAlpha( 0.0, dynamic->ReplacableSkinID, dynamic->iAlpha );
|
||||
}
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
// TODO: re-implement this
|
||||
// przywrócenie standardowych, bo zawsze są zmieniane
|
||||
glLightfv( GL_LIGHT0, GL_AMBIENT, Global::ambientDayLight );
|
||||
glLightfv( GL_LIGHT0, GL_DIFFUSE, Global::diffuseDayLight );
|
||||
glLightfv( GL_LIGHT0, GL_SPECULAR, Global::specularDayLight );
|
||||
#endif
|
||||
}
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
2
World.h
2
World.h
@@ -13,6 +13,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "Camera.h"
|
||||
#include "Ground.h"
|
||||
#include "sky.h"
|
||||
#include "sun.h"
|
||||
#include "mczapkie/mover.h"
|
||||
|
||||
class TWorld
|
||||
@@ -53,6 +54,7 @@ class TWorld
|
||||
GLuint base; // numer DL dla znaków w napisach
|
||||
texture_manager::size_type light; // numer tekstury dla smugi
|
||||
TSky Clouds;
|
||||
cSun Sun;
|
||||
TEvent *KeyEvents[10]; // eventy wyzwalane z klawiaury
|
||||
TMoverParameters *mvControlled; // wskaźnik na człon silnikowy, do wyświetlania jego parametrów
|
||||
int iCheckFPS; // kiedy znów sprawdzić FPS, żeby wyłączać optymalizacji od razu do zera
|
||||
|
||||
@@ -128,6 +128,7 @@
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sun.cpp" />
|
||||
<ClCompile Include="Texture.cpp" />
|
||||
<ClCompile Include="TextureDDS.cpp" />
|
||||
<ClCompile Include="Timer.cpp" />
|
||||
@@ -186,6 +187,7 @@
|
||||
<ClInclude Include="Sound.h" />
|
||||
<ClInclude Include="Spring.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
<ClInclude Include="sun.h" />
|
||||
<ClInclude Include="targetver.h" />
|
||||
<ClInclude Include="Texture.h" />
|
||||
<ClInclude Include="TextureDDS.h" />
|
||||
|
||||
@@ -189,6 +189,9 @@
|
||||
<ClCompile Include="Names.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sun.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="opengl\glew.h">
|
||||
@@ -365,6 +368,9 @@
|
||||
<ClInclude Include="Console\MWD.h">
|
||||
<Filter>Header Files\console</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="sun.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="maszyna.rc">
|
||||
|
||||
21
sky.cpp
21
sky.cpp
@@ -32,13 +32,22 @@ void TSky::Init()
|
||||
|
||||
void TSky::Render()
|
||||
{
|
||||
#ifndef EU07_USE_OLD_LIGHTING_MODEL
|
||||
return;
|
||||
#endif
|
||||
if (mdCloud)
|
||||
{ // jeśli jest model nieba
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask( GL_FALSE );
|
||||
glPushMatrix();
|
||||
// glDisable(GL_DEPTH_TEST);
|
||||
glTranslatef(Global::pCameraPosition.x, Global::pCameraPosition.y,
|
||||
Global::pCameraPosition.z);
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
// TODO: re-implement this
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
|
||||
#else
|
||||
glDisable( GL_LIGHTING );
|
||||
#endif
|
||||
if (Global::bUseVBO)
|
||||
{ // renderowanie z VBO
|
||||
mdCloud->RaRender(100, 0);
|
||||
@@ -49,11 +58,15 @@ void TSky::Render()
|
||||
mdCloud->Render(100, 0);
|
||||
mdCloud->RenderAlpha(100, 0);
|
||||
}
|
||||
// glEnable(GL_DEPTH_TEST);
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
// glEnable(GL_LIGHTING);
|
||||
glPopMatrix();
|
||||
#ifdef EU07_USE_OLD_LIGHTING_MODEL
|
||||
// TODO: re-implement this
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, Global::lightPos);
|
||||
#else
|
||||
glEnable( GL_LIGHTING );
|
||||
#endif
|
||||
glDepthMask( GL_TRUE );
|
||||
glEnable( GL_DEPTH_TEST );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
298
sun.cpp
Normal file
298
sun.cpp
Normal file
@@ -0,0 +1,298 @@
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "sun.h"
|
||||
#include "globals.h"
|
||||
#include "mtable.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cSun -- class responsible for dynamic calculation of position and intensity of the Sun,
|
||||
|
||||
cSun::cSun() {
|
||||
|
||||
setLocation( 19.00f, 52.00f ); // default location roughly in centre of Poland
|
||||
m_observer.press = 1013.0; // surface pressure, millibars
|
||||
m_observer.temp = 15.0; // ambient dry-bulb temperature, degrees C
|
||||
|
||||
TIME_ZONE_INFORMATION timezoneinfo; // TODO: timezone dependant on geographic location
|
||||
::GetTimeZoneInformation( &timezoneinfo );
|
||||
m_observer.timezone = -timezoneinfo.Bias / 60.0f;
|
||||
}
|
||||
|
||||
cSun::~cSun() { gluDeleteQuadric( sunsphere ); }
|
||||
|
||||
void
|
||||
cSun::init() {
|
||||
|
||||
sunsphere = gluNewQuadric();
|
||||
gluQuadricNormals( sunsphere, GLU_SMOOTH );
|
||||
}
|
||||
|
||||
void
|
||||
cSun::update() {
|
||||
|
||||
move();
|
||||
Math3D::vector3 position( 0.0f, 0.0f, -2000.0f );
|
||||
position.RotateX( (float)( m_body.elevref * ( M_PI / 180.0 ) ) );
|
||||
position.RotateY( (float)( ( 90.0 - m_body.hrang ) * ( M_PI / 180.0 ) ) );
|
||||
|
||||
m_position = position;
|
||||
}
|
||||
|
||||
void
|
||||
cSun::render( Math3D::vector3 const &Origin ) {
|
||||
|
||||
/*
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, position.getVector() ); // sun
|
||||
|
||||
GLfloat LightPosition[]= { 10.0f, 50.0f, -5.0f, 1.0f }; // ambient
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, LightPosition );
|
||||
*/
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_FOG);
|
||||
glColor4f( 255.0f/255.0f, 242.0f/255.0f, 231.0f/255.0f, 1.f );
|
||||
// debug line to locate the sun easier
|
||||
Math3D::vector3 position = m_position + Origin;
|
||||
glBegin( GL_LINES );
|
||||
glVertex3f( position.x, position.y, position.z );
|
||||
glVertex3f( position.x, 0.0f, position.z );
|
||||
glEnd();
|
||||
glPushMatrix();
|
||||
glTranslatef( position.x, position.y, position.z );
|
||||
// radius is a result of scaling true distance down to 2km -- it's scaled by equal ratio
|
||||
gluSphere( sunsphere, (float)(m_body.distance * 9.359157), 12, 12 );
|
||||
glPopMatrix();
|
||||
glEnable(GL_FOG);
|
||||
glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
Math3D::vector3
|
||||
cSun::getDirection() {
|
||||
|
||||
Math3D::vector3 position( 0.f, 0.f, -1.f );
|
||||
position.RotateX( (float)(m_body.elevref * (M_PI/180.0)) );
|
||||
position.RotateY( (float)((90.0 - m_body.hrang) * (M_PI/180.0)) );
|
||||
position.Normalize();
|
||||
return position;
|
||||
}
|
||||
|
||||
float
|
||||
cSun::getAngle() {
|
||||
|
||||
return (float)m_body.elevref;
|
||||
}
|
||||
|
||||
float cSun::getIntensity() {
|
||||
|
||||
irradiance();
|
||||
return (float)( m_body.etr/ 1399.0 ); // arbitrary scaling factor taken from etrn value
|
||||
}
|
||||
|
||||
void cSun::setLocation( float const Longitude, float const Latitude ) {
|
||||
|
||||
// convert fraction from geographical base of 6o minutes
|
||||
m_observer.longitude = (int)Longitude + (Longitude - (int)(Longitude)) * 100.0 / 60.0;
|
||||
m_observer.latitude = (int)Latitude + (Latitude - (int)(Latitude)) * 100.0 / 60.0 ;
|
||||
}
|
||||
|
||||
void cSun::setTemperature( float const Temperature ) {
|
||||
|
||||
m_observer.temp = Temperature;
|
||||
}
|
||||
|
||||
void cSun::setPressure( float const Pressure ) {
|
||||
|
||||
m_observer.press = Pressure;
|
||||
}
|
||||
|
||||
void cSun::move() {
|
||||
|
||||
static double degrad = 57.295779513; // converts from radians to degrees
|
||||
static double raddeg = 0.0174532925; // converts from degrees to radians
|
||||
|
||||
SYSTEMTIME localtime; // time for the calculation
|
||||
time( &localtime );
|
||||
|
||||
double ut = localtime.wHour
|
||||
+ localtime.wMinute / 60.0 // too low resolution, noticeable skips
|
||||
+ localtime.wSecond / 3600.0; // good enough in normal circumstances
|
||||
/*
|
||||
+ localtime.wMilliseconds / 3600000.0; // for really smooth movement
|
||||
*/
|
||||
double daynumber = 367 * localtime.wYear
|
||||
- 7 * ( localtime.wYear + ( localtime.wMonth + 9 ) /12 ) / 4
|
||||
+ 275 * localtime.wMonth / 9
|
||||
+ localtime.wDay
|
||||
- 730530
|
||||
+ (ut / 24.0);
|
||||
|
||||
// Universal Coordinated (Greenwich standard) time
|
||||
m_observer.utime = ut * 3600.0;
|
||||
m_observer.utime = m_observer.utime / 3600.0 - m_observer.timezone;
|
||||
|
||||
// mean longitude
|
||||
m_body.mnlong = 280.460 + 0.9856474 * daynumber;
|
||||
m_body.mnlong -= 360.0 * (int) ( m_body.mnlong / 360.0 ); // clamp the range to 0-360
|
||||
if( m_body.mnlong < 0.0 ) m_body.mnlong += 360.0;
|
||||
|
||||
// mean anomaly
|
||||
m_body.mnanom = 357.528 + 0.9856003 * daynumber;
|
||||
m_body.mnanom -= 360.0 * (int) ( m_body.mnanom / 360.0 ); // clamp the range to 0-360
|
||||
if( m_body.mnanom < 0.0 ) m_body.mnanom += 360.0;
|
||||
|
||||
// ecliptic longitude
|
||||
m_body.eclong = m_body.mnlong
|
||||
+ 1.915 * sin( m_body.mnanom * raddeg )
|
||||
+ 0.020 * sin ( 2.0 * m_body.mnanom * raddeg );
|
||||
m_body.eclong -= 360.0 * (int)( m_body.eclong / 360.0 );
|
||||
if( m_body.eclong < 0.0 ) m_body.eclong += 360.0; // clamp the range to 0-360
|
||||
|
||||
// obliquity of the ecliptic
|
||||
m_body.ecobli = 23.439 - 4.0e-07 * daynumber;
|
||||
|
||||
// declination
|
||||
m_body.declin = degrad * asin( sin (m_body.ecobli * raddeg) * sin (m_body.eclong * raddeg) );
|
||||
|
||||
// right ascension
|
||||
double top = cos ( raddeg * m_body.ecobli ) * sin ( raddeg * m_body.eclong );
|
||||
double bottom = cos ( raddeg * m_body.eclong );
|
||||
|
||||
m_body.rascen = degrad * atan2( top, bottom );
|
||||
if( m_body.rascen < 0.0 ) m_body.rascen += 360.0; // (make it a positive angle)
|
||||
|
||||
// Greenwich mean sidereal time
|
||||
m_observer.gmst = 6.697375 + 0.0657098242 * daynumber + m_observer.utime;
|
||||
|
||||
m_observer.gmst -= 24.0 * (int)( m_observer.gmst / 24.0 );
|
||||
if( m_observer.gmst < 0.0 ) m_observer.gmst += 24.0;
|
||||
|
||||
// local mean sidereal time
|
||||
m_observer.lmst = m_observer.gmst * 15.0 + m_observer.longitude;
|
||||
|
||||
m_observer.lmst -= 360.0 * (int)( m_observer.lmst / 360.0 );
|
||||
if( m_observer.lmst < 0.0 ) m_observer.lmst += 360.0;
|
||||
|
||||
// hour angle
|
||||
m_body.hrang = m_observer.lmst - m_body.rascen;
|
||||
|
||||
if( m_body.hrang < -180.0 ) m_body.hrang += 360.0; // (force it between -180 and 180 degrees)
|
||||
else if( m_body.hrang > 180.0 ) m_body.hrang -= 360.0;
|
||||
|
||||
double cz; // cosine of the solar zenith angle
|
||||
|
||||
double tdatcd = cos( raddeg * m_body.declin );
|
||||
double tdatch = cos( raddeg * m_body.hrang );
|
||||
double tdatcl = cos( raddeg * m_observer.latitude );
|
||||
double tdatsd = sin( raddeg * m_body.declin );
|
||||
double tdatsl = sin( raddeg * m_observer.latitude );
|
||||
|
||||
cz = tdatsd * tdatsl + tdatcd * tdatcl * tdatch;
|
||||
|
||||
// (watch out for the roundoff errors)
|
||||
if( fabs (cz) > 1.0 ) { cz >= 0.0 ? cz = 1.0 : cz = -1.0; }
|
||||
|
||||
m_body.zenetr = acos( cz ) * degrad;
|
||||
m_body.elevetr = 90.0 - m_body.zenetr;
|
||||
refract();
|
||||
|
||||
// additional calculations for proper object sizing.
|
||||
// orbit eccentricity
|
||||
double e = 0.016709 - 1.151e-9 * daynumber;
|
||||
// eccentric anomaly
|
||||
double E = m_body.mnanom + e * degrad * sin(m_body.mnanom) * ( 1.0 + e * cos(m_body.mnanom) );
|
||||
double xv = cos(E) - e;
|
||||
double yv = sqrt(1.0 - e*e) * sin(E);
|
||||
m_body.distance = sqrt( xv*xv + yv*yv );
|
||||
}
|
||||
|
||||
void cSun::refract() {
|
||||
|
||||
static double raddeg = 0.0174532925; // converts from degrees to radians
|
||||
|
||||
double prestemp; // temporary pressure/temperature correction
|
||||
double refcor; // temporary refraction correction
|
||||
double tanelev; // tangent of the solar elevation angle
|
||||
|
||||
// if the sun is near zenith, the algorithm bombs; refraction near 0.
|
||||
if( m_body.elevetr > 85.0 )
|
||||
refcor = 0.0;
|
||||
else {
|
||||
|
||||
tanelev = tan( raddeg * m_body.elevetr );
|
||||
if( m_body.elevetr >= 5.0 )
|
||||
refcor = 58.1 / tanelev
|
||||
- 0.07 / pow( tanelev, 3 )
|
||||
+ 0.000086 / pow( tanelev, 5 );
|
||||
else if( m_body.elevetr >= -0.575 )
|
||||
refcor = 1735.0
|
||||
+ m_body.elevetr * ( -518.2 + m_body.elevetr *
|
||||
( 103.4 + m_body.elevetr * ( -12.79 + m_body.elevetr * 0.711 ) ) );
|
||||
else
|
||||
refcor = -20.774 / tanelev;
|
||||
|
||||
prestemp = ( m_observer.press * 283.0 ) / ( 1013.0 * ( 273.0 + m_observer.temp ) );
|
||||
refcor *= prestemp / 3600.0;
|
||||
}
|
||||
|
||||
// refracted solar elevation angle
|
||||
m_body.elevref = m_body.elevetr + refcor;
|
||||
|
||||
// refracted solar zenith angle
|
||||
m_body.zenref = 90.0 - m_body.elevref;
|
||||
}
|
||||
|
||||
void cSun::irradiance() {
|
||||
|
||||
static double degrad = 57.295779513; // converts from radians to degrees
|
||||
static double raddeg = 0.0174532925; // converts from degrees to radians
|
||||
|
||||
SYSTEMTIME localtime; // time for the calculation
|
||||
time( &localtime );
|
||||
|
||||
m_body.dayang = ( yearday( localtime.wDay, localtime.wMonth, localtime.wYear ) - 1 ) * 360.0 / 365.0;
|
||||
double sd = sin( raddeg * m_body.dayang ); // sine of the day angle
|
||||
double cd = cos( raddeg * m_body.dayang ); // cosine of the day angle or delination
|
||||
m_body.erv = 1.000110 + 0.034221*cd + 0.001280*sd;
|
||||
double d2 = 2.0 * m_body.dayang;
|
||||
double c2 = cos( raddeg * d2 );
|
||||
double s2 = sin( raddeg * d2 );
|
||||
m_body.erv += 0.000719*c2 + 0.000077*s2;
|
||||
|
||||
double solcon = 1367.0; // Solar constant, 1367 W/sq m
|
||||
|
||||
m_body.coszen = cos( raddeg * m_body.zenref );
|
||||
if( m_body.coszen > 0.0 ) {
|
||||
m_body.etrn = solcon * m_body.erv;
|
||||
m_body.etr = m_body.etrn * m_body.coszen;
|
||||
}
|
||||
else {
|
||||
m_body.etrn = 0.0;
|
||||
m_body.etr = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
int cSun::yearday( int Day, const int Month, const int Year ) {
|
||||
|
||||
char daytab[ 2 ][ 13 ] = {
|
||||
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
|
||||
{ 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
|
||||
};
|
||||
int i, leap;
|
||||
|
||||
leap = ( Year%4 == 0 ) && ( Year%100 != 0 ) || ( Year%400 == 0 );
|
||||
for( i = 1; i < Month; ++i )
|
||||
Day += daytab[ leap ][ i ];
|
||||
|
||||
return Day;
|
||||
}
|
||||
|
||||
// obtains current time for calculations
|
||||
void
|
||||
cSun::time( SYSTEMTIME *Time ) {
|
||||
|
||||
::GetLocalTime( Time );
|
||||
// NOTE: we're currently using local time to determine day/month/year
|
||||
// TODO: enter scenario-defined day/month/year instead.
|
||||
Time->wHour = GlobalTime->hh;
|
||||
Time->wMinute = GlobalTime->mm;
|
||||
Time->wSecond = std::floor( GlobalTime->mr );
|
||||
}
|
||||
99
sun.h
Normal file
99
sun.h
Normal file
@@ -0,0 +1,99 @@
|
||||
#pragma once
|
||||
|
||||
#include "windows.h"
|
||||
#include "opengl/glew.h"
|
||||
#include "opengl/wglew.h"
|
||||
#include "dumb3d.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cSun -- class responsible for dynamic calculation of position and intensity of the Sun,
|
||||
// given current weather, time and geographic location.
|
||||
|
||||
class cSun {
|
||||
|
||||
public:
|
||||
// types:
|
||||
|
||||
// methods:
|
||||
void init();
|
||||
void update();
|
||||
void render( Math3D::vector3 const &Origin );
|
||||
// returns location of the sun in the 3d scene
|
||||
Math3D::vector3 getPosition() { return m_position; }
|
||||
// returns vector pointing at the sun
|
||||
Math3D::vector3 getDirection();
|
||||
// returns current elevation above horizon
|
||||
float getAngle();
|
||||
// returns current intensity of the sun
|
||||
float getIntensity();
|
||||
// sets current geographic location
|
||||
void setLocation( float const Longitude, float const Latitude );
|
||||
// sets ambient temperature in degrees C.
|
||||
void setTemperature( float const Temperature );
|
||||
// sets surface pressure in milibars
|
||||
void setPressure( float const Pressure );
|
||||
|
||||
// constructors:
|
||||
cSun();
|
||||
|
||||
// deconstructor:
|
||||
~cSun();
|
||||
|
||||
// members:
|
||||
|
||||
protected:
|
||||
// types:
|
||||
|
||||
// methods:
|
||||
// calculates sun position on the sky given specified time and location
|
||||
void move();
|
||||
// calculates position adjustment due to refraction
|
||||
void refract();
|
||||
// calculates light intensity at current moment
|
||||
void irradiance();
|
||||
// calculates day of year from given date
|
||||
int yearday( int Day, int const Month, int const Year );
|
||||
// obtains current time for calculations
|
||||
void time( SYSTEMTIME *Time );
|
||||
|
||||
// members:
|
||||
GLUquadricObj *sunsphere; // temporary handler for sun positioning test
|
||||
|
||||
struct celestialbody { // main planet parameters
|
||||
|
||||
double dayang; // day angle (daynum*360/year-length) degrees
|
||||
double mnlong; // mean longitude, degrees
|
||||
double mnanom; // mean anomaly, degrees
|
||||
double eclong; // ecliptic longitude, degrees.
|
||||
double ecobli; // obliquity of ecliptic.
|
||||
double declin; // declination--zenith angle of solar noon at equator, degrees NORTH.
|
||||
double rascen; // right ascension, degrees
|
||||
double hrang; // hour angle--hour of sun from solar noon, degrees WEST
|
||||
double zenetr; // solar zenith angle, no atmospheric correction (= ETR)
|
||||
double zenref; // solar zenith angle, deg. from zenith, refracted
|
||||
double coszen; // cosine of refraction corrected solar zenith angle
|
||||
double elevetr; // solar elevation, no atmospheric correction (= ETR)
|
||||
double elevref; // solar elevation angle, deg. from horizon, refracted.
|
||||
double distance; // distance from earth in AUs
|
||||
double erv; // earth radius vector (multiplied to solar constant)
|
||||
double etr; // extraterrestrial (top-of-atmosphere) W/sq m global horizontal solar irradiance
|
||||
double etrn; // extraterrestrial (top-of-atmosphere) W/sq m direct normal solar irradiance
|
||||
};
|
||||
|
||||
struct observer { // weather, time and position data in observer's location
|
||||
|
||||
double latitude; // latitude, degrees north (south negative)
|
||||
double longitude; // longitude, degrees east (west negative)
|
||||
double utime; // universal (Greenwich) standard time
|
||||
double timezone; // time zone, east (west negative). USA: Mountain = -7, Central = -6, etc.
|
||||
double gmst; // Greenwich mean sidereal time, hours
|
||||
double lmst; // local mean sidereal time, degrees
|
||||
double temp; // ambient dry-bulb temperature, degrees C, used for refraction correction
|
||||
double press; // surface pressure, millibars, used for refraction correction and ampress
|
||||
};
|
||||
|
||||
celestialbody m_body;
|
||||
observer m_observer;
|
||||
Math3D::vector3 m_position;
|
||||
};
|
||||
Reference in New Issue
Block a user