axmol/extensions/fairygui/tween/GPath.h

66 lines
1.5 KiB
C
Raw Normal View History

2020-08-04 12:31:33 +08:00
#ifndef __GPATH_H__
#define __GPATH_H__
#include "FairyGUIMacros.h"
#include "cocos2d.h"
NS_FGUI_BEGIN
struct GPathPoint
{
enum class CurveType
{
CRSpline,
Bezier,
CubicBezier,
Straight
};
2022-08-08 18:02:17 +08:00
ax::Vec3 pos;
ax::Vec3 control1;
ax::Vec3 control2;
2020-08-04 12:31:33 +08:00
CurveType curveType;
2022-08-08 18:02:17 +08:00
GPathPoint(const ax::Vec3& pos);
GPathPoint(const ax::Vec3& pos, const ax::Vec3& control);
GPathPoint(const ax::Vec3& pos, const ax::Vec3& control1, const ax::Vec3& control2);
GPathPoint(const ax::Vec3& pos, CurveType curveType);
2020-08-04 12:31:33 +08:00
};
class GPath
{
public:
GPath();
void create(GPathPoint* points, int count);
void clear();
2022-08-08 18:02:17 +08:00
ax::Vec3 getPointAt(float t);
2020-08-04 12:31:33 +08:00
float getLength() { return _fullLength; }
int getSegmentCount() { return (int)_segments.size(); }
float getSegmentLength(int segmentIndex);
void getPointsInSegment(int segmentIndex, float t0, float t1,
2022-08-08 18:02:17 +08:00
std::vector<ax::Vec3>& points, std::vector<float>* ts = nullptr, float pointDensity = 0.1f);
void getAllPoints(std::vector<ax::Vec3>& points, float pointDensity = 0.1f);
2020-08-04 12:31:33 +08:00
struct Segment
{
GPathPoint::CurveType type;
float length;
int ptStart;
int ptCount;
};
private:
void createSplineSegment();
2022-08-08 18:02:17 +08:00
ax::Vec3 onCRSplineCurve(int ptStart, int ptCount, float t);
ax::Vec3 onBezierCurve(int ptStart, int ptCount, float t);
2020-08-04 12:31:33 +08:00
std::vector<Segment> _segments;
2022-08-08 18:02:17 +08:00
std::vector<ax::Vec3> _points;
2020-08-04 12:31:33 +08:00
float _fullLength;
};
NS_FGUI_END
#endif