From 1709ccc36de5124946daa0f35f69c87451c1efd6 Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 28 Jan 2014 21:42:23 +1100 Subject: [PATCH] Started to set the gravity for selected material based on the normal of the triangle where the kart is on. --- src/graphics/material.cpp | 6 ++++++ src/graphics/material.hpp | 10 ++++++++++ src/karts/kart.cpp | 14 ++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/graphics/material.cpp b/src/graphics/material.cpp index c1311c401..0fde95157 100644 --- a/src/graphics/material.cpp +++ b/src/graphics/material.cpp @@ -146,6 +146,7 @@ Material::Material(const XMLNode *node, int index, bool deprecated) node->get("water-splash", &m_water_splash ); node->get("jump", &m_is_jump_texture ); + node->get("has-gravity", &m_has_gravity ); if (m_collision_reaction != NORMAL) { @@ -344,6 +345,10 @@ Material::Material(const XMLNode *node, int index, bool deprecated) } } // for i getNumNodes() + + if(m_has_gravity) + m_high_tire_adhesion = true; + install(/*is_full_path*/false); } // Material @@ -410,6 +415,7 @@ void Material::init(unsigned int index) m_is_heightmap = false; m_water_splash = false; m_is_jump_texture = false; + m_has_gravity = false; for (int n=0; ngetMaterial(); if (!material) // kart falling off the track { + Vec3 gravity(0, -9.8f, 0); + btRigidBody *body = getVehicle()->getRigidBody(); + body->setGravity(gravity); + // let kart fall a bit before rescuing const Vec3 *min, *max; World::getWorld()->getTrack()->getAABB(&min, &max); @@ -1221,6 +1225,16 @@ void Kart::update(float dt) } else { + Vec3 gravity(0.0f, -9.8f, 0.0f); + btRigidBody *body = getVehicle()->getRigidBody(); + // If the material should overwrite the gravity, + if(material->hasGravity()) + { + Vec3 normal = m_terrain_info->getNormal(); + gravity = normal * -9.8f; + } + body->setGravity(gravity); + handleMaterialSFX(material); if (material->isDriveReset() && isOnGround()) new RescueAnimation(this);