set(LUGARU_SRCS
${SRCDIR}/main.cpp
${SRCDIR}/Animation/Animation.cpp
+ ${SRCDIR}/Animation/Joint.cpp
+ ${SRCDIR}/Animation/Muscle.cpp
${SRCDIR}/Animation/Skeleton.cpp
${SRCDIR}/Frustum.cpp
${SRCDIR}/Account.cpp
set(LUGARU_H
${SRCDIR}/Animation/Animation.h
+ ${SRCDIR}/Animation/Joint.h
+ ${SRCDIR}/Animation/Muscle.h
${SRCDIR}/Animation/Skeleton.h
${SRCDIR}/Frustum.h
${SRCDIR}/Account.h
--- /dev/null
+/*
+Copyright (C) 2003, 2010 - Wolfire Games
+Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
+
+This file is part of Lugaru.
+
+Lugaru is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+Lugaru is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "Animation/Joint.h"
+
+Joint::Joint() :
+ blurred(0),
+ length(0),
+ mass(0),
+ lower(false),
+ hasparent(false),
+ locked(false),
+ modelnum(0),
+ visible(false),
+ parent(nullptr),
+ sametwist(false),
+ label(0),
+ hasgun(0),
+ delay(0)
+{
+}
--- /dev/null
+/*
+Copyright (C) 2003, 2010 - Wolfire Games
+Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
+
+This file is part of Lugaru.
+
+Lugaru is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+Lugaru is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _JOINT_H_
+#define _JOINT_H_
+
+#include "Quaternions.h"
+
+class Joint
+{
+public:
+ XYZ position;
+ XYZ oldposition;
+ XYZ realoldposition;
+ XYZ velocity;
+ XYZ oldvelocity;
+ XYZ startpos;
+ float blurred;
+ float length;
+ float mass;
+ bool lower;
+ bool hasparent;
+ bool locked;
+ int modelnum;
+ bool visible;
+ Joint* parent;
+ bool sametwist;
+ int label;
+ int hasgun;
+ float delay;
+ XYZ velchange;
+
+ Joint();
+};
+
+#endif
--- /dev/null
+/*
+Copyright (C) 2003, 2010 - Wolfire Games
+Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
+
+This file is part of Lugaru.
+
+Lugaru is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+Lugaru is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "Animation/Muscle.h"
+
+extern float multiplier;
+extern bool freeze;
+
+Muscle::Muscle()
+{
+ 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;
+}
+
+Muscle::~Muscle()
+{
+ free(vertices);
+ free(verticeslow);
+ free(verticesclothes);
+}
+
+
+/* EFFECT
+ * sets strength, length,
+ * parent1->position, parent2->position,
+ * parent1->velocity, parent2->velocity
+ * used for ragdolls?
+ *
+ * USES:
+ * Skeleton::DoConstraints
+ */
+void Muscle::DoConstraint(bool spinny)
+{
+ // FIXME: relaxlength shouldn't be static, but may not always be set
+ // so I don't want to change the existing behavior even though it's probably a bug
+ static float relaxlength;
+
+ float oldlength = length;
+
+ if (type != boneconnect) {
+ relaxlength = findDistance(&parent1->position, &parent2->position);
+ }
+
+ if (type == boneconnect) {
+ strength = 1;
+ }
+ if (type == constraint) {
+ strength = 0;
+ }
+
+ // clamp strength
+ if (strength < 0)
+ strength = 0;
+ if (strength > 1)
+ strength = 1;
+
+ length -= (length - relaxlength) * (1 - strength) * multiplier * 10000;
+ length -= (length - targetlength) * (strength) * multiplier * 10000;
+ if (strength == 0)
+ length = relaxlength;
+
+ if ((relaxlength - length > 0 && relaxlength - oldlength < 0) || (relaxlength - length < 0 && relaxlength - oldlength > 0))
+ length = relaxlength;
+
+ // clamp length
+ if (length < minlength)
+ length = minlength;
+ if (length > maxlength)
+ length = maxlength;
+
+ if (length == relaxlength)
+ return;
+
+ // relax muscle?
+
+ //Find midpoint
+ XYZ midp = (parent1->position * parent1->mass + parent2->position * parent2->mass) / (parent1->mass + parent2->mass);
+
+ //Find vector from midpoint to second vector
+ XYZ vel = parent2->position - midp;
+
+ //Change to unit vector
+ Normalise(&vel);
+
+ //Apply velocity change
+ XYZ newpoint1 = midp - vel * length * (parent2->mass / (parent1->mass + parent2->mass));
+ XYZ newpoint2 = midp + vel * length * (parent1->mass / (parent1->mass + parent2->mass));
+ if (!freeze && spinny) {
+ parent1->velocity = parent1->velocity + (newpoint1 - parent1->position) / multiplier / 4;
+ parent2->velocity = parent2->velocity + (newpoint2 - parent2->position) / multiplier / 4;
+ } else {
+ parent1->velocity = parent1->velocity + (newpoint1 - parent1->position);
+ parent2->velocity = parent2->velocity + (newpoint2 - parent2->position);
+ }
+
+ //Move child point to within certain distance of parent point
+ parent1->position = newpoint1;
+ parent2->position = newpoint2;
+}
--- /dev/null
+/*
+Copyright (C) 2003, 2010 - Wolfire Games
+Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
+
+This file is part of Lugaru.
+
+Lugaru is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+Lugaru is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _MUSCLE_H_
+#define _MUSCLE_H_
+
+#include "Animation/Joint.h"
+
+enum muscle_type {boneconnect, constraint, muscle};
+
+class Muscle
+{
+public:
+ int numvertices;
+ int* vertices;
+ int numverticeslow;
+ int* verticeslow;
+ int numverticesclothes;
+ int* verticesclothes;
+ float length;
+ float targetlength;
+ Joint* parent1;
+ Joint* parent2;
+ float maxlength;
+ float minlength;
+ muscle_type type;
+ bool visible;
+ float rotate1, rotate2, rotate3;
+ float lastrotate1, lastrotate2, lastrotate3;
+ float oldrotate1, oldrotate2, oldrotate3;
+ float newrotate1, newrotate2, newrotate3;
+
+ float strength;
+
+ Muscle();
+ ~Muscle();
+ void DoConstraint(bool spinny);
+};
+
+#endif
free(param);
}
-enum {boneconnect, constraint, muscle};
-
-
-/* EFFECT
- * sets strength, length,
- * parent1->position, parent2->position,
- * parent1->velocity, parent2->velocity
- * used for ragdolls?
- *
- * USES:
- * Skeleton::DoConstraints
- */
-void Muscle::DoConstraint(bool spinny)
-{
- // FIXME: relaxlength shouldn't be static, but may not always be set
- // so I don't want to change the existing behavior even though it's probably a bug
- static float relaxlength;
-
- float oldlength = length;
-
- if (type != boneconnect)
- relaxlength = findDistance(&parent1->position, &parent2->position);
-
- if (type == boneconnect)
- strength = 1;
- if (type == constraint)
- strength = 0;
-
- // clamp strength
- if (strength < 0)
- strength = 0;
- if (strength > 1)
- strength = 1;
-
- length -= (length - relaxlength) * (1 - strength) * multiplier * 10000;
- length -= (length - targetlength) * (strength) * multiplier * 10000;
- if (strength == 0)
- length = relaxlength;
-
- if ((relaxlength - length > 0 && relaxlength - oldlength < 0) || (relaxlength - length < 0 && relaxlength - oldlength > 0))
- length = relaxlength;
-
- // clamp length
- if (length < minlength)
- length = minlength;
- if (length > maxlength)
- length = maxlength;
-
- if (length == relaxlength)
- return;
-
- // relax muscle?
-
- //Find midpoint
- XYZ midp = (parent1->position * parent1->mass + parent2->position * parent2->mass) / (parent1->mass + parent2->mass);
-
- //Find vector from midpoint to second vector
- XYZ vel = parent2->position - midp;
-
- //Change to unit vector
- Normalise(&vel);
-
- //Apply velocity change
- XYZ newpoint1 = midp - vel * length * (parent2->mass / (parent1->mass + parent2->mass));
- XYZ newpoint2 = midp + vel * length * (parent1->mass / (parent1->mass + parent2->mass));
- if (!freeze && spinny) {
- parent1->velocity = parent1->velocity + (newpoint1 - parent1->position) / multiplier / 4;
- parent2->velocity = parent2->velocity + (newpoint2 - parent2->position) / multiplier / 4;
- } else {
- parent1->velocity = parent1->velocity + (newpoint1 - parent1->position);
- parent2->velocity = parent2->velocity + (newpoint2 - parent2->position);
- }
-
- //Move child point to within certain distance of parent point
- parent1->position = newpoint1;
- parent2->position = newpoint2;
-}
-
/* EFFECT
* sets forward, lowforward, specialforward[]
*
joints = 0;
}
-Muscle::Muscle()
-{
- 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 = 0;
- 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;
-}
-
-Muscle::~Muscle()
-{
- dealloc2(vertices);
- dealloc2(verticeslow);
- dealloc2(verticesclothes);
-}
-
#if 0
// the following functions are not used anywhere
{
static float jointcolor[4];
- if (muscleview != 2) {
- jointcolor[0] = 0;
- jointcolor[1] = 0;
- jointcolor[2] = .5;
- jointcolor[3] = 1;
- }
-
if (muscleview == 2) {
jointcolor[0] = 0;
jointcolor[1] = 0;
jointcolor[2] = 0;
jointcolor[3] = .5;
+ } else {
+ jointcolor[0] = 0;
+ jointcolor[1] = 0;
+ jointcolor[2] = .5;
+ jointcolor[3] = 1;
}
+
//Calc motionblur-ness
for (int i = 0; i < num_joints; i++) {
joints[i].oldposition = joints[i].position;
#define _SKELETON_H_
#include "Models.h"
-#include "Quaternions.h"
-
/**> HEADER FILES <**/
#include "gamegl.h"
#include "Sprite.h"
#include "binio.h"
#include "Animation/Animation.h"
+#include "Animation/Joint.h"
+#include "Animation/Muscle.h"
enum bodyparts {
head, neck,
rightknee, rightankle, rightfoot
};
-class Joint
-{
-public:
- XYZ position;
- XYZ oldposition;
- XYZ realoldposition;
- XYZ velocity;
- XYZ oldvelocity;
- XYZ startpos;
- float blurred;
- float length;
- float mass;
- bool lower;
- bool hasparent;
- bool locked;
- int modelnum;
- bool visible;
- Joint* parent;
- bool sametwist;
- int label;
- int hasgun;
- float delay;
- XYZ velchange;
-
- Joint() {
- blurred = 0;
- length = 0;
- mass = 0;
- lower = 0;
- hasparent = 0;
- locked = 0;
- modelnum = 0;
- visible = 0;
- parent = 0;
- sametwist = 0;
- label = 0;
- hasgun = 0;
- delay = 0;
- }
-};
-
-class Muscle
-{
-public:
- int numvertices;
- int* vertices;
- int numverticeslow;
- int* verticeslow;
- int numverticesclothes;
- int* verticesclothes;
- float length;
- float targetlength;
- Joint* parent1;
- Joint* parent2;
- float maxlength;
- float minlength;
- int type;
- bool visible;
- float rotate1, rotate2, rotate3;
- float lastrotate1, lastrotate2, lastrotate3;
- float oldrotate1, oldrotate2, oldrotate3;
- float newrotate1, newrotate2, newrotate3;
-
- float strength;
-
- Muscle();
- ~Muscle();
- void DoConstraint(bool spinny);
-};
-
const int max_joints = 50;
class Skeleton