tahoma2d/toonz/sources/include/toonz/iknode.h

99 lines
2.5 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef IKNODE_H
#define IKNODE_H
#include <math.h>
#include <assert.h>
#include "tgeometry.h"
#undef DVAPI
#undef DVVAR
#ifdef TOONZLIB_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
2016-06-15 18:43:10 +12:00
class DVAPI IKNode {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
enum Purpose { JOINT, EFFECTOR };
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
IKNode() : m_parent(0), m_pos() {
2020-05-11 20:30:29 +12:00
r = TPointD(0.0, 1.0); // r will be updated when the node is added
// in the skeleton
2016-06-15 18:43:10 +12:00
theta = 0.0;
m_parent = 0;
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setParent(IKNode *parent) { m_parent = parent; }
void setRealParent(IKNode *realParent) { m_parent = realParent; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setTheta(double newTheta) { theta = newTheta; }
void setTheta0(double newTheta) { theta0 = newTheta; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setIndex(int index) { m_index = index; }
int getIndex() const { return m_index; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
IKNode *getParent() const { return m_parent; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
Purpose getPurpose() { return m_purpose; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setPos(const TPointD &pos) { m_pos = pos; }
TPointD getPos() const { return m_pos; }
void setPurpose(Purpose purpose);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setSeqNumJoint(int number) { m_seqNumJoint = number; }
void setSeqNumEffector(int number) { m_seqNumEffector = number; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int getEffectorNum() const { return m_seqNumEffector; }
int getJointNum() const { return m_seqNumJoint; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
double getTheta() const { return theta; }
double getTheta0() const { return theta0; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool IsEffector() const { return m_purpose == EFFECTOR; }
bool IsJoint() const { return m_purpose == JOINT; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
const TPointD &GetS() const { return s; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setR(TPointD pos) { r = pos; }
void setS(TPointD pos) { s = pos; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void computeS(void);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
double AddToTheta(double delta) {
theta += delta;
return theta;
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isFrozen() const { return freezed; }
2020-05-11 20:30:29 +12:00
void freeze() { freezed = true; } // keeps the theta angle constant
2016-06-15 18:43:10 +12:00
void unFreeze() { freezed = false; }
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
int m_index;
IKNode *m_parent;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TPointD m_pos;
Purpose m_purpose;
2020-05-11 20:30:29 +12:00
int m_seqNumJoint; // Joint index in the Joint sequence
int m_seqNumEffector; // index of the effector in the sequence of effectors
2016-03-19 06:57:51 +13:00
2020-05-11 20:30:29 +12:00
TPointD r; // Relative position
TPointD s; // Global position
// TPointD w; // Global axis rotation
2016-03-19 06:57:51 +13:00
2020-05-11 20:30:29 +12:00
double theta; // joint angle(radians)
double theta0; // initial angle of the joint(radians)
double minTheta; // lower angle limit
double maxTheta; // high angle limit
double restAngle;
2016-03-19 06:57:51 +13:00
2020-05-11 20:30:29 +12:00
bool freezed;
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
#endif // IKNODE_H