Added a setting to stk_config.xml to replace normals that are

'too different' from the normal of the triangle with the
normal of the triangle for interpolating the normals which
are used by the physics.
This should make 'smooth normals' more useful for tracks where
track and (say) a wall are connected, resulting in incorrect
normals for the physics.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11989 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2012-11-18 22:22:30 +00:00
parent 9b08adb960
commit 43b7f28d54
4 changed files with 34 additions and 6 deletions

View File

@ -39,8 +39,23 @@
it will be ignored. --> it will be ignored. -->
<news max-display="10"/> <news max-display="10"/>
<!-- If the normals (for wheel raycasts) should be smoothened --> <!-- smooth-normals: If the normals (for wheel raycasts) should be smoothened.
<physics smooth-normals="true"/> This is a global setting, it still needs to be activated for each
track individually.
smooth-angle-limits: If the angle between the normal of a vertex and
the normal of a triangle are larger than this value, the normal
of the triangle will be used in interpolating the normals. This
has the effect of an edge split modifier - if the flat track and (say)
a wall at a 90 egree angle are not separated, the normal at that
vertex will be 45 degrees, resulting in completely wrong physics.
The angle limit in this case will discard the 45 degrees, and use
the normal of the flat triangle (pointing upwards). In the worst
case (all three normals discarded, the interpolation will just
return the normal of the triangle (i.e. de facto no interpolation),
but it helps making smoothing much more useful without fixing tracks.
-->
<physics smooth-normals="true"
smooth-angle-limit="0.65"/>
<!-- The title music. --> <!-- The title music. -->
<music title="main_theme.music"/> <music title="main_theme.music"/>

View File

@ -139,6 +139,7 @@ void STKConfig::load(const std::string &filename)
CHECK_NEG(m_replay_delta_angle, "replay delta-angle" ); CHECK_NEG(m_replay_delta_angle, "replay delta-angle" );
CHECK_NEG(m_replay_delta_pos2, "replay delta-position" ); CHECK_NEG(m_replay_delta_pos2, "replay delta-position" );
CHECK_NEG(m_replay_dt, "replay delta-t" ); CHECK_NEG(m_replay_dt, "replay delta-t" );
CHECK_NEG(m_smooth_angle_limit, "physics smooth-angle-limit" );
// Square distance to make distance checks cheaper (no sqrt) // Square distance to make distance checks cheaper (no sqrt)
m_replay_delta_pos2 *= m_replay_delta_pos2; m_replay_delta_pos2 *= m_replay_delta_pos2;
@ -159,6 +160,7 @@ void STKConfig::init_defaults()
m_anvil_time = m_music_credit_time = m_anvil_time = m_music_credit_time =
m_delay_finish_time = m_skid_fadeout_time = m_delay_finish_time = m_skid_fadeout_time =
m_near_ground = m_item_switch_time = m_near_ground = m_item_switch_time =
m_smooth_angle_limit =
m_penalty_time = m_explosion_impulse_objects = UNDEFINED; m_penalty_time = m_explosion_impulse_objects = UNDEFINED;
m_bubble_gum_counter = -100; m_bubble_gum_counter = -100;
m_max_karts = -100; m_max_karts = -100;
@ -241,7 +243,8 @@ void STKConfig::getAllData(const XMLNode * root)
if (const XMLNode *physics_node= root->getNode("physics")) if (const XMLNode *physics_node= root->getNode("physics"))
{ {
physics_node->get("smooth-normals", &m_smooth_normals ); physics_node->get("smooth-normals", &m_smooth_normals );
physics_node->get("smooth-angle-limit", &m_smooth_angle_limit);
} }
if (const XMLNode *startup_node= root->getNode("startup")) if (const XMLNode *startup_node= root->getNode("startup"))

View File

@ -89,6 +89,10 @@ public:
a history files. */ a history files. */
bool m_smooth_normals; /**< If normals for raycasts for wheels bool m_smooth_normals; /**< If normals for raycasts for wheels
should be interpolated. */ should be interpolated. */
/** If the angle between a normal on a vertex and the normal of the
* triangle are more than this value, the physics will use the normal
* of the triangle in smoothing normal. */
float m_smooth_angle_limit;
int m_max_skidmarks; /**<Maximum number of skid marks/kart. */ int m_max_skidmarks; /**<Maximum number of skid marks/kart. */
float m_skid_fadeout_time; /**<Time till skidmarks fade away. */ float m_skid_fadeout_time; /**<Time till skidmarks fade away. */
float m_near_ground; /**<Determines when a kart is not near float m_near_ground; /**<Determines when a kart is not near

View File

@ -66,9 +66,15 @@ void TriangleMesh::addTriangle(const btVector3 &t1, const btVector3 &t2,
const Material* m) const Material* m)
{ {
m_triangleIndex2Material.push_back(m); m_triangleIndex2Material.push_back(m);
m_normals.push_back(n1);
m_normals.push_back(n2); btVector3 normal = (t2-t1).cross(t3-t1);
m_normals.push_back(n3); normal.normalize();
m_normals.push_back( normal.angle(n1)>stk_config->m_smooth_angle_limit
? normal : n1 );
m_normals.push_back( normal.angle(n2)>stk_config->m_smooth_angle_limit
? normal : n2 );
m_normals.push_back( normal.angle(n3)>stk_config->m_smooth_angle_limit
? normal : n3 );
m_mesh.addTriangle(t1, t2, t3); m_mesh.addTriangle(t1, t2, t3);
} // addTriangle } // addTriangle