Make getNode return pointer. (easier with dynamic_cast later)
This commit is contained in:
parent
9d65e2047c
commit
505b50da0c
@ -64,7 +64,7 @@ Bowling::Bowling(AbstractKart *kart)
|
||||
{
|
||||
unsigned int sector = ((LinearWorld*)World::getWorld())->
|
||||
getTrackSector(kart->getWorldKartId()).getCurrentGraphNode();
|
||||
quadNormal = QuadGraph::get()->getNode(sector).getNormal();
|
||||
quadNormal = QuadGraph::get()->getNode(sector)->getNormal();
|
||||
}
|
||||
else
|
||||
quadNormal = btVector3(.0f, 1.0f, .0f);
|
||||
|
@ -161,8 +161,8 @@ void Item::initItem(ItemType type, const Vec3 &xyz)
|
||||
Vec3 distances;
|
||||
QuadGraph::get()->spatialToTrack(&distances, m_xyz, m_graph_node);
|
||||
m_distance_from_center = distances.getX();
|
||||
const GraphNode &gn = QuadGraph::get()->getNode(m_graph_node);
|
||||
const Vec3 right = gn.getRightUnitVector();
|
||||
const GraphNode* gn = QuadGraph::get()->getNode(m_graph_node);
|
||||
const Vec3& right = gn->getRightUnitVector();
|
||||
// Give it 10% more space, since the kart will not always come
|
||||
// parallel to the drive line.
|
||||
Vec3 delta = right * sqrt(m_distance_2) * 1.3f;
|
||||
|
@ -228,7 +228,7 @@ void ItemManager::insertItem(Item *item)
|
||||
// If the item is on the driveline, store it at the appropriate index
|
||||
if(graph_node > -1)
|
||||
{
|
||||
int sector = QuadGraph::get()->getNode(graph_node).getNodeIndex();
|
||||
int sector = QuadGraph::get()->getNode(graph_node)->getNodeIndex();
|
||||
(*m_items_in_quads)[sector].push_back(item);
|
||||
}
|
||||
else // otherwise store it in the 'outside' index
|
||||
|
@ -100,7 +100,7 @@ RubberBall::RubberBall(AbstractKart *kart)
|
||||
// initialises the current graph node
|
||||
TrackSector::update(getXYZ());
|
||||
const Vec3& normal =
|
||||
QuadGraph::get()->getNode(getCurrentGraphNode()).getNormal();
|
||||
QuadGraph::get()->getNode(getCurrentGraphNode())->getNormal();
|
||||
TerrainInfo::update(getXYZ(), -normal);
|
||||
initializeControlPoints(m_owner->getXYZ());
|
||||
|
||||
@ -136,7 +136,7 @@ void RubberBall::initializeControlPoints(const Vec3 &xyz)
|
||||
// left or right when firing the ball off track.
|
||||
getNextControlPoint();
|
||||
m_control_points[2] =
|
||||
QuadGraph::get()->getNode(m_last_aimed_graph_node).getCenter();
|
||||
QuadGraph::get()->getNode(m_last_aimed_graph_node)->getCenter();
|
||||
|
||||
// This updates m_last_aimed_graph_node, and sets m_control_points[3]
|
||||
getNextControlPoint();
|
||||
@ -201,12 +201,12 @@ unsigned int RubberBall::getSuccessorToHitTarget(unsigned int node_index,
|
||||
|
||||
unsigned int sect =
|
||||
lin_world->getSectorForKart(m_target);
|
||||
succ = QuadGraph::get()->getNode(node_index).getSuccessorToReach(sect);
|
||||
succ = QuadGraph::get()->getNode(node_index)->getSuccessorToReach(sect);
|
||||
|
||||
if(dist)
|
||||
*dist += QuadGraph::get()->getNode(node_index)
|
||||
.getDistanceToSuccessor(succ);
|
||||
return QuadGraph::get()->getNode(node_index).getSuccessor(succ);
|
||||
->getDistanceToSuccessor(succ);
|
||||
return QuadGraph::get()->getNode(node_index)->getSuccessor(succ);
|
||||
} // getSuccessorToHitTarget
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -236,9 +236,9 @@ void RubberBall::getNextControlPoint()
|
||||
|
||||
m_last_aimed_graph_node = next;
|
||||
m_length_cp_2_3 = dist;
|
||||
const Quad &quad =
|
||||
const GraphNode* gn =
|
||||
QuadGraph::get()->getNode(m_last_aimed_graph_node);
|
||||
m_control_points[3] = quad.getCenter();
|
||||
m_control_points[3] = gn->getCenter();
|
||||
} // getNextControlPoint
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -212,10 +212,10 @@ void EndController::handleSteering(float dt)
|
||||
*/
|
||||
//Reaction to being outside of the road
|
||||
if( fabsf(m_world->getDistanceToCenterForKart( m_kart->getWorldKartId() )) >
|
||||
0.5f* QuadGraph::get()->getNode(m_track_node).getPathWidth()+0.5f )
|
||||
0.5f* QuadGraph::get()->getNode(m_track_node)->getPathWidth()+0.5f )
|
||||
{
|
||||
const int next = m_next_node_index[m_track_node];
|
||||
target_point = QuadGraph::get()->getNode(next).getCenter();
|
||||
target_point = QuadGraph::get()->getNode(next)->getCenter();
|
||||
#ifdef AI_DEBUG
|
||||
Log::debug("end_controller.cpp", "- Outside of road: steer to center point.");
|
||||
#endif
|
||||
@ -275,7 +275,7 @@ void EndController::findNonCrashingPoint(Vec3 *result)
|
||||
target_sector = m_next_node_index[sector];
|
||||
|
||||
//direction is a vector from our kart to the sectors we are testing
|
||||
direction = QuadGraph::get()->getNode(target_sector).getCenter()
|
||||
direction = QuadGraph::get()->getNode(target_sector)->getCenter()
|
||||
- m_kart->getXYZ();
|
||||
|
||||
float len=direction.length_2d();
|
||||
@ -300,9 +300,9 @@ void EndController::findNonCrashingPoint(Vec3 *result)
|
||||
|
||||
//If we are outside, the previous sector is what we are looking for
|
||||
if ( distance + m_kart_width * 0.5f
|
||||
> QuadGraph::get()->getNode(sector).getPathWidth()*0.5f )
|
||||
> QuadGraph::get()->getNode(sector)->getPathWidth()*0.5f )
|
||||
{
|
||||
*result = QuadGraph::get()->getNode(sector).getCenter();
|
||||
*result = QuadGraph::get()->getNode(sector)->getCenter();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -476,14 +476,14 @@ void SkiddingAI::handleSteering(float dt)
|
||||
m_world->getDistanceToCenterForKart( m_kart->getWorldKartId() );
|
||||
|
||||
if( fabsf(side_dist) >
|
||||
0.5f* QuadGraph::get()->getNode(m_track_node).getPathWidth()+0.5f )
|
||||
0.5f* QuadGraph::get()->getNode(m_track_node)->getPathWidth()+0.5f )
|
||||
{
|
||||
steer_angle = steerToPoint(QuadGraph::get()->getNode(next)
|
||||
.getCenter());
|
||||
->getCenter());
|
||||
|
||||
#ifdef AI_DEBUG
|
||||
m_debug_sphere[0]->setPosition(QuadGraph::get()->getNode(next)
|
||||
.getCenter().toIrrVector());
|
||||
->getCenter().toIrrVector());
|
||||
Log::debug(getControllerName().c_str(),
|
||||
"Outside of road: steer to center point.");
|
||||
#endif
|
||||
@ -636,7 +636,7 @@ void SkiddingAI::handleItemCollectionAndAvoidance(Vec3 *aim_point,
|
||||
const float max_item_lookahead_distance = 30.f;
|
||||
while(distance < max_item_lookahead_distance)
|
||||
{
|
||||
int n_index= QuadGraph::get()->getNode(node).getNodeIndex();
|
||||
int n_index= QuadGraph::get()->getNode(node)->getNodeIndex();
|
||||
const std::vector<Item *> &items_ahead =
|
||||
ItemManager::get()->getItemsInQuads(n_index);
|
||||
for(unsigned int i=0; i<items_ahead.size(); i++)
|
||||
@ -782,7 +782,7 @@ void SkiddingAI::handleItemCollectionAndAvoidance(Vec3 *aim_point,
|
||||
Vec3 xyz = item_to_collect->getXYZ();
|
||||
Vec3 item_direction = xyz - m_kart->getXYZ();
|
||||
Vec3 plane_normal = QuadGraph::get()->getNode(m_track_node)
|
||||
.getNormal();
|
||||
->getNormal();
|
||||
float dist_to_plane = item_direction.dot(plane_normal);
|
||||
Vec3 projected_xyz = xyz - dist_to_plane*plane_normal;
|
||||
|
||||
@ -865,7 +865,7 @@ bool SkiddingAI::handleSelectedItem(Vec3 kart_aim_direction, Vec3 *aim_point)
|
||||
// the kart is. The current quad provides a good estimate of the kart's plane.
|
||||
const Vec3 &xyz = m_item_to_collect->getXYZ();
|
||||
Vec3 item_direction = xyz - m_kart->getXYZ();
|
||||
Vec3 plane_normal = QuadGraph::get()->getNode(m_track_node).getNormal();
|
||||
Vec3 plane_normal = QuadGraph::get()->getNode(m_track_node)->getNormal();
|
||||
float dist_to_plane = item_direction.dot(plane_normal);
|
||||
Vec3 projected_xyz = xyz - dist_to_plane*plane_normal;
|
||||
|
||||
@ -926,7 +926,7 @@ bool SkiddingAI::steerToAvoid(const std::vector<const Item *> &items_to_avoid,
|
||||
// rightmost point - if so, nothing to do.
|
||||
Vec3 left(items_to_avoid[index_left_most]->getXYZ());
|
||||
int node_index = items_to_avoid[index_left_most]->getGraphNode();
|
||||
Vec3 normal = QuadGraph::get()->getNode(node_index).getNormal();
|
||||
Vec3 normal = QuadGraph::get()->getNode(node_index)->getNormal();
|
||||
Vec3 p1 = line_to_target.start,
|
||||
p2 = line_to_target.getMiddle() + normal.toIrrVector(),
|
||||
p3 = line_to_target.end;
|
||||
@ -946,7 +946,7 @@ bool SkiddingAI::steerToAvoid(const std::vector<const Item *> &items_to_avoid,
|
||||
{
|
||||
Vec3 left(items_to_avoid[index_left_most]->getXYZ());
|
||||
int node_index = items_to_avoid[index_left_most]->getGraphNode();
|
||||
Vec3 normal = QuadGraph::get()->getNode(node_index).getNormal();
|
||||
Vec3 normal = QuadGraph::get()->getNode(node_index)->getNormal();
|
||||
Vec3 p1 = line_to_target.start,
|
||||
p2 = line_to_target.getMiddle() + normal.toIrrVector(),
|
||||
p3 = line_to_target.end;
|
||||
@ -1104,7 +1104,7 @@ void SkiddingAI::evaluateItems(const Item *item, Vec3 kart_aim_direction,
|
||||
// the kart is. The current quad provides a good estimate of the kart's plane.
|
||||
const Vec3 &xyz = item->getXYZ();
|
||||
Vec3 item_direction = xyz - m_kart->getXYZ();
|
||||
Vec3 plane_normal = QuadGraph::get()->getNode(m_track_node).getNormal();
|
||||
Vec3 plane_normal = QuadGraph::get()->getNode(m_track_node)->getNormal();
|
||||
float dist_to_plane = item_direction.dot(plane_normal);
|
||||
Vec3 projected_xyz = xyz - dist_to_plane*plane_normal;
|
||||
|
||||
@ -1712,8 +1712,8 @@ void SkiddingAI::handleNitroAndZipper()
|
||||
{
|
||||
GraphNode::DirectionType dir;
|
||||
unsigned int last;
|
||||
const GraphNode &gn = QuadGraph::get()->getNode(m_track_node);
|
||||
gn.getDirectionData(m_successor_index[m_track_node], &dir, &last);
|
||||
const GraphNode* gn = QuadGraph::get()->getNode(m_track_node);
|
||||
gn->getDirectionData(m_successor_index[m_track_node], &dir, &last);
|
||||
if(dir==GraphNode::DIR_STRAIGHT)
|
||||
{
|
||||
float diff = QuadGraph::get()->getDistanceFromStart(last)
|
||||
@ -1861,23 +1861,23 @@ void SkiddingAI::findNonCrashingPointNew(Vec3 *result, int *last_node)
|
||||
*last_node = m_next_node_index[m_track_node];
|
||||
const core::vector2df xz = m_kart->getXYZ().toIrrVector2d();
|
||||
|
||||
const GraphNode &g = QuadGraph::get()->getNode(*last_node);
|
||||
const GraphNode* g = QuadGraph::get()->getNode(*last_node);
|
||||
|
||||
// Index of the left and right end of a quad.
|
||||
const unsigned int LEFT_END_POINT = 0;
|
||||
const unsigned int RIGHT_END_POINT = 1;
|
||||
core::line2df left (xz, g[LEFT_END_POINT ].toIrrVector2d());
|
||||
core::line2df right(xz, g[RIGHT_END_POINT].toIrrVector2d());
|
||||
core::line2df left (xz, (*g)[LEFT_END_POINT ].toIrrVector2d());
|
||||
core::line2df right(xz, (*g)[RIGHT_END_POINT].toIrrVector2d());
|
||||
|
||||
#if defined(AI_DEBUG) && defined(AI_DEBUG_NEW_FIND_NON_CRASHING)
|
||||
const Vec3 eps1(0,0.5f,0);
|
||||
m_curve[CURVE_LEFT]->clear();
|
||||
m_curve[CURVE_LEFT]->addPoint(m_kart->getXYZ()+eps1);
|
||||
m_curve[CURVE_LEFT]->addPoint(g[LEFT_END_POINT]+eps1);
|
||||
m_curve[CURVE_LEFT]->addPoint((*g)[LEFT_END_POINT]+eps1);
|
||||
m_curve[CURVE_LEFT]->addPoint(m_kart->getXYZ()+eps1);
|
||||
m_curve[CURVE_RIGHT]->clear();
|
||||
m_curve[CURVE_RIGHT]->addPoint(m_kart->getXYZ()+eps1);
|
||||
m_curve[CURVE_RIGHT]->addPoint(g[RIGHT_END_POINT]+eps1);
|
||||
m_curve[CURVE_RIGHT]->addPoint((*g)[RIGHT_END_POINT]+eps1);
|
||||
m_curve[CURVE_RIGHT]->addPoint(m_kart->getXYZ()+eps1);
|
||||
#endif
|
||||
#if defined(AI_DEBUG_KART_HEADING) || defined(AI_DEBUG_NEW_FIND_NON_CRASHING)
|
||||
@ -1890,13 +1890,13 @@ void SkiddingAI::findNonCrashingPointNew(Vec3 *result, int *last_node)
|
||||
while(1)
|
||||
{
|
||||
unsigned int next_sector = m_next_node_index[*last_node];
|
||||
const GraphNode &g_next = QuadGraph::get()->getNode(next_sector);
|
||||
const GraphNode* g_next = QuadGraph::get()->getNode(next_sector);
|
||||
// Test if the next left point is to the right of the left
|
||||
// line. If so, a new left line is defined.
|
||||
if(left.getPointOrientation(g_next[LEFT_END_POINT].toIrrVector2d())
|
||||
if(left.getPointOrientation((*g_next)[LEFT_END_POINT].toIrrVector2d())
|
||||
< 0 )
|
||||
{
|
||||
core::vector2df p = g_next[LEFT_END_POINT].toIrrVector2d();
|
||||
core::vector2df p = (*g_next)[LEFT_END_POINT].toIrrVector2d();
|
||||
// Stop if the new point is to the right of the right line
|
||||
if(right.getPointOrientation(p)<0)
|
||||
break;
|
||||
@ -1912,10 +1912,10 @@ void SkiddingAI::findNonCrashingPointNew(Vec3 *result, int *last_node)
|
||||
|
||||
// Test if new right point is to the left of the right line. If
|
||||
// so, a new right line is defined.
|
||||
if(right.getPointOrientation(g_next[RIGHT_END_POINT].toIrrVector2d())
|
||||
if(right.getPointOrientation((*g_next)[RIGHT_END_POINT].toIrrVector2d())
|
||||
> 0 )
|
||||
{
|
||||
core::vector2df p = g_next[RIGHT_END_POINT].toIrrVector2d();
|
||||
core::vector2df p = (*g_next)[RIGHT_END_POINT].toIrrVector2d();
|
||||
// Break if new point is to the left of left line
|
||||
if(left.getPointOrientation(p)>0)
|
||||
break;
|
||||
@ -1937,7 +1937,7 @@ void SkiddingAI::findNonCrashingPointNew(Vec3 *result, int *last_node)
|
||||
// 0.5f*(left.end.Y+right.end.Y));
|
||||
//*result = ppp;
|
||||
|
||||
*result = QuadGraph::get()->getNode(*last_node).getCenter();
|
||||
*result = QuadGraph::get()->getNode(*last_node)->getCenter();
|
||||
} // findNonCrashingPointNew
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -1974,7 +1974,7 @@ void SkiddingAI::findNonCrashingPointFixed(Vec3 *aim_position, int *last_node)
|
||||
target_sector = m_next_node_index[*last_node];
|
||||
|
||||
//direction is a vector from our kart to the sectors we are testing
|
||||
direction = QuadGraph::get()->getNode(target_sector).getCenter()
|
||||
direction = QuadGraph::get()->getNode(target_sector)->getCenter()
|
||||
- m_kart->getXYZ();
|
||||
|
||||
float len=direction.length();
|
||||
@ -2004,16 +2004,16 @@ void SkiddingAI::findNonCrashingPointFixed(Vec3 *aim_position, int *last_node)
|
||||
|
||||
//If we are outside, the previous node is what we are looking for
|
||||
if ( distance + m_kart_width * 0.5f
|
||||
> QuadGraph::get()->getNode(*last_node).getPathWidth()*0.5f )
|
||||
> QuadGraph::get()->getNode(*last_node)->getPathWidth()*0.5f )
|
||||
{
|
||||
*aim_position = QuadGraph::get()->getNode(*last_node)
|
||||
.getCenter();
|
||||
->getCenter();
|
||||
return;
|
||||
}
|
||||
}
|
||||
*last_node = target_sector;
|
||||
} // for i<100
|
||||
*aim_position = QuadGraph::get()->getNode(*last_node).getCenter();
|
||||
*aim_position = QuadGraph::get()->getNode(*last_node)->getCenter();
|
||||
} // findNonCrashingPointFixed
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -2021,7 +2021,7 @@ void SkiddingAI::findNonCrashingPointFixed(Vec3 *aim_position, int *last_node)
|
||||
* 1. the test:
|
||||
*
|
||||
* distance + m_kart_width * 0.5f
|
||||
* > QuadGraph::get()->getNode(*last_node).getPathWidth() )
|
||||
* > QuadGraph::get()->getNode(*last_node)->getPathWidth() )
|
||||
*
|
||||
* is incorrect, it should compare with getPathWith*0.5f (since distance
|
||||
* is the distance from the center, i.e. it is half the path width if
|
||||
@ -2078,12 +2078,12 @@ void SkiddingAI::findNonCrashingPointFixed(Vec3 *aim_position, int *last_node)
|
||||
if(fabsf(diff)>1.5f)
|
||||
{
|
||||
*aim_position = QuadGraph::get()->getNode(target_sector)
|
||||
.getCenter();
|
||||
->getCenter();
|
||||
return;
|
||||
}
|
||||
|
||||
//direction is a vector from our kart to the sectors we are testing
|
||||
direction = QuadGraph::get()->getNode(target_sector).getCenter()
|
||||
direction = QuadGraph::get()->getNode(target_sector)->getCenter()
|
||||
- m_kart->getXYZ();
|
||||
|
||||
float len=direction.length();
|
||||
@ -2113,17 +2113,17 @@ void SkiddingAI::findNonCrashingPointFixed(Vec3 *aim_position, int *last_node)
|
||||
|
||||
//If we are outside, the previous node is what we are looking for
|
||||
if ( distance + m_kart_width * 0.5f
|
||||
> QuadGraph::get()->getNode(*last_node).getPathWidth() )
|
||||
> QuadGraph::get()->getNode(*last_node)->getPathWidth() )
|
||||
{
|
||||
*aim_position = QuadGraph::get()->getNode(*last_node)
|
||||
.getCenter();
|
||||
->getCenter();
|
||||
return;
|
||||
}
|
||||
}
|
||||
angle = angle1;
|
||||
*last_node = target_sector;
|
||||
} // for i<100
|
||||
*aim_position = QuadGraph::get()->getNode(*last_node).getCenter();
|
||||
*aim_position = QuadGraph::get()->getNode(*last_node)->getCenter();
|
||||
} // findNonCrashingPoint
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -2134,13 +2134,13 @@ void SkiddingAI::determineTrackDirection()
|
||||
{
|
||||
const QuadGraph *qg = QuadGraph::get();
|
||||
unsigned int succ = m_successor_index[m_track_node];
|
||||
unsigned int next = qg->getNode(m_track_node).getSuccessor(succ);
|
||||
unsigned int next = qg->getNode(m_track_node)->getSuccessor(succ);
|
||||
|
||||
//float angle_to_track = qg->getNode(m_track_node).getAngleToSuccessor(succ)
|
||||
//float angle_to_track = qg->getNode(m_track_node)->getAngleToSuccessor(succ)
|
||||
// - m_kart->getHeading();
|
||||
Vec3 track_direction = -qg->getNode(m_track_node).getCenter()
|
||||
+ qg->getNode(next).getCenter();
|
||||
//Vec3 kart_direction = qg->getNode(m_track_node).getCenter() + m_kart->getVelocity();
|
||||
Vec3 track_direction = -qg->getNode(m_track_node)->getCenter()
|
||||
+ qg->getNode(next)->getCenter();
|
||||
//Vec3 kart_direction = qg->getNode(m_track_node)->getCenter() + m_kart->getVelocity();
|
||||
|
||||
float angle_to_track = 0;
|
||||
if (m_kart->getVelocity().length() > 0.0f)
|
||||
@ -2165,15 +2165,15 @@ void SkiddingAI::determineTrackDirection()
|
||||
return;
|
||||
}
|
||||
|
||||
qg->getNode(next).getDirectionData(m_successor_index[next],
|
||||
&m_current_track_direction,
|
||||
&m_last_direction_node);
|
||||
qg->getNode(next)->getDirectionData(m_successor_index[next],
|
||||
&m_current_track_direction,
|
||||
&m_last_direction_node);
|
||||
|
||||
#ifdef AI_DEBUG
|
||||
m_curve[CURVE_QG]->clear();
|
||||
for(unsigned int i=m_track_node; i<=m_last_direction_node; i++)
|
||||
{
|
||||
m_curve[CURVE_QG]->addPoint(qg->getNode(i).getCenter());
|
||||
m_curve[CURVE_QG]->addPoint(qg->getNode(i)->getCenter());
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -2206,7 +2206,7 @@ void SkiddingAI::handleCurve()
|
||||
const QuadGraph *qg = QuadGraph::get();
|
||||
Vec3 xyz = m_kart->getXYZ();
|
||||
Vec3 tangent = m_kart->getTrans()(Vec3(0,0,1)) - xyz;
|
||||
Vec3 last_xyz = qg->getNode(m_last_direction_node).getCenter();
|
||||
Vec3 last_xyz = qg->getNode(m_last_direction_node)->getCenter();
|
||||
|
||||
determineTurnRadius(xyz, tangent, last_xyz,
|
||||
&m_curve_center, &m_current_curve_radius);
|
||||
@ -2225,10 +2225,10 @@ void SkiddingAI::handleCurve()
|
||||
// Pick either the lower left or right point:
|
||||
int index = m_current_track_direction==GraphNode::DIR_LEFT
|
||||
? 0 : 1;
|
||||
float r = (m_curve_center - qg->getNode(i)[index]).length();
|
||||
float r = (m_curve_center - *(qg->getNode(i))[index]).length();
|
||||
if(m_current_curve_radius < r)
|
||||
{
|
||||
last_xyz = qg->getNode(i)[index];
|
||||
last_xyz = *(qg->getNode(i)[index]);
|
||||
determineTurnRadius(xyz, tangent, last_xyz,
|
||||
&m_curve_center, &m_current_curve_radius);
|
||||
m_last_direction_node = i;
|
||||
@ -2298,7 +2298,7 @@ bool SkiddingAI::canSkid(float steer_fraction)
|
||||
|
||||
const float MIN_SKID_SPEED = 5.0f;
|
||||
const QuadGraph *qg = QuadGraph::get();
|
||||
Vec3 last_xyz = qg->getNode(m_last_direction_node).getCenter();
|
||||
Vec3 last_xyz = qg->getNode(m_last_direction_node)->getCenter();
|
||||
|
||||
// Only try skidding when a certain minimum speed is reached.
|
||||
if(m_kart->getSpeed()<MIN_SKID_SPEED) return false;
|
||||
|
@ -482,14 +482,14 @@ void SkiddingAI::handleSteering(float dt)
|
||||
m_world->getDistanceToCenterForKart( m_kart->getWorldKartId() );
|
||||
|
||||
if( fabsf(side_dist) >
|
||||
0.5f* QuadGraph::get()->getNode(m_track_node).getPathWidth()+0.5f )
|
||||
0.5f* QuadGraph::get()->getNode(m_track_node)->getPathWidth()+0.5f )
|
||||
{
|
||||
steer_angle = steerToPoint(QuadGraph::get()->getNode(next)
|
||||
.getCenter());
|
||||
->getCenter());
|
||||
|
||||
#ifdef AI_DEBUG
|
||||
m_debug_sphere[0]->setPosition(QuadGraph::get()->getNode(next)
|
||||
.getCenter().toIrrVector());
|
||||
->getCenter().toIrrVector());
|
||||
Log::debug(getControllerName().c_str(),
|
||||
"Outside of road: steer to center point.");
|
||||
#endif
|
||||
@ -642,7 +642,7 @@ void SkiddingAI::handleItemCollectionAndAvoidance(Vec3 *aim_point,
|
||||
const float max_item_lookahead_distance = 30.f;
|
||||
while(distance < max_item_lookahead_distance)
|
||||
{
|
||||
int n_index= QuadGraph::get()->getNode(node).getNodeIndex();
|
||||
int n_index= QuadGraph::get()->getNode(node)->getNodeIndex();
|
||||
const std::vector<Item *> &items_ahead =
|
||||
ItemManager::get()->getItemsInQuads(n_index);
|
||||
for(unsigned int i=0; i<items_ahead.size(); i++)
|
||||
@ -788,7 +788,7 @@ void SkiddingAI::handleItemCollectionAndAvoidance(Vec3 *aim_point,
|
||||
Vec3 xyz = item_to_collect->getXYZ();
|
||||
Vec3 item_direction = xyz - m_kart->getXYZ();
|
||||
Vec3 plane_normal = QuadGraph::get()->getNode(m_track_node)
|
||||
.getNormal();
|
||||
->getNormal();
|
||||
float dist_to_plane = item_direction.dot(plane_normal);
|
||||
Vec3 projected_xyz = xyz - dist_to_plane*plane_normal;
|
||||
|
||||
@ -871,7 +871,7 @@ bool SkiddingAI::handleSelectedItem(Vec3 kart_aim_direction, Vec3 *aim_point)
|
||||
// the kart is. The current quad provides a good estimate of the kart's plane.
|
||||
const Vec3 &xyz = m_item_to_collect->getXYZ();
|
||||
Vec3 item_direction = xyz - m_kart->getXYZ();
|
||||
Vec3 plane_normal = QuadGraph::get()->getNode(m_track_node).getNormal();
|
||||
Vec3 plane_normal = QuadGraph::get()->getNode(m_track_node)->getNormal();
|
||||
float dist_to_plane = item_direction.dot(plane_normal);
|
||||
Vec3 projected_xyz = xyz - dist_to_plane*plane_normal;
|
||||
|
||||
@ -932,7 +932,7 @@ bool SkiddingAI::steerToAvoid(const std::vector<const Item *> &items_to_avoid,
|
||||
// rightmost point - if so, nothing to do.
|
||||
Vec3 left(items_to_avoid[index_left_most]->getXYZ());
|
||||
int node_index = items_to_avoid[index_left_most]->getGraphNode();
|
||||
Vec3 normal = QuadGraph::get()->getNode(node_index).getNormal();
|
||||
Vec3 normal = QuadGraph::get()->getNode(node_index)->getNormal();
|
||||
Vec3 p1 = line_to_target.start,
|
||||
p2 = line_to_target.getMiddle() + normal.toIrrVector(),
|
||||
p3 = line_to_target.end;
|
||||
@ -952,7 +952,7 @@ bool SkiddingAI::steerToAvoid(const std::vector<const Item *> &items_to_avoid,
|
||||
{
|
||||
Vec3 left(items_to_avoid[index_left_most]->getXYZ());
|
||||
int node_index = items_to_avoid[index_left_most]->getGraphNode();
|
||||
Vec3 normal = QuadGraph::get()->getNode(node_index).getNormal();
|
||||
Vec3 normal = QuadGraph::get()->getNode(node_index)->getNormal();
|
||||
Vec3 p1 = line_to_target.start,
|
||||
p2 = line_to_target.getMiddle() + normal.toIrrVector(),
|
||||
p3 = line_to_target.end;
|
||||
@ -1110,7 +1110,7 @@ void SkiddingAI::evaluateItems(const Item *item, Vec3 kart_aim_direction,
|
||||
// the kart is. The current quad provides a good estimate of the kart's plane.
|
||||
const Vec3 &xyz = item->getXYZ();
|
||||
Vec3 item_direction = xyz - m_kart->getXYZ();
|
||||
Vec3 plane_normal = QuadGraph::get()->getNode(m_track_node).getNormal();
|
||||
Vec3 plane_normal = QuadGraph::get()->getNode(m_track_node)->getNormal();
|
||||
float dist_to_plane = item_direction.dot(plane_normal);
|
||||
Vec3 projected_xyz = xyz - dist_to_plane*plane_normal;
|
||||
|
||||
@ -1761,8 +1761,8 @@ void SkiddingAI::handleNitroAndZipper()
|
||||
{
|
||||
GraphNode::DirectionType dir;
|
||||
unsigned int last;
|
||||
const GraphNode &gn = QuadGraph::get()->getNode(m_track_node);
|
||||
gn.getDirectionData(m_successor_index[m_track_node], &dir, &last);
|
||||
const GraphNode* gn = QuadGraph::get()->getNode(m_track_node);
|
||||
gn->getDirectionData(m_successor_index[m_track_node], &dir, &last);
|
||||
if(dir==GraphNode::DIR_STRAIGHT)
|
||||
{
|
||||
float diff = QuadGraph::get()->getDistanceFromStart(last)
|
||||
@ -1910,23 +1910,23 @@ void SkiddingAI::findNonCrashingPointNew(Vec3 *result, int *last_node)
|
||||
*last_node = m_next_node_index[m_track_node];
|
||||
const core::vector2df xz = m_kart->getXYZ().toIrrVector2d();
|
||||
|
||||
const GraphNode &g = QuadGraph::get()->getNode(*last_node);
|
||||
const GraphNode* g = QuadGraph::get()->getNode(*last_node);
|
||||
|
||||
// Index of the left and right end of a quad.
|
||||
const unsigned int LEFT_END_POINT = 0;
|
||||
const unsigned int RIGHT_END_POINT = 1;
|
||||
core::line2df left (xz, g[LEFT_END_POINT ].toIrrVector2d());
|
||||
core::line2df right(xz, g[RIGHT_END_POINT].toIrrVector2d());
|
||||
core::line2df left (xz, (*g)[LEFT_END_POINT ].toIrrVector2d());
|
||||
core::line2df right(xz, (*g)[RIGHT_END_POINT].toIrrVector2d());
|
||||
|
||||
#if defined(AI_DEBUG) && defined(AI_DEBUG_NEW_FIND_NON_CRASHING)
|
||||
const Vec3 eps1(0,0.5f,0);
|
||||
m_curve[CURVE_LEFT]->clear();
|
||||
m_curve[CURVE_LEFT]->addPoint(m_kart->getXYZ()+eps1);
|
||||
m_curve[CURVE_LEFT]->addPoint(g[LEFT_END_POINT]+eps1);
|
||||
m_curve[CURVE_LEFT]->addPoint((*g)[LEFT_END_POINT]+eps1);
|
||||
m_curve[CURVE_LEFT]->addPoint(m_kart->getXYZ()+eps1);
|
||||
m_curve[CURVE_RIGHT]->clear();
|
||||
m_curve[CURVE_RIGHT]->addPoint(m_kart->getXYZ()+eps1);
|
||||
m_curve[CURVE_RIGHT]->addPoint(g[RIGHT_END_POINT]+eps1);
|
||||
m_curve[CURVE_RIGHT]->addPoint((*g)[RIGHT_END_POINT]+eps1);
|
||||
m_curve[CURVE_RIGHT]->addPoint(m_kart->getXYZ()+eps1);
|
||||
#endif
|
||||
#if defined(AI_DEBUG_KART_HEADING) || defined(AI_DEBUG_NEW_FIND_NON_CRASHING)
|
||||
@ -1939,13 +1939,13 @@ void SkiddingAI::findNonCrashingPointNew(Vec3 *result, int *last_node)
|
||||
while(1)
|
||||
{
|
||||
unsigned int next_sector = m_next_node_index[*last_node];
|
||||
const GraphNode &g_next = QuadGraph::get()->getNode(next_sector);
|
||||
const GraphNode* g_next = QuadGraph::get()->getNode(next_sector);
|
||||
// Test if the next left point is to the right of the left
|
||||
// line. If so, a new left line is defined.
|
||||
if(left.getPointOrientation(g_next[LEFT_END_POINT].toIrrVector2d())
|
||||
if(left.getPointOrientation((*g_next)[LEFT_END_POINT].toIrrVector2d())
|
||||
< 0 )
|
||||
{
|
||||
core::vector2df p = g_next[LEFT_END_POINT].toIrrVector2d();
|
||||
core::vector2df p = (*g_next)[LEFT_END_POINT].toIrrVector2d();
|
||||
// Stop if the new point is to the right of the right line
|
||||
if(right.getPointOrientation(p)<0)
|
||||
break;
|
||||
@ -1961,10 +1961,10 @@ void SkiddingAI::findNonCrashingPointNew(Vec3 *result, int *last_node)
|
||||
|
||||
// Test if new right point is to the left of the right line. If
|
||||
// so, a new right line is defined.
|
||||
if(right.getPointOrientation(g_next[RIGHT_END_POINT].toIrrVector2d())
|
||||
if(right.getPointOrientation((*g_next)[RIGHT_END_POINT].toIrrVector2d())
|
||||
> 0 )
|
||||
{
|
||||
core::vector2df p = g_next[RIGHT_END_POINT].toIrrVector2d();
|
||||
core::vector2df p = (*g_next)[RIGHT_END_POINT].toIrrVector2d();
|
||||
// Break if new point is to the left of left line
|
||||
if(left.getPointOrientation(p)>0)
|
||||
break;
|
||||
@ -1986,7 +1986,7 @@ void SkiddingAI::findNonCrashingPointNew(Vec3 *result, int *last_node)
|
||||
// 0.5f*(left.end.Y+right.end.Y));
|
||||
//*result = ppp;
|
||||
|
||||
*result = QuadGraph::get()->getNode(*last_node).getCenter();
|
||||
*result = QuadGraph::get()->getNode(*last_node)->getCenter();
|
||||
} // findNonCrashingPointNew
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -2023,7 +2023,7 @@ void SkiddingAI::findNonCrashingPointFixed(Vec3 *aim_position, int *last_node)
|
||||
target_sector = m_next_node_index[*last_node];
|
||||
|
||||
//direction is a vector from our kart to the sectors we are testing
|
||||
direction = QuadGraph::get()->getNode(target_sector).getCenter()
|
||||
direction = QuadGraph::get()->getNode(target_sector)->getCenter()
|
||||
- m_kart->getXYZ();
|
||||
|
||||
float len=direction.length();
|
||||
@ -2053,16 +2053,16 @@ void SkiddingAI::findNonCrashingPointFixed(Vec3 *aim_position, int *last_node)
|
||||
|
||||
//If we are outside, the previous node is what we are looking for
|
||||
if ( distance + m_kart_width * 0.5f
|
||||
> QuadGraph::get()->getNode(*last_node).getPathWidth()*0.5f )
|
||||
> QuadGraph::get()->getNode(*last_node)->getPathWidth()*0.5f )
|
||||
{
|
||||
*aim_position = QuadGraph::get()->getNode(*last_node)
|
||||
.getCenter();
|
||||
->getCenter();
|
||||
return;
|
||||
}
|
||||
}
|
||||
*last_node = target_sector;
|
||||
} // for i<100
|
||||
*aim_position = QuadGraph::get()->getNode(*last_node).getCenter();
|
||||
*aim_position = QuadGraph::get()->getNode(*last_node)->getCenter();
|
||||
} // findNonCrashingPointFixed
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -2070,7 +2070,7 @@ void SkiddingAI::findNonCrashingPointFixed(Vec3 *aim_position, int *last_node)
|
||||
* 1. the test:
|
||||
*
|
||||
* distance + m_kart_width * 0.5f
|
||||
* > QuadGraph::get()->getNode(*last_node).getPathWidth() )
|
||||
* > QuadGraph::get()->getNode(*last_node)->getPathWidth() )
|
||||
*
|
||||
* is incorrect, it should compare with getPathWith*0.5f (since distance
|
||||
* is the distance from the center, i.e. it is half the path width if
|
||||
@ -2127,12 +2127,12 @@ void SkiddingAI::findNonCrashingPointFixed(Vec3 *aim_position, int *last_node)
|
||||
if(fabsf(diff)>1.5f)
|
||||
{
|
||||
*aim_position = QuadGraph::get()->getNode(target_sector)
|
||||
.getCenter();
|
||||
->getCenter();
|
||||
return;
|
||||
}
|
||||
|
||||
//direction is a vector from our kart to the sectors we are testing
|
||||
direction = QuadGraph::get()->getNode(target_sector).getCenter()
|
||||
direction = QuadGraph::get()->getNode(target_sector)->getCenter()
|
||||
- m_kart->getXYZ();
|
||||
|
||||
float len=direction.length();
|
||||
@ -2162,17 +2162,17 @@ void SkiddingAI::findNonCrashingPointFixed(Vec3 *aim_position, int *last_node)
|
||||
|
||||
//If we are outside, the previous node is what we are looking for
|
||||
if ( distance + m_kart_width * 0.5f
|
||||
> QuadGraph::get()->getNode(*last_node).getPathWidth() )
|
||||
> QuadGraph::get()->getNode(*last_node)->getPathWidth() )
|
||||
{
|
||||
*aim_position = QuadGraph::get()->getNode(*last_node)
|
||||
.getCenter();
|
||||
->getCenter();
|
||||
return;
|
||||
}
|
||||
}
|
||||
angle = angle1;
|
||||
*last_node = target_sector;
|
||||
} // for i<100
|
||||
*aim_position = QuadGraph::get()->getNode(*last_node).getCenter();
|
||||
*aim_position = QuadGraph::get()->getNode(*last_node)->getCenter();
|
||||
} // findNonCrashingPoint
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -2183,13 +2183,13 @@ void SkiddingAI::determineTrackDirection()
|
||||
{
|
||||
const QuadGraph *qg = QuadGraph::get();
|
||||
unsigned int succ = m_successor_index[m_track_node];
|
||||
unsigned int next = qg->getNode(m_track_node).getSuccessor(succ);
|
||||
unsigned int next = qg->getNode(m_track_node)->getSuccessor(succ);
|
||||
|
||||
//float angle_to_track = qg->getNode(m_track_node).getAngleToSuccessor(succ)
|
||||
//float angle_to_track = qg->getNode(m_track_node)->getAngleToSuccessor(succ)
|
||||
// - m_kart->getHeading();
|
||||
Vec3 track_direction = -qg->getNode(m_track_node).getCenter()
|
||||
+ qg->getNode(next).getCenter();
|
||||
//Vec3 kart_direction = qg->getNode(m_track_node).getCenter() + m_kart->getVelocity();
|
||||
Vec3 track_direction = -qg->getNode(m_track_node)->getCenter()
|
||||
+ qg->getNode(next)->getCenter();
|
||||
//Vec3 kart_direction = qg->getNode(m_track_node)->getCenter() + m_kart->getVelocity();
|
||||
|
||||
float angle_to_track = 0;
|
||||
if (m_kart->getVelocity().length() > 0.0f)
|
||||
@ -2214,7 +2214,7 @@ void SkiddingAI::determineTrackDirection()
|
||||
return;
|
||||
}
|
||||
|
||||
qg->getNode(next).getDirectionData(m_successor_index[next],
|
||||
qg->getNode(next)->getDirectionData(m_successor_index[next],
|
||||
&m_current_track_direction,
|
||||
&m_last_direction_node);
|
||||
|
||||
@ -2222,7 +2222,7 @@ void SkiddingAI::determineTrackDirection()
|
||||
m_curve[CURVE_QG]->clear();
|
||||
for(unsigned int i=m_track_node; i<=m_last_direction_node; i++)
|
||||
{
|
||||
m_curve[CURVE_QG]->addPoint(qg->getNode(i).getCenter());
|
||||
m_curve[CURVE_QG]->addPoint(qg->getNode(i)->getCenter());
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -2255,7 +2255,7 @@ void SkiddingAI::handleCurve()
|
||||
const QuadGraph *qg = QuadGraph::get();
|
||||
Vec3 xyz = m_kart->getXYZ();
|
||||
Vec3 tangent = m_kart->getTrans()(Vec3(0,0,1)) - xyz;
|
||||
Vec3 last_xyz = qg->getNode(m_last_direction_node).getCenter();
|
||||
Vec3 last_xyz = qg->getNode(m_last_direction_node)->getCenter();
|
||||
|
||||
determineTurnRadius(xyz, tangent, last_xyz,
|
||||
&m_curve_center, &m_current_curve_radius);
|
||||
@ -2274,10 +2274,10 @@ void SkiddingAI::handleCurve()
|
||||
// Pick either the lower left or right point:
|
||||
int index = m_current_track_direction==GraphNode::DIR_LEFT
|
||||
? 0 : 1;
|
||||
float r = (m_curve_center - qg->getNode(i)[index]).length();
|
||||
float r = (m_curve_center - *(qg->getNode(i))[index]).length();
|
||||
if(m_current_curve_radius < r)
|
||||
{
|
||||
last_xyz = qg->getNode(i)[index];
|
||||
last_xyz = *(qg->getNode(i))[index];
|
||||
determineTurnRadius(xyz, tangent, last_xyz,
|
||||
&m_curve_center, &m_current_curve_radius);
|
||||
m_last_direction_node = i;
|
||||
@ -2347,7 +2347,7 @@ bool SkiddingAI::canSkid(float steer_fraction)
|
||||
|
||||
const float MIN_SKID_SPEED = 5.0f;
|
||||
const QuadGraph *qg = QuadGraph::get();
|
||||
Vec3 last_xyz = qg->getNode(m_last_direction_node).getCenter();
|
||||
Vec3 last_xyz = qg->getNode(m_last_direction_node)->getCenter();
|
||||
|
||||
// Only try skidding when a certain minimum speed is reached.
|
||||
if(m_kart->getSpeed()<MIN_SKID_SPEED) return false;
|
||||
|
@ -1294,7 +1294,7 @@ void Kart::update(float dt)
|
||||
if (QuadGraph::get())
|
||||
{
|
||||
sector = ((LinearWorld*)World::getWorld())->getTrackSector(getWorldKartId()).getCurrentGraphNode();
|
||||
quadNormal = QuadGraph::get()->getNode(sector).getNormal();
|
||||
quadNormal = QuadGraph::get()->getNode(sector)->getNormal();
|
||||
btQuaternion q = getTrans().getRotation();
|
||||
float roll = quadNormal.angle((Vec3(0, 1, 0).rotate(q.getAxis(), q.getAngle())));
|
||||
|
||||
@ -1376,7 +1376,7 @@ void Kart::update(float dt)
|
||||
// We do this for now because dist_to_sector is not defined
|
||||
float dist_to_sector;
|
||||
if (QuadGraph::get())
|
||||
dist_to_sector = getXYZ().distance(QuadGraph::get()->getNode(sector).getCenter());
|
||||
dist_to_sector = getXYZ().distance(QuadGraph::get()->getNode(sector)->getCenter());
|
||||
else
|
||||
dist_to_sector = 0;
|
||||
|
||||
@ -1944,9 +1944,9 @@ void Kart::crashed(const Material *m, const Vec3 &normal)
|
||||
{
|
||||
// Use the first predecessor node, which is the most
|
||||
// natural one (i.e. the one on the main driveline).
|
||||
const GraphNode &gn = QuadGraph::get()->getNode(
|
||||
QuadGraph::get()->getNode(sector).getPredecessor(0));
|
||||
Vec3 impulse = gn.getCenter() - getXYZ();
|
||||
const GraphNode* gn = QuadGraph::get()->getNode(
|
||||
QuadGraph::get()->getNode(sector)->getPredecessor(0));
|
||||
Vec3 impulse = gn->getCenter() - getXYZ();
|
||||
impulse.setY(0);
|
||||
if(impulse.getX() || impulse.getZ())
|
||||
impulse.normalize();
|
||||
@ -2423,7 +2423,7 @@ void Kart::updateSliding()
|
||||
if (QuadGraph::get())
|
||||
{
|
||||
int sector = ((LinearWorld*)World::getWorld())->getTrackSector(getWorldKartId()).getCurrentGraphNode();
|
||||
Vec3 quadNormal = QuadGraph::get()->getNode(sector).getNormal();
|
||||
Vec3 quadNormal = QuadGraph::get()->getNode(sector)->getNormal();
|
||||
Vec3 kart_up = m.getColumn(1);
|
||||
distanceFromUp = kart_up.dot(quadNormal);
|
||||
}
|
||||
|
@ -647,8 +647,8 @@ unsigned int LinearWorld::getRescuePositionIndex(AbstractKart *kart)
|
||||
// ------------------------------------------------------------------------
|
||||
btTransform LinearWorld::getRescueTransform(unsigned int index) const
|
||||
{
|
||||
const Vec3 &xyz = QuadGraph::get()->getNode(index).getCenter();
|
||||
const Vec3 &normal = QuadGraph::get()->getNode(index).getNormal();
|
||||
const Vec3 &xyz = QuadGraph::get()->getNode(index)->getCenter();
|
||||
const Vec3 &normal = QuadGraph::get()->getNode(index)->getNormal();
|
||||
btTransform pos;
|
||||
pos.setOrigin(xyz);
|
||||
|
||||
@ -879,8 +879,8 @@ void LinearWorld::checkForWrongDirection(unsigned int i, float dt)
|
||||
return;
|
||||
|
||||
// check if the player is going in the wrong direction
|
||||
GraphNode& node = QuadGraph::get()->getNode(sector);
|
||||
Vec3 center_line = node.getUpperCenter() - node.getLowerCenter();
|
||||
const GraphNode* node = QuadGraph::get()->getNode(sector);
|
||||
Vec3 center_line = node->getUpperCenter() - node->getLowerCenter();
|
||||
float angle_diff = kart->getVelocity().angle(center_line);
|
||||
|
||||
if (angle_diff > M_PI)
|
||||
|
@ -23,13 +23,13 @@
|
||||
#include "input/input_device.hpp"
|
||||
#include "input/input_manager.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "scriptengine/script_engine.hpp"
|
||||
#include "states_screens/dialogs/tutorial_message_dialog.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "tracks/track_object.hpp"
|
||||
#include "tracks/track_object_manager.hpp"
|
||||
|
||||
#include <angelscript.h>
|
||||
#include "scriptarray.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
#include <iostream> //debug
|
||||
|
@ -72,17 +72,17 @@ void GraphNode::addSuccessor(unsigned int to)
|
||||
{
|
||||
m_successor_nodes.push_back(to);
|
||||
// to is the graph node
|
||||
GraphNode &gn_to = QuadGraph::get()->getNode(to);
|
||||
GraphNode* gn_to = QuadGraph::get()->getNode(to);
|
||||
|
||||
// Note that the first predecessor is (because of the way the quad graph
|
||||
// is exported) the most 'natural' one, i.e. the one on the main
|
||||
// driveline.
|
||||
gn_to.m_predecessor_nodes.push_back(m_node_index);
|
||||
gn_to->m_predecessor_nodes.push_back(m_node_index);
|
||||
|
||||
Vec3 d = m_lower_center - gn_to.m_lower_center;
|
||||
Vec3 d = m_lower_center - gn_to->m_lower_center;
|
||||
m_distance_to_next.push_back(d.length());
|
||||
|
||||
Vec3 diff = gn_to.getCenter() - getCenter();
|
||||
Vec3 diff = gn_to->getCenter() - getCenter();
|
||||
|
||||
core::CMatrix4<float> m;
|
||||
m.buildRotateFromTo(getNormal().toIrrVector(),
|
||||
@ -123,8 +123,8 @@ void GraphNode::setupPathsToNode()
|
||||
// not be used.
|
||||
for(unsigned int i=0; i<getNumberOfSuccessors(); i++)
|
||||
{
|
||||
GraphNode &gn = QuadGraph::get()->getNode(getSuccessor(i));
|
||||
gn.markAllSuccessorsToUse(i, &m_path_to_node);
|
||||
GraphNode* gn = QuadGraph::get()->getNode(getSuccessor(i));
|
||||
gn->markAllSuccessorsToUse(i, &m_path_to_node);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
for(unsigned int i = 0; i < m_path_to_node.size(); ++i)
|
||||
@ -154,8 +154,8 @@ void GraphNode::markAllSuccessorsToUse(unsigned int n,
|
||||
(*path_to_node)[m_node_index] = n;
|
||||
for(unsigned int i=0; i<getNumberOfSuccessors(); i++)
|
||||
{
|
||||
GraphNode &gn = QuadGraph::get()->getNode(getSuccessor(i));
|
||||
gn.markAllSuccessorsToUse(n, path_to_node);
|
||||
GraphNode* gn = QuadGraph::get()->getNode(getSuccessor(i));
|
||||
gn->markAllSuccessorsToUse(n, path_to_node);
|
||||
}
|
||||
} // markAllSuccesorsToUse
|
||||
|
||||
@ -185,5 +185,5 @@ void GraphNode::setChecklineRequirements(int latest_checkline)
|
||||
*/
|
||||
bool GraphNode::ignoreSuccessorForAI(unsigned int i) const
|
||||
{
|
||||
return QuadGraph::get()->getNode(m_successor_nodes[i]).letAIIgnore();
|
||||
return QuadGraph::get()->getNode(m_successor_nodes[i])->letAIIgnore();
|
||||
} // ignoreSuccessorForAI
|
||||
|
@ -210,9 +210,9 @@ public:
|
||||
/** True if this node should be ignored by the AI. */
|
||||
bool letAIIgnore() const { return m_ai_ignore; }
|
||||
// ------------------------------------------------------------------------
|
||||
virtual float getDistance2FromPoint(const Vec3 &xyz) = 0;
|
||||
virtual float getDistance2FromPoint(const Vec3 &xyz) const = 0;
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void getDistances(const Vec3 &xyz, Vec3 *result) = 0;
|
||||
virtual void getDistances(const Vec3 &xyz, Vec3 *result) const = 0;
|
||||
|
||||
}; // GraphNode
|
||||
|
||||
|
@ -168,7 +168,7 @@ void GraphStructure::createMesh(bool show_invisible,
|
||||
|
||||
m_mesh_buffer->append(new_v, n*4, ind, n*6);
|
||||
|
||||
if (hasLapLine())
|
||||
if (0)
|
||||
{
|
||||
video::S3DVertex lap_v[4];
|
||||
irr::u16 lap_ind[6];
|
||||
|
@ -41,7 +41,7 @@ Node2D::Node2D(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2, const Vec3 &p3,
|
||||
* \param result The X coordinate contains the sidewards distance, the
|
||||
* Z coordinate the forward distance.
|
||||
*/
|
||||
void Node2D::getDistances(const Vec3 &xyz, Vec3 *result)
|
||||
void Node2D::getDistances(const Vec3 &xyz, Vec3 *result) const
|
||||
{
|
||||
core::vector2df xyz2d(xyz.getX(), xyz.getZ());
|
||||
core::vector2df closest = m_line.getClosestPoint(xyz2d);
|
||||
@ -61,7 +61,7 @@ void Node2D::getDistances(const Vec3 &xyz, Vec3 *result)
|
||||
* which belongs to this graph node. The value is computed in 2d only!
|
||||
* \param xyz The point for which the distance to the line is computed.
|
||||
*/
|
||||
float Node2D::getDistance2FromPoint(const Vec3 &xyz)
|
||||
float Node2D::getDistance2FromPoint(const Vec3 &xyz) const
|
||||
{
|
||||
core::vector2df xyz2d(xyz.getX(), xyz.getZ());
|
||||
core::vector2df closest = m_line.getClosestPoint(xyz2d);
|
||||
|
@ -47,9 +47,9 @@ public:
|
||||
const Vec3 &normal, unsigned int node_index, bool invisible,
|
||||
bool ai_ignore);
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void getDistances(const Vec3 &xyz, Vec3 *result) OVERRIDE;
|
||||
virtual void getDistances(const Vec3 &xyz, Vec3 *result) const OVERRIDE;
|
||||
// ------------------------------------------------------------------------
|
||||
virtual float getDistance2FromPoint(const Vec3 &xyz) OVERRIDE;
|
||||
virtual float getDistance2FromPoint(const Vec3 &xyz) const OVERRIDE;
|
||||
|
||||
};
|
||||
#endif
|
||||
|
@ -66,7 +66,7 @@ Node3D::Node3D(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2, const Vec3 &p3,
|
||||
* \param result The X coordinate contains the sidewards distance, the
|
||||
* Z coordinate the forward distance.
|
||||
*/
|
||||
void Node3D::getDistances(const Vec3 &xyz, Vec3 *result)
|
||||
void Node3D::getDistances(const Vec3 &xyz, Vec3 *result) const
|
||||
{
|
||||
core::vector3df xyz_irr = xyz.toIrrVector();
|
||||
core::vector3df closest = m_line.getClosestPoint(xyz.toIrrVector());
|
||||
@ -87,7 +87,7 @@ void Node3D::getDistances(const Vec3 &xyz, Vec3 *result)
|
||||
* which belongs to this node.
|
||||
* \param xyz The point for which the distance to the line is computed.
|
||||
*/
|
||||
float Node3D::getDistance2FromPoint(const Vec3 &xyz)
|
||||
float Node3D::getDistance2FromPoint(const Vec3 &xyz) const
|
||||
{
|
||||
core::vector3df closest = m_line.getClosestPoint(xyz.toIrrVector());
|
||||
return (closest-xyz.toIrrVector()).getLengthSQ();
|
||||
|
@ -56,9 +56,9 @@ public:
|
||||
return true;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void getDistances(const Vec3 &xyz, Vec3 *result) OVERRIDE;
|
||||
virtual void getDistances(const Vec3 &xyz, Vec3 *result) const OVERRIDE;
|
||||
// ------------------------------------------------------------------------
|
||||
virtual float getDistance2FromPoint(const Vec3 &xyz) OVERRIDE;
|
||||
virtual float getDistance2FromPoint(const Vec3 &xyz) const OVERRIDE;
|
||||
|
||||
};
|
||||
#endif
|
||||
|
@ -437,20 +437,20 @@ void QuadGraph::setDefaultStartPositions(AlignedArray<btTransform>
|
||||
else
|
||||
{
|
||||
// First find on which segment we have to start
|
||||
while(distance_from_start > getNode(current_node).getNodeLength())
|
||||
while(distance_from_start > getNode(current_node)->getNodeLength())
|
||||
{
|
||||
distance_from_start -= getNode(current_node).getNodeLength();
|
||||
distance_from_start -= getNode(current_node)->getNodeLength();
|
||||
// Only follow the main driveline, i.e. first predecessor
|
||||
current_node = getNode(current_node).getPredecessor(0);
|
||||
current_node = getNode(current_node)->getPredecessor(0);
|
||||
}
|
||||
const GraphNode &gn = getNode(current_node);
|
||||
Vec3 center_line = gn.getLowerCenter() - gn.getUpperCenter();
|
||||
const GraphNode* gn = getNode(current_node);
|
||||
Vec3 center_line = gn->getLowerCenter() - gn->getUpperCenter();
|
||||
center_line.normalize();
|
||||
|
||||
Vec3 horizontal_line = gn[2] - gn[3];
|
||||
Vec3 horizontal_line = (*gn)[2] - (*gn)[3];
|
||||
horizontal_line.normalize();
|
||||
|
||||
Vec3 start = gn.getUpperCenter()
|
||||
Vec3 start = gn->getUpperCenter()
|
||||
+ center_line * distance_from_start
|
||||
+ horizontal_line * x_pos;
|
||||
// Add a certain epsilon to the height in case that the
|
||||
@ -458,7 +458,7 @@ void QuadGraph::setDefaultStartPositions(AlignedArray<btTransform>
|
||||
(*start_transforms)[i].setOrigin(start+Vec3(0,upwards_distance,0));
|
||||
(*start_transforms)[i].setRotation(
|
||||
btQuaternion(btVector3(0, 1, 0),
|
||||
gn.getAngleToSuccessor(0)));
|
||||
gn->getAngleToSuccessor(0)));
|
||||
if(x_pos >= max_x_dist-sidewards_distance*0.5f)
|
||||
{
|
||||
x_pos = -max_x_dist;
|
||||
@ -563,23 +563,23 @@ void QuadGraph::updateDistancesForAllSuccessors(unsigned int indx, float delta,
|
||||
}
|
||||
recursive_count++;
|
||||
|
||||
GraphNode &g=getNode(indx);
|
||||
g.setDistanceFromStart(g.getDistanceFromStart()+delta);
|
||||
for(unsigned int i=0; i<g.getNumberOfSuccessors(); i++)
|
||||
GraphNode* g = getNode(indx);
|
||||
g->setDistanceFromStart(g->getDistanceFromStart()+delta);
|
||||
for(unsigned int i=0; i<g->getNumberOfSuccessors(); i++)
|
||||
{
|
||||
GraphNode &g_next = getNode(g.getSuccessor(i));
|
||||
GraphNode* g_next = getNode(g->getSuccessor(i));
|
||||
// Stop when we reach the start node, i.e. the only node with a
|
||||
// distance of 0
|
||||
if(g_next.getDistanceFromStart()==0)
|
||||
if(g_next->getDistanceFromStart()==0)
|
||||
continue;
|
||||
|
||||
// Only increase the distance from start of a successor node, if
|
||||
// this successor has a distance from start that is smaller then
|
||||
// the increased amount.
|
||||
if(g.getDistanceFromStart()+g.getDistanceToSuccessor(i) >
|
||||
g_next.getDistanceFromStart())
|
||||
if(g->getDistanceFromStart()+g->getDistanceToSuccessor(i) >
|
||||
g_next->getDistanceFromStart())
|
||||
{
|
||||
updateDistancesForAllSuccessors(g.getSuccessor(i), delta,
|
||||
updateDistancesForAllSuccessors(g->getSuccessor(i), delta,
|
||||
recursive_count);
|
||||
}
|
||||
}
|
||||
@ -648,14 +648,14 @@ void QuadGraph::determineDirection(unsigned int current,
|
||||
|
||||
// Compute the angle from n (=current) to n+1 (=next)
|
||||
float angle_current = getAngleToNext(current, succ_index);
|
||||
unsigned int next = getNode(current).getSuccessor(succ_index);
|
||||
unsigned int next = getNode(current)->getSuccessor(succ_index);
|
||||
float angle_next = getAngleToNext(next, 0);
|
||||
float rel_angle = normalizeAngle(angle_next-angle_current);
|
||||
// Small angles are considered to be straight
|
||||
if(fabsf(rel_angle)<max_straight_angle)
|
||||
rel_angle = 0;
|
||||
|
||||
next = getNode(next).getSuccessor(0); // next is now n+2
|
||||
next = getNode(next)->getSuccessor(0); // next is now n+2
|
||||
|
||||
// If the direction is still the same during a lap the last node
|
||||
// in the same direction is the previous node;
|
||||
@ -678,7 +678,7 @@ void QuadGraph::determineDirection(unsigned int current,
|
||||
break;
|
||||
rel_angle = new_rel_angle;
|
||||
|
||||
next = getNode(next).getSuccessor(0);
|
||||
next = getNode(next)->getSuccessor(0);
|
||||
} // while(1)
|
||||
|
||||
GraphNode::DirectionType dir =
|
||||
@ -708,7 +708,7 @@ void QuadGraph::spatialToTrack(Vec3 *dst, const Vec3& xyz,
|
||||
return;
|
||||
}
|
||||
|
||||
getNode(sector).getDistances(xyz, dst);
|
||||
getNode(sector)->getDistances(xyz, dst);
|
||||
} // spatialToTrack
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -728,7 +728,7 @@ void QuadGraph::findRoadSector(const Vec3& xyz, int *sector,
|
||||
{
|
||||
// Most likely the kart will still be on the sector it was before,
|
||||
// so this simple case is tested first.
|
||||
if(*sector!=UNKNOWN_SECTOR && getNode(*sector).pointInside(xyz) )
|
||||
if(*sector!=UNKNOWN_SECTOR && getNode(*sector)->pointInside(xyz) )
|
||||
{
|
||||
return;
|
||||
} // if still on same quad
|
||||
@ -756,8 +756,8 @@ void QuadGraph::findRoadSector(const Vec3& xyz, int *sector,
|
||||
indx = (*all_sectors)[i];
|
||||
else
|
||||
indx = indx<(int)m_all_nodes.size()-1 ? indx +1 : 0;
|
||||
const GraphNode &gn = getNode(indx);
|
||||
if(gn.pointInside(xyz))
|
||||
const GraphNode* gn = getNode(indx);
|
||||
if(gn->pointInside(xyz))
|
||||
{
|
||||
*sector = indx;
|
||||
}
|
||||
@ -846,8 +846,8 @@ int QuadGraph::findOutOfRoadSector(const Vec3& xyz,
|
||||
float dist_2 = m_all_nodes[next_sector]->getDistance2FromPoint(xyz);
|
||||
if(dist_2<min_dist_2)
|
||||
{
|
||||
const GraphNode &gn = getNode(next_sector);
|
||||
float dist = xyz.getY() - gn.getMinHeight();
|
||||
const GraphNode* gn = getNode(next_sector);
|
||||
float dist = xyz.getY() - gn->getMinHeight();
|
||||
// While negative distances are unlikely, we allow some small
|
||||
// negative numbers in case that the kart is partly in the
|
||||
// track. Only do the height test in phase==0, in phase==1
|
||||
@ -920,5 +920,5 @@ const bool QuadGraph::differentNodeColor(int n, NodeColor* c) const
|
||||
*c = COLOR_YELLOW;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return n == 0;
|
||||
} // differentNodeColor
|
||||
|
@ -164,7 +164,10 @@ public:
|
||||
int getNumberOfSuccessors(int n) const;
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the quad that belongs to a graph node. */
|
||||
GraphNode& getNode(unsigned int j) const { return *m_all_nodes[j]; }
|
||||
GraphNode* getNode(unsigned int j) { return m_all_nodes[j]; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the quad that belongs to a graph node (const version). */
|
||||
const GraphNode* getNode(unsigned int j) const { return m_all_nodes[j]; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the distance from the start to the beginning of a quad. */
|
||||
float getDistanceFromStart(int j) const;
|
||||
|
@ -52,13 +52,14 @@
|
||||
#include "physics/physics.hpp"
|
||||
#include "physics/triangle_mesh.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
#include "scriptengine/script_engine.hpp"
|
||||
#include "tracks/bezier_curve.hpp"
|
||||
#include "tracks/battle_graph.hpp"
|
||||
#include "tracks/check_manager.hpp"
|
||||
#include "tracks/graph_node.hpp"
|
||||
#include "tracks/model_definition_loader.hpp"
|
||||
#include "tracks/track_manager.hpp"
|
||||
#include "tracks/quad_graph.hpp"
|
||||
#include "tracks/track_manager.hpp"
|
||||
#include "tracks/track_object_manager.hpp"
|
||||
#include "utils/constants.hpp"
|
||||
#include "utils/log.hpp"
|
||||
@ -698,7 +699,7 @@ void Track::loadQuadGraph(unsigned int mode_id, const bool reverse)
|
||||
#ifdef DEBUG
|
||||
for(unsigned int i=0; i<QuadGraph::get()->getNumNodes(); i++)
|
||||
{
|
||||
assert(QuadGraph::get()->getNode(i).getPredecessor(0)!=-1);
|
||||
assert(QuadGraph::get()->getNode(i)->getPredecessor(0)!=-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -2292,7 +2293,7 @@ void Track::itemCommand(const XMLNode *node)
|
||||
// If a valid road_sector is not found
|
||||
if (road_sector == QuadGraph::UNKNOWN_SECTOR)
|
||||
road_sector = QuadGraph::get()->findOutOfRoadSector(xyz, road_sector);
|
||||
const Vec3& quadnormal = QuadGraph::get()->getNode(road_sector).getNormal();
|
||||
const Vec3& quadnormal = QuadGraph::get()->getNode(road_sector)->getNormal();
|
||||
|
||||
const Material *m;
|
||||
Vec3 hit_point;
|
||||
@ -2385,7 +2386,7 @@ bool Track::findGround(AbstractKart *kart)
|
||||
{
|
||||
int sector = ((LinearWorld*)World::getWorld())->getTrackSector(kart->getWorldKartId()).getCurrentGraphNode();
|
||||
if (sector != QuadGraph::UNKNOWN_SECTOR)
|
||||
quadNormal = QuadGraph::get()->getNode(sector).getNormal();
|
||||
quadNormal = QuadGraph::get()->getNode(sector)->getNormal();
|
||||
}
|
||||
|
||||
to = to + -1000.0f*quadNormal;
|
||||
@ -2438,6 +2439,14 @@ bool Track::findGround(AbstractKart *kart)
|
||||
return true;
|
||||
} // findGround
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
float Track::getTrackLength() const
|
||||
{
|
||||
return QuadGraph::get()->getLapLength();
|
||||
} // getTrackLength
|
||||
|
||||
float Track::getTrackLength() const {return QuadGraph::get()->getLapLength();}
|
||||
float Track::getAngle(int n) const { return QuadGraph::get()->getAngleToNext(n, 0); }
|
||||
//-----------------------------------------------------------------------------
|
||||
float Track::getAngle(int n) const
|
||||
{
|
||||
return QuadGraph::get()->getAngleToNext(n, 0);
|
||||
} // getAngle
|
||||
|
@ -40,7 +40,6 @@ class ModelDefinitionLoader;
|
||||
|
||||
#include "LinearMath/btTransform.h"
|
||||
|
||||
#include "scriptengine/script_engine.hpp"
|
||||
#include "utils/aligned_array.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
#include "utils/vec3.hpp"
|
||||
@ -62,11 +61,6 @@ class TriangleMesh;
|
||||
class World;
|
||||
class XMLNode;
|
||||
|
||||
namespace Scripting
|
||||
{
|
||||
class ScriptEngine;
|
||||
}
|
||||
|
||||
const int HEIGHT_MAP_RESOLUTION = 256;
|
||||
|
||||
// TODO: eventually remove this and fully replace with scripting
|
||||
|
@ -65,8 +65,8 @@ void TrackSector::update(const Vec3 &xyz)
|
||||
{
|
||||
// keep the current quad as the latest valid one IF the player has one
|
||||
// of the required checklines
|
||||
const GraphNode& gn = QuadGraph::get()->getNode(m_current_graph_node);
|
||||
const std::vector<int>& checkline_requirements = gn.getChecklineRequirements();
|
||||
const GraphNode* gn = QuadGraph::get()->getNode(m_current_graph_node);
|
||||
const std::vector<int>& checkline_requirements = gn->getChecklineRequirements();
|
||||
|
||||
if (checkline_requirements.size() == 0)
|
||||
{
|
||||
@ -111,9 +111,9 @@ void TrackSector::rescue()
|
||||
// STK does not keep track of where the kart is coming from, so always
|
||||
// use the first predecessor, which is the one on the main driveline.
|
||||
m_current_graph_node = QuadGraph::get()->getNode(m_current_graph_node)
|
||||
.getPredecessor(0);
|
||||
->getPredecessor(0);
|
||||
m_last_valid_graph_node = QuadGraph::get()->getNode(m_current_graph_node)
|
||||
.getPredecessor(0);
|
||||
->getPredecessor(0);
|
||||
} // rescue
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -123,7 +123,7 @@ void TrackSector::rescue()
|
||||
*/
|
||||
float TrackSector::getRelativeDistanceToCenter() const
|
||||
{
|
||||
float w = QuadGraph::get()->getNode(m_current_graph_node).getPathWidth();
|
||||
float w = QuadGraph::get()->getNode(m_current_graph_node)->getPathWidth();
|
||||
// w * 0.5 is the distance from center of the quad to the left or right
|
||||
// This way we get a value between -1 and 1.
|
||||
float ratio = getDistanceToCenter()/(w*0.5f);
|
||||
|
Loading…
x
Reference in New Issue
Block a user