diff options
Diffstat (limited to 'src/Skeleton.cpp')
-rw-r--r-- | src/Skeleton.cpp | 187 |
1 files changed, 98 insertions, 89 deletions
diff --git a/src/Skeleton.cpp b/src/Skeleton.cpp index a5516c6..8ac7c4f 100644 --- a/src/Skeleton.cpp +++ b/src/Skeleton.cpp @@ -96,106 +96,115 @@ void Skeleton::DoConstraints() 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]){ - //Length constraints + friction = 20; + move->y += 0.35; + groundlevel = 0; + numrepeats = 2; + 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]) + continue; + + // Length constraints joints[i].DoConstraint(); - //Ground constraint - offset=0; - overpoint=joints[i].position; - overpoint.y+=10; - underpoint=joints[i].position; - underpoint.y-=offset; - whichtri=collide->LineCheck2(overpoint,underpoint,&impact,*move,rotation); - if(collide->normals[whichtri].y<=.8)whichtri=collide->LineCheck2(joints[i].realoldposition,joints[i].position,&impact,*move,rotation); - if(joints[i].position.y<=groundlevel+offset||whichtri!=-1){ - if(whichtri==-1||(whichtri!=-1&&collide->normals[whichtri].y>.8)){ - if(whichtri==-1)joints[i].position.y=groundlevel+offset; - if(whichtri!=-1){ - joints[i].position=impact; - joints[i].position.y+=offset; + // Ground constraint + auto& pos = joints[i].position; + overpoint = pos; + overpoint.y += 10; + underpoint = pos; + underpoint.y -= offset = 0; + whichtri = collide->LineCheck2(overpoint, underpoint, + &impact, *move, rotation); + if (whichtri == -1 + || collide->normals[whichtri].y <= 0.8) + whichtri = collide->LineCheck2( + joints[i].realoldposition, pos, + &impact, *move, rotation); + + if (pos.y <= groundlevel + offset || whichtri != -1) { + if (whichtri == -1 + || collide->normals[whichtri].y > 0.8) { + if (whichtri == -1) { + pos.y = groundlevel + offset; + } else { + pos = impact; + pos.y += offset; } - joints[i].velocity.y*=-.3; - joints[i].velocity.x*=.3; - joints[i].velocity.z*=.3; + joints[i].velocity.y *= -0.3; + joints[i].velocity.x *= 0.3; + joints[i].velocity.z *= 0.3; } - offset=.2; - if(whichtri!=-1&&collide->normals[whichtri].y<=.8){ - normalrotated=DoRotation(collide->normals[whichtri],0,rotation,0); - joints[i].position=impact+normalrotated*offset; - ReflectVector(&joints[i].velocity,&normalrotated); - joints[i].velocity*=.3; - } - if(broken<=1){ - XYZ avgvelocity; - avgvelocity=0; - float gLoc[3]; - ALint tempint; - for(int k=0; k<num_joints; k++){ - avgvelocity+=joints[k].velocity; - } - avgvelocity/=num_joints; - if(joints[i].label==head&&(findLengthfast(joints[i].velocity)>2||findLengthfast(avgvelocity)>2)){ - avgvelocity+=joints[i].velocity; - 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 - alGetSourceiv(gSourceID[headlandsound], AL_SOURCE_STATE, &tempint); -#else - alGetSourcei(gSourceID[headlandsound], AL_SOURCE_STATE, &tempint); -#endif - if (tempint != AL_PLAYING){ - alSourcef(gSourceID[headlandsound], AL_MIN_GAIN, ALfloat(findLengthfast(avgvelocity)*2/findDistancefast(joints[i].position,camera.position)*soundscalefactor*2)); - alSourcef(gSourceID[headlandsound], AL_MAX_GAIN, ALfloat(findLengthfast(avgvelocity)*2/findDistancefast(joints[i].position,camera.position)*soundscalefactor*2)); - alSourcefv(gSourceID[headlandsound], AL_POSITION, gLoc); - alSourcePlay(gSourceID[headlandsound]);} - } - avgvelocity=0; - for(int k=0; k<num_joints; k++){ - avgvelocity+=joints[k].velocity; + + offset = 0.2; + if (whichtri != -1 + && collide->normals[whichtri].y <= 0.8) { + normalrotated = DoRotation(collide->normals[whichtri], 0, rotation, 0); + pos = impact + normalrotated * offset; + ReflectVector(&joints[i].velocity, &normalrotated); + joints[i].velocity *= 0.3; } - avgvelocity/=num_joints; - if((joints[i].label==abdomen)&&(findLengthfast(joints[i].velocity)>2||findLengthfast(avgvelocity)>2)){ - avgvelocity+=joints[i].velocity; - 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 - alGetSourceiv(gSourceID[bodylandsound], AL_SOURCE_STATE, &tempint); -#else - alGetSourcei(gSourceID[bodylandsound], AL_SOURCE_STATE, &tempint); -#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)); - alSourcefv(gSourceID[bodylandsound], AL_POSITION, gLoc); - alSourcePlay(gSourceID[bodylandsound]);} + + if (broken > 1) + continue; + XYZ avgvelocity {0}; + for (int k = 0; k < num_joints; k++) + avgvelocity += joints[k].velocity; + avgvelocity /= num_joints; + + int landsound = -1; + switch (joints[i].label) { + case head: + landsound = headlandsound; + break; + case abdomen: + landsound = bodylandsound; + break; } + ALint playing = AL_PLAYING; + if (landsound >= 0) + alGetSourcei(gSourceID[landsound], + AL_SOURCE_STATE, &playing); + + if (playing != AL_PLAYING + && (findLengthfast(joints[i].velocity) > 2 + || findLengthfast(avgvelocity) > 2)) { + ALfloat gain = + findLengthfast(avgvelocity + + joints[i].velocity) + / findDistancefast(pos, + camera.position) + * soundscalefactor * 4; + alSourcef(gSourceID[landsound], + AL_MIN_GAIN, gain); + alSourcef(gSourceID[landsound], + AL_MAX_GAIN, gain); + + float gLoc[3] { + pos.x / soundscalefactor, + pos.y / soundscalefactor, + pos.z / soundscalefactor, + }; + alSourcefv(gSourceID[landsound], + AL_POSITION, gLoc); + alSourcePlay(gSourceID[landsound]); } - }} + } } - if(num_muscles) - for(int i=0; i<num_muscles; i++){ + + for (int i = 0; i < num_muscles; i++) //Length constraints 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; + for (int i = 0; i < num_joints; i++) { + joints[i].realoldposition = joints[i].position; + //Add velocity + if (joints[i].existing + || i == jointlabels[lefthand] + || i == jointlabels[righthand]) + joints[i].position += joints[i].velocity * multiplier; } } |