aboutsummaryrefslogtreecommitdiff
path: root/src/Person.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Person.cpp')
-rw-r--r--src/Person.cpp229
1 files changed, 106 insertions, 123 deletions
diff --git a/src/Person.cpp b/src/Person.cpp
index c27435c..1d47543 100644
--- a/src/Person.cpp
+++ b/src/Person.cpp
@@ -839,125 +839,123 @@ void draw_muscle(Muscle& mus, int who, int whichcostume)
int Person::DrawSkeleton(int who)
{
- //Guns
- if(whichgun==sniperrifle){
- FindRotationGun(skeleton.joints[skeleton.jointlabels[righthand]].position,skeleton.joints[skeleton.jointlabels[lefthand]].position);
- glPushMatrix();
- glTranslatef( skeleton.joints[skeleton.jointlabels[righthand]].position.x,
- skeleton.joints[skeleton.jointlabels[righthand]].position.y,
- skeleton.joints[skeleton.jointlabels[righthand]].position.z);
- glRotatef(-gunrotate1+90,0,1,0);
- glRotatef(-gunrotate2+90,0,0,1);
- glRotatef(-gunrotate3,0,1,0);
- gunmodels[sniperriflemodel].draw();
- glPopMatrix();
- }
+ auto left_hand = skeleton.jointlabels[lefthand];
+ auto left_wrist = skeleton.joints[left_hand].position;
+ auto right_hand = skeleton.jointlabels[righthand];
+ auto right_wrist = skeleton.joints[right_hand].position;
+ auto head_pos = skeleton.joints[skeleton.jointlabels[head]].position;
+ auto neck_pos = skeleton.joints[skeleton.jointlabels[neck]].position;
- if(whichgun==shotgun){
- FindRotationGun(skeleton.joints[skeleton.jointlabels[righthand]].position,skeleton.joints[skeleton.jointlabels[lefthand]].position);
+ switch (whichgun) {
+ case sniperrifle:
+ FindRotationGun(right_wrist, left_wrist);
glPushMatrix();
- glTranslatef( skeleton.joints[skeleton.jointlabels[righthand]].position.x,
- skeleton.joints[skeleton.jointlabels[righthand]].position.y,
- skeleton.joints[skeleton.jointlabels[righthand]].position.z);
- glRotatef(2,1,0,0);
- glRotatef(-gunrotate1+90+1,0,1,0);
- glRotatef(-gunrotate2+90,0,0,1);
- glRotatef(-gunrotate3,0,1,0);
- glTranslatef(0,-.4,0);
- gunmodels[shotgunmodel].draw();
- glPopMatrix();
- }
-
- if(whichgun==assaultrifle){
- FindRotationGun(skeleton.joints[skeleton.jointlabels[righthand]].position,skeleton.joints[skeleton.jointlabels[lefthand]].position);
+ glTranslatef(right_wrist.x, right_wrist.y, right_wrist.z);
+ glRotatef(90 - gunrotate1, 0, 1, 0);
+ glRotatef(90 - gunrotate2, 0, 0, 1);
+ glRotatef(-gunrotate3, 0, 1, 0);
+ gunmodels[sniperriflemodel].draw();
+ glPopMatrix();
+ break;
+ case shotgun:
+ FindRotationGun(right_wrist, left_wrist);
glPushMatrix();
- glTranslatef( skeleton.joints[skeleton.jointlabels[righthand]].position.x,
- skeleton.joints[skeleton.jointlabels[righthand]].position.y,
- skeleton.joints[skeleton.jointlabels[righthand]].position.z);
- glRotatef(-gunrotate1+90,0,1,0);
- glRotatef(-gunrotate2+90,0,0,1);
- glRotatef(-gunrotate3,0,1,0);
- gunmodels[assaultriflemodel].draw();
- glPopMatrix();
- }
-
- if(whichgun==handgun1){
- if(!thirdperson&&who==0)FindRotationGun(skeleton.joints[skeleton.jointlabels[righthand]].position,(skeleton.joints[skeleton.jointlabels[head]].position*.65+skeleton.joints[skeleton.jointlabels[neck]].position*.35));
- if(thirdperson||who!=0)FindRotationGun(skeleton.joints[skeleton.jointlabels[righthand]].position,(skeleton.joints[skeleton.jointlabels[head]].position*.35+skeleton.joints[skeleton.jointlabels[neck]].position*.65));
+ glTranslatef(right_wrist.x, right_wrist.y, right_wrist.z);
+ glRotatef(2, 1, 0, 0);
+ glRotatef(90 + 1 - gunrotate1, 0, 1, 0);
+ glRotatef(90 - gunrotate2, 0, 0, 1);
+ glRotatef(-gunrotate3, 0, 1, 0);
+ glTranslatef(0, -0.4, 0);
+ gunmodels[shotgunmodel].draw();
+ glPopMatrix();
+ break;
+ case assaultrifle:
+ FindRotationGun(right_wrist, left_wrist);
glPushMatrix();
- glTranslatef( skeleton.joints[skeleton.jointlabels[righthand]].position.x,
- skeleton.joints[skeleton.jointlabels[righthand]].position.y,
- skeleton.joints[skeleton.jointlabels[righthand]].position.z);
- glRotatef(-gunrotate1+90-1.5,0,1,0);
- glRotatef(-gunrotate2+90,0,0,1);
- glRotatef(-gunrotate3,0,1,0);
- glTranslatef(0,0,.15);
- gunmodels[handgunbasemodel].draw();
- glTranslatef(0,-recoil*.3,0);
- gunmodels[handgunslidemodel].draw();
- glPopMatrix();
- }
+ glTranslatef(right_wrist.x, right_wrist.y, right_wrist.z);
+ glRotatef(90 - gunrotate1, 0, 1, 0);
+ glRotatef(90 - gunrotate2, 0, 0, 1);
+ glRotatef(-gunrotate3, 0, 1, 0);
+ gunmodels[assaultriflemodel].draw();
+ glPopMatrix();
+ break;
+ case handgun1:
+ case handgun2:
+ if (who || thirdperson)
+ FindRotationGun(right_wrist,
+ head_pos * 0.35 + neck_pos * 0.65);
+ else
+ FindRotationGun(right_wrist,
+ head_pos * 0.65 + neck_pos * 0.35);
- if(whichgun==handgun2){
- if(!thirdperson&&who==0)FindRotationGun(skeleton.joints[skeleton.jointlabels[righthand]].position,(skeleton.joints[skeleton.jointlabels[head]].position*.65+skeleton.joints[skeleton.jointlabels[neck]].position*.35));
- if(thirdperson||who!=0)FindRotationGun(skeleton.joints[skeleton.jointlabels[righthand]].position,(skeleton.joints[skeleton.jointlabels[head]].position*.35+skeleton.joints[skeleton.jointlabels[neck]].position*.65));
glPushMatrix();
- glTranslatef( skeleton.joints[skeleton.jointlabels[righthand]].position.x,
- skeleton.joints[skeleton.jointlabels[righthand]].position.y,
- skeleton.joints[skeleton.jointlabels[righthand]].position.z);
- glRotatef(-gunrotate1+90-1.5,0,1,0);
- glRotatef(-gunrotate2+90,0,0,1);
- glRotatef(-gunrotate3,0,1,0);
- glTranslatef(0,0,.15);
- gunmodels[handgun2basemodel].draw();
- glTranslatef(0,-recoil*.3,0);
- gunmodels[handgun2slidemodel].draw();
- glPopMatrix();
- }
+ glTranslatef(right_wrist.x, right_wrist.y, right_wrist.z);
+ glRotatef(90 - 1.5 - gunrotate1, 0, 1, 0);
+ glRotatef(90 - gunrotate2, 0, 0, 1);
+ glRotatef(-gunrotate3, 0, 1, 0);
+ glTranslatef(0, 0, 0.15);
- if(whichgun==grenade){
+ if (whichgun == handgun1)
+ gunmodels[handgunbasemodel].draw();
+ else
+ gunmodels[handgun2basemodel].draw();
+ glTranslatef(0, recoil * -0.3, 0);
+ if (whichgun == handgun1)
+ gunmodels[handgunslidemodel].draw();
+ else
+ gunmodels[handgun2slidemodel].draw();
+ glPopMatrix();
+ break;
+ case grenade:
glPushMatrix();
- glTranslatef( skeleton.joints[skeleton.jointlabels[righthand]].position.x,
- skeleton.joints[skeleton.jointlabels[righthand]].position.y,
- skeleton.joints[skeleton.jointlabels[righthand]].position.z);
- glRotatef(-90,1,0,0);
- glTranslatef(0,0,.05);
- if(reloading<=0){
- gunmodels[grenadebasemodel].draw();
- if(grenphase==0)gunmodels[grenadepinmodel].draw();
- glTranslatef(0,0,.005);
- gunmodels[grenadespoonmodel].draw();
- }
- glPopMatrix();
- }
+ glTranslatef(right_wrist.x, right_wrist.y, right_wrist.z);
+ glRotatef(-90, 1, 0, 0);
+ glTranslatef(0, 0, 0.05);
+ if (reloading <= 0) {
+ gunmodels[grenadebasemodel].draw();
+ if (grenphase == 0)
+ gunmodels[grenadepinmodel].draw();
+ glTranslatef(0, 0, 0.005);
+ gunmodels[grenadespoonmodel].draw();
+ }
+ glPopMatrix();
- if(whichgun==grenade){
glPushMatrix();
- glTranslatef( skeleton.joints[skeleton.jointlabels[lefthand]].position.x,
- skeleton.joints[skeleton.jointlabels[lefthand]].position.y,
- skeleton.joints[skeleton.jointlabels[lefthand]].position.z);
- glRotatef(-90,1,0,0);
- glTranslatef(0,0,-.15);
- if(reloading<=0){
- if(grenphase==1)gunmodels[grenadepinmodel].draw();
- }
- glPopMatrix();
- }
- if(!litup){
- glDisable(GL_LIGHT1);
+ glTranslatef(left_wrist.x, left_wrist.y, left_wrist.z);
+ glRotatef(-90, 1, 0, 0);
+ glTranslatef(0, 0, -0.15);
+ if (reloading <= 0 && grenphase == 1)
+ gunmodels[grenadepinmodel].draw();
+ glPopMatrix();
+ break;
+ case knife:
+ auto wrist = skeleton.joints[skeleton.jointlabels[righthand]];
+ glPushMatrix();
+ glTranslatef(wrist.position.x,
+ wrist.position.y, wrist.position.z);
+ glRotatef(90 - 1.5 - wrist.rotate1, 0, 1, 0);
+ glRotatef(90 - wrist.rotate2, 0, 0, 1);
+ glRotatef(-wrist.rotate3, 0, 1, 0);
+ glTranslatef(0, -0.2, 0);
+ gunmodels[knifemodel].draw();
+ glPopMatrix();
+ break;
}
- if(litup){
- GLfloat LightAmbient[]= { 0,0,0, 1.0f};
- GLfloat LightDiffuse[]= { 1,1,1, 1.0f };
- XYZ lightpoint;
- lightpoint=skeleton.joints[skeleton.jointlabels[lefthand]].position;
- GLfloat LightPosition[]= {lightpoint.x,lightpoint.y,lightpoint.z,0};
+
+ if (litup) {
+ GLfloat LightAmbient[] {0, 0, 0, 1.0f};
+ GLfloat LightDiffuse[] {1, 1, 1, 1.0f};
+ auto hand = skeleton.jointlabels[lefthand];
+ XYZ lightpoint = skeleton.joints[hand].position;
+ GLfloat LightPosition[] {lightpoint.x,
+ lightpoint.y, lightpoint.z, 0};
glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glEnable(GL_LIGHT1);
-
- litup=0;
+ litup = 0;
+ } else {
+ glDisable(GL_LIGHT1);
}
//Find forward vectors
@@ -1036,30 +1034,15 @@ int Person::DrawSkeleton(int who)
for (int i = 0; i < skeleton.num_joints; i++)
draw_joint(skeleton.joints[i], who, whichcostume);
-
for (int i = 0; i < skeleton.num_muscles; i++)
draw_muscle(skeleton.muscles[i], who, whichcostume);
- if(whichgun==knife){
- glPushMatrix();
- glTranslatef( skeleton.joints[skeleton.jointlabels[righthand]].position.x,
- skeleton.joints[skeleton.jointlabels[righthand]].position.y,
- skeleton.joints[skeleton.jointlabels[righthand]].position.z);
- glRotatef(-skeleton.joints[skeleton.jointlabels[righthand]].rotate1+90-1.5,0,1,0);
- glRotatef(-skeleton.joints[skeleton.jointlabels[righthand]].rotate2+90,0,0,1);
- glRotatef(-skeleton.joints[skeleton.jointlabels[righthand]].rotate3,0,1,0);
- glTranslatef(0,-.2,0);
- gunmodels[knifemodel].draw();
- glPopMatrix();
- }
-
- if(skeleton.offset&&skeleton.free<1){
- for(int i=0;i<skeleton.num_joints;i++){
- skeleton.joints[i].position=skeleton.joints[i].oldposition;
+ if (skeleton.offset && skeleton.free < 1)
+ for (int i = 0; i < skeleton.num_joints; i++) {
+ auto joint = skeleton.joints[i];
+ joint.position = joint.oldposition;
}
- }
glDisable(GL_LIGHT1);
-
return 0;
}