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

天行健 君子當(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>
            午夜精品一区二区三区电影天堂| 午夜天堂精品久久久久| 一区二区欧美激情| 亚洲精品极品| 亚洲欧美日韩一区二区在线| 久久国产日韩欧美| 欧美激情片在线观看| 亚洲精品在线视频| 午夜精品999| 欧美夫妇交换俱乐部在线观看| 欧美日韩和欧美的一区二区| 国产深夜精品福利| 日韩视频在线观看国产| 久久精品国产v日韩v亚洲| 久久精品国产综合精品| 欧美理论在线| 亚洲国产日韩在线| 亚洲一区中文字幕在线观看| 欧美成人国产| 欧美在线三区| 国产精品美女久久久久av超清 | 欧美激情黄色片| 欧美精品七区| 亚洲国产一区二区三区在线播 | 欧美专区第一页| 亚洲美女精品久久| 性欧美video另类hd性玩具| 欧美日韩一区二区三区在线 | 欧美三级视频在线| 亚洲免费观看在线观看| 欧美高清在线| 久久综合久久综合这里只有精品| 国产伦精品一区二区三区| 亚洲曰本av电影| 久久男人av资源网站| 在线看不卡av| 欧美成人激情视频| 国产精品一二一区| 亚洲美女av网站| 亚洲国产成人精品久久久国产成人一区| 久久精品国产2020观看福利| 欧美激情综合亚洲一二区| 久久久久久成人| 久久精品国产视频| 在线观看日韩专区| 免费看av成人| 欧美成人四级电影| 亚洲人成亚洲人成在线观看图片 | 欧美一区二区三区免费视频| 欧美影院视频| 午夜精品一区二区三区四区 | 久久青草福利网站| 久久精品理论片| 国产精品网站在线观看| 久久久久国内| 国产视频久久久久| 午夜一区在线| 欧美在线亚洲综合一区| 国产精品免费aⅴ片在线观看| 日韩视频在线观看免费| 亚洲免费观看视频| 欧美日韩aaaaa| 亚洲美女视频网| 一区二区三区欧美激情| 欧美日韩国产丝袜另类| 亚洲美女精品成人在线视频| 在线综合亚洲| 欧美午夜a级限制福利片| 久久精品国产精品亚洲| 国产视频久久久久久久| 欧美一区二区三区四区视频| 日韩一区二区电影网| 欧美激情一区二区三区| 亚洲欧洲一区二区在线观看| 欧美jizzhd精品欧美喷水 | 欧美国产视频在线| 亚洲免费成人av电影| 亚洲一区二区三| 久久久一本精品99久久精品66| 日韩视频专区| 国产精品xvideos88| 亚洲男人第一av网站| 91久久国产自产拍夜夜嗨| 美女精品自拍一二三四| 欧美在线一二三区| 一区在线免费| 亚洲一区二区三区国产| 91久久精品网| 欧美三区在线观看| 久久成人精品无人区| 亚洲国产老妈| 狠狠入ady亚洲精品| 亚洲午夜久久久久久尤物| 在线视频国产日韩| 欧美精品九九| 午夜国产精品视频| 亚洲国产天堂久久国产91| 亚洲专区免费| 亚洲国产精品精华液2区45| 欧美日韩一区二区三区四区五区| 欧美一区二区黄| 亚洲国产精品久久久久婷婷老年| 亚洲影视综合| 亚洲国产精品久久久久婷婷884 | 夜色激情一区二区| 欧美成人国产一区二区| 亚洲一区二区精品| 欧美顶级艳妇交换群宴| 午夜精品亚洲一区二区三区嫩草| 伊人久久大香线| 国产精品揄拍500视频| 你懂的视频欧美| 亚洲国产精品久久久久秋霞影院| 欧美亚洲一区| 国产色产综合色产在线视频| 欧美精品亚洲一区二区在线播放| 午夜国产欧美理论在线播放| 亚洲精选在线| 欧美激情国产日韩| 久久亚洲一区二区| 樱花yy私人影院亚洲| 欧美性事在线| 欧美精品福利在线| 免费成人高清| 久久久久久久久一区二区| 亚洲欧美精品| 亚洲色图自拍| 久久精品麻豆| 亚洲欧美日韩在线一区| 99视频+国产日韩欧美| 亚洲国产高清在线| 在线观看一区二区精品视频| 国产亚洲精品久| 另类激情亚洲| 久久久久国产精品厨房| 欧美中在线观看| 欧美一区2区三区4区公司二百| 一区二区动漫| 免费不卡亚洲欧美| 久久中文精品| 免费观看一区| 久久在线91| 蜜臀99久久精品久久久久久软件 | 亚洲一区二区三区在线播放| 亚洲午夜女主播在线直播| 夜夜嗨一区二区| 在线一区观看| 亚洲一区视频| 午夜精品久久久久久久99樱桃| 亚洲综合日韩| 久久激情一区| 久久免费国产| 午夜精品亚洲| 久久久久国产成人精品亚洲午夜| 欧美一区二区三区日韩| 久久裸体艺术| 亚洲国产欧美久久| 夜色激情一区二区| 欧美激情精品久久久久| 亚洲欧洲久久| 中文精品视频| 欧美在线观看网址综合| 久久久之久亚州精品露出| 猫咪成人在线观看| 欧美精品观看| 国产日韩在线视频| 亚洲国产精品久久久久秋霞蜜臀 | 国产嫩草影院久久久久| 欧美精品成人一区二区在线观看| 欧美另类99xxxxx| 国产精品美女久久久浪潮软件| 国产日韩欧美亚洲一区| 亚洲国产高清aⅴ视频| 亚洲一级黄色片| 久久午夜视频| 一区二区久久久久| 欧美在线视频免费观看| 欧美人妖另类| 国产丝袜一区二区| 亚洲精品三级| 久久久精品性| 亚洲麻豆av| 久久久久久有精品国产| 欧美色欧美亚洲另类七区| 黄网站免费久久| 亚洲一区免费观看| 欧美激情1区2区| 午夜精品美女自拍福到在线| 欧美高清hd18日本| 狠狠干综合网| 香蕉av777xxx色综合一区| 欧美激情视频在线免费观看 欧美视频免费一 | 亚洲视频高清| 欧美福利视频网站| 国产综合色产在线精品| 国产精品永久免费视频| 日韩午夜视频在线观看| 美日韩精品免费| 性欧美激情精品| 国产精品成人观看视频免费 |