diff options
Diffstat (limited to 'src/Skeleton.cpp')
-rw-r--r-- | src/Skeleton.cpp | 97 |
1 files changed, 47 insertions, 50 deletions
diff --git a/src/Skeleton.cpp b/src/Skeleton.cpp index e039bc4..a5516c6 100644 --- a/src/Skeleton.cpp +++ b/src/Skeleton.cpp @@ -29,10 +29,8 @@ extern int whichtri; extern XYZ normalrotated; extern bool groundish; - void Joint::DoConstraint() { - if(hasparent){ //Find midpoint midp=(position+parent->position)/2; @@ -53,22 +51,22 @@ void Muscle::DoConstraint(int broken) { oldlength=length; relaxlength=findDistance(parent1->position,parent2->position); - + if(type==boneconnect)strength=1; if(type==constraint)strength=0; - + if(strength<0)strength=0; if(strength>1)strength=1; - + length-=(length-relaxlength)*(1-strength)*multiplier*multiplier*10000; length-=(length-targetlength)*(strength)*multiplier*multiplier*10000; if(strength==0)length=relaxlength; - + if((relaxlength-length>0&&relaxlength-oldlength<0)||(relaxlength-length<0&&relaxlength-oldlength>0))length=relaxlength; - + if(length<minlength)length=minlength; if(length>maxlength&&!broken)length=maxlength; - + //Find midpoint midp=(parent1->position+parent2->position)/2; //Find vector from midpoint to second vector @@ -88,7 +86,7 @@ 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(); @@ -101,9 +99,9 @@ void Skeleton::DoConstraints(Model *collide, XYZ *move, float rotation) friction=20; numrepeats=2; groundlevel=0; - + move->y+=.35; - + for(int j=0; j<numrepeats; j++){ for(int i=0; i<num_joints; i++){ if(joints[i].existing||i==jointlabels[lefthand]||i==jointlabels[righthand]){ @@ -149,7 +147,7 @@ void Skeleton::DoConstraints(Model *collide, XYZ *move, float rotation) gLoc[0]=joints[i].position.x/soundscalefactor; gLoc[1]=joints[i].position.y/soundscalefactor; gLoc[2]=joints[i].position.z/soundscalefactor; -#ifdef DEBIAN_NEEDS_TO_UPDATE_THEIR_OPENAL +#ifdef DEBIAN_NEEDS_TO_UPDATE_THEIR_OPENAL alGetSourceiv(gSourceID[headlandsound], AL_SOURCE_STATE, &tempint); #else alGetSourcei(gSourceID[headlandsound], AL_SOURCE_STATE, &tempint); @@ -174,7 +172,7 @@ void Skeleton::DoConstraints(Model *collide, XYZ *move, float rotation) alGetSourceiv(gSourceID[bodylandsound], AL_SOURCE_STATE, &tempint); #else alGetSourcei(gSourceID[bodylandsound], AL_SOURCE_STATE, &tempint); -#endif +#endif if (tempint != AL_PLAYING){ alSourcef(gSourceID[bodylandsound], AL_MIN_GAIN, ALfloat(findLengthfast(joints[i].velocity)*1/findDistancefast(joints[i].position,camera.position)*soundscalefactor*2)); alSourcef(gSourceID[bodylandsound], AL_MAX_GAIN, ALfloat(findLengthfast(joints[i].velocity)*1/findDistancefast(joints[i].position,camera.position)*soundscalefactor*2)); @@ -190,11 +188,11 @@ void Skeleton::DoConstraints(Model *collide, XYZ *move, float rotation) muscles[i].DoConstraint(broken); } } - + for(int i=0; i<num_joints; i++){ joints[i].realoldposition=joints[i].position; } - + //Add velocity for(int i=0; i<num_joints; i++){ if(joints[i].existing||i==jointlabels[lefthand]||i==jointlabels[righthand])joints[i].position=joints[i].position+joints[i].velocity*multiplier; @@ -218,7 +216,7 @@ void Skeleton::Draw(int muscleview) jointcolor[2]=.5; jointcolor[3]=1; } - + if(muscleview==2){ jointcolor[0]=0; jointcolor[1]=0; @@ -287,9 +285,9 @@ void Skeleton::Draw(int muscleview) glVertex3f(muscles[i].parent1->position.x,muscles[i].parent1->position.y,muscles[i].parent1->position.z); glVertex3f(muscles[i].parent2->position.x,muscles[i].parent2->position.y,muscles[i].parent2->position.z); } - } + } glEnd(); - + if(muscleview!=2){ glPointSize(3); glBegin(GL_POINTS); @@ -301,7 +299,7 @@ void Skeleton::Draw(int muscleview) } glEnd(); } - + //Set old position to current position if(muscleview==2) for(int i=0; i<num_joints; i++){ @@ -318,13 +316,13 @@ void Skeleton::AddJoint(float x, float y, float z, int which) 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++; } } @@ -355,7 +353,7 @@ void Skeleton::DeleteMuscle(int whichmuscle) muscles[whichmuscle].visible=muscles[num_muscles-1].visible; muscles[whichmuscle].type=muscles[num_muscles-1].type; muscles[whichmuscle].targetlength=muscles[num_muscles-1].targetlength; - + num_muscles--; } } @@ -367,13 +365,13 @@ void Skeleton::SetJoint(float x, float y, float z, int which, int whichjoint) 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); - } + } } } @@ -388,7 +386,7 @@ void Skeleton::AddMuscle(int attach1,int attach2,float minlength,float maxlength muscles[num_muscles].type=type; muscles[num_muscles].minlength=minlength; muscles[num_muscles].maxlength=maxlength; - + num_muscles++; } } @@ -404,7 +402,7 @@ void Skeleton::FindRotationJoint(int which) { XYZ temppoint1,temppoint2,tempforward; float distance; - + temppoint1=joints[which].position; temppoint2=joints[which].parent->position; distance=findDistance(temppoint1,temppoint2); @@ -432,7 +430,7 @@ void Skeleton::FindRotationMuscle(int which) { XYZ temppoint1,temppoint2,tempforward; float distance; - + temppoint1=muscles[which].parent1->position; temppoint2=muscles[which].parent2->position; distance=findDistance(temppoint1,temppoint2); @@ -490,23 +488,23 @@ void Animation::Load(char *fileName) } } } - + files.EndLoad(); - + for(int j=0;j<numframes;j++){ for(int i=0;i<testskeleton.num_joints;i++){ - testskeleton.joints[i].position=position[i][j]; + 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); - + CrossProduct(testskeleton.joints[testskeleton.lowforwardjoints[1]].position-testskeleton.joints[testskeleton.lowforwardjoints[0]].position,testskeleton.joints[testskeleton.lowforwardjoints[2]].position-testskeleton.joints[testskeleton.lowforwardjoints[0]].position,&testskeleton.lowforward); Normalise(&testskeleton.lowforward); - + //Special forwards testskeleton.specialforward[0]=testskeleton.forward; - + testskeleton.specialforward[1]=testskeleton.joints[testskeleton.jointlabels[rightshoulder]].position+testskeleton.joints[testskeleton.jointlabels[rightwrist]].position; testskeleton.specialforward[1]=testskeleton.joints[testskeleton.jointlabels[rightelbow]].position-testskeleton.specialforward[1]/2; testskeleton.specialforward[1]+=testskeleton.forward*.2; @@ -515,7 +513,7 @@ void Animation::Load(char *fileName) testskeleton.specialforward[2]=testskeleton.joints[testskeleton.jointlabels[leftelbow]].position-testskeleton.specialforward[2]/2; testskeleton.specialforward[2]+=testskeleton.forward*.2; Normalise(&testskeleton.specialforward[2]); - + testskeleton.specialforward[3]=testskeleton.joints[testskeleton.jointlabels[righthip]].position+testskeleton.joints[testskeleton.jointlabels[rightankle]].position; testskeleton.specialforward[3]=testskeleton.specialforward[3]/2-testskeleton.joints[testskeleton.jointlabels[rightknee]].position; testskeleton.specialforward[3]+=testskeleton.lowforward*.2; @@ -567,7 +565,7 @@ void Animation::Load(char *fileName) } } } - + for(int k=0;k<2;k++) for(int j=0;j<numframes;j++){ for(int i=0;i<testskeleton.num_muscles;i++){ @@ -579,7 +577,7 @@ void Animation::Load(char *fileName) if(j!=0&&mrotate2[i][j]<mrotate2[i][j-1]-180)mrotate2[i][j]+=360; 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; - + if(j==0&&mrotate3[i][j]>mrotate3[i][numframes-1]+180)mrotate3[i][j]-=360; if(j==0&&mrotate3[i][j]<mrotate3[i][numframes-1]-180)mrotate3[i][j]+=360; if(j==0&&mrotate2[i][j]>mrotate2[i][numframes-1]+180)mrotate2[i][j]-=360; @@ -597,7 +595,7 @@ void Animation::Load(char *fileName) 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; - + if(j==0&&rotate3[i][j]>rotate3[i][numframes-1]+180)rotate3[i][j]-=360; if(j==0&&rotate3[i][j]<rotate3[i][numframes-1]-180)rotate3[i][j]+=360; if(j==0&&rotate2[i][j]>rotate2[i][numframes-1]+180)rotate2[i][j]-=360; @@ -635,21 +633,21 @@ void Animation::Load(char *fileName, float rotate) } } files.EndLoad(); - + for(int j=0;j<numframes;j++){ for(int i=0;i<testskeleton.num_joints;i++){ - testskeleton.joints[i].position=position[i][j]; + 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); - + CrossProduct(testskeleton.joints[testskeleton.lowforwardjoints[1]].position-testskeleton.joints[testskeleton.lowforwardjoints[0]].position,testskeleton.joints[testskeleton.lowforwardjoints[2]].position-testskeleton.joints[testskeleton.lowforwardjoints[0]].position,&testskeleton.lowforward); Normalise(&testskeleton.lowforward); - + //Special forwards testskeleton.specialforward[0]=testskeleton.forward; - + testskeleton.specialforward[1]=testskeleton.joints[testskeleton.jointlabels[rightshoulder]].position+testskeleton.joints[testskeleton.jointlabels[rightwrist]].position; testskeleton.specialforward[1]=testskeleton.joints[testskeleton.jointlabels[rightelbow]].position-testskeleton.specialforward[1]/2; testskeleton.specialforward[1]+=testskeleton.forward*.2; @@ -658,7 +656,7 @@ void Animation::Load(char *fileName, float rotate) testskeleton.specialforward[2]=testskeleton.joints[testskeleton.jointlabels[leftelbow]].position-testskeleton.specialforward[2]/2; testskeleton.specialforward[2]+=testskeleton.forward*.2; Normalise(&testskeleton.specialforward[2]); - + testskeleton.specialforward[3]=testskeleton.joints[testskeleton.jointlabels[righthip]].position+testskeleton.joints[testskeleton.jointlabels[rightankle]].position; testskeleton.specialforward[3]=testskeleton.specialforward[3]/2-testskeleton.joints[testskeleton.jointlabels[rightknee]].position; testskeleton.specialforward[3]+=testskeleton.lowforward*.2; @@ -710,7 +708,7 @@ void Animation::Load(char *fileName, float rotate) } } } - + for(int k=0;k<2;k++) for(int j=0;j<numframes;j++){ for(int i=0;i<testskeleton.num_muscles;i++){ @@ -722,7 +720,7 @@ void Animation::Load(char *fileName, float rotate) if(j!=0&&mrotate2[i][j]<mrotate2[i][j-1]-180)mrotate2[i][j]+=360; 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; - + if(j==0&&mrotate3[i][j]>mrotate3[i][numframes-1]+180)mrotate3[i][j]-=360; if(j==0&&mrotate3[i][j]<mrotate3[i][numframes-1]-180)mrotate3[i][j]+=360; if(j==0&&mrotate2[i][j]>mrotate2[i][numframes-1]+180)mrotate2[i][j]-=360; @@ -740,7 +738,7 @@ void Animation::Load(char *fileName, float rotate) 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; - + if(j==0&&rotate3[i][j]>rotate3[i][numframes-1]+180)rotate3[i][j]-=360; if(j==0&&rotate3[i][j]<rotate3[i][numframes-1]-180)rotate3[i][j]+=360; if(j==0&&rotate2[i][j]>rotate2[i][numframes-1]+180)rotate2[i][j]-=360; @@ -801,13 +799,12 @@ void Skeleton::Load(char *fileName) } } files.EndLoad(); - + for(int i=0;i<num_joints;i++){ for(int j=0;j<num_joints;j++){ if(joints[i].label==j)jointlabels[j]=i; } } - - broken=0; -} + broken=0; +} |