-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.hpp
118 lines (110 loc) · 2.86 KB
/
Player.hpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#pragma once
#include "cs314_math.hpp"
#include "TimedItem.hpp"
#include "VelocityVerlet.hpp"
class cStaticEnvironment;
class cPlayer : public iTimedItem
{
public:
cPlayer(cStaticEnvironment* environment);
~cPlayer(void);
void SetPOV();
virtual void Update(float elapsed_time);;
virtual void Reset(){};
virtual bool IsDone(){
// a players work is never done
return false;
};
cCoord3 GetForwardDirection() const{
return -cAngleAxis(mHeading, cCoord3::YAxis()).rev_rotate(cCoord3::ZAxis());
}
cCoord3 GetLeftRightDirection() const {
return cAngleAxis(mHeading, cCoord3::YAxis()).rev_rotate(cCoord3::XAxis());
}
cCoord3 GetCOMVelocity() const {
return mCenterOfMass.mVel;
}
void SetForwardVelocity(float v){
cCoord3 direction = GetForwardDirection();
//mCenterOfMass.mVel = v*direction;
mCurrentMovement.z = v;
}
bool IsOnGround() const{
return mIsOnGround;
}
bool JustHitGround() const{
return mHitGround;
}
void Jump(){
mIsJumping = true;
}
void SetLateralVelocity(float v){
cCoord3 direction = GetLeftRightDirection();
mCurrentMovement.x = v;
}
void AddForwardVelocity(float v){
cCoord3 direction = GetForwardDirection();
mCurrentMovement.z += v;
}
void AddLateralVelocity(float v){
cCoord3 direction = GetLeftRightDirection();
mCurrentMovement.x += v;
}
cCoord3 GetCOMPosition() const{
return mCenterOfMass.mPos;
}
float GetHeadingAngle(){
return mHeading;
}
void RotateLeftRight(float radians){
mHeading = NormalizeRadians(mHeading - radians);
}
void TiltUpDown(float radians){
mPitch = Clamp(-0.49f*AKJ_PIf, NormalizeRadians(mPitch+radians), 0.49f*AKJ_PIf);
}
void SetPosition(cCoord3 pos){
mPosition = pos;
}
void RotatePOV(cUnitQuat rot){
mOrientation = rot*mOrientation;
}
void Translate(cCoord3& translate){
mPosition += translate;
}
cCoord3 GetTargetLocation() const { return mTargetLocation; }
cCoord3 GetTargetOrientation() const { return mTargetOrientation; }
cCoord3 GetHeadingVector(){
p4::Log::TMI("Heading: %f", mHeading);
cAngleAxis aay(-mHeading, cCoord3::YAxis());
cAngleAxis aaz(mPitch, cCoord3::XAxis());
return aay.rotate(aaz.rotate(-cCoord3::ZAxis())).normalized();
}
cCoord3 GetPosition() const{
return mPosition;
}
float GetGroundDistance() const { return mGroundDistance; }
cCoord3 GetHeightOffset() const{
return cCoord3(0.0, 2.0, 0.0);
}
int GetScore() const { return mScore; }
void SetScore(int val) { mScore = val; }
void AddToScore(int val) { mScore += val; }
private:
float mPitch;
float mHeading;
float mDrivingForce;
bool mIsJumping;
bool mHitGround;
bool mIsOnGround;
int mScore;
cVelocityVerlet mCenterOfMass;
WorldConstraintForce mCollisionForce;
cCoord3 mCurrentMovement;
cCoord3 mHeadingVector;
cCoord3 mPosition;
cCoord3 mTargetLocation;
cCoord3 mTargetOrientation;
float mGroundDistance;
cUnitQuat mOrientation;
cStaticEnvironment* mEnvironment;
};