aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2021-10-01 16:13:41 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2021-10-01 16:13:41 +0700
commit7e530bdcc6ef88a1174f3408a7b2fed4eff43222 (patch)
tree39070c9566730db6f06e153e9e5bc76eade16d94 /src
parentf076e700c738a9aea4fbac936f3b281cd35ee475 (diff)
downloadblackshades-7e530bdcc6ef88a1174f3408a7b2fed4eff43222.tar.gz
Remove Skeleton.num_joints
Diffstat (limited to 'src')
-rw-r--r--src/Constants.h8
-rw-r--r--src/GameTick.cpp290
-rw-r--r--src/Globals.cpp2
-rw-r--r--src/Person.cpp167
-rw-r--r--src/Skeleton.cpp182
-rw-r--r--src/Skeleton.h16
6 files changed, 230 insertions, 435 deletions
diff --git a/src/Constants.h b/src/Constants.h
index 4528498..654c904 100644
--- a/src/Constants.h
+++ b/src/Constants.h
@@ -34,10 +34,10 @@
#define zombiewalkanim 21
#define getupfrontanim 22
#define getupbackanim 23
-#define lyinganim 24
-#define diveanim 25
-#define throwanim 26
-#define thrownanim 27
+#define diveanim 24
+#define throwanim 25
+#define thrownanim 26
+#define lyinganim 27
#define nogun 0
#define sniperrifle 1
diff --git a/src/GameTick.cpp b/src/GameTick.cpp
index 9a79086..3b9cf5a 100644
--- a/src/GameTick.cpp
+++ b/src/GameTick.cpp
@@ -1570,14 +1570,14 @@ void Game::Tick()
person[i].skeleton.free=1;
person[i].longdead=1;
- for(int j=0;j<person[i].skeleton.num_joints;j++){
- person[i].skeleton.joints[j].position+=person[i].skeleton.joints[j].offset;
- person[i].skeleton.joints[j].position=DoRotation(person[i].skeleton.joints[j].position,0,person[i].playerrotation,0);
- person[i].skeleton.joints[j].position+=person[i].playercoords;
- person[i].skeleton.joints[j].realoldposition=person[i].skeleton.joints[j].position;
- person[i].skeleton.joints[j].velocity=DoRotation(person[i].skeleton.joints[j].velocity,0,person[i].playerrotation,0);
- person[i].skeleton.joints[j].velocity+=person[i].velocity;
- person[i].skeleton.joints[j].velocity+=person[i].facing*4;
+ for (auto& joint : person[i].skeleton.joints) {
+ joint.position += joint.offset;
+ joint.position = DoRotation(joint.position, 0, person[i].playerrotation, 0);
+ joint.position += person[i].playercoords;
+ joint.realoldposition = joint.position;
+ joint.velocity = DoRotation(joint.velocity, 0, person[i].playerrotation, 0);
+ joint.velocity += person[i].velocity;
+ joint.velocity += person[i].facing * 4;
}
}
}
@@ -1598,11 +1598,10 @@ void Game::Tick()
person[i].oldaverageloc=person[i].averageloc;
person[i].averageloc=0;
- for(int j=0;j<person[i].skeleton.num_joints;j++){
- person[i].averageloc+=person[i].skeleton.joints[j].position;
- }
+ for (auto& joint : person[i].skeleton.joints)
+ person[i].averageloc += joint.position;
- person[i].averageloc/=person[i].skeleton.num_joints;
+ person[i].averageloc /= max_joints;
person[i].playercoords=person[i].averageloc;
if(person[i].longdead<multiplier/2&&person[i].longdead>0)person[i].DrawSkeleton(i);
if(findDistancefast(person[i].averageloc,person[i].oldaverageloc)<.2*multiplier)person[i].longdead-=multiplier/2;
@@ -1623,9 +1622,9 @@ void Game::Tick()
//Find playercoords
person[i].playercoords=person[i].averageloc;
- for(int j=0;j<person[i].skeleton.num_joints;j++){
- if(person[i].skeleton.joints[j].position.y>person[i].playercoords.y)person[i].playercoords.y=person[i].skeleton.joints[j].position.y;
- }
+ for (auto& joint : person[i].skeleton.joints)
+ if (joint.position.y > person[i].playercoords.y)
+ person[i].playercoords.y = joint.position.y;
//Find orientation
XYZ firsttop=person[i].skeleton.joints[person[i].skeleton.jointlabels[neck]].position-person[i].skeleton.joints[person[i].skeleton.jointlabels[groin]].position;
@@ -1637,7 +1636,7 @@ void Game::Tick()
person[i].playervelocity=0;
if(person[i].targetanimation==getupfrontanim)person[i].playerrotation+=180;
- for(int j=0;j<person[i].skeleton.num_joints;j++){
+ for (int j = 0; j < max_joints; ++j) {
person[i].tempanimation.position[j][0]=person[i].skeleton.joints[j].position-person[i].playercoords;
person[i].tempanimation.position[j][0]=DoRotation(person[i].tempanimation.position[j][0],0,-person[i].playerrotation,0);
}
@@ -1680,14 +1679,15 @@ void Game::Tick()
person[person[0].killtarget].skeleton.free=1;
person[person[0].killtarget].longdead=1;
- for(int j=0;j<person[person[0].killtarget].skeleton.num_joints;j++){
- person[person[0].killtarget].skeleton.joints[j].position=DoRotation(person[person[0].killtarget].skeleton.joints[j].position,0,person[person[0].killtarget].playerrotation,0);
- person[person[0].killtarget].skeleton.joints[j].position+=person[person[0].killtarget].playercoords;
- person[person[0].killtarget].skeleton.joints[j].realoldposition=person[person[0].killtarget].skeleton.joints[j].position;
- person[person[0].killtarget].skeleton.joints[j].velocity=person[person[0].killtarget].velocity;
- person[person[0].killtarget].skeleton.joints[j].velocity.x+=abs(Random()%10)-5;
- person[person[0].killtarget].skeleton.joints[j].velocity.y+=abs(Random()%10)-5;
- person[person[0].killtarget].skeleton.joints[j].velocity.z+=abs(Random()%10)-5;
+ for (auto& joint : person[person[0].killtarget].skeleton.joints) {
+ joint.position = DoRotation(joint.position,
+ 0, person[person[0].killtarget].playerrotation, 0);
+ joint.position += person[person[0].killtarget].playercoords;
+ joint.realoldposition = joint.position;
+ joint.velocity = person[person[0].killtarget].velocity;
+ joint.velocity.x += abs(Random() % 10) - 5;
+ joint.velocity.y += abs(Random() % 10) - 5;
+ joint.velocity.z += abs(Random() % 10) - 5;
}
if(person[0].whichgun!=knife){
@@ -1727,15 +1727,15 @@ void Game::Tick()
person[person[0].killtarget].skeleton.free=1;
person[person[0].killtarget].longdead=1;
- for(int j=0;j<person[person[0].killtarget].skeleton.num_joints;j++){
- person[person[0].killtarget].skeleton.joints[j].position=DoRotation(person[person[0].killtarget].skeleton.joints[j].position,0,person[person[0].killtarget].playerrotation,0);
- person[person[0].killtarget].skeleton.joints[j].position+=person[person[0].killtarget].playercoords;
- person[person[0].killtarget].skeleton.joints[j].realoldposition=person[person[0].killtarget].skeleton.joints[j].position;
- person[person[0].killtarget].skeleton.joints[j].velocity=person[person[0].killtarget].velocity;
+ for (auto& joint : person[person[0].killtarget].skeleton.joints) {
+ joint.position = DoRotation(joint.position, 0, person[person[0].killtarget].playerrotation, 0);
+ joint.position += person[person[0].killtarget].playercoords;
+ joint.realoldposition = joint.position;
+ joint.velocity = person[person[0].killtarget].velocity;
- person[person[0].killtarget].skeleton.joints[j].velocity.x+=abs(Random()%10)-5;
- person[person[0].killtarget].skeleton.joints[j].velocity.y+=abs(Random()%10)-5;
- person[person[0].killtarget].skeleton.joints[j].velocity.z+=abs(Random()%10)-5;
+ joint.velocity.x += abs(Random() % 10) - 5;
+ joint.velocity.y += abs(Random() % 10) - 5;
+ joint.velocity.z += abs(Random() % 10) - 5;
}
if(person[0].whichgun!=knife){
@@ -2211,46 +2211,24 @@ void Game::Tick()
totalarea=0;
- for(int j=0;j<person[whichhit].skeleton.num_joints;j++){
-
- person[whichhit].skeleton.joints[j].position=DoRotation(person[whichhit].skeleton.joints[j].position,0,person[whichhit].playerrotation,0);
-
- person[whichhit].skeleton.joints[j].position+=person[whichhit].playercoords;
-
- person[whichhit].skeleton.joints[j].realoldposition=person[whichhit].skeleton.joints[j].position;
-
- person[whichhit].skeleton.joints[j].velocity=person[whichhit].velocity;
-
- person[whichhit].skeleton.joints[j].velocity.x+=(float)(abs(Random()%20)-10)/2;
-
- person[whichhit].skeleton.joints[j].velocity.y+=(float)(abs(Random()%20)-10)/2;
-
- person[whichhit].skeleton.joints[j].velocity.z+=(float)(abs(Random()%20)-10)/2;
-
- }
-
- }
-
- for(int j=0;j<person[whichhit].skeleton.num_joints;j++){
-
- if(findDistancefast(person[whichhit].skeleton.joints[j].position,hitstruct.hitlocation)<200){
-
- totalarea+=(200/findDistancefast(person[whichhit].skeleton.joints[j].position,hitstruct.hitlocation));
-
+ for (auto& joint : person[whichhit].skeleton.joints) {
+ joint.position = DoRotation(joint.position, 0, person[whichhit].playerrotation, 0);
+ joint.position += person[whichhit].playercoords;
+ joint.realoldposition = joint.position;
+ joint.velocity = person[whichhit].velocity;
+ joint.velocity.x += (abs(Random()%20) - 10) / 2.0f;
+ joint.velocity.y += (abs(Random()%20) - 10) / 2.0f;
+ joint.velocity.z += (abs(Random()%20) - 10) / 2.0f;
}
-
}
- for(int j=0;j<person[whichhit].skeleton.num_joints;j++){
-
- if(findDistancefast(person[whichhit].skeleton.joints[j].position,hitstruct.hitlocation)<200){
-
- person[whichhit].skeleton.joints[j].velocity+=aim*((200/findDistancefast(person[whichhit].skeleton.joints[j].position,hitstruct.hitlocation))/totalarea*200);
-
+ for (auto& joint : person[whichhit].skeleton.joints) {
+ auto distance = findDistancefast(joint.position, hitstruct.hitlocation);
+ if (distance < 200) {
+ totalarea += 200 / distance;
+ joint.velocity += aim * 200 / distance / totalarea * 200;
}
-
}
-
}
if(person[whichhit].health>0){
@@ -2281,43 +2259,23 @@ void Game::Tick()
person[whichhit].skeleton.offset=1;
- for(int j=0;j<person[whichhit].skeleton.num_joints;j++){
-
- if(findDistancefast(DoRotation(person[whichhit].skeleton.joints[j].position,0,person[whichhit].playerrotation,0)+person[whichhit].playercoords,hitstruct.hitlocation)<200){
-
- totalarea+=(200/findDistancefast(DoRotation(person[whichhit].skeleton.joints[j].position,0,person[whichhit].playerrotation,0)+person[whichhit].playercoords,hitstruct.hitlocation));
-
+ for (auto& joint : person[whichhit].skeleton.joints) {
+ auto distance = findDistancefast(DoRotation(joint.position, 0, person[whichhit].playerrotation, 0) + person[whichhit].playercoords, hitstruct.hitlocation);
+ if(distance < 200) {
+ totalarea += 200 / distance;
+ joint.offset += DoRotation(aim * 200 / distance / totalarea * 10,
+ 0, -person[whichhit].playerrotation, 0);
}
-
- }
-
- float offsetlength;
-
- for(int j=0;j<person[whichhit].skeleton.num_joints;j++){
-
- if(findDistancefast(DoRotation(person[whichhit].skeleton.joints[j].position,0,person[whichhit].playerrotation,0)+person[whichhit].playercoords,hitstruct.hitlocation)<200){
-
- person[whichhit].skeleton.joints[j].offset+=DoRotation(aim*((200/findDistancefast(DoRotation(person[whichhit].skeleton.joints[j].position,0,person[whichhit].playerrotation,0)+person[whichhit].playercoords,hitstruct.hitlocation))/totalarea*10),0,-person[whichhit].playerrotation,0);
-
- }
-
- offsetlength=findLengthfast(person[whichhit].skeleton.joints[j].offset);
-
- if(offsetlength>36){
-
- Normalise(&person[whichhit].skeleton.joints[j].offset);
-
- person[whichhit].skeleton.joints[j].offset*=6;
-
+ if (findLengthfast(joint.offset) > 36) {
+ Normalise(&joint.offset);
+ joint.offset *= 6;
}
-
}
-
}
if(hitstruct.joint1->modelnum==headmodel&&person[whichhit].health<=0){
- for(int j=0;j<person[whichhit].skeleton.num_joints;j++){
+ for (int j = 0; j < max_joints; ++j) {
if(&person[whichhit].skeleton.joints[j]==hitstruct.joint1||&person[whichhit].skeleton.joints[j]==hitstruct.joint2){
@@ -2900,18 +2858,16 @@ void Game::Tick()
person[j].longdead=1;
- for (int k = 0; k < person[j].skeleton.num_joints; ++k) {
- person[j].skeleton.joints[k].realoldposition
- = person[j].skeleton.joints[k].position
- = DoRotation(person[j].skeleton.joints[k].position,
+ for (auto& joint : person[j].skeleton.joints) {
+ joint.realoldposition = joint.position
+ = DoRotation(joint.position,
0, person[j].playerrotation, 0)
+ person[j].playercoords;
- person[j].skeleton.joints[k].velocity = person[j].velocity;
- person[j].skeleton.joints[k].velocity.x += abs(Random()%10)-5;
- person[j].skeleton.joints[k].velocity.y += abs(Random()%10)-5;
- person[j].skeleton.joints[k].velocity.z += abs(Random()%10)-5;
-
+ joint.velocity = person[j].velocity;
+ joint.velocity.x += abs(Random()%10)-5;
+ joint.velocity.y += abs(Random()%10)-5;
+ joint.velocity.z += abs(Random()%10)-5;
}
hitstruct.joint1->velocity += sprites.velocity[i];
@@ -2930,52 +2886,24 @@ void Game::Tick()
person[j].skeleton.offset=1;
- for(int k=0;k<person[j].skeleton.num_joints;k++){
-
- if(findDistancefast(DoRotation(person[j].skeleton.joints[k].position,0,person[j].playerrotation,0)+person[j].playercoords,hitstruct.hitlocation)<200){
-
- totalarea+=(200/findDistancefast(DoRotation(person[j].skeleton.joints[k].position,0,person[j].playerrotation,0)+person[j].playercoords,hitstruct.hitlocation));
-
- }
-
- }
-
- float offsetlength;
-
- for(int k=0;k<person[j].skeleton.num_joints;k++){
-
- if(findDistancefast(DoRotation(person[j].skeleton.joints[k].position,0,person[j].playerrotation,0)+person[j].playercoords,hitstruct.hitlocation)<200){
-
- person[j].skeleton.joints[k].offset+=DoRotation(sprites.velocity[i]*.1*((200/findDistancefast(DoRotation(person[j].skeleton.joints[k].position,0,person[j].playerrotation,0)+person[j].playercoords,hitstruct.hitlocation))/totalarea*10),0,-person[j].playerrotation,0);
-
+ for (auto& joint : person[j].skeleton.joints) {
+ auto distance = findDistancefast(DoRotation(joint.position, 0, person[j].playerrotation, 0) + person[j].playercoords, hitstruct.hitlocation);
+ if (distance < 200) {
+ totalarea += 200 / distance;
+ joint.offset += DoRotation(sprites.velocity[i] * 0.1 * 200 / distance / totalarea * 10, 0, -person[j].playerrotation, 0);
}
-
- offsetlength=findLengthfast(person[j].skeleton.joints[k].offset);
-
- if(offsetlength>9){
-
- Normalise(&person[j].skeleton.joints[k].offset);
-
- person[j].skeleton.joints[k].offset*=3;
-
+ if (findLengthfast(joint.offset) > 9) {
+ Normalise(&joint.offset);
+ joint.offset *= 3;
}
-
}
-
}}
-
sprites.velocity[i]*=-.3;
-
}
-
}
-
}
-
}
-
sprites.oldlocation[i]=sprites.location[i];
-
}
//Explode
@@ -3084,72 +3012,44 @@ void Game::Tick()
person[k].bjoint1 = &person[k].skeleton.joints[person[k].skeleton.jointlabels[head]];
person[k].bjoint2 = &person[k].skeleton.joints[person[k].skeleton.jointlabels[neck]];
- for(int j=0;j<person[k].skeleton.num_joints;j++){
-
- person[k].skeleton.joints[j].position=DoRotation(person[k].skeleton.joints[j].position,0,person[k].playerrotation,0);
-
- person[k].skeleton.joints[j].position+=person[k].playercoords;
-
- person[k].skeleton.joints[j].realoldposition=person[k].skeleton.joints[j].position;
-
- person[k].skeleton.joints[j].velocity=DoRotation(person[k].skeleton.joints[j].velocity,0,person[k].playerrotation,0);
-
- person[k].skeleton.joints[j].velocity+=person[k].velocity;
-
- person[k].skeleton.joints[j].velocity.x+=abs(Random()%20)-10;
-
- person[k].skeleton.joints[j].velocity.y+=abs(Random()%20)-10;
-
- person[k].skeleton.joints[j].velocity.z+=abs(Random()%20)-10;
-
+ for (auto& joint : person[k].skeleton.joints) {
+ joint.position = DoRotation(joint.position, 0, person[k].playerrotation, 0);
+ joint.position += person[k].playercoords;
+ joint.realoldposition = joint.position;
+ joint.velocity = DoRotation(joint.velocity, 0, person[k].playerrotation, 0);
+ joint.velocity += person[k].velocity;
+ joint.velocity.x += abs(Random() % 20) - 10;
+ joint.velocity.y += abs(Random() % 20) - 10;
+ joint.velocity.z += abs(Random() % 20) - 10;
}}
- for(int j=0;j<person[k].skeleton.num_joints;j++){
-
- relation=person[k].skeleton.joints[j].position-sprites.location[i];
-
- Normalise(&relation);
-
- if(findDistance(person[k].skeleton.joints[j].position,sprites.location[i])>1)person[k].skeleton.joints[j].velocity+=relation/findDistance(person[k].skeleton.joints[j].position,sprites.location[i])*300;
-
- else person[k].skeleton.joints[j].velocity+=relation*300;
-
- }
-
person[k].longdead=1;
-
- for(int j=0;j<person[k].skeleton.num_joints;j++){
-
- //Sever stuff
-
- if(findLengthfast(person[k].skeleton.joints[j].velocity)>1500&&person[k].skeleton.joints[j].existing==1&&abs(Random()%3)!=1){
-
- sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,person[k].skeleton.joints[j].position, person[k].skeleton.joints[j].velocity/3, 9);
-
- person[k].skeleton.DeleteJoint(j);
-
+ for (auto& joint : person[k].skeleton.joints) {
+ relation = joint.position - sprites.location[i];
+ Normalise(&relation);
+ auto distance = findDistance(joint.position, sprites.location[i]);
+ if (distance > 1)
+ joint.velocity += relation / distance * 300;
+ else
+ joint.velocity += relation * 300;
+
+ // Sever stuff
+ if (findLengthfast(joint.velocity) > 1500
+ && joint.existing && abs(Random() % 3) != 1) {
+ sprites.MakeSprite(bloodspritedown, 0.8, 1, 0.2, 0.2, joint.position, joint.velocity / 3, 9);
+ person[k].skeleton.DeleteJoint(&joint
+ - person[k].skeleton.joints);
person[k].skeleton.broken=2;
-
person[k].health=-10000;
-
- person[k].skeleton.joints[j].existing=0;
-
+ joint.existing = false;
}
-
}
-
}
-
}
-
}
-
}
-
}
-
}
-
}
//camera shake
diff --git a/src/Globals.cpp b/src/Globals.cpp
index d1ae639..dba8ad5 100644
--- a/src/Globals.cpp
+++ b/src/Globals.cpp
@@ -21,7 +21,7 @@ int environment;
float soundscalefactor;
int slomo;
-Animation animation[30];
+Animation animation[27];
Model skeletonmodels[10];
Model gunmodels[11];
Costume costume[10];
diff --git a/src/Person.cpp b/src/Person.cpp
index 7630000..bd1e5cb 100644
--- a/src/Person.cpp
+++ b/src/Person.cpp
@@ -51,28 +51,21 @@ HitStruct Person::BulletCollideWithPlayer(int who, XYZ start, XYZ end){
XYZ collisionpoint;
GLfloat M[16];
int collide;
- XYZ average;
- int howmany;
- float distancemax;
HitStruct hitstruct;
hitstruct.collision=0;
//Make bounding sphere
- average=0;
- howmany=0;
- for(int j=0;j<skeleton.num_joints;j++){
- average.x=average.x+skeleton.joints[j].position.x;
- average.y=average.y+skeleton.joints[j].position.y;
- average.z=average.z+skeleton.joints[j].position.z;
- howmany++;
- }
- average=average/howmany;
- distancemax=0;
- for(int j=0;j<skeleton.num_joints;j++){
- if(findDistancefast(average,skeleton.joints[j].position)>distancemax){
- distancemax=findDistancefast(average,skeleton.joints[j].position);
- }
- }
- distancemax=sqrt(distancemax);
+
+ XYZ average {};
+ for (auto& joint : skeleton.joints)
+ average += joint.position;
+ average /= max_joints;
+
+ float distancemax = 0.0f;
+ for (auto& joint : skeleton.joints)
+ distancemax = max(distancemax,
+ findDistancefast(average, joint.position));
+ distancemax = sqrt(distancemax);
+
//Collide with player
if(skeleton.free<1){
start=start-playercoords;
@@ -85,18 +78,18 @@ HitStruct Person::BulletCollideWithPlayer(int who, XYZ start, XYZ end){
if(sphere_line_intersection(tempbulletloc[0].x,tempbulletloc[0].y,tempbulletloc[0].z,
tempbulletloc[1].x,tempbulletloc[1].y,tempbulletloc[1].z,
average.x, average.y, average.z, distancemax)){
- for(int j=0;j<skeleton.num_joints;j++){
- if(skeleton.joints[j].hasparent&&skeleton.joints[j].visible){
- tempbulletloc[0]=start;
- tempbulletloc[1]=end;
+ for (auto& joint : skeleton.joints) {
+ if (joint.hasparent && joint.visible) {
+ tempbulletloc[0] = start;
+ tempbulletloc[1] = end;
glPushMatrix();
glLoadIdentity();
- glScalef(1,1/skeleton.joints[j].length,1);
- glRotatef(skeleton.joints[j].rotate2-90,0,0,1);
- glRotatef(skeleton.joints[j].rotate1-90,0,1,0);
- glTranslatef( (-(skeleton.joints[j].position.x+skeleton.joints[j].parent->position.x)/2),
- (-(skeleton.joints[j].position.y+skeleton.joints[j].parent->position.y)/2),
- (-(skeleton.joints[j].position.z+skeleton.joints[j].parent->position.z)/2));
+ glScalef(1, 1 / joint.length, 1);
+ glRotatef(joint.rotate2 - 90, 0, 0, 1);
+ glRotatef(joint.rotate1 - 90, 0, 1, 0);
+ 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);
glTranslatef(tempbulletloc[0].x,tempbulletloc[0].y,tempbulletloc[0].z);
glGetFloatv(GL_MODELVIEW_MATRIX,M);
tempbulletloc[0].x=M[12];
@@ -105,29 +98,29 @@ HitStruct Person::BulletCollideWithPlayer(int who, XYZ start, XYZ end){
glPopMatrix();
glPushMatrix();
glLoadIdentity();
- glScalef(1,1/skeleton.joints[j].length,1);
- glRotatef(skeleton.joints[j].rotate2-90,0,0,1);
- glRotatef(skeleton.joints[j].rotate1-90,0,1,0);
- glTranslatef( (-(skeleton.joints[j].position.x+skeleton.joints[j].parent->position.x)/2),
- (-(skeleton.joints[j].position.y+skeleton.joints[j].parent->position.y)/2),
- (-(skeleton.joints[j].position.z+skeleton.joints[j].parent->position.z)/2));
+ glScalef(1, 1 / joint.length, 1);
+ glRotatef(joint.rotate2 - 90, 0, 0, 1);
+ glRotatef(joint.rotate1 - 90, 0, 1, 0);
+ 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);
glTranslatef(tempbulletloc[1].x,tempbulletloc[1].y,tempbulletloc[1].z);
glGetFloatv(GL_MODELVIEW_MATRIX,M);
tempbulletloc[1].x=M[12];
tempbulletloc[1].y=M[13];
tempbulletloc[1].z=M[14];
glPopMatrix();
- collide=skeletonmodels[skeleton.joints[j].modelnum].LineCheck(tempbulletloc[0],tempbulletloc[1],&collisionpoint);
+ collide=skeletonmodels[joint.modelnum].LineCheck(tempbulletloc[0],tempbulletloc[1],&collisionpoint);
if(collide!=-1)
{
glPushMatrix();
glLoadIdentity();
- glTranslatef( (skeleton.joints[j].position.x+skeleton.joints[j].parent->position.x)/2,
- (skeleton.joints[j].position.y+skeleton.joints[j].parent->position.y)/2,
- (skeleton.joints[j].position.z+skeleton.joints[j].parent->position.z)/2);
- glRotatef(-skeleton.joints[j].rotate1+90,0,1,0);
- glRotatef(-skeleton.joints[j].rotate2+90,0,0,1);
- glScalef(1,skeleton.joints[j].length,1);
+ 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);
+ glScalef(1, joint.length, 1);
glTranslatef(collisionpoint.x,collisionpoint.y,collisionpoint.z);
glGetFloatv(GL_MODELVIEW_MATRIX,M);
collisionpoint.x=M[12];
@@ -136,8 +129,8 @@ HitStruct Person::BulletCollideWithPlayer(int who, XYZ start, XYZ end){
glPopMatrix();
hitstruct.collision=1;
hitstruct.hitlocation=collisionpoint;
- hitstruct.joint1=&skeleton.joints[j];
- hitstruct.joint2=skeleton.joints[j].parent;
+ hitstruct.joint1 = &joint;
+ hitstruct.joint2 = joint.parent;
}
}
}
@@ -302,7 +295,7 @@ void Person::DoAnimations(int who)
if(target>1)currentframe=targetframe;
- for(int i=0;i<skeleton.num_joints;i++){
+ for (int i = 0; i < max_joints; ++i) {
if(currentanimation!=lyinganim){
skeleton.joints[i].velocity=((animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target))-(skeleton.joints[i].position))/multiplier;
skeleton.joints[i].position=animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target);
@@ -357,33 +350,26 @@ void Person::DoAnimations(int who)
}
XYZ rotatearound;
XYZ oldpos;
- if(whichgun==sniperrifle){
- for(int i=0;i<skeleton.num_joints;i++){
- if(skeleton.joints[i].label!=righthand&&skeleton.joints[i].label!=rightelbow&&skeleton.joints[i].label!=rightwrist&&skeleton.joints[i].label!=lefthand&&skeleton.joints[i].label!=leftelbow&&skeleton.joints[i].label!=leftwrist){
- }else{
- skeleton.joints[i].position=animation[rifleholdanim].position[i][0];
- if(currentanimation==crouchanim||targetanimation==crouchanim)skeleton.joints[i].position-=(animation[idleanim].position[skeleton.jointlabels[neck]][0]-skeleton.joints[skeleton.jointlabels[neck]].position);
- }
- }
- }
- if(whichgun==shotgun){
- for(int i=0;i<skeleton.num_joints;i++){
- if(skeleton.joints[i].label!=righthand&&skeleton.joints[i].label!=rightelbow&&skeleton.joints[i].label!=rightwrist&&skeleton.joints[i].label!=lefthand&&skeleton.joints[i].label!=leftelbow&&skeleton.joints[i].label!=leftwrist){
- }else{
- skeleton.joints[i].position=animation[rifleholdanim].position[i][0];
- if(currentanimation==crouchanim||targetanimation==crouchanim)skeleton.joints[i].position-=(animation[idleanim].position[skeleton.jointlabels[neck]][0]-skeleton.joints[skeleton.jointlabels[neck]].position);
+ switch (whichgun) {
+ case sniperrifle:
+ case shotgun:
+ case assaultrifle:
+ for (int i = 0; i < max_joints; ++i)
+ switch (skeleton.joints[i].label) {
+ case leftelbow:
+ case leftwrist:
+ case lefthand:
+ case rightelbow:
+ case rightwrist:
+ case righthand:
+ skeleton.joints[i].position = animation[rifleholdanim].position[i][0];
+ if (currentanimation == crouchanim
+ || targetanimation == crouchanim)
+ skeleton.joints[i].position += skeleton.joints[skeleton.jointlabels[neck]].position
+ - animation[idleanim].position[skeleton.jointlabels[neck]][0];
}
- }
- }
- if(whichgun==assaultrifle){
- for(int i=0;i<skeleton.num_joints;i++){
- if(skeleton.joints[i].label!=righthand&&skeleton.joints[i].label!=rightelbow&&skeleton.joints[i].label!=rightwrist&&skeleton.joints[i].label!=lefthand&&skeleton.joints[i].label!=leftelbow&&skeleton.joints[i].label!=leftwrist){
- }else{
- skeleton.joints[i].position=animation[rifleholdanim].position[i][0];
- if(currentanimation==crouchanim||targetanimation==crouchanim)skeleton.joints[i].position-=(animation[idleanim].position[skeleton.jointlabels[neck]][0]-skeleton.joints[skeleton.jointlabels[neck]].position);
- }
- }
}
+
if((aiming||aimamount>0||whichgun==grenade)&&whichgun!=nogun){
if(aiming&&targetanimation!=joganim){
if(aimamount<1)aimamount+=multiplier*4;
@@ -401,7 +387,7 @@ void Person::DoAnimations(int who)
if(grenamount<0)grenamount=0;
}
rotatearound=skeleton.joints[skeleton.jointlabels[neck]].position;
- for(int i=0;i<skeleton.num_joints;i++){
+ for (int i = 0; i < max_joints; ++i){
if(skeleton.joints[i].label!=righthand&&skeleton.joints[i].label!=rightelbow&&skeleton.joints[i].label!=rightwrist&&skeleton.joints[i].label!=lefthand&&skeleton.joints[i].label!=leftelbow&&skeleton.joints[i].label!=leftwrist){
}else{
if(whichgun==sniperrifle){
@@ -473,7 +459,7 @@ void Person::DoAnimations(int who)
}
//Whack
if(attackframe>-1&&whichgun!=grenade){
- for(int i=0;i<skeleton.num_joints;i++){
+ for (int i = 0; i < max_joints; ++i) {
if(!skeleton.joints[i].lower){
if(attackframe==animation[riflehitanim].numframes)skeleton.joints[i].position=skeleton.joints[i].position*(attacktarget)+animation[riflehitanim].position[i][attackframe-1]*(1-attacktarget);
if(attackframe>0&&attackframe<animation[riflehitanim].numframes)skeleton.joints[i].position=animation[riflehitanim].position[i][attackframe-1]*(1-attacktarget)+animation[riflehitanim].position[i][attackframe]*(attacktarget);
@@ -490,7 +476,7 @@ void Person::DoAnimations(int who)
}
//Throw grenade
if(attackframe>-1&&whichgun==grenade&&ammo>0){
- for(int i=0;i<skeleton.num_joints;i++){
+ for (int i = 0; i < max_joints; ++i) {
if(!skeleton.joints[i].lower){
if(attackframe==animation[grenadethrowanim].numframes)skeleton.joints[i].position=skeleton.joints[i].position*(attacktarget)+animation[grenadethrowanim].position[i][attackframe-1]*(1-attacktarget);
if(attackframe>0&&attackframe<animation[grenadethrowanim].numframes)skeleton.joints[i].position=animation[grenadethrowanim].position[i][attackframe-1]*(1-attacktarget)+animation[grenadethrowanim].position[i][attackframe]*(attacktarget);
@@ -521,20 +507,16 @@ void Person::DoAnimations(int who)
}
rotatearound=skeleton.joints[skeleton.jointlabels[abdomen]].position;
- if(who==0)
- for(int i=0;i<skeleton.num_joints;i++){
- if(skeleton.joints[i].lower==0)
- skeleton.joints[i].position=rotatearound+DoRotation(skeleton.joints[i].position-rotatearound,playerrotation2/2,0,0);
- }
- if(who==0)
- for(int i=0;i<skeleton.num_joints;i++){
- if(skeleton.joints[i].lower==1&&skeleton.joints[i].label!=groin)
- skeleton.joints[i].position=DoRotation(skeleton.joints[i].position,0,playerlowrotation-playerrotation,0);
- }
- //head facing
- if(who==0){
- rotatearound=skeleton.joints[skeleton.jointlabels[neck]].position;
- skeleton.joints[skeleton.jointlabels[head]].position=rotatearound+DoRotation(skeleton.joints[skeleton.jointlabels[head]].position-rotatearound,playerrotation2/2,0,0);
+ if (who == 0) {
+ for (auto& joint : skeleton.joints)
+ if (!joint.lower)
+ joint.position = rotatearound
+ + DoRotation(joint.position - rotatearound, playerrotation2 / 2, 0, 0);
+ else if (joint.label != groin)
+ joint.position = DoRotation(joint.position, 0, playerlowrotation - playerrotation, 0);
+ rotatearound = skeleton.joints[skeleton.jointlabels[neck]].position;
+ skeleton.joints[skeleton.jointlabels[head]].position = rotatearound
+ + DoRotation(skeleton.joints[skeleton.jointlabels[head]].position - rotatearound, playerrotation2 / 2, 0, 0);
}
skeleton.DoConstraints();
@@ -1023,8 +1005,7 @@ int Person::DrawSkeleton(int who)
if (skeleton.offset && skeleton.free < 1) {
XYZ normal;
skeleton.offset = 0;
- for (int i = 0; i < skeleton.num_joints; i++) {
- auto& joint = skeleton.joints[i];
+ for (auto& joint : skeleton.joints) {
joint.oldposition = joint.position;
joint.position += joint.offset;
if (findLengthfast(joint.offset) >= multiplier * multiplier * 25) {
@@ -1105,7 +1086,7 @@ int Person::DrawSkeleton(int who)
+ skeleton.lowforward * 0.2;
Normalise(specialfwd++);
- for(int i = 0; i < skeleton.num_joints; i++)
+ for (int i = 0; i < max_joints; i++)
if (skeleton.joints[i].hasparent
&& skeleton.joints[i].visible)
skeleton.FindRotationJoint(i);
@@ -1116,16 +1097,14 @@ int Person::DrawSkeleton(int who)
}
}
- for (int i = 0; i < skeleton.num_joints; i++)
+ for (int i = 0; i < max_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 (skeleton.offset && skeleton.free < 1)
- for (int i = 0; i < skeleton.num_joints; i++) {
- auto& joint = skeleton.joints[i];
+ for (auto& joint : skeleton.joints)
joint.position = joint.oldposition;
- }
glDisable(GL_LIGHT1);
return 0;
diff --git a/src/Skeleton.cpp b/src/Skeleton.cpp
index 7315fac..ba27aa4 100644
--- a/src/Skeleton.cpp
+++ b/src/Skeleton.cpp
@@ -84,13 +84,10 @@ void Muscle::DoConstraint(int broken)
void Skeleton::DoConstraints()
{
- numrepeats=3;
-
- for(int j=0; j<numrepeats; j++){
- for(int i=0; i<num_joints; i++){
- joints[i].DoConstraint();
- }
- }
+ numrepeats = 3;
+ for(int i = 0; i < numrepeats; ++i)
+ for (auto& joint : joints)
+ joint.DoConstraint();
}
void Skeleton::DoConstraints(Model *collide, XYZ *move, float rotation)
@@ -100,7 +97,7 @@ void Skeleton::DoConstraints(Model *collide, XYZ *move, float rotation)
groundlevel = 0;
numrepeats = 2;
for (int j = 0; j < numrepeats; j++) {
- for (int i = 0; i < num_joints; i++) {
+ for (int i = 0; i < max_joints; i++) {
if (!joints[i].existing
&& i != jointlabels[lefthand]
&& i != jointlabels[righthand])
@@ -148,9 +145,9 @@ void Skeleton::DoConstraints(Model *collide, XYZ *move, float rotation)
if (broken > 1)
continue;
XYZ avgvelocity {0};
- for (int k = 0; k < num_joints; k++)
+ for (int k = 0; k < max_joints; k++)
avgvelocity += joints[k].velocity;
- avgvelocity /= num_joints;
+ avgvelocity /= max_joints;
int landsound = -1;
switch (joints[i].label) {
@@ -181,7 +178,7 @@ void Skeleton::DoConstraints(Model *collide, XYZ *move, float rotation)
muscles[i].DoConstraint(broken);
}
- for (int i = 0; i < num_joints; i++) {
+ for (int i = 0; i < max_joints; i++) {
joints[i].realoldposition = joints[i].position;
//Add velocity
if (joints[i].existing
@@ -193,9 +190,8 @@ void Skeleton::DoConstraints(Model *collide, XYZ *move, float rotation)
void Skeleton::DoGravity()
{
- for(int i=0; i<num_joints; i++){
- joints[i].velocity.y+=gravity*multiplier;
- }
+ for (auto& joint : joints)
+ joint.velocity.y += gravity * multiplier;
}
void Skeleton::Draw(int muscleview)
@@ -216,7 +212,7 @@ void Skeleton::Draw(int muscleview)
jointcolor[3]=.5;
}
//Calc motionblur-ness
- for(int i=0; i<num_joints; i++){
+ for(int i=0; i<max_joints; i++){
joints[i].oldposition=joints[i].position;
joints[i].blurred=findDistance(joints[i].position,joints[i].oldposition)*100;
if(joints[i].blurred<1)joints[i].blurred=1;
@@ -227,7 +223,7 @@ void Skeleton::Draw(int muscleview)
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_QUADS);
- for(int i=0; i<num_joints; i++){
+ for(int i=0; i<max_joints; i++){
if(joints[i].hasparent){
glColor4f(jointcolor[0],jointcolor[1],jointcolor[2],jointcolor[3]/joints[i].blurred);
glVertex3f(joints[i].position.x,joints[i].position.y,joints[i].position.z);
@@ -254,7 +250,7 @@ void Skeleton::Draw(int muscleview)
glEnd();
glBegin(GL_LINES);
- for(int i=0; i<num_joints; i++){
+ for(int i=0; i<max_joints; i++){
if(joints[i].hasparent){
glColor4f(jointcolor[0],jointcolor[1],jointcolor[2],jointcolor[3]/joints[i].blurred);
glVertex3f(joints[i].position.x,joints[i].position.y,joints[i].position.z);
@@ -283,7 +279,7 @@ void Skeleton::Draw(int muscleview)
if(muscleview!=2){
glPointSize(3);
glBegin(GL_POINTS);
- for(int i=0; i<num_joints; i++){
+ for(int i=0; i<max_joints; i++){
if(i!=selected)glColor4f(0,0,.5,1);
if(i==selected)glColor4f(1,1,0,1);
if(joints[i].locked&&i!=selected)glColor4f(1,0,0,1);
@@ -294,42 +290,24 @@ void Skeleton::Draw(int muscleview)
//Set old position to current position
if(muscleview==2)
- for(int i=0; i<num_joints; i++){
+ for(int i=0; i<max_joints; i++){
joints[i].oldposition=joints[i].position;
}
glDepthMask(1);
}
-void Skeleton::AddJoint(float x, float y, float z, int which)
-{
- if(num_joints<max_joints-1){
- joints[num_joints].velocity=0;
- joints[num_joints].position.x=x;
- joints[num_joints].position.y=y;
- joints[num_joints].position.z=z;
- joints[num_joints].locked=0;
-
- if(which>=num_joints||which<0)joints[num_joints].hasparent=0;
- if(which<num_joints&&which>=0){
- joints[num_joints].parent=&joints[which];
- joints[num_joints].hasparent=1;
- joints[num_joints].length=findDistance(joints[num_joints].position,joints[num_joints].parent->position);
- }
- num_joints++;
- }
-}
-
void Skeleton::DeleteJoint(int whichjoint)
{
- if(whichjoint<num_joints&&whichjoint>=0){
+ if (whichjoint < max_joints && whichjoint >= 0) {
for(int i=0;i<num_muscles;i++){
while(muscles[i].parent1==&joints[whichjoint]&&i<num_muscles)DeleteMuscle(i);
while(muscles[i].parent2==&joints[whichjoint]&&i<num_muscles)DeleteMuscle(i);
}
- for(int i=0;i<num_joints;i++){
- if(joints[i].parent==&joints[whichjoint])joints[i].hasparent=0;
- }
- joints[whichjoint].hasparent=0;
+
+ for (auto& joint : joints)
+ if (joint.parent == &joints[whichjoint])
+ joint.hasparent = 0;
+ joints[whichjoint].hasparent = 0;
}
}
@@ -350,48 +328,6 @@ void Skeleton::DeleteMuscle(int whichmuscle)
}
}
-void Skeleton::SetJoint(float x, float y, float z, int which, int whichjoint)
-{
- if(whichjoint<num_joints){
- joints[whichjoint].velocity=0;
- joints[whichjoint].position.x=x;
- joints[whichjoint].position.y=y;
- joints[whichjoint].position.z=z;
-
- if(which>=num_joints||which<0)joints[whichjoint].hasparent=0;
- if(which<num_joints&&which>=0){
- joints[whichjoint].parent=&joints[which];
- joints[whichjoint].hasparent=1;
- joints[whichjoint].length=findDistance(joints[whichjoint].position,joints[whichjoint].parent->position);
- }
- }
-}
-
-void Skeleton::AddMuscle(int attach1,int attach2,float minlength,float maxlength,int type)
-{
- if (num_muscles < max_muscles - 1 && attach1 != attach2
- && attach1 < num_joints && attach1 >= 0
- && attach2 < num_joints && attach2 >= 0) {
- muscles[num_muscles].parent1=&joints[attach1];
- muscles[num_muscles].parent2=&joints[attach2];
- muscles[num_muscles].length=findDistance(muscles[num_muscles].parent1->position,muscles[num_muscles].parent2->position);
- muscles[num_muscles].targetlength=findDistance(muscles[num_muscles].parent1->position,muscles[num_muscles].parent2->position);
- muscles[num_muscles].strength=.7;
- muscles[num_muscles].type=type;
- muscles[num_muscles].minlength=minlength;
- muscles[num_muscles].maxlength=maxlength;
-
- num_muscles++;
- }
-}
-
-void Skeleton::MusclesSet()
-{
- for(int i=0;i<num_muscles;i++){
- muscles[i].length=findDistance(muscles[i].parent1->position,muscles[i].parent2->position);
- }
-}
-
void Skeleton::FindRotationJoint(int which)
{
XYZ temppoint1,temppoint2,tempforward;
@@ -446,13 +382,12 @@ void Skeleton::FindRotationMuscle(int which)
tempforward.y=0;
Normalise(&tempforward);
muscles[which].rotate3=acos(0-tempforward.z)*rad2deg;
- for(int i=0;i<num_joints;i++){
- if(&joints[i]==muscles[which].parent1){
- joints[i].rotate1=muscles[which].rotate1;
- joints[i].rotate2=muscles[which].rotate2;
- joints[i].rotate3=muscles[which].rotate3;
+ for (auto& joint : joints)
+ if (&joint == muscles[which].parent1) {
+ joint.rotate1=muscles[which].rotate1;
+ joint.rotate2=muscles[which].rotate2;
+ joint.rotate3=muscles[which].rotate3;
}
- }
if(0>tempforward.x)muscles[which].rotate3=360-muscles[which].rotate3;
}
@@ -473,9 +408,8 @@ void Animation::load(const char* name)
free(data.ptr);
for(int j=0;j<numframes;j++){
- for(int i=0;i<testskeleton.num_joints;i++){
- testskeleton.joints[i].position=position[i][j];
- }
+ for (int i = 0; i < max_joints; ++i)
+ testskeleton.joints[i].position = position[i][j];
//Find forward vectors
CrossProduct(testskeleton.joints[testskeleton.forwardjoints[1]].position-testskeleton.joints[testskeleton.forwardjoints[0]].position,testskeleton.joints[testskeleton.forwardjoints[2]].position-testskeleton.joints[testskeleton.forwardjoints[0]].position,&testskeleton.forward);
Normalise(&testskeleton.forward);
@@ -505,21 +439,24 @@ void Animation::load(const char* name)
Normalise(&testskeleton.specialforward[4]);
//Find joint rotations
- for(int i=0;i<testskeleton.num_joints;i++){
- if(testskeleton.joints[i].hasparent&&testskeleton.joints[i].visible)
- {
+ for (int i = 0; i < max_joints; ++i)
+ if (testskeleton.joints[i].hasparent
+ && testskeleton.joints[i].visible) {
testskeleton.FindRotationJoint(i);
+ rotate1[i][j]=testskeleton.joints[i].rotate1;
+ rotate2[i][j]=testskeleton.joints[i].rotate2;
+ rotate3[i][j]=testskeleton.joints[i].rotate3;
+ if(j!=0&&rotate3[i][j]>rotate3[i][j-1]+180)rotate3[i][j]-=360;
+ if(j!=0&&rotate3[i][j]<rotate3[i][j-1]-180)rotate3[i][j]+=360;
+ if(j!=0&&rotate2[i][j]>rotate2[i][j-1]+180)rotate2[i][j]-=360;
+ if(j!=0&&rotate2[i][j]<rotate2[i][j-1]-180)rotate2[i][j]+=360;
+ if(j!=0&&rotate1[i][j]>rotate1[i][j-1]+180)rotate1[i][j]-=360;
+ if(j!=0&&rotate1[i][j]<rotate1[i][j-1]-180)rotate1[i][j]+=360;
}
- }
- for(int i=0;i<testskeleton.num_muscles;i++){
- if(testskeleton.muscles[i].visible)
- {
+
+ for (int i = 0; i < max_muscles; ++i)
+ if (testskeleton.muscles[i].visible) {
testskeleton.FindRotationMuscle(i);
- }
- }
- for(int i=0;i<testskeleton.num_muscles;i++){
- if(testskeleton.muscles[i].visible)
- {
mrotate1[i][j]=testskeleton.muscles[i].rotate1;
mrotate2[i][j]=testskeleton.muscles[i].rotate2;
mrotate3[i][j]=testskeleton.muscles[i].rotate3;
@@ -530,28 +467,12 @@ void Animation::load(const char* name)
if(j!=0&&mrotate1[i][j]>mrotate1[i][j-1]+180)mrotate1[i][j]-=360;
if(j!=0&&mrotate1[i][j]<mrotate1[i][j-1]-180)mrotate1[i][j]+=360;
}
- }
- for(int i=0;i<testskeleton.num_joints;i++){
- if(testskeleton.joints[i].hasparent&&testskeleton.joints[i].visible)
- {
- rotate1[i][j]=testskeleton.joints[i].rotate1;
- rotate2[i][j]=testskeleton.joints[i].rotate2;
- rotate3[i][j]=testskeleton.joints[i].rotate3;
- if(j!=0&&rotate3[i][j]>rotate3[i][j-1]+180)rotate3[i][j]-=360;
- if(j!=0&&rotate3[i][j]<rotate3[i][j-1]-180)rotate3[i][j]+=360;
- if(j!=0&&rotate2[i][j]>rotate2[i][j-1]+180)rotate2[i][j]-=360;
- if(j!=0&&rotate2[i][j]<rotate2[i][j-1]-180)rotate2[i][j]+=360;
- if(j!=0&&rotate1[i][j]>rotate1[i][j-1]+180)rotate1[i][j]-=360;
- if(j!=0&&rotate1[i][j]<rotate1[i][j-1]-180)rotate1[i][j]+=360;
- }
- }
}
for(int k=0;k<2;k++)
for(int j=0;j<numframes;j++){
- for(int i=0;i<testskeleton.num_muscles;i++){
- if(testskeleton.muscles[i].visible)
- {
+ for (int i = 0; i < max_muscles; ++i)
+ if(testskeleton.muscles[i].visible) {
if(j!=0&&mrotate3[i][j]>mrotate3[i][j-1]+180)mrotate3[i][j]-=360;
if(j!=0&&mrotate3[i][j]<mrotate3[i][j-1]-180)mrotate3[i][j]+=360;
if(j!=0&&mrotate2[i][j]>mrotate2[i][j-1]+180)mrotate2[i][j]-=360;
@@ -566,10 +487,9 @@ void Animation::load(const char* name)
if(j==0&&mrotate1[i][j]>mrotate1[i][numframes-1]+180)mrotate1[i][j]-=360;
if(j==0&&mrotate1[i][j]<mrotate1[i][numframes-1]-180)mrotate1[i][j]+=360;
}
- }
- for(int i=0;i<testskeleton.num_joints;i++){
- if(testskeleton.joints[i].hasparent&&testskeleton.joints[i].visible)
- {
+
+ for (int i = 0; i < max_joints; ++i)
+ if(testskeleton.joints[i].hasparent&&testskeleton.joints[i].visible) {
if(j!=0&&rotate3[i][j]>rotate3[i][j-1]+180)rotate3[i][j]-=360;
if(j!=0&&rotate3[i][j]<rotate3[i][j-1]-180)rotate3[i][j]+=360;
if(j!=0&&rotate2[i][j]>rotate2[i][j-1]+180)rotate2[i][j]-=360;
@@ -584,17 +504,15 @@ void Animation::load(const char* name)
if(j==0&&rotate1[i][j]>rotate1[i][numframes-1]+180)rotate1[i][j]-=360;
if(j==0&&rotate1[i][j]<rotate1[i][numframes-1]-180)rotate1[i][j]+=360;
}
- }
}
}
void Skeleton::reload()
{
broken = 0;
- num_joints = 20;
- JointData joints_data[num_joints];
+ JointData joints_data[max_joints];
loadJoints(joints_data);
- for (int i = 0; i < num_joints; ++i) {
+ for (int i = 0; i < max_joints; ++i) {
joints[i].label = joints_data[i].label;
joints[i].position.x = joints_data[i].x;
joints[i].position.y = joints_data[i].y;
diff --git a/src/Skeleton.h b/src/Skeleton.h
index 35bdb43..31ece37 100644
--- a/src/Skeleton.h
+++ b/src/Skeleton.h
@@ -91,20 +91,22 @@ class Animation
XYZ position[max_joints][max_frames];
float speed[max_frames];
XYZ forward[max_frames];
- float rotate1[max_joints][max_frames],rotate2[max_joints][max_frames],rotate3[max_joints][max_frames];
- float mrotate1[max_joints][max_frames],mrotate2[max_joints][max_frames],mrotate3[max_joints][max_frames];
+ float rotate1[max_joints][max_frames];
+ float rotate2[max_joints][max_frames];
+ float rotate3[max_joints][max_frames];
+ float mrotate1[max_joints][max_frames];
+ float mrotate2[max_joints][max_frames];
+ float mrotate3[max_joints][max_frames];
void load(const char* name);
};
class Skeleton
{
public:
- int num_joints;
Joint joints[max_joints];
int jointlabels[max_joints];
-
- int num_muscles;
Muscle muscles[max_muscles];
+ int num_muscles;
int selected;
@@ -127,12 +129,8 @@ class Skeleton
void DoConstraints(Model *collide, XYZ *move, float rotation);
void DoGravity();
void DoBalance();
- void MusclesSet();
void Draw(int muscleview);
- void AddJoint(float x, float y, float z, int which);
- void SetJoint(float x, float y, float z, int which, int whichjoint);
void DeleteJoint(int whichjoint);
- void AddMuscle(int attach1,int attach2,float maxlength,float minlength,int type);
void DeleteMuscle(int whichmuscle);
void FindRotationJoint(int which);
void FindRotationMuscle(int which);