-
Notifications
You must be signed in to change notification settings - Fork 389
Expand file tree
/
Copy pathMoveComponent.cpp
More file actions
35 lines (30 loc) · 891 Bytes
/
MoveComponent.cpp
File metadata and controls
35 lines (30 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// ----------------------------------------------------------------
// From Game Programming in C++ by Sanjay Madhav
// Copyright (C) 2017 Sanjay Madhav. All rights reserved.
//
// Released under the BSD License
// See LICENSE in root directory for full details.
// ----------------------------------------------------------------
#include "MoveComponent.h"
#include "Actor.h"
MoveComponent::MoveComponent(class Actor* owner, int updateOrder)
:Component(owner, updateOrder)
,mAngularSpeed(0.0f)
,mForwardSpeed(0.0f)
{
}
void MoveComponent::Update(float deltaTime)
{
if (!Math::NearZero(mAngularSpeed))
{
float rot = mOwner->GetRotation();
rot += mAngularSpeed * deltaTime;
mOwner->SetRotation(rot);
}
if (!Math::NearZero(mForwardSpeed))
{
Vector2 pos = mOwner->GetPosition();
pos += mOwner->GetForward() * mForwardSpeed * deltaTime;
mOwner->SetPosition(pos);
}
}