5 Player::Player(Game
* agame
) {
10 game
->gravityManager
->subscribe(this);
13 void Player::equip(Weapon
* aweapon
) {
14 //desequipar a anterior aqui mais tarde
18 Ponto
Player::leftFeet() {
23 Ponto
Player::rightFeet() {
28 Ponto
Player::leftArm() {
34 return weapon
->getLeftHand();
37 Ponto
Player::rightArm() {
43 return weapon
->getRightHand();
46 Ponto
Player::cintura() {
51 Ponto
Player::pescoco() {
56 double areaTriangle(double a
, double b
, double c
) {
57 if (a
< b
) std::swap(a
,b
);
58 if (a
< c
) std::swap(a
,c
);
59 if (b
< c
) std::swap(b
,c
);
62 return sqrt((a
+(b
+c
))*(c
-(a
-b
))*(c
+(a
-b
))*(a
+(b
-c
)))/4.0;
65 //retorna cotovelo em relacao ao ombro, usa matematica levemente pesada, cuidado ao mexer
66 Ponto
Player::getCotovelo(Ponto ombro
, Ponto hand
) {
67 double a
= tamanhoBraco();
68 double b
= tamanhoAntebraco();
69 double d
= distance(ombro
,hand
);
70 double area
= areaTriangle(a
,b
,d
);
71 double ylinha
= 2.0*area
/d
;
72 double xlinha
= sqrt(a
*a
-ylinha
*ylinha
);
73 double sinTheta
= (hand
.y
-ombro
.y
)/d
;
74 double cosTheta
= (hand
.x
-ombro
.x
)/d
;
76 ret
.x
= (cosTheta
*xlinha
-sinTheta
*ylinha
);
77 ret
.y
= (sinTheta
*xlinha
+cosTheta
*ylinha
);
81 //cuidado, distancia da arma nao pode exceder tamanhoBraco+tamanhoAntebraco
82 double Player::tamanhoBraco() {
86 double Player::tamanhoAntebraco() {
90 double Player::getAngle() {
91 Ponto
gameaim(aim
.x
+game
->camera
.x
,aim
.y
+game
->camera
.y
);
92 Ponto
gameneck(pescoco().x
+getX(),pescoco().y
+getY());
93 double hyp
= sqrt((gameaim
.x
-gameneck
.x
)*(gameaim
.x
-gameneck
.x
) +
94 (gameaim
.y
-gameneck
.y
)*(gameaim
.y
-gameneck
.y
));
95 if (gameaim
.y
<= gameneck
.y
)
96 return -acos((-gameaim
.x
+gameneck
.x
)/hyp
);
98 return acos((-gameaim
.x
+gameneck
.x
)/hyp
);
101 void Player::desenha() {
102 game
->desenhaMira(aim
);
104 glTranslatef(getX(),getY(),0);
105 Ponto leftfeet
= leftFeet();
106 Ponto rightfeet
= rightFeet();
107 Ponto hips
= cintura();
108 Ponto leftarm
= leftArm();
109 Ponto rightarm
= rightArm();
110 Ponto neck
= pescoco();
112 glVertex3f(hips
.x
,hips
.y
,0);
113 glVertex3f(neck
.x
,neck
.y
,0);
115 glVertex3f(leftfeet
.x
,leftfeet
.y
,0);
116 glVertex3f(hips
.x
,hips
.y
,0);
118 glVertex3f(rightfeet
.x
,rightfeet
.y
,0);
119 glVertex3f(hips
.x
,hips
.y
,0);
121 Ponto rightelbow
= getCotovelo(neck
,rightarm
+neck
);
122 Ponto leftelbow
= getCotovelo(neck
,leftarm
+neck
);
124 glTranslatef(neck
.x
,neck
.y
,0);
125 glRotatef(getAngle()*180.0/PI
,0,0,-1);
128 glVertex3f(leftelbow
.x
,leftelbow
.y
,0);
129 glVertex3f(leftelbow
.x
,leftelbow
.y
,0);
130 glVertex3f(leftarm
.x
,leftarm
.y
,0);
133 glVertex3f(rightelbow
.x
,rightelbow
.y
,0);
134 glVertex3f(rightelbow
.x
,rightelbow
.y
,0);
135 glVertex3f(rightarm
.x
,rightarm
.y
,0);
137 if (weapon
!= NULL
) weapon
->desenha();
140 glTranslatef(neck
.x
,neck
.y
-10,0);
147 Linha
Player::getBaseLine() {
148 Ponto leftfeet
= leftFeet();
149 Ponto rightfeet
= rightFeet();
150 Linha
ret(leftfeet
.x
+getX(),leftfeet
.y
+getY(),rightfeet
.x
+getX(),rightfeet
.y
+getY());
154 void Player::setAim(double x
, double y
) {