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;
66 //retorna cotovelo em relacao ao ombro, usa matematica levemente pesada, cuidado ao mexer
67 Ponto
Player::getCotovelo(Ponto ombro
, Ponto hand
) {
68 double a
= tamanhoBraco();
69 double b
= tamanhoAntebraco();
70 double d
= distance(ombro
,hand
);
71 double area
= areaTriangle(a
,b
,d
);
72 double ylinha
= 2.0*area
/d
;
73 double xlinha
= sqrt(a
*a
-ylinha
*ylinha
);
74 double sinTheta
= ylinha
/a
;
75 double cosTheta
= xlinha
/a
;
77 ret
.x
= -(cosTheta
*xlinha
-sinTheta
*ylinha
);
78 ret
.y
= -(sinTheta
*xlinha
+cosTheta
*ylinha
);
82 //cuidado, distancia da arma nao pode exceder tamanhoBraco+tamanhoAntebraco
83 double Player::tamanhoBraco() {
87 double Player::tamanhoAntebraco() {
91 double Player::getAngle() {
92 Ponto
gameaim(aim
.x
+game
->camera
.x
,aim
.y
+game
->camera
.y
);
93 Ponto
gameneck(pescoco().x
+getX(),pescoco().y
+getY());
94 double hyp
= sqrt((gameaim
.x
-gameneck
.x
)*(gameaim
.x
-gameneck
.x
) +
95 (gameaim
.y
-gameneck
.y
)*(gameaim
.y
-gameneck
.y
));
96 if (gameaim
.y
<= gameneck
.y
)
97 return -acos((-gameaim
.x
+gameneck
.x
)/hyp
);
99 return acos((-gameaim
.x
+gameneck
.x
)/hyp
);
102 void Player::desenha() {
103 game
->desenhaMira(aim
);
105 glTranslatef(getX(),getY(),0);
106 Ponto leftfeet
= leftFeet();
107 Ponto rightfeet
= rightFeet();
108 Ponto hips
= cintura();
109 Ponto leftarm
= leftArm();
110 Ponto rightarm
= rightArm();
111 Ponto neck
= pescoco();
113 glVertex3f(hips
.x
,hips
.y
,0);
114 glVertex3f(neck
.x
,neck
.y
,0);
116 glVertex3f(leftfeet
.x
,leftfeet
.y
,0);
117 glVertex3f(hips
.x
,hips
.y
,0);
119 glVertex3f(rightfeet
.x
,rightfeet
.y
,0);
120 glVertex3f(hips
.x
,hips
.y
,0);
122 Ponto rightelbow
= getCotovelo(neck
,rightarm
+neck
);
123 Ponto leftelbow
= getCotovelo(neck
,leftarm
+neck
);
125 glTranslatef(neck
.x
,neck
.y
,0);
126 glRotatef(getAngle()*180.0/PI
,0,0,-1);
129 glVertex3f(leftelbow
.x
,leftelbow
.y
,0);
130 glVertex3f(leftelbow
.x
,leftelbow
.y
,0);
131 glVertex3f(leftarm
.x
,leftarm
.y
,0);
134 glVertex3f(rightelbow
.x
,rightelbow
.y
,0);
135 glVertex3f(rightelbow
.x
,rightelbow
.y
,0);
136 glVertex3f(rightarm
.x
,rightarm
.y
,0);
138 if (weapon
!= NULL
) weapon
->desenha();
141 glTranslatef(neck
.x
,neck
.y
-10,0);
148 Linha
Player::getBaseLine() {
149 Ponto leftfeet
= leftFeet();
150 Ponto rightfeet
= rightFeet();
151 Linha
ret(leftfeet
.x
+getX(),leftfeet
.y
+getY(),rightfeet
.x
+getX(),rightfeet
.y
+getY());
155 void Player::setAim(double x
, double y
) {