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

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

Timing in Animation and Movement(3)

Moving with Time

Time−based motion doesn't just apply to animation. Movement is also a major part of your game, and basing movement on time guarantees that all systems will run your game consistently, regardless of how fast or how slow they are.

The most common use for time−based movement is when you want to move an object a set distance over a period of time. For example, suppose a player moves his joystick to the right, so your game responds by moving the on−screen game character to the right a little bit−let's say 64 units over a period of one second, which equates to 0.064 units of movement per millisecond.

Using a small function, you can calculate the number of units (as a floating−point value) to move an object based on the elapsed time between frames.

float CalcMovement(DWORD ElapsedTime, float PixelsPerSec)
{
  return (PixelsPerSec / 1000.0f * (float)ElapsedTime);
}

As you can see in the CalculateMovement function, you are using the following calculation:

PixelsPerSec / 1000.0f * ElapsedTime;

The PixelsPerSec variable contains the number of units you want to move over the period of a second. The 1000.0 value means 1000 milliseconds. Basically, you're breaking down the number of units to move per millisecond. Finally, you need to multiply by ElapsedTime to calculate the total movement to apply.

This sort of movement based on time is very basic, but it should not be overlooked. Knowledge of this function of time−based movement is essential to using more advanced features, such as smoothly moving objects along a pre−determined path.

 

Moving along Paths

As you read in the previous section, time−based movement is determined by taking the distance to travel, dividing it by 1,000, and multiplying the result by the elapsed time. In that section, I used an example in which a player pressed right on the joystick, and his character moved right a set amount of units. But what about those times when you want an object to move without user intervention? For instance, suppose a player pushes a button and bullets fly out of the big gun he is carrying. Those bullets travel along a set path at a set speed. You can set a velocity for each of those bullets, negating the need to use paths, but what about those super−bullets in your game that can swoop through parts of your level, perhaps along a pre−set path?

Those special instances require you to set up the coordinates of the travel paths in advance, and to do some quick calculations to determine where an object can be placed inside those paths. And what about moving objects such as characters, power−ups, and platforms? You guessed it−using paths is the perfect solution for all your movement needs!

I am going to discuss two of the most frequently used types of paths−straight and curved. I will start by explaining how to use straight paths.

 

Following Straight Paths

A straight path is just that−straight. The path moves from the starting point to the ending point with no breaks or turns. Generally, you define a straight line using a pair of coordinates−the starting point and the ending point. To follow a straight path, you only need to walk along the line from Point A to Point B.

To move an object along a straight path, you must calculate the coordinates of a point along the line using some simple formulas. For instance, as Figure 2.2 illustrates, to calculate a point at the midpoint of the line using a scalar value (ranging from 0 to 1), you calculate the difference in the endpoint's coordinates, multiply by the scalar value, and add the result to the starting point's coordinates.

// Define starting and ending points of straight path
// Scalar = position to calculate (0 to 1)
D3DXVECTOR3 vecStart = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 vecEnd = D3DXVECTOR3(10.0f, 20.0f, 30.0f);
D3DXVECTOR3 vecPos = (vecEnd − vecStart) * Scalar + vecStart;

If you were to set Scalar to 0.5, then vecPos would contain the coordinates 5.0, 10.0, 15.0, which happen to be the midpoint of the path. Now suppose you don't want to use a scalar value. What about using 3D units instead? For example, instead of using a scalar value of 0.5, suppose you want to know the coordinates of a point that is 32 units from the starting coordinates.

To calculate the coordinates using 3D units as a measurement, calculate the length of the path using the D3DXVec3Length function, and then divide the position you want to use by the resulting value to obtain a scalar value to use in the previous calculations.

For example, to find the coordinates of the point that is 32 units into the path defined previously, you can use the following code:

// Pos = position (in 3−D units) of point in path to calculate
// Define starting and ending points of straight path
D3DXVECTOR3 vecStart = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 vecEnd = D3DXVECTOR3(10.0f, 20.0f, 30.0f);

// Get the length of the path
float Length = D3DXVec3Length(&(vecEnd−vecStart));

// Calculate the scalar by dividing pos by length
float Scalar = Pos / Length;

// Use scalar to calculate coordinates
D3DXVECTOR3 vecPos = (vecEnd − vecStart) * Scalar + vecStart;

Now that you can calculate the exact position of any point along the path, you can use this knowledge to move an object along the path. Following the time−based theory of movement, suppose you want to move an object from one point to another over a period of 1,000 milliseconds. The following code (processed once per frame) will accomplish this, continuously looping back from the end to the start of the path in an endless cycle.

// vecPoints[2] = path's starting and ending coordinate vectors
// Every frame, use the following code to position an object along the straight path based on the current time.
float Scalar = (float)(timeGetTime() % 1001) / 1000.0f;

D3DXVECTOR3 vecPos = (vecPoints[1] − vecPoints[0]) * Scalar + vecPoints[0];

// Use vecPos.x, vecPos.y, and vecPos.z coordinates for object


posted on 2008-04-16 14:16 lovedday 閱讀(415) 評論(0)  編輯 收藏 引用


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


公告

導(dǎo)航

統(tǒng)計

常用鏈接

隨筆分類(178)

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

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲亚洲精品三区日韩精品在线视频| 在线精品视频一区二区| 一二三区精品| 中文欧美日韩| 国产乱码精品| 久久久久久久久久久久久9999| 亚洲欧美日韩电影| 黄网动漫久久久| 欧美激情精品久久久久久久变态 | 亚洲午夜av在线| 国产精品视频在线观看| 久久久久看片| 欧美v亚洲v综合ⅴ国产v| 一区二区三区精品视频在线观看| 99国内精品久久| 国产欧美日韩一区二区三区在线 | 亚洲人成网站在线播| 99热在这里有精品免费| 国产一区二区三区奇米久涩 | 久久最新视频| 欧美精品亚洲精品| 久久久欧美精品| 欧美精品在线播放| 久久久久久日产精品| 欧美精品三区| 开心色5月久久精品| 欧美日韩免费精品| 免费观看欧美在线视频的网站| 欧美精品黄色| 久久免费视频一区| 国产精品久久国产精品99gif| 卡通动漫国产精品| 国产精品最新自拍| 亚洲精品欧洲| 在线观看日韩精品| 亚洲免费一级电影| 亚洲社区在线观看| 欧美国内亚洲| 欧美jjzz| 国产自产在线视频一区| 在线一区观看| 9国产精品视频| 久久综合999| 久久久777| 国产乱子伦一区二区三区国色天香| 亚洲国产精品99久久久久久久久| 国产精品久久中文| 亚洲毛片视频| 亚洲免费不卡| 欧美国产先锋| 亚洲高清电影| 亚洲国产成人tv| 久久精品亚洲热| 久久精品人人爽| 国产精品一区二区三区成人| 日韩网站在线观看| 在线亚洲欧美视频| 欧美日韩一区在线观看| 亚洲电影在线免费观看| 亚洲大胆视频| 老鸭窝毛片一区二区三区| 久久久999精品视频| 国产日产精品一区二区三区四区的观看方式 | 国产精品自拍三区| 亚洲一品av免费观看| 亚洲资源在线观看| 国产精品video| 亚洲制服av| 久久三级视频| 在线日韩视频| 牛人盗摄一区二区三区视频| 欧美二区视频| 99riav国产精品| 欧美三区美女| 午夜一区二区三视频在线观看| 欧美在线观看视频一区二区三区 | 国产精品高潮粉嫩av| 亚洲手机成人高清视频| 欧美中文字幕不卡| 亚洲国产精品成人精品| 欧美丰满少妇xxxbbb| 亚洲精品在线免费| 欧美一区二区视频网站| 激情欧美日韩一区| 欧美女主播在线| 亚洲免费影视| 欧美大片91| 亚洲无亚洲人成网站77777| 国产精品成人免费| 久久久久久久久久看片| 亚洲高清不卡av| 欧美亚洲日本国产| 亚洲国产日韩综合一区| 欧美日韩直播| 久久久久一区| 99视频+国产日韩欧美| 久久免费视频一区| 国产精品99久久久久久白浆小说 | 欧美大片在线观看| 亚洲欧美日韩国产中文| 欧美粗暴jizz性欧美20| 亚洲欧美激情一区二区| 伊人久久亚洲美女图片| 国产精品v欧美精品v日本精品动漫| 亚洲综合导航| 亚洲九九爱视频| 久久婷婷一区| 亚洲影院色在线观看免费| 伊人久久大香线蕉av超碰演员| 欧美新色视频| 欧美岛国激情| 久久精品女人| 亚洲午夜av| 99re6这里只有精品| 免费日韩成人| 久久国产精品高清| 在线视频你懂得一区| 亚洲第一黄网| 国产在线观看精品一区二区三区| 欧美日韩大片| 奶水喷射视频一区| 久久九九有精品国产23| 午夜精品福利在线观看| 一区二区三区久久| 亚洲精品欧洲精品| 亚洲国产婷婷综合在线精品 | 亚洲美女黄网| 亚洲国产毛片完整版 | 国产精品捆绑调教| 欧美看片网站| 欧美国产日本韩| 久久综合伊人77777尤物| 欧美影片第一页| 欧美一区二区三区婷婷月色 | 亚洲乱码国产乱码精品精98午夜| 牛牛精品成人免费视频| 久久先锋资源| 麻豆精品在线视频| 麻豆成人综合网| 麻豆精品视频在线观看| 久久久久久久国产| 老司机aⅴ在线精品导航| 久久久久久九九九九| 久久国产精品亚洲va麻豆| 欧美一区二区三区久久精品茉莉花| 亚洲永久精品大片| 亚洲免费网址| 欧美一区二区三区在线视频 | 在线天堂一区av电影| 国产精品99久久久久久久女警 | 理论片一区二区在线| 老妇喷水一区二区三区| 欧美成人激情视频| 亚洲国产毛片完整版| 99爱精品视频| 亚洲免费在线精品一区| 欧美在线精品一区| 老牛国产精品一区的观看方式| 欧美成人一区二区三区片免费| 欧美韩国日本一区| 国产精品久久久久久久免费软件| 国产精品一区三区| 激情成人综合| 亚洲免费观看高清完整版在线观看熊 | 好吊色欧美一区二区三区视频| 狠狠色狠狠色综合日日五| 亚洲二区三区四区| 一区二区三区日韩| 久久精品国产亚洲高清剧情介绍| 玖玖玖国产精品| 91久久精品美女| 亚洲免费一级电影| 免费欧美视频| 国产伦精品一区二区三区视频孕妇 | 国产精品扒开腿做爽爽爽视频 | 有坂深雪在线一区| 亚洲少妇最新在线视频| 久久久夜夜夜| 日韩视频一区| 久久久久中文| 国产精品大片| 91久久久久久| 欧美一区观看| 最新国产精品拍自在线播放| 亚洲女与黑人做爰| 欧美黄色日本| 国模私拍视频一区| 亚洲先锋成人| 亚洲第一伊人| 久久国产日韩欧美| 国产精品国产三级国产aⅴ入口| 亚洲国产成人精品女人久久久| 午夜精品福利一区二区三区av | 欧美成人精品一区二区三区| 日韩亚洲精品在线| 久久先锋影音av| 国产亚洲精品7777| 亚洲欧美国产精品va在线观看| 亚洲国产日韩在线| 久久一二三国产|