Skip to content

Commit

Permalink
[cpp] Initial pass at physics, incomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
badlogic committed Dec 22, 2023
1 parent 0b9bab2 commit 5ffdcdb
Show file tree
Hide file tree
Showing 25 changed files with 1,346 additions and 166 deletions.
18 changes: 13 additions & 5 deletions spine-cpp/spine-cpp/include/spine/AnimationState.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,22 @@ namespace spine {
/// When the mix percentage (mix time / mix duration) is less than the attachment threshold, attachment timelines for the
/// animation being mixed out will be applied. Defaults to 0, so attachment timelines are not applied for an animation being
/// mixed out.
float getAttachmentThreshold();
float getMixAttachmentThreshold();

void setAttachmentThreshold(float inValue);
void setMixAttachmentThreshold(float inValue);

/// When getAlpha() is greater than alphaAttachmentThreshold, attachment timelines are applied.
/// Defaults to 0, so attachment timelines are always applied. */
float getAlphaAttachmentThreshold();

void setAlphaAttachmentThreshold(float inValue);

/// When the mix percentage (mix time / mix duration) is less than the draw order threshold, draw order timelines for the
/// animation being mixed out will be applied. Defaults to 0, so draw order timelines are not applied for an animation being
/// mixed out.
float getDrawOrderThreshold();
float getMixDrawOrderThreshold();

void setDrawOrderThreshold(float inValue);
void setMixDrawOrderThreshold(float inValue);

/// The animation queued to start after this animation, or NULL.
TrackEntry *getNext();
Expand Down Expand Up @@ -271,6 +277,8 @@ namespace spine {

void setListener(AnimationStateListenerObject *listener);

bool wasApplied();

private:
Animation *_animation;
TrackEntry *_previous;
Expand All @@ -280,7 +288,7 @@ namespace spine {
int _trackIndex;

bool _loop, _holdPrevious, _reverse, _shortestRotation;
float _eventThreshold, _attachmentThreshold, _drawOrderThreshold;
float _eventThreshold, _mixAttachmentThreshold, _alphaAttachmentThreshold, _mixDrawOrderThreshold;
float _animationStart, _animationEnd, _animationLast, _nextAnimationLast;
float _delay, _trackTime, _trackLast, _nextTrackLast, _trackEnd, _timeScale;
float _alpha, _mixTime, _mixDuration, _interruptAlpha, _totalAlpha;
Expand Down
4 changes: 3 additions & 1 deletion spine-cpp/spine-cpp/include/spine/Bone.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ namespace spine {

friend class PathConstraint;

friend class PhysicsConstraint;

friend class Skeleton;

friend class RegionAttachment;
Expand Down Expand Up @@ -104,7 +106,7 @@ namespace spine {
Bone(BoneData &data, Skeleton &skeleton, Bone *parent = NULL);

/// Same as updateWorldTransform. This method exists for Bone to implement Spine::Updatable.
virtual void update();
virtual void update(Physics physics);

/// Computes the world transform using the parent bone and this bone's local transform.
void updateWorldTransform();
Expand Down
10 changes: 10 additions & 0 deletions spine-cpp/spine-cpp/include/spine/BoneData.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ namespace spine {

Color &getColor();

const String &getIcon();

void setIcon(const String &icon);

bool isVisible();

void setVisible(bool inValue);

private:
const int _index;
const String _name;
Expand All @@ -134,6 +142,8 @@ namespace spine {
TransformMode _transformMode;
bool _skinRequired;
Color _color;
String _icon;
bool _visible;
};
}

Expand Down
4 changes: 3 additions & 1 deletion spine-cpp/spine-cpp/include/spine/IkConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace spine {

IkConstraint(IkConstraintData &data, Skeleton &skeleton);

virtual void update();
virtual void update(Physics physics);

virtual int getOrder();

Expand Down Expand Up @@ -100,6 +100,8 @@ namespace spine {

void setActive(bool inValue);

void setToSetupPose();

private:
IkConstraintData &_data;
Vector<Bone *> _bones;
Expand Down
5 changes: 5 additions & 0 deletions spine-cpp/spine-cpp/include/spine/MathUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace spine {
public:
static const float Pi;
static const float Pi_2;
static const float InvPi_2;
static const float Deg_Rad;
static const float Rad_Deg;

Expand Down Expand Up @@ -77,6 +78,8 @@ namespace spine {
/// degrees), largest error of 0.00488 radians (0.2796 degrees).
static float atan2(float y, float x);

static float atan2Deg(float x, float y);

static float acos(float v);

static float sqrt(float v);
Expand All @@ -92,6 +95,8 @@ namespace spine {
static float randomTriangular(float min, float max, float mode);

static float pow(float a, float b);

static float ceil(float v);
};

struct SP_API Interpolation {
Expand Down
4 changes: 3 additions & 1 deletion spine-cpp/spine-cpp/include/spine/PathConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace spine {
public:
PathConstraint(PathConstraintData &data, Skeleton &skeleton);

virtual void update();
virtual void update(Physics physics);

virtual int getOrder();

Expand Down Expand Up @@ -95,6 +95,8 @@ namespace spine {

void setActive(bool inValue);

void setToSetupPose();

private:
static const float EPSILON;
static const int NONE;
Expand Down
49 changes: 49 additions & 0 deletions spine-cpp/spine-cpp/include/spine/Physics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated July 28, 2023. Replaces all prior versions.
*
* Copyright (c) 2013-2023, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software or
* otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE
* SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_Physics_h
#define Spine_Physics_h

/** Determines how physics and other non-deterministic updates are applied. */
namespace spine {
enum Physics {
/** Physics are not updated or applied. */
none,

/** Physics are reset to the current pose. */
reset,

/** Physics are updated and the pose from physics is applied. */
update,

/** Physics are not updated but the pose from physics is applied. */
pose
};
}

#endif
170 changes: 170 additions & 0 deletions spine-cpp/spine-cpp/include/spine/PhysicsConstraint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated July 28, 2023. Replaces all prior versions.
*
* Copyright (c) 2013-2023, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software or
* otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE
* SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/

#ifndef Spine_PhysicsConstraint_h
#define Spine_PhysicsConstraint_h

#include <spine/ConstraintData.h>

#include <spine/Vector.h>

namespace spine {
class PhysicsConstraintData;

class Skeleton;

class Bone;

class SP_API PhysicsConstraint : public Updatable {

RTTI_DECL
public:
explicit PhysicsConstraint(PhysicsConstraintData& data, Skeleton& skeleton);

void setBone(Bone* bone);
Bone* getBone() const;

void setInertia(float value);
float getInertia() const;

void setStrength(float value);
float getStrength() const;

void setDamping(float value);
float getDamping() const;

void setMassInverse(float value);
float getMassInverse() const;

void setWind(float value);
float getWind() const;

void setGravity(float value);
float getGravity() const;

void setMix(float value);
float getMix() const;

void setReset(bool value);
bool getReset() const;

void setUx(float value);
float getUx() const;

void setUy(float value);
float getUy() const;

void setCx(float value);
float getCx() const;

void setCy(float value);
float getCy() const;

void setTx(float value);
float getTx() const;

void setTy(float value);
float getTy() const;

void setXOffset(float value);
float getXOffset() const;

void setXVelocity(float value);
float getXVelocity() const;

void setYOffset(float value);
float getYOffset() const;

void setYVelocity(float value);
float getYVelocity() const;

void setRotateOffset(float value);
float getRotateOffset() const;

void setRotateVelocity(float value);
float getRotateVelocity() const;

void setScaleOffset(float value);
float getScaleOffset() const;

void setScaleVelocity(float value);
float getScaleVelocity() const;

void setActive(bool value);
bool isActive() const;

void setRemaining(float value);
float getRemaining() const;

void setLastTime(float value);
float getLastTime() const;

void reset();

void setToSetupPose();

void update(Physics physics) override;

private:
const PhysicsConstraintData& _data;
Bone* _bone;

float _inertia;
float _strength;
float _damping;
float _massInverse;
float _wind;
float _gravity;
float _mix;

bool _reset;
float _ux;
float _uy;
float _cx;
float _cy;
float _tx;
float _ty;
float _xOffset;
float _xVelocity;
float _yOffset;
float _yVelocity;
float _rotateOffset;
float _rotateVelocity;
float _scaleOffset;
float _scaleVelocity;

bool _active;

Skeleton& _skeleton;
float _remaining;
float _lastTime;
};
}

#endif /* Spine_PhysicsConstraint_h */
Loading

0 comments on commit 5ffdcdb

Please sign in to comment.