genapts850: Add support for bidirectional lights that were created as omnis until now
This commit is contained in:
parent
28edfb0fb8
commit
95830a9a98
2 changed files with 38 additions and 13 deletions
|
@ -569,7 +569,7 @@ int LinearFeature::Finish( bool closed, unsigned int idx )
|
|||
{
|
||||
markStarted = false;
|
||||
cur_light_dist = 0.0f;
|
||||
bool directional_light = lights[i]->IsDirectional();
|
||||
int light_direction = lights[i]->LightDirection();
|
||||
bool alternate = false;
|
||||
|
||||
// which material for this light
|
||||
|
@ -647,33 +647,53 @@ int LinearFeature::Finish( bool closed, unsigned int idx )
|
|||
tmp = SGGeodesy::direct( prev_outer, heading, cur_light_dist );
|
||||
}
|
||||
|
||||
SGVec3f vec;
|
||||
if ( !directional_light )
|
||||
SGVec3f vec1, vec2;
|
||||
if ( light_direction == 0)
|
||||
{
|
||||
// calculate the omnidirectional normal
|
||||
vec = normalize(SGVec3f::fromGeod(tmp));
|
||||
} else
|
||||
vec1 = normalize(SGVec3f::fromGeod(tmp));
|
||||
} else if ( light_direction == 1)
|
||||
{
|
||||
// calculate the directional normal
|
||||
// calculate the directional normal. These lights all face to the right
|
||||
double heading_vec = SGMiscd::normalizePeriodic( 0, 360, heading + 90.0 );
|
||||
SGVec3f cart1 = SGVec3f::fromGeod(tmp);
|
||||
SGVec3f cart2 = SGVec3f::fromGeod( SGGeodesy::direct( tmp, heading_vec, 10 ) );
|
||||
vec = normalize(cart2 - cart1);
|
||||
vec1 = normalize(cart2 - cart1);
|
||||
} else //( light_direction == 2)
|
||||
{
|
||||
// calculate the directional normals for bidirectional lights
|
||||
SGVec3f cart1 = SGVec3f::fromGeod(tmp);
|
||||
SGVec3f cart2 = SGVec3f::fromGeod( SGGeodesy::direct( tmp, heading, 10 ) );
|
||||
vec1 = normalize(cart2 - cart1);
|
||||
cart2 = SGVec3f::fromGeod( SGGeodesy::direct( tmp, heading, -10 ) );
|
||||
vec2 = normalize(cart2 - cart1);
|
||||
}
|
||||
|
||||
if (!alternate)
|
||||
{
|
||||
cur_light_contour.AddLight( tmp, vec );
|
||||
cur_light_contour.AddLight( tmp, vec1 );
|
||||
if ( light_direction == 2)
|
||||
{
|
||||
cur_light_contour.AddLight( tmp, vec2 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (switch_poly)
|
||||
{
|
||||
cur_light_contour.AddLight( tmp, vec );
|
||||
cur_light_contour.AddLight( tmp, vec1 );
|
||||
if ( light_direction == 2)
|
||||
{
|
||||
cur_light_contour.AddLight( tmp, vec2 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
alt_light_contour.AddLight( tmp, vec );
|
||||
alt_light_contour.AddLight( tmp, vec1 );
|
||||
if ( light_direction == 2)
|
||||
{
|
||||
alt_light_contour.AddLight( tmp, vec2 );
|
||||
}
|
||||
}
|
||||
switch_poly = !switch_poly;
|
||||
}
|
||||
|
|
|
@ -55,9 +55,14 @@ public:
|
|||
unsigned int start_idx;
|
||||
unsigned int end_idx;
|
||||
|
||||
bool IsDirectional()
|
||||
// 1 for unidirectional
|
||||
// 2 for bidirectional
|
||||
// 0 for omnidirectional
|
||||
int LightDirection()
|
||||
{
|
||||
return (type == 103 || type == 104) ? true : false;
|
||||
if (type == 103 || type == 104) return 1;
|
||||
else if (type == 101 || type == 105) return 2;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
typedef std::vector <Lighting*> LightingList;
|
||||
|
@ -123,4 +128,4 @@ private:
|
|||
|
||||
typedef std::vector <LinearFeature *> FeatureList;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue