青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當(dāng)自強(qiáng)而不息

Controlling Players and Characters(11)

 

Faster than the Speed of Pythagoras


To determine the distance away from a route point, you can use the standard
Pythagorean Theorem, but in order to speed things up, you can toss the sqrt
operation out the door and use the sum of the squares of the lengths instead.
To see what I mean, take a look at the following two lines of code:

float Distance = sqrt(Length1*Length1 + Length2*Length2);
float Distance = Length1*Length1 + Length2*Length2;

Notice that the preceding two lines of code are almost identical, except the second
line omits the sqrt function, making the second line execute much faster. The
downside is that you don’t get the exact length, which really isn’t a problem.

NOTE
The Pythagorean Theorem is probably the most famous theorem in geometry. It states that the
square of the length of the hypotenuse of a right triangle is equal to the sum of the squares of the
lengths of the sides. Basically, it means that the square root of the lengths of two sides (when
both are squared and added together) equals the length of the third side of a right triangle.

For example, imagine that you are measuring the distance between two points and
you want to see whether that distance is less than 40. If the coordinates of the two
points are 0,0 and 30,20, the faster distance calculation will give you a distance of
1,300 (because the length of the two sides are 30 and 20, respectively).

How can you determine the distance now? By calculating the square (the number
times itself) of the distance, that’s how! So, by taking 40 times 40, you get 1,600. By
comparing the distance of 1,300 between the points, you can see that indeed the
distance is less than 1,600 and, thus, less than the original distance of 40 you were
checking.

To get back to what I was originally talking about, you can use the faster method
of distance calculation to determine when a character is close enough to a route
point. Say that you want a route point considered as being touched by a character
if that character comes within so many units from it. Utilizing the faster method of
distance calculation, you can use the following function to determine whether that
is the case:

BOOL TouchedRoutePoint(
  float CharXPos, float CharZPos, // Character coordinates
  float RouteXPos, float RouteZPos, // Route point coordinates
  float Distance) // Distance to check
{
  // Square the distance to adjust for faster distance checking
  Distance *= Distance;

  // Now calculate the distance
  float XDiff = (float)fabs(RouteXPos - CharXPos);
  float ZDiff = (float)fabs(RouteZPos - CharZPos);
  float Dist = XDiff*XDiff + ZDiff*ZDiff;

  // Return results
  if(Dist <= Distance) // Within range being checked
    return TRUE;

  return FALSE; // Out of distance range
}

When calling TouchedRoutePoint with the character coordinates, the coordinates of
the route point, and the distance from the point to check, you will receive a value
of TRUE if the character is within Distance units from the route point coordinates.
A return value of FALSE means that the character is not within Distance units from
the route point.

 

Walking the Route
 

At long last, you can put everything together and force a character to walk from
one route point to the next. Here’s a small program that takes the five route points
defined previously and puts a character at point one, forcing the character to walk
from point to point forever:

sRoutePoint Route[5] = {
  { -200.0f, -100.0f },
  { 100.0f, -300.0f },
  { 300.0f, -200.0f },
  { 200.0f, 100.0f },
  { 0.0f, 400.0f }
};

long NumRoutePoints = 5;

// Character coordinates and movement variables
float CharXPos = Route[0].XPos;
float CharZPos = Route[0].ZPos;
float MoveX, MoveZ;
float Speed; // Walking speed of character

// Start track to 2nd point
long TargetRoutePoint = 1;
SetupMovement(TargetRoutePoint);

// Loop forever, moving and checking for route points reached
while(1) {
  // Is character within range of route point?
  if(TouchedRoutePoint(TargetRoutePoint, 32.0f) == TRUE) {
    // Move to next route point
    TargetRoutePoint++;
    if(TargetRoutePoint >= NumRoutePoints)
    TargetRoutePoint = 0;
    SetupMovement(TargetRoutePoint);
  }

  // Move character
  CharXPos += MoveX;
  CharZPos += MoveZ;
}

// Function to check if within range of route point
BOOL TouchedRoutePoint(long PointNum, float Distance)
{
  Distance *= Distance;
  float XDiff = (float)fabs(CharXPos - Route[PointNum].XPos);
  float ZDiff = (float)fabs(CharZPos - Route[PointNum].ZPos);
  float Dist = XDiff*XDiff + ZDiff*ZDiff;


  if(Dist <= Distance)
    return TRUE;
 

  return FALSE;
}

// Function to calculate movement variables
void SetupMovement(long PointNum)
{
  float XDiff = (float)fabs(CharXPos - Route[PointNum].XPos);
  float ZDiff = (float)fabs(CharZPos - Route[PointNum].ZPos);
  float Length = sqrt(XDiff*XDiff + ZDiff*ZDiff);


  MoveX = (Route[PointNum].XPos - CharXPos) / Length * Speed;
  MoveZ = (Route[PointNum].ZPos - CharZPos) / Length * Speed;
}


posted on 2007-11-14 15:37 lovedday 閱讀(213) 評(píng)論(0)  編輯 收藏 引用


只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


公告

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

隨筆分類(lèi)(178)

3D游戲編程相關(guān)鏈接

搜索

最新評(píng)論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲欧美日韩国产成人| 久久精品日韩| 小黄鸭视频精品导航| 午夜综合激情| 亚洲一区二区成人| 日韩视频不卡| 亚洲一区二区三区精品在线| 亚洲高清毛片| 在线视频欧美一区| 一区二区三区福利| 欧美一区午夜视频在线观看| 久久精选视频| 欧美日韩日本网| 国产精品色午夜在线观看| 在线观看欧美| 欧美在线短视频| 亚洲国产三级| 午夜久久影院| 欧美成人在线免费观看| 国产精品a久久久久久| 亚洲成人影音| 亚洲尤物视频在线| 欧美大片免费观看在线观看网站推荐| 一区二区三区四区国产精品| 美女啪啪无遮挡免费久久网站| 国产欧美一区二区三区国产幕精品 | 国产精品国产三级国产专区53| 国产美女诱惑一区二区| 亚洲免费电影在线| 久久深夜福利免费观看| 亚洲最新中文字幕| 欧美日韩国产一区精品一区 | 国产精品捆绑调教| 日韩午夜三级在线| 国产伦精品一区二区三区免费| 国内成人自拍视频| 久久久久久午夜| 欧美淫片网站| 国产一区二区三区免费在线观看| 亚洲一二三区在线| 亚洲免费视频观看| 国产欧美日韩在线视频| 女生裸体视频一区二区三区| 免费日韩av电影| 99精品国产热久久91蜜凸| 亚洲欧洲在线一区| 欧美天天综合网| 亚洲欧美日韩专区| 亚洲欧美视频在线| 亚洲国产精品久久| 亚洲综合第一| 久久国产手机看片| 好吊视频一区二区三区四区| 亚洲欧美中文在线视频| 久久九九精品| 亚洲高清免费视频| 欧美日韩一二三四五区| 欧美成人一区二区| 国产精品理论片| 一区二区三区www| 亚洲婷婷国产精品电影人久久| 亚洲狠狠婷婷| 性色av一区二区三区| 亚洲一区二区高清| 欧美日韩国产免费| 亚洲中无吗在线| 国产区日韩欧美| 欧美在线播放高清精品| 午夜精品久久久久99热蜜桃导演| 欧美理论电影在线观看| 亚洲国产精品一区二区www| 一区二区三区日韩在线观看| 国内伊人久久久久久网站视频| 亚洲一区视频| 久久精品123| 亚洲日本激情| 国产精品porn| 久久久国产一区二区三区| 亚洲成人在线视频网站| 日韩亚洲欧美高清| 国产精品系列在线播放| 欧美日本一道本| 国产欧美一区二区视频| 亚洲日本电影在线| 国产精品久久久一本精品| 久久九九99| 久久久久国产免费免费| 一区免费观看视频| 香蕉精品999视频一区二区| 亚洲精品少妇网址| 亚洲国产精品成人| 欧美韩日精品| 欧美大尺度在线| 欧美激情一区| 亚洲欧洲视频| 亚洲精品久久久久| 日韩小视频在线观看| av不卡免费看| 午夜免费在线观看精品视频| 午夜精品亚洲| 久久综合五月| 久久蜜臀精品av| 亚洲在线免费| 亚洲天堂av电影| 久久久青草婷婷精品综合日韩| 久久久精品国产免大香伊| 国产精品久久久久9999吃药| 日韩亚洲欧美成人一区| 亚洲欧美日韩中文在线制服| 最新成人在线| 激情文学一区| 免费成人在线观看视频| 亚洲人成网在线播放| 久久综合国产精品| 国内视频一区| 欧美日韩精品一区二区三区| 亚洲精品一区二区三区樱花| 亚洲一区二区三| 国内一区二区三区在线视频| 久久综合狠狠综合久久综青草 | 亚洲伊人伊色伊影伊综合网| 国产精品国产| 久久国产精品99久久久久久老狼| 免费不卡在线观看| 亚洲国产老妈| 亚洲精品裸体| 樱花yy私人影院亚洲| 欧美午夜精品久久久久久人妖| 亚洲免费人成在线视频观看| 激情六月综合| 久久er99精品| 日韩一区二区精品在线观看| 欧美成人免费在线观看| 一区二区三区四区在线| 欧美多人爱爱视频网站| 亚洲欧美第一页| 99riav1国产精品视频| 亚洲大黄网站| 久久久视频精品| 久热爱精品视频线路一| 国产在线播精品第三| 新67194成人永久网站| 久久精品亚洲一区二区| 久久一日本道色综合久久| 国产一区二区精品久久99| 欧美一级免费视频| 久久精品国产精品亚洲精品| 国内精品久久久久久影视8| 欧美一区二区视频免费观看| 久久亚洲国产精品一区二区| **欧美日韩vr在线| 欧美国产精品专区| 亚洲天堂网在线观看| 亚洲欧美日韩人成在线播放| 国产精品永久| 亚洲精品午夜| 国产精品99久久久久久人| 欧美一区高清| 午夜国产精品影院在线观看| 久久精品色图| 欧美日韩国产页| 亚洲六月丁香色婷婷综合久久| 欧美在线看片a免费观看| 欧美在线资源| 亚洲午夜小视频| 亚洲靠逼com| 久久综合影视| 国产欧美精品日韩区二区麻豆天美 | 午夜精品美女久久久久av福利| 久久综合狠狠综合久久综合88 | 亚洲欧美久久久久一区二区三区| 午夜国产精品视频免费体验区| 麻豆国产精品777777在线| 国产精品羞羞答答xxdd| 欧美日韩国产免费观看| 夜夜嗨一区二区| 久久久精品久久久久| 亚洲日本成人| 国产日韩专区在线| 欧美久久九九| 久久精品久久99精品久久| 99re热精品| 欧美gay视频激情| 欧美一站二站| 在线一区亚洲| 亚洲国产精品尤物yw在线观看| 欧美色欧美亚洲另类二区| 老司机成人网| 久久gogo国模裸体人体| 在线亚洲欧美专区二区| 亚洲国产老妈| 欧美sm重口味系列视频在线观看| 欧美一级播放| 亚洲欧美一区二区三区极速播放 | 亚洲午夜国产成人av电影男同| 久久综合一区| 久久久久成人精品| 性色一区二区三区| 亚洲一区二区视频在线| 亚洲精品国产精品国产自|