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

天行健 君子當(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>
            欧美一区二区三区的| 欧美一区二区成人6969| 免费欧美在线视频| 亚洲欧洲精品天堂一级| 亚洲日本欧美在线| 欧美精品久久久久久久久久| 99伊人成综合| 亚洲欧美在线x视频| 国产亚洲欧美另类中文 | 欧美成人一区在线| 久久一综合视频| 中文网丁香综合网| 欧美影院精品一区| 亚洲经典三级| 亚洲在线黄色| 亚洲国产激情| 亚洲视频在线观看一区| 国产永久精品大片wwwapp| 欧美激情女人20p| 国产精品一区在线观看| 欧美电影免费网站| 国产精品推荐精品| 亚洲国产天堂久久综合网| 国产精品嫩草99av在线| 欧美成人情趣视频| 国产欧美日韩在线 | 久久久免费av| 欧美日韩麻豆| 欧美风情在线| 国产一二三精品| 中文精品视频一区二区在线观看| 国内自拍一区| 亚洲国产激情| 欧美中文字幕久久| 一区二区三区福利| 免费久久99精品国产自在现线| 午夜精品福利电影| 欧美日韩视频不卡| 91久久线看在观草草青青| 国产最新精品精品你懂的| 一区二区三区视频观看| 亚洲精品乱码久久久久久蜜桃91| 欧美一区免费视频| 性久久久久久久久| 欧美日韩在线播| 亚洲精品社区| 亚洲精选91| 欧美多人爱爱视频网站| 免费欧美网站| 在线精品福利| 久久琪琪电影院| 另类春色校园亚洲| 伊人精品成人久久综合软件| 午夜久久tv| 久久激情五月婷婷| 国产精品欧美经典| 这里只有精品视频| 亚洲欧美视频一区| 国产精品日韩欧美一区二区三区| 亚洲精品综合在线| 一区二区三区日韩欧美精品| 欧美久久久久免费| 99国产精品自拍| 亚洲深夜影院| 国产精品狼人久久影院观看方式| 一本色道久久综合亚洲精品小说 | 久久av红桃一区二区小说| 欧美午夜一区二区| 亚洲一区三区视频在线观看| 亚洲欧美另类在线| 国产日韩欧美中文| 久久精品日韩欧美| 亚洲国产cao| 亚洲视频一区二区在线观看| 国产精品久久久一区二区三区| 一区二区三区四区蜜桃| 午夜精品美女自拍福到在线| 国产毛片精品视频| 久久久噜噜噜久久中文字幕色伊伊| 麻豆精品视频在线观看视频| 亚洲区中文字幕| 欧美日韩一区二| 欧美亚洲在线播放| 亚洲第一主播视频| 午夜精品久久久久久久久久久 | 欧美jizzhd精品欧美喷水| 亚洲激情自拍| 性18欧美另类| 亚洲第一网站| 国产精品久久久亚洲一区| 久久精品亚洲热| 亚洲精品久久视频| 久久国产一区二区| 日韩视频专区| 国产午夜精品在线观看| 欧美高清视频在线播放| 久久精品亚洲精品国产欧美kt∨| 欧美国产第一页| 日韩视频一区| 国产日韩欧美三区| 欧美成人性网| 香港成人在线视频| 最新成人在线| 久久天堂国产精品| 亚洲午夜极品| 亚洲国产国产亚洲一二三| 国产精品少妇自拍| 欧美福利一区二区| 久久成人人人人精品欧| 一区二区免费在线播放| 另类图片国产| 久久国产夜色精品鲁鲁99| 中文欧美字幕免费| 亚洲欧洲日本专区| 激情av一区| 国产精品稀缺呦系列在线| 欧美激情精品久久久久久| 欧美在线首页| 午夜精品亚洲一区二区三区嫩草| 亚洲精品视频啊美女在线直播| 蜜桃久久av一区| 久久久久国产精品厨房| 亚洲综合色激情五月| 日韩午夜av电影| 亚洲第一精品福利| 尤物视频一区二区| 国产综合第一页| 国产亚洲成av人在线观看导航 | 欧美一区二区三区久久精品茉莉花 | 国产欧亚日韩视频| 国产精品久久毛片a| 欧美日韩美女在线观看| 欧美国产一区二区| 欧美激情视频一区二区三区不卡| 久久美女性网| 乱中年女人伦av一区二区| 久久国产主播精品| 久久免费高清| 另类酷文…触手系列精品集v1小说| 欧美在线观看视频一区二区三区| 亚洲欧美综合| 久久gogo国模裸体人体| 久久福利资源站| 久久久999精品| 男男成人高潮片免费网站| 欧美黄色精品| 欧美亚日韩国产aⅴ精品中极品| 欧美日本在线观看| 国产精品男女猛烈高潮激情| 国产精品久久久久久久浪潮网站| 国产精品女主播| 国产综合18久久久久久| 亚洲第一福利视频| 日韩亚洲精品电影| 亚洲免费影院| 久久免费高清| 亚洲国产精品激情在线观看| 亚洲欧洲精品一区二区三区波多野1战4| 亚洲欧洲另类| 亚洲一区欧美激情| 久久美女艺术照精彩视频福利播放| 老司机午夜精品视频在线观看| 欧美国产日韩免费| 国产精品免费看久久久香蕉| 国产日韩欧美在线视频观看| 亚洲国产精品成人精品| 日韩香蕉视频| 久久激情视频免费观看| 欧美激情免费观看| 亚洲专区一区| 欧美高清一区| 国产综合自拍| 一区二区三区四区国产精品| 欧美一级理论片| 亚洲国产小视频在线观看| 亚洲一区二区免费看| 久久综合伊人77777尤物| 欧美日韩在线观看视频| 国模私拍一区二区三区| 在线性视频日韩欧美| 久久尤物电影视频在线观看| 亚洲精品在线看| 久久久一区二区| 国产精品美女久久久久久免费| 亚洲二区免费| 亚洲女同同性videoxma| 欧美高清日韩| 欧美一区二区三区四区在线观看| 欧美高清一区| 樱花yy私人影院亚洲| 亚洲欧美制服中文字幕| 亚洲国产高清自拍| 欧美专区福利在线| 国产精品私拍pans大尺度在线| 亚洲乱码国产乱码精品精| 老司机免费视频久久| 亚洲欧美日本精品| 欧美午夜精品久久久久免费视| 亚洲日本成人| 欧美顶级少妇做爰|