5
bool ROADSTRIP::ReadFrom(std::istream & openfile, std::ostream & error_output)
11
//number of patches in this road strip
15
//add all road patches to this strip
17
for (int i = 0; i < num; i++)
19
BEZIER * prevbezier = NULL;
21
prevbezier = &patches.back().GetPatch();
23
patches.push_back(ROADPATCH());
24
patches.back().GetPatch().ReadFrom(openfile);
27
prevbezier->Attach(patches.back().GetPatch());
29
if (patches.back().GetPatch().CheckForProblems())
37
error_output << "Rejected " << badcount << " bezier patch(es) from roadstrip due to errors" << std::endl;
40
if (patches.size() > 2)
42
//only close it if it ends near where it starts
43
if (((patches.back().GetPatch().GetFL() - patches.front().GetPatch().GetBL()).Magnitude() < 0.1) &&
44
((patches.back().GetPatch().GetFR() - patches.front().GetPatch().GetBR()).Magnitude() < 0.1))
46
patches.back().GetPatch().Attach(patches.front().GetPatch());
51
GenerateSpacePartitioning();
56
void ROADSTRIP::GenerateSpacePartitioning()
60
for (std::list <ROADPATCH>::iterator i = patches.begin(); i != patches.end(); ++i)
62
ROADPATCH * rp = &(*i);
63
aabb_part.Add(rp, i->GetPatch().GetAABB());
69
bool ROADSTRIP::Collide(const MATHVECTOR <float, 3> & origin, const MATHVECTOR <float, 3> & direction, float seglen, MATHVECTOR <float, 3> & outtri, const BEZIER * & colpatch, MATHVECTOR <float, 3> & normal) const
71
std::list <ROADPATCH *> candidates;
72
aabb_part.Query(AABB<float>::RAY(origin, direction, seglen), candidates);
74
for (std::list <ROADPATCH *>::iterator i = candidates.begin(); i != candidates.end(); ++i)
76
MATHVECTOR <float, 3> coltri, colnorm;
77
if ((*i)->Collide(origin, direction, seglen, coltri, colnorm))
79
if (!col || (coltri-origin).Magnitude() < (outtri-origin).Magnitude())
83
colpatch = &(*i)->GetPatch();
93
void ROADSTRIP::Reverse()
97
for (std::list <ROADPATCH>::iterator i = patches.begin(); i != patches.end(); ++i)
99
i->GetPatch().Reverse();
100
i->GetPatch().ResetDistFromStart();
103
//fix pointers to next patches for race placement
104
for (std::list <ROADPATCH>::iterator i = patches.begin(); i != patches.end(); ++i)
106
std::list <ROADPATCH>::iterator n = i;
108
BEZIER * nextpatchptr = NULL;
109
if (n != patches.end())
111
nextpatchptr = &(n->GetPatch());
112
i->GetPatch().Attach(*nextpatchptr);
116
i->GetPatch().ResetNextPatch();
117
i->GetPatch().Attach(patches.front().GetPatch());
122
/*void ROADSTRIP::CreateRacingLine(
123
SCENENODE * parentnode,
124
TEXTURE_GL & racingline_texture,
125
std::ostream & error_output)
127
for (std::list <ROADPATCH>::iterator i = patches.begin(); i != patches.end(); ++i)
129
std::list <ROADPATCH>::iterator n = i;
131
ROADPATCH * nextpatch(NULL);
132
if (n != patches.end())
136
i->AddRacinglineScenenode(parentnode, nextpatch, racingline_texture, error_output);
b'\\ No newline at end of file'