aboutsummaryrefslogtreecommitdiff
path: root/src/Person.cpp
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2021-06-22 22:46:51 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2021-06-22 22:46:51 +0700
commitf1616b3fb6207ac4c2747df6973ffed67834ed5b (patch)
treee6b6aebd48f75e70363bb37015d7ac7e9a6e78bf /src/Person.cpp
parent93c57836fbaf6a1329f536ab9d1919f97a58de8f (diff)
downloadblackshades-f1616b3fb6207ac4c2747df6973ffed67834ed5b.tar.gz
Refactor draw_{joint,muscle}
Diffstat (limited to 'src/Person.cpp')
-rw-r--r--src/Person.cpp133
1 files changed, 84 insertions, 49 deletions
diff --git a/src/Person.cpp b/src/Person.cpp
index 597aba3..c27435c 100644
--- a/src/Person.cpp
+++ b/src/Person.cpp
@@ -23,6 +23,9 @@ extern int aimkey;
extern int psychicaimkey;
extern int psychickey;
+extern Model skeletonmodels[10];
+extern Costume costume[2];
+
HitStruct Person::BulletCollideWithPlayer(int who, XYZ start, XYZ end){
XYZ tempbulletloc[2];
XYZ collisionpoint;
@@ -761,9 +764,81 @@ void Person::FindRotationGun(XYZ start, XYZ target)
if(0>tempforward.x)gunrotate3=360-gunrotate3;
}
-extern Model skeletonmodels[10];
-extern Costume costume[2];
-int Person::DrawSkeleton(int who){
+float* determine_color(int model, int who, int whichcostume)
+{
+ switch (model) {
+ case 0:
+ if (who || thirdperson)
+ return costume[whichcostume].headcolor;
+ else if (!who && thirdperson)
+ return nullptr;
+ case 1:
+ if (who || thirdperson)
+ return costume[whichcostume].chestcolor;
+ case 2:
+ return costume[whichcostume].abdomencolor;
+ case 3:
+ return costume[whichcostume].upperarmcolor;
+ case 4:
+ return costume[whichcostume].lowerarmcolor;
+ case 5:
+ return costume[whichcostume].handcolor;
+ case 6:
+ return costume[whichcostume].upperlegcolor;
+ case 7:
+ return costume[whichcostume].lowerlegcolor;
+ case 8:
+ return costume[whichcostume].footcolor;
+ default:
+ return nullptr;
+ }
+}
+
+void draw_joint(Joint& joint, int who, int whichcostume)
+{
+ if (!joint.hasparent || !joint.visible)
+ return;
+
+ glPushMatrix();
+ glTranslatef((joint.position.x + joint.parent->position.x) / 2,
+ (joint.position.y + joint.parent->position.y) / 2,
+ (joint.position.z + joint.parent->position.z) / 2);
+ glRotatef(90 - joint.rotate1, 0, 1, 0);
+ glRotatef(90 - joint.rotate2, 0, 0, 1);
+ glRotatef(-joint.rotate3, 0, 1, 0);
+
+ auto model = joint.modelnum;
+ if (auto color = determine_color(model, who, whichcostume))
+ skeletonmodels[joint.modelnum].draw(*color, color[1], color[2]);
+ else
+ skeletonmodels[9].draw();
+ glPopMatrix();
+}
+
+void draw_muscle(Muscle& mus, int who, int whichcostume)
+{
+ if (!mus.visible)
+ return;
+
+ auto pos1 = mus.parent1->position;
+ auto pos2 = mus.parent2->position;
+ glPushMatrix();
+ glTranslatef((pos1.x + pos2.x) / 2,
+ (pos1.y + pos2.y) / 2, (pos1.z + pos2.z) / 2);
+ glRotatef(90 - mus.rotate1, 0, 1, 0);
+ glRotatef(90 - mus.rotate2, 0, 0, 1);
+ glRotatef(-mus.rotate3, 0, 1, 0);
+
+ auto model = mus.parent1->modelnum;
+ if (auto color = determine_color(model, who, whichcostume))
+ skeletonmodels[model].draw(*color, color[1], color[2]);
+ else
+ skeletonmodels[9].draw();
+ glPopMatrix();
+}
+
+int Person::DrawSkeleton(int who)
+{
//Guns
if(whichgun==sniperrifle){
FindRotationGun(skeleton.joints[skeleton.jointlabels[righthand]].position,skeleton.joints[skeleton.jointlabels[lefthand]].position);
@@ -958,54 +1033,13 @@ int Person::DrawSkeleton(int who){
skeleton.FindRotationMuscle(i);
}
}}}
- for(int i=0;i<skeleton.num_joints;i++){
- if(skeleton.joints[i].hasparent&&skeleton.joints[i].visible)
- {
- glPushMatrix();
- glTranslatef( (skeleton.joints[i].position.x+skeleton.joints[i].parent->position.x)/2,
- (skeleton.joints[i].position.y+skeleton.joints[i].parent->position.y)/2,
- (skeleton.joints[i].position.z+skeleton.joints[i].parent->position.z)/2);
- glRotatef(-skeleton.joints[i].rotate1+90,0,1,0);
- glRotatef(-skeleton.joints[i].rotate2+90,0,0,1);
- glRotatef(-skeleton.joints[i].rotate3,0,1,0);
- if(skeleton.joints[i].modelnum==0&&(who!=0||thirdperson))skeletonmodels[skeleton.joints[i].modelnum].draw(costume[whichcostume].headcolor[0],costume[whichcostume].headcolor[1],costume[whichcostume].headcolor[2]);
- if(skeleton.joints[i].modelnum==0&&(who==0&&thirdperson))skeletonmodels[9].draw();
- if(skeleton.joints[i].modelnum==1&&(who!=0||thirdperson))skeletonmodels[skeleton.joints[i].modelnum].draw(costume[whichcostume].chestcolor[0],costume[whichcostume].chestcolor[1],costume[whichcostume].chestcolor[2]);
- if(skeleton.joints[i].modelnum==2)skeletonmodels[skeleton.joints[i].modelnum].draw(costume[whichcostume].abdomencolor[0],costume[whichcostume].abdomencolor[1],costume[whichcostume].abdomencolor[2]);
- if(skeleton.joints[i].modelnum==3)skeletonmodels[skeleton.joints[i].modelnum].draw(costume[whichcostume].upperarmcolor[0],costume[whichcostume].upperarmcolor[1],costume[whichcostume].upperarmcolor[2]);
- if(skeleton.joints[i].modelnum==4)skeletonmodels[skeleton.joints[i].modelnum].draw(costume[whichcostume].lowerarmcolor[0],costume[whichcostume].lowerarmcolor[1],costume[whichcostume].lowerarmcolor[2]);
- if(skeleton.joints[i].modelnum==5)skeletonmodels[skeleton.joints[i].modelnum].draw(costume[whichcostume].handcolor[0],costume[whichcostume].handcolor[1],costume[whichcostume].handcolor[2]);
- if(skeleton.joints[i].modelnum==6)skeletonmodels[skeleton.joints[i].modelnum].draw(costume[whichcostume].upperlegcolor[0],costume[whichcostume].upperlegcolor[1],costume[whichcostume].upperlegcolor[2]);
- if(skeleton.joints[i].modelnum==7)skeletonmodels[skeleton.joints[i].modelnum].draw(costume[whichcostume].lowerlegcolor[0],costume[whichcostume].lowerlegcolor[1],costume[whichcostume].lowerlegcolor[2]);
- if(skeleton.joints[i].modelnum==8)skeletonmodels[skeleton.joints[i].modelnum].draw(costume[whichcostume].footcolor[0],costume[whichcostume].footcolor[1],costume[whichcostume].footcolor[2]);
- glPopMatrix();
- }
- }
- for(int i=0;i<skeleton.num_muscles;i++){
- if(skeleton.muscles[i].visible)
- {
- glPushMatrix();
- glTranslatef( (skeleton.muscles[i].parent1->position.x+skeleton.muscles[i].parent2->position.x)/2,
- (skeleton.muscles[i].parent1->position.y+skeleton.muscles[i].parent2->position.y)/2,
- (skeleton.muscles[i].parent1->position.z+skeleton.muscles[i].parent2->position.z)/2);
- glRotatef(-skeleton.muscles[i].rotate1+90,0,1,0);
- glRotatef(-skeleton.muscles[i].rotate2+90,0,0,1);
- glRotatef(-skeleton.muscles[i].rotate3,0,1,0);
- if(skeleton.muscles[i].parent1->modelnum==0&&(who!=0||thirdperson))skeletonmodels[skeleton.muscles[i].parent1->modelnum].draw(costume[whichcostume].headcolor[0],costume[whichcostume].headcolor[1],costume[whichcostume].headcolor[2]);
- if(skeleton.muscles[i].parent1->modelnum==0&&(who==0&&thirdperson))skeletonmodels[9].draw();
- if(skeleton.muscles[i].parent1->modelnum==1&&(who!=0||thirdperson))skeletonmodels[skeleton.muscles[i].parent1->modelnum].draw(costume[whichcostume].chestcolor[0],costume[whichcostume].chestcolor[1],costume[whichcostume].chestcolor[2]);
- if(skeleton.muscles[i].parent1->modelnum==2)skeletonmodels[skeleton.muscles[i].parent1->modelnum].draw(costume[whichcostume].abdomencolor[0],costume[whichcostume].abdomencolor[1],costume[whichcostume].abdomencolor[2]);
- if(skeleton.muscles[i].parent1->modelnum==3)skeletonmodels[skeleton.muscles[i].parent1->modelnum].draw(costume[whichcostume].upperarmcolor[0],costume[whichcostume].upperarmcolor[1],costume[whichcostume].upperarmcolor[2]);
- if(skeleton.muscles[i].parent1->modelnum==4)skeletonmodels[skeleton.muscles[i].parent1->modelnum].draw(costume[whichcostume].lowerarmcolor[0],costume[whichcostume].lowerarmcolor[1],costume[whichcostume].lowerarmcolor[2]);
- if(skeleton.muscles[i].parent1->modelnum==5)skeletonmodels[skeleton.muscles[i].parent1->modelnum].draw(costume[whichcostume].handcolor[0],costume[whichcostume].handcolor[1],costume[whichcostume].handcolor[2]);
- if(skeleton.muscles[i].parent1->modelnum==6)skeletonmodels[skeleton.muscles[i].parent1->modelnum].draw(costume[whichcostume].upperlegcolor[0],costume[whichcostume].upperlegcolor[1],costume[whichcostume].upperlegcolor[2]);
- if(skeleton.muscles[i].parent1->modelnum==7)skeletonmodels[skeleton.muscles[i].parent1->modelnum].draw(costume[whichcostume].lowerlegcolor[0],costume[whichcostume].lowerlegcolor[1],costume[whichcostume].lowerlegcolor[2]);
- if(skeleton.muscles[i].parent1->modelnum==8)skeletonmodels[skeleton.muscles[i].parent1->modelnum].draw(costume[whichcostume].footcolor[0],costume[whichcostume].footcolor[1],costume[whichcostume].footcolor[2]);
+ 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);
- glPopMatrix();
- }
- }
if(whichgun==knife){
glPushMatrix();
glTranslatef( skeleton.joints[skeleton.jointlabels[righthand]].position.x,
@@ -1018,6 +1052,7 @@ int Person::DrawSkeleton(int who){
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;