本文整理汇总了C++中BEZIER类的典型用法代码示例。如果您正苦于以下问题:C++ BEZIER类的具体用法?C++ BEZIER怎么用?C++ BEZIER使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BEZIER类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetHorizontalDistanceAlongPatch
///note that carposition must be in patch space
///returns distance from left side of the track
float GetHorizontalDistanceAlongPatch(const BEZIER & patch, MATHVECTOR <float, 3> carposition)
{
MATHVECTOR <float, 3> leftside = (patch.GetPoint(0,0) + patch.GetPoint(3,0))*0.5;
MATHVECTOR <float, 3> rightside = (patch.GetPoint(0,3) + patch.GetPoint(3,3))*0.5;
MATHVECTOR <float, 3> patchwidthvector = rightside - leftside;
return patchwidthvector.Normalize().dot(carposition-leftside);
}
示例2: GetPatchRadius
double GetPatchRadius(const BEZIER & patch)
{
if (patch.GetNextPatch() && patch.GetNextPatch()->GetNextPatch())
{
double track_radius = 0;
/*MATHVECTOR <float, 3> d1 = -GetPatchDirection(patch);
MATHVECTOR <float, 3> d2 = GetPatchDirection(*patch.GetNextPatch());*/
MATHVECTOR <float, 3> d1 = -(patch.GetNextPatch()->GetRacingLine() - patch.GetRacingLine());
MATHVECTOR <float, 3> d2 = patch.GetNextPatch()->GetNextPatch()->GetRacingLine() - patch.GetNextPatch()->GetRacingLine();
d1[1] = 0;
d2[1] = 0;
float d1mag = d1.Magnitude();
float d2mag = d2.Magnitude();
float diff = d2mag - d1mag;
double dd = ((d1mag < 0.0001) || (d2mag < 0.0001)) ? 0.0 : d1.Normalize().dot(d2.Normalize());
float angle = acos((dd>=1.0L)?1.0L:(dd<=-1.0L)?-1.0L:dd);
float d1d2mag = d1mag + d2mag;
float alpha = (d1d2mag < 0.0001) ? 0.0f : (M_PI * diff + 2.0 * d1mag * angle) / d1d2mag / 2.0;
if (fabs(alpha - M_PI/2.0) < 0.001) track_radius = 10000.0;
else track_radius = d1mag / 2.0 / cos(alpha);
return track_radius;
}
else //fall back
return 0;
}
示例3: TrimPatch
///trim the patch's width in-place
void TrimPatch(BEZIER & patch, float trimleft_front, float trimright_front, float trimleft_back, float trimright_back)
{
MATHVECTOR <float, 3> frontvector = (patch.GetPoint(0,3) - patch.GetPoint(0,0));
MATHVECTOR <float, 3> backvector = (patch.GetPoint(3,3) - patch.GetPoint(3,0));
float frontwidth = frontvector.Magnitude();
float backwidth = backvector.Magnitude();
if (trimleft_front + trimright_front > frontwidth)
{
float scale = frontwidth/(trimleft_front + trimright_front);
trimleft_front *= scale;
trimright_front *= scale;
}
if (trimleft_back + trimright_back > backwidth)
{
float scale = backwidth/(trimleft_back + trimright_back);
trimleft_back *= scale;
trimright_back *= scale;
}
MATHVECTOR <float, 3> newfl = patch.GetPoint(0,0);
MATHVECTOR <float, 3> newfr = patch.GetPoint(0,3);
MATHVECTOR <float, 3> newbl = patch.GetPoint(3,0);
MATHVECTOR <float, 3> newbr = patch.GetPoint(3,3);
if (frontvector.Magnitude() > 0.001)
{
MATHVECTOR <float, 3> trimdirection_front = frontvector.Normalize();
newfl = patch.GetPoint(0,0) + trimdirection_front*trimleft_front;
newfr = patch.GetPoint(0,3) - trimdirection_front*trimright_front;
}
if (backvector.Magnitude() > 0.001)
{
MATHVECTOR <float, 3> trimdirection_back = backvector.Normalize();
newbl = patch.GetPoint(3,0) + trimdirection_back*trimleft_back;
newbr = patch.GetPoint(3,3) - trimdirection_back*trimright_back;
}
patch.SetFromCorners(newfl, newfr, newbl, newbr);
}
示例4: RevisePatch
BEZIER AI::RevisePatch(const BEZIER * origpatch, bool use_racingline)
{
BEZIER patch = *origpatch;
//take into account the racing line
//use_racingline = false;
if (use_racingline && patch.GetNextPatch() && patch.HasRacingline())
{
float widthfront = std::min((patch.GetNextPatch()->GetRacingLine()-patch.GetPoint(0,0)).Magnitude(),
(patch.GetNextPatch()->GetRacingLine()-patch.GetPoint(0,3)).Magnitude());
float widthback = std::min((patch.GetRacingLine()-patch.GetPoint(3,0)).Magnitude(),
(patch.GetRacingLine()-patch.GetPoint(3,3)).Magnitude());
float trimleft_front = (patch.GetNextPatch()->GetRacingLine() - patch.GetPoint(0,0)).Magnitude()-widthfront;
float trimright_front = (patch.GetNextPatch()->GetRacingLine() - patch.GetPoint(0,3)).Magnitude()-widthfront;
float trimleft_back = (patch.GetRacingLine() - patch.GetPoint(3,0)).Magnitude()-widthback;
float trimright_back = (patch.GetRacingLine() - patch.GetPoint(3,3)).Magnitude()-widthback;
TrimPatch(patch, trimleft_front, trimright_front, trimleft_back, trimright_back);
}
//check for revisions due to other cars
/*const float trim_falloff_distance = 100.0; //trim fallof distance in meters per (meters per second)
const MATHVECTOR <float, 3> throttle_axis(-1,0,0); //positive is in front of the car
std::map <const CAR *, PATH_REVISION> & revmap = path_revisions;
for (std::map <const CAR *, PATH_REVISION>::iterator i = revmap.begin(); i != revmap.end(); i++)
{
if (i->first != c->car)
{
//compute relative info
MATHVECTOR <float, 3> myvel = c->car->GetVelocity();
MATHVECTOR <float, 3> othervel = i->first->GetVelocity();
(-c->car->GetOrientation()).RotateVector(myvel);
(-i->first->GetOrientation()).RotateVector(othervel);
float speed_diff = myvel.dot(throttle_axis) - othervel.dot(throttle_axis); //positive if other car is faster //actually positive if my car is faster, right?
float cardist_back = patch.dist_from_start - i->second.car_pos_along_track; //positive if patch is ahead of car
float patchlen = GetPatchDirection(patch).Magnitude();
float cardist_front = (patch.dist_from_start+patchlen) - i->second.car_pos_along_track;
const float minfalloff = 10;
const float maxfalloff = 60;
float cur_trim_falloff_distance_fwd = minfalloff;
float cur_trim_falloff_distance_rear = minfalloff;
float falloff = clamp(trim_falloff_distance*std::abs(speed_diff),minfalloff,maxfalloff);
if (speed_diff > 0)
{
//cur_trim_falloff_distance_fwd = falloff;
}
else
cur_trim_falloff_distance_rear = falloff;
float scale_front = clamp(1.0f-cardist_front/cur_trim_falloff_distance_fwd, 0, 1);
if (cardist_front < 0)
scale_front = clamp(1.0f+cardist_front/cur_trim_falloff_distance_rear, 0, 1);
float scale_back = clamp(1.0f-cardist_back/cur_trim_falloff_distance_fwd, 0, 1);
if (cardist_back < 0)
scale_back = clamp(1.0f+cardist_back/cur_trim_falloff_distance_rear, 0, 1);
std::cout << speed_diff << ", " << cur_trim_falloff_distance_fwd << ", " << cur_trim_falloff_distance_rear << ", " << cardist_front << ", " << cardist_back << ", " << scale_front << ", " << scale_back << std::endl;
float trimleft_front = i->second.trimleft_front*scale_front;
float trimright_front = i->second.trimright_front*scale_front;
float trimleft_back = i->second.trimleft_back*scale_back;
float trimright_back = i->second.trimright_back*scale_back;
TrimPatch(patch, trimleft_front, trimright_front, trimleft_back, trimright_back);
}
}*/
return patch;
}
示例5: GetPatchWidthVector
MATHVECTOR <float, 3> GetPatchWidthVector(const BEZIER & patch)
{
return ((patch.GetPoint(0,0) + patch.GetPoint(3,0)) -
(patch.GetPoint(0,3) + patch.GetPoint(3,3))) * 0.5;
}
示例6: GetPatchBackCenter
MATHVECTOR <float, 3> GetPatchBackCenter(const BEZIER & patch)
{
return (patch.GetPoint(3,0) + patch.GetPoint(3,3)) * 0.5;
}
示例7: GetPatchFrontCenter
MATHVECTOR <float, 3> GetPatchFrontCenter(const BEZIER & patch)
{
return (patch.GetPoint(0,0) + patch.GetPoint(0,3)) * 0.5;
}
示例8: Attach
void BEZIER::Attach(BEZIER & other, bool reverse)
{
/*if (!reverse)
{
//move the other patch to the location of this patch and force its
// intermediate points into a nice grid layout
other.SetFromCorners(other.points[0][0], other.points[0][3], points[0][0], points[0][3]);
for (int x = 0; x < 4; x++)
{
//slope points in the forward direction
MATHVECTOR<float,3> slope = other.points[0][x] - points[3][x];
if (slope.Magnitude() > 0.0001)
slope = slope.Normalize();
float otherlen = (other.points[0][x] - other.points[3][x]).Magnitude();
float mylen = (points[0][x] - points[3][x]).Magnitude();
float meanlen = (otherlen + mylen)/2.0;
float leglen = meanlen / 3.0;
if (slope.Magnitude() > 0.0001)
{
other.points[2][x] = other.points[3][x] + slope*leglen;
points[1][x] = points[0][x] + slope*(-leglen);
}
else
{
other.points[2][x] = other.points[3][x];
points[1][x] = points[0][x];
}
}
}*/
//CheckForProblems();
//store the pointer to next patch
next_patch = &other;
//calculate the track radius at the connection of this patch and next patch
MATHVECTOR<float,3> a = SurfCoord(0.5,0.0);
MATHVECTOR<float,3> b = SurfCoord(0.5,1.0);
MATHVECTOR<float,3> c = other.SurfCoord(0.5,1.0);
if (reverse)
{
a = SurfCoord(0.5,1.0);
b = SurfCoord(0.5,0.0);
c = other.SurfCoord(0.5,0.0);
//Reverse();
}
//racing_line = a;
MATHVECTOR<float,3> d1 = a - b;
MATHVECTOR<float,3> d2 = c - b;
float diff = d2.Magnitude() - d1.Magnitude();
double dd = ((d1.Magnitude() < 0.0001) || (d2.Magnitude() < 0.0001)) ? 0.0 : d1.Normalize().dot(d2.Normalize());
float angle = acos((dd>=1.0L)?1.0L:(dd<=-1.0L)?-1.0L:dd);
float d1d2mag = d1.Magnitude() + d2.Magnitude();
float alpha = (d1d2mag < 0.0001) ? 0.0f : (M_PI * diff + 2.0 * d1.Magnitude() * angle) / d1d2mag / 2.0;
if (fabs(alpha - M_PI/2.0) < 0.001) track_radius = 10000.0;
else track_radius = d1.Magnitude() / 2.0 / cos(alpha);
if (d1.Magnitude() < 0.0001)
track_curvature = 0.0;
else
track_curvature = 2.0 * cos(alpha) / d1.Magnitude();
//determine it's a left or right turn at the connection
MATHVECTOR<float,3> d = d1.cross(d2);
if (fabs(d[0]) < 0.1 && fabs(d[1]) < 0.1 && fabs(d[2]) < 0.1)
{
turn = 0; //straight ahead
}
else if (d[1] > 0.0) turn = -1; //left turn ahead
else turn = 1; //right turn ahead
//calculate distance from start of the road
if (other.next_patch == NULL || reverse) other.dist_from_start = dist_from_start + d1.Magnitude();
length = d1.Magnitude();
}
示例9: AutoTrace
void AutoTrace()
{
if (activestrip != NULL)
{
BEZIER * lastbez = activestrip->GetLastPatch();
if (lastbez != NULL && editordata.numbezinput == 4)
{
VERTEX tvec[4];
/*VERTEX fl = lastbez->points[0][0];
VERTEX fr = lastbez->points[0][3];
VERTEX bl = lastbez->points[3][0];
VERTEX br = lastbez->points[3][3];*/
bool success(true);
BEZIER patch;
if (vertmode == TWOVERTS)
{
success = success && objects.AutoFindClosestVert(lastbez->points[0][0], lastbez->points[0][3], (lastbez->points[0][0]-lastbez->points[3][0]), tvec[0]);
success = success && objects.AutoFindClosestVert(lastbez->points[0][3], lastbez->points[0][0], (lastbez->points[0][3]-lastbez->points[3][3]), tvec[1]);
if (success)
{
patch.SetFromCorners(tvec[0], tvec[1], editordata.bezinput[0], editordata.bezinput[3]);
}
}
else if (vertmode == THREEVERTS)
{
success = success && objects.AutoFindClosestVert(lastbez->points[0][0], lastbez->points[0][1], (lastbez->points[0][0]-lastbez->points[3][0]), tvec[0]);
success = success && objects.AutoFindClosestVert(lastbez->points[0][1], lastbez->points[0][3], (lastbez->points[0][1]-lastbez->points[3][1]), tvec[1]);
tvec[2] = tvec[1];
success = success && objects.AutoFindClosestVert(lastbez->points[0][3], lastbez->points[0][1], (lastbez->points[0][3]-lastbez->points[3][3]), tvec[3]);
if (success)
{
for (int i = 0; i < 4; i++)
patch.points[3][i] = editordata.bezinput[i];
for (int i = 0; i < 4; i++)
patch.points[0][i] = tvec[i];
patch.CalculateMiddleRows();
}
}
else if (vertmode == FOURVERTS)
{
for (int i = 0; i < 4; i++)
{
int nextvert = i + 1;
if (nextvert >= 4)
nextvert = 2;
success = success && objects.AutoFindClosestVert(lastbez->points[0][i], lastbez->points[0][nextvert], (lastbez->points[0][i]-lastbez->points[3][i]), tvec[i]);
}
if (success)
{
for (int i = 0; i < 4; i++)
patch.points[3][i] = editordata.bezinput[i];
for (int i = 0; i < 4; i++)
patch.points[0][i] = tvec[i];
patch.CalculateMiddleRows();
}
}
else
assert(0);
if (success)
{
activestrip->Add(patch);
editordata.numbezinput = 4;
editordata.bezinput[0] = patch.points[0][0];
editordata.bezinput[1] = patch.points[0][1];
editordata.bezinput[2] = patch.points[0][2];
editordata.bezinput[3] = patch.points[0][3];
mq1.AddMessage("Auto-traced road");
}
else
{
mq1.AddMessage("Can't auto-trace road: found no candidate points");
}
}
else
{
mq1.AddMessage("Can't auto-trace road: must start road first");
}
}
else
{
mq1.AddMessage("Can't auto-trace road: no roads selected");
}
}
示例10: drawGLScene
//.........这里部分代码省略.........
#ifdef PERFORMANCE_PROFILE
t2 = GetMicroSeconds();
cout << "foliage.Draw() ticks: " << t2-t1 << endl;
t1 = GetMicroSeconds();
#endif
//glDisable(GL_CLIP_PLANE1);
ships.Draw(false);
terrain.Draw(cam, 1.0f, false, false, true, false, timefactor, fps, day_time);
//terrain.Draw(cam, 1.0f, false, false, true, false, timefactor, fps, day_time);
//rain is drawn over everything else
if (!underwater)
backdrop.DrawRain(day_time);
#ifdef PERFORMANCE_PROFILE
t2 = GetMicroSeconds();
cout << "DrawRain() ticks: " << t2-t1 << endl;
t1 = GetMicroSeconds();
#endif
glDisable(GL_CLIP_PLANE1);
*/
//glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/*if (0)
{
//experimental bezier stuff
BEZIER patch;
VERTEX fl, fr, bl, br;
//fl.Set(20,40,0);
fl.Set(5,10,0);
fr = fl;
bl = fl;
br = fl;
fr.x += 15;
fr.y += 3;
br.x += 12;
br.z += 8;
bl.z += 10;
bl.y -= 2;
patch.SetFromCorners(fl, fr, bl, br);
BEZIER nextpatch;
VERTEX offset;
offset.x += -7;
offset.z += -10;
fl = fl + offset;
fr = fr + offset;
bl = bl + offset;
br = br + offset;
nextpatch.SetFromCorners(fl, fr, bl, br);
//patch.Attach(nextpatch);
BEZIER thirdpatch;
示例11:
MATHVECTOR <float, 3> AI_Car_Experimental::GetPatchWidthVector(const BEZIER & patch)
{
return ((patch.GetPoint(0,0) + patch.GetPoint(3,0)) -
(patch.GetPoint(0,3) + patch.GetPoint(3,3))) * 0.5;
}