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

天行健 君子當自強而不息

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 閱讀(216) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美大片在线看| 亚洲欧美日韩视频一区| 欧美激情第六页| 麻豆成人综合网| 免费久久精品视频| 欧美大片91| 欧美日本不卡| 国产精品盗摄久久久| 欧美视频三区在线播放| 国产精品乱码久久久久久| 国产精品亚洲综合色区韩国| 国产一区二区三区在线观看免费视频| 黄色日韩精品| 亚洲日本中文字幕区| 欧美在线啊v一区| 欧美在线www| 欧美国产日韩在线观看| 国产精品日韩一区二区| 一色屋精品亚洲香蕉网站| 亚洲精品日韩综合观看成人91| 日韩午夜在线观看视频| 欧美在线视频在线播放完整版免费观看 | 久久成人免费日本黄色| 免费在线一区二区| 国产精品免费网站在线观看| 国产一区二区三区四区| 日韩一区二区精品在线观看| 欧美一区二区三区精品电影| 亚洲国产精品99久久久久久久久| 亚洲精品在线电影| 久久亚洲综合色| 国产欧美一区二区白浆黑人| 亚洲精品国久久99热| 久久久噜噜噜| 亚洲一二三区精品| 欧美精品久久久久久久久老牛影院 | 欧美一区二区私人影院日本 | 亚洲系列中文字幕| 久久在线免费观看视频| 国产精品久久国产精品99gif | 久久精品夜色噜噜亚洲a∨ | 最新国产成人在线观看| 久久精品九九| 亚洲天堂av电影| 欧美日韩国产一级| 亚洲免费观看视频| 欧美激情第1页| 午夜在线不卡| 国产精品一区视频网站| 亚洲一级片在线看| 欧美高清视频免费观看| 久久久噜噜噜久久中文字幕色伊伊| 欧美午夜精品久久久久久久| 亚洲免费不卡| 最新国产成人在线观看| 久久综合亚州| 亚洲国产日韩一区二区| 女同一区二区| 免费视频久久| 免费在线欧美视频| 亚洲大片一区二区三区| 麻豆乱码国产一区二区三区| 香蕉乱码成人久久天堂爱免费 | 欧美日韩精品免费| 亚洲激情影院| 亚洲精华国产欧美| 欧美大胆人体视频| 99精品视频一区二区三区| 亚洲激情专区| 欧美日韩综合精品| 香蕉成人伊视频在线观看| 亚洲无限av看| 国产伦精品一区二区三区高清| 亚洲永久免费精品| 亚洲欧美在线看| 好吊视频一区二区三区四区| 欧美sm重口味系列视频在线观看| 玖玖国产精品视频| 亚洲毛片一区二区| 一区二区三区www| 国产精品日本精品| 欧美国产1区2区| 欧美午夜在线视频| 久久久999精品| 美女图片一区二区| 中文av字幕一区| 欧美亚洲在线| 亚洲精品视频在线播放| 亚洲特级片在线| 在线日韩视频| 一区二区三区日韩在线观看 | 麻豆精品网站| 宅男精品视频| 欧美在线高清视频| 99视频精品| 欧美一级黄色网| 亚洲免费成人av| 午夜免费电影一区在线观看| 亚洲国产裸拍裸体视频在线观看乱了中文| 亚洲国产三级在线| 国产区二精品视| 亚洲国产美女| 国产日韩av高清| 亚洲毛片一区| 在线观看精品视频| 亚洲香蕉伊综合在人在线视看| 激情文学综合丁香| 亚洲天堂免费观看| 亚洲国产日本| 久久久久国产精品厨房| 中文国产成人精品| 噜噜噜噜噜久久久久久91| 欧美与欧洲交xxxx免费观看| 欧美激情四色 | 国产综合色精品一区二区三区| 亚洲美女免费精品视频在线观看| 黄色成人在线| 久久夜色精品国产欧美乱| 欧美视频在线观看一区| 最新日韩欧美| 亚洲精品之草原avav久久| 麻豆91精品| 免费成人av资源网| 激情综合视频| 久久精品国产精品| 欧美在线一区二区三区| 欧美亚男人的天堂| 亚洲精品视频在线播放| 亚洲精品乱码久久久久久日本蜜臀 | 亚洲欧美国产一区二区三区| 欧美国产日韩一区二区| 欧美黄色小视频| 在线成人av.com| 久久免费观看视频| 欧美成人免费全部| 亚洲欧洲三级电影| 欧美本精品男人aⅴ天堂| 亚洲高清电影| 亚洲精品中文字幕女同| 欧美精品亚洲| 在线一区日本视频| 午夜亚洲性色视频| 国产欧美日韩一区二区三区| 性欧美xxxx大乳国产app| 久久精品国产69国产精品亚洲| 国产一区二区三区四区老人| 久久av一区| 牛牛国产精品| 亚洲精品视频一区| 欧美日韩亚洲视频一区| 亚洲性感美女99在线| 欧美一区二区在线免费播放| 国产一区二区三区最好精华液| 亚洲在线免费| 免费观看30秒视频久久| 亚洲人久久久| 国产精品高潮呻吟久久| 香蕉久久一区二区不卡无毒影院 | 久久免费视频这里只有精品| 韩国成人福利片在线播放| 久久精品视频在线看| 欧美成人精品高清在线播放| 日韩视频―中文字幕| 国产精品国产一区二区| 亚洲欧美日韩另类| 欧美成人自拍视频| 亚洲调教视频在线观看| 国产一区二区三区四区| 欧美精品在欧美一区二区少妇| 亚洲免费在线视频| 亚洲黄色av一区| 久久精品国产99精品国产亚洲性色| 在线日韩欧美视频| 国产精品高潮在线| 欧美成人乱码一区二区三区| 亚洲在线中文字幕| 亚洲人成毛片在线播放| 久久久精品性| 亚洲性感美女99在线| 黄色另类av| 国产精品久久久久9999| 久久综合五月| 国产精品久久福利| 欧美大尺度在线| 午夜精品短视频| 亚洲区一区二区三区| 国产日本精品| 欧美视频免费| 久久亚洲影院| 性视频1819p久久| 夜夜夜久久久| 亚洲国产高潮在线观看| 久久免费观看视频| 欧美一区二区三区日韩| 亚洲伊人第一页| 一区二区欧美日韩| 99精品视频免费| 亚洲欧洲日本一区二区三区| 国产一区二区中文| 国产伦精品一区二区|