Allow starting position on an upside down surface in arena

Todo: referee and make btKart cast ray at correct normal
This commit is contained in:
Benau 2016-09-17 09:53:44 +08:00
parent a0005d57e9
commit 606a5401d3
4 changed files with 36 additions and 6 deletions

View File

@ -391,7 +391,10 @@ void Kart::reset()
Vec3 front(0, 0, getKartLength()*0.5f);
m_xyz_front = getTrans()(front);
m_terrain_info->update(getTrans().getBasis());
// Base on update() below, require if starting point of kart is not near
// 0, 0, 0 (like in battle arena)
m_terrain_info->update(getTrans().getBasis(),
getTrans().getOrigin() + getTrans().getBasis() * Vec3(0, 0.3f, 0));
// Reset is also called when the kart is created, at which time
// m_controller is not yet defined, so this has to be tested here.

View File

@ -162,7 +162,7 @@ unsigned int WorldWithRank::getRescuePositionIndex(AbstractKart *kart)
for(unsigned int k=0; k<getCurrentNumKarts(); k++)
{
if(kart->getWorldKartId()==k) continue;
float abs_distance2 = (getKart(k)->getXYZ()-v).length2_2d();
float abs_distance2 = (getKart(k)->getXYZ()-v).length2();
const float CLEAR_SPAWN_RANGE2 = 5*5;
if( abs_distance2 < CLEAR_SPAWN_RANGE2)
{

View File

@ -56,7 +56,6 @@
#include "tracks/arena_graph.hpp"
#include "tracks/bezier_curve.hpp"
#include "tracks/check_manager.hpp"
#include "tracks/graph_node.hpp"
#include "tracks/model_definition_loader.hpp"
#include "tracks/node_3d.hpp"
#include "tracks/quad_graph.hpp"
@ -687,6 +686,34 @@ void Track::loadArenaGraph(const XMLNode &node)
}
} // loadArenaGraph
//-----------------------------------------------------------------------------
btQuaternion Track::getArenaStartRotation(const Vec3& xyz, float heading)
{
btQuaternion def_pos(Vec3(0, 1, 0), heading * DEGREE_TO_RAD);
if (!ArenaGraph::get())
return def_pos;
// Set the correct axis based on normal of the starting position
int node = Graph::UNKNOWN_SECTOR;
Graph::get()->findRoadSector(xyz, &node);
if (node == Graph::UNKNOWN_SECTOR)
{
Log::warn("track", "Starting position is not on ArenaGraph");
return def_pos;
}
const Vec3& normal = Graph::get()->getQuad(node)->getNormal();
Vec3 axis = -normal.cross(Vec3(0, 1, 0));
if (axis.length() == 0)
axis = Vec3(0, 0, 1);
btQuaternion q(axis, normal.angle(Vec3(0, 1, 0)));
btMatrix3x3 m;
m.setRotation(q);
return btQuaternion(m.getColumn(1), heading * DEGREE_TO_RAD) * q;
} // getArenaStartRotation
//-----------------------------------------------------------------------------
/** Loads the quad graph, i.e. the definition of all quads, and the way
* they are connected to each other.
@ -1961,9 +1988,8 @@ void Track::loadObjects(const XMLNode* root, const std::string& path, ModelDefin
}
m_start_transforms[position].setOrigin(xyz);
m_start_transforms[position].setRotation(
btQuaternion(btVector3(0,1,0),
h*DEGREE_TO_RAD ) );
m_start_transforms[position]
.setRotation(getArenaStartRotation(xyz, h));
}
else if (name == "camera")
{

View File

@ -375,6 +375,7 @@ private:
void loadTrackInfo();
void loadQuadGraph(unsigned int mode_id, const bool reverse);
void loadArenaGraph(const XMLNode &node);
btQuaternion getArenaStartRotation(const Vec3& xyz, float heading);
void convertTrackToBullet(scene::ISceneNode *node);
bool loadMainTrack(const XMLNode &node);
void loadMinimap();