source: GTP-Internal/trunk/App/Demos/Illum/Ocean/Ship.cpp @ 1777

Revision 1777, 1.0 KB checked in by szirmay, 18 years ago (diff)
Line 
1#include "dxstdafx.h"
2#include "Ship.h"
3
4Ship::Ship(void)
5{
6        accelerate = brake = turnLeft = turnRight = false;
7        velocity = D3DXVECTOR2(1,1);
8        angularVelocity = 0.0;
9}
10
11Ship::~Ship(void)
12{
13}
14
15void Ship::Move(double elapsedTime)
16{
17        if(accelerate)
18        {
19                velocity += direction/100;
20        }
21        if(brake)
22        {
23                velocity *= 0.5;
24        }
25        if(turnLeft)
26        {
27                if(angularVelocity < 0.174532925) //10 degrees
28                        angularVelocity += 0.8 * elapsedTime;
29        }
30        if(turnRight)
31        {
32                if(angularVelocity > -0.174532925)
33                        angularVelocity -= 0.8 * elapsedTime;
34        }
35
36        velocity = D3DXVECTOR2(cos(-angularVelocity * elapsedTime) * velocity.x + sin(-angularVelocity * elapsedTime) * velocity.y, -sin(-angularVelocity * elapsedTime) * velocity.x + cos(-angularVelocity * elapsedTime) * velocity.y);
37        direction = D3DXVECTOR2(cos(-angularVelocity * elapsedTime) * direction.x + sin(-angularVelocity * elapsedTime) * direction.y, -sin(-angularVelocity * elapsedTime) * direction.x + cos(-angularVelocity * elapsedTime) * direction.y);
38        position += velocity * elapsedTime;
39}
Note: See TracBrowser for help on using the repository browser.