X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FAnimation%2FMuscle.cpp;h=c65bbbdcf389fb45cdf8b4c51ac72fcafbf4f056;hb=8f372db25c010303cc25868b48cb5c0d0a540067;hp=4a5a04762a5101fc6f1f1a60ad5f2bdb82fbacab;hpb=1d589bc3024e30dd51e41b6041b57649190bef4d;p=lugaru.git diff --git a/Source/Animation/Muscle.cpp b/Source/Animation/Muscle.cpp index 4a5a047..c65bbbd 100644 --- a/Source/Animation/Muscle.cpp +++ b/Source/Animation/Muscle.cpp @@ -1,6 +1,6 @@ /* Copyright (C) 2003, 2010 - Wolfire Games -Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) +Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file) This file is part of Lugaru. @@ -18,43 +18,93 @@ You should have received a copy of the GNU General Public License along with Lugaru. If not, see . */ -#include "Animation/Muscle.h" +#include "Animation/Muscle.hpp" + +#include "Utils/binio.h" extern float multiplier; extern bool freeze; Muscle::Muscle() + : length(0) + , targetlength(0) + , parent1(0) + , parent2(0) + , maxlength(0) + , minlength(0) + , type(boneconnect) + , visible(false) + , rotate1(0) + , rotate2(0) + , rotate3(0) + , lastrotate1(0) + , lastrotate2(0) + , lastrotate3(0) + , oldrotate1(0) + , oldrotate2(0) + , oldrotate3(0) + , newrotate1(0) + , newrotate2(0) + , newrotate3(0) + , + + strength(0) +{ +} + +void Muscle::load(FILE* tfile, int vertexNum, std::vector& joints) { - vertices = 0; - verticeslow = 0; - verticesclothes = 0; - - numvertices = 0; - numverticeslow = 0; - numverticesclothes = 0; - length = 0; - targetlength = 0; - parent1 = 0; - parent2 = 0; - maxlength = 0; - minlength = 0; - type = boneconnect; - visible = 0; - rotate1 = 0, rotate2 = 0, rotate3 = 0; - lastrotate1 = 0, lastrotate2 = 0, lastrotate3 = 0; - oldrotate1 = 0, oldrotate2 = 0, oldrotate3 = 0; - newrotate1 = 0, newrotate2 = 0, newrotate3 = 0; - - strength = 0; + int numvertices, vertice, parentID; + + // read info + funpackf(tfile, "Bf Bf Bf Bf Bf Bi Bi", &length, &targetlength, &minlength, &maxlength, &strength, &type, &numvertices); + + // read vertices + for (int j = 0; j < numvertices; j++) { + funpackf(tfile, "Bi", &vertice); + if (vertice < vertexNum) { + vertices.push_back(vertice); + } + } + + // read more info + funpackf(tfile, "Bb Bi", &visible, &parentID); + parent1 = &joints[parentID]; + funpackf(tfile, "Bi", &parentID); + parent2 = &joints[parentID]; } -Muscle::~Muscle() +void Muscle::loadVerticesLow(FILE* tfile, int vertexNum) { - free(vertices); - free(verticeslow); - free(verticesclothes); + int numvertices, vertice; + + // read numvertices + funpackf(tfile, "Bi", &numvertices); + + // read vertices + for (int j = 0; j < numvertices; j++) { + funpackf(tfile, "Bi", &vertice); + if (vertice < vertexNum) { + verticeslow.push_back(vertice); + } + } } +void Muscle::loadVerticesClothes(FILE* tfile, int vertexNum) +{ + int numvertices, vertice; + + // read numvertices + funpackf(tfile, "Bi", &numvertices); + + // read vertices + for (int j = 0; j < numvertices; j++) { + funpackf(tfile, "Bi", &vertice); + if (vertice < vertexNum) { + verticesclothes.push_back(vertice); + } + } +} /* EFFECT * sets strength, length, @@ -85,27 +135,34 @@ void Muscle::DoConstraint(bool spinny) } // clamp strength - if (strength < 0) + if (strength < 0) { strength = 0; - if (strength > 1) + } + if (strength > 1) { strength = 1; + } length -= (length - relaxlength) * (1 - strength) * multiplier * 10000; - length -= (length - targetlength) * (strength) * multiplier * 10000; - if (strength == 0) + length -= (length - targetlength) * strength * multiplier * 10000; + if (strength == 0) { length = relaxlength; + } - if ((relaxlength - length > 0 && relaxlength - oldlength < 0) || (relaxlength - length < 0 && relaxlength - oldlength > 0)) + if ((relaxlength - length > 0 && relaxlength - oldlength < 0) || (relaxlength - length < 0 && relaxlength - oldlength > 0)) { length = relaxlength; + } // clamp length - if (length < minlength) + if (length < minlength) { length = minlength; - if (length > maxlength) + } + if (length > maxlength) { length = maxlength; + } - if (length == relaxlength) + if (length == relaxlength) { return; + } // relax muscle?