本文整理汇总了C++中TVector::dist方法的典型用法代码示例。如果您正苦于以下问题:C++ TVector::dist方法的具体用法?C++ TVector::dist怎么用?C++ TVector::dist使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TVector
的用法示例。
在下文中一共展示了TVector::dist方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: find_collision
/* find if any of the current balls intersect with each other in the
* current timestep. returns the index of the 2 intersecting balls,
* the point and time of intersection */
int find_collision(TVector& point, double& timePoint, double time2,
int& ball1, int& ball2) {
TVector relativeV;
TRay rays;
double Mytime = 0.0, Add = time2/150.0, timedummy = 10000, timedummy2 = -1;
TVector posi;
/* Test all balls against each other in 150 small steps */
for (int i = 0; i < ball_count - 1; i++){
for (int j = i+1; j < ball_count; j++){
// Find Distance
relativeV = ball_vel[i]-ball_vel[j];
rays = TRay(old_pos[i],TVector::unit(relativeV));
Mytime = 0.0;
// If distance detween centers greater than 2*radius an
// intersection occurred loop to find the exact intersection point
if ( (rays.dist(old_pos[j])) > ball_r * 2 )
continue;
while (Mytime < time2) {
Mytime += Add;
posi = old_pos[i] + relativeV*Mytime;
if (posi.dist(old_pos[j]) <= ball_r * 2 ) {
point = posi;
if (timedummy > (Mytime - Add)) timedummy = Mytime-Add;
ball1 = i;
ball2 = j;
break;
}
}
}
}
if (timedummy!=10000) {
timePoint=timedummy;
return 1;
}
return 0;
}
示例2: FindBallCol
int FindBallCol(TVector& point, double& TimePoint, double Time2, int& BallNr1, int& BallNr2)
{
TVector RelativeV;
TRay rays;
double MyTime=0.0, Add=Time2/150.0, Timedummy=10000, Timedummy2=-1;
TVector posi;
//Test all balls against eachother in 150 small steps
for (int i=0;i<NrOfBalls-1;i++)
{
for (int j=i+1;j<NrOfBalls;j++)
{
RelativeV=ArrayVel[i]-ArrayVel[j];
rays=TRay(OldPos[i],TVector::unit(RelativeV));
MyTime=0.0;
if ( (rays.dist(OldPos[j])) > 40) continue;
while (MyTime<Time2)
{
MyTime+=Add;
posi=OldPos[i]+RelativeV*MyTime;
if (posi.dist(OldPos[j])<=40) {
point=posi;
if (Timedummy>(MyTime-Add)) Timedummy=MyTime-Add;
BallNr1=i;
BallNr2=j;
break;
}
}
}
}
if (Timedummy!=10000) { TimePoint=Timedummy;
return 1;
}
return 0;
}
示例3: FindBallCol
bool MyGameState::FindBallCol(TVector& point, double& TimePoint, double Time2, int& BallNr1, int& BallNr2){
TVector RelativeV;
TRay rays;
double MyTime=0.0, Add=Time2/150.0, Timedummy=10000, Timedummy2=-1;
TVector posi;
//Test all balls against eachother in 150 small steps
for (int i = 0; i <= 15-1; i++){
for (int j = i + 1; j<= 15; j++){
RelativeV = movement[i] - movement[j];
rays = TRay(oldPos[i],TVector::unit(RelativeV));
MyTime=0.0;
if ( rays.dist(oldPos[j]) > 10){
continue;
}
while (MyTime < Time2){
MyTime += Add;
posi = oldPos[i] + RelativeV * MyTime;
if (posi.dist(oldPos[j]) <= 3) {
point = posi;
if (Timedummy > (MyTime-Add)) {
Timedummy = MyTime - Add;
}
BallNr1=i;
BallNr2=j;
break;
}
}
}
}
if (Timedummy!=10000) {
TimePoint=Timedummy;
return true;
}
return false;
}