载入中...
搜索中...
未找到
Skeleton2D.h
浏览该文件的文档.
1#pragma once
2
3#include "ik.hpp"
4
5namespace eve::ik {
6
13public:
14 Skeleton2D();
15 ~Skeleton2D() = default;
16
17 Skeleton2D(const Skeleton2D &) = delete;
18 Skeleton2D &operator=(const Skeleton2D &) = delete;
19
21 int createBone(int parentId, float length = 1.f);
22
23 int getBoneCount() const;
24 int getRootId() const { return 0; }
25 int getParent(int boneId) const;
26 int getChildCount(int boneId) const;
27 int getChild(int boneId, int childIndex) const;
28
29 float getLength(int boneId) const;
30 void setLength(int boneId, float length);
31
32 void setPosition(int boneId, float x, float y);
33 float getX(int boneId) const;
34 float getY(int boneId) const;
35
36 void setOrientation(int boneId, float x, float y);
37 float getOrientationX(int boneId) const;
38 float getOrientationY(int boneId) const;
39
41 void setRotation(int boneId, float angle);
42 float getRotation(int boneId) const;
43
45 void setConstraints(int boneId, float minAngle, float maxAngle);
46 void clearConstraints(int boneId);
47 bool hasConstraints(int boneId) const;
48
49 void initStraightPose(float rootX = 0.f, float rootY = 0.f);
50 void bind();
51 void forwardKinematics();
52 void updateRotations();
53
54 float totalLengthTo(int boneId) const;
55
56 ::ik::skeleton2d &native() { return sk_; }
57 ::ik::ecs2d &state() { return state_; }
58 const ::ik::skeleton2d &native() const { return sk_; }
59 const ::ik::ecs2d &state() const { return state_; }
60
61private:
62 void ensureSorted();
63 void ensureStateSize();
64 ::ik::bone2d *boneAt(int boneId) const;
65 void requireBone(int boneId) const;
66
67 ::ik::skeleton2d sk_;
68 ::ik::ecs2d state_;
69};
70
71} // namespace eve::ik
int y
Definition Grass.cpp:135
int x
Definition Grass.cpp:135
Script-facing 2D skeleton + pose state (ik::skeleton2d + ik::ecs2d). Bone indices are stable after ea...
Definition Skeleton2D.h:12
float getLength(int boneId) const
void setOrientation(int boneId, float x, float y)
int getRootId() const
Definition Skeleton2D.h:24
void setRotation(int boneId, float angle)
Local hinge angle (radians) relative to parent forward.
float totalLengthTo(int boneId) const
::ik::skeleton2d & native()
Definition Skeleton2D.h:56
::ik::ecs2d & state()
Definition Skeleton2D.h:57
Skeleton2D & operator=(const Skeleton2D &)=delete
float getY(int boneId) const
int getChildCount(int boneId) const
const ::ik::skeleton2d & native() const
Definition Skeleton2D.h:58
bool hasConstraints(int boneId) const
int getBoneCount() const
float getX(int boneId) const
void initStraightPose(float rootX=0.f, float rootY=0.f)
float getRotation(int boneId) const
int getParent(int boneId) const
void clearConstraints(int boneId)
float getOrientationX(int boneId) const
float getOrientationY(int boneId) const
void setConstraints(int boneId, float minAngle, float maxAngle)
Joint limits for the single 2D hinge DOF.
void setLength(int boneId, float length)
int createBone(int parentId, float length=1.f)
Create a child bone under parentId; returns new bone id.
const ::ik::ecs2d & state() const
Definition Skeleton2D.h:59
void setPosition(int boneId, float x, float y)
Skeleton2D(const Skeleton2D &)=delete
int getChild(int boneId, int childIndex) const