51 _animations(nullptr), _animId(0), _animFrame(0) {
57 auto *rayTexture =
static_cast<RayTexture *
>(texture);
58 raylib::Model &model = _mesh.
handle();
59 for (
int i = 0; i < model.materialCount; i++) {
60 raylib::SetMaterialTexture(&model.materials[i], raylib::MATERIAL_MAP_DIFFUSE, rayTexture->handle());
70 return _animations ? _animations->getSize() : 0;
76 _last = frameCount() > 0 ? frameCount() - 1 : 0;
83 if (frameCount() == 0)
86 const bool wrapped = (_animFrame >= _last);
88 _animFrame = wrapped ? _first : _animFrame + 1;
94 const int frames = frameCount();
98 _first = clamp(first, frames);
99 _last = clamp(last, frames);
101 std::swap(_first, _last);
109 if (frameCount() == 0)
112 _animFrame = (frame < _first || frame > _last) ? _first : frame;
121 return {_position.x, _position.y, _position.z};
125 _position = {float(position.
x), float(position.
y), float(position.
z)};
129 return {_rotation.x, _rotation.y, _rotation.z};
133 _rotation = {float(rotation.
x), float(rotation.
y), float(rotation.
z)};
134 _mesh.handle().transform = raylib::MatrixRotateXYZ(
135 (raylib::Vector3){DEG2RAD * _rotation.x, DEG2RAD * _rotation.y, DEG2RAD * _rotation.z});
139 raylib::BoundingBox box = _mesh.boundingBox();
140 raylib::Vector3 s = {box.max.x - box.min.x, box.max.y - box.min.y, box.max.z - box.min.z};
141 return {s.x * _scale.x, s.y * _scale.y, s.z * _scale.z};
145 raylib::BoundingBox box = _mesh.boundingBox();
146 raylib::Vector3 s = {box.max.x - box.min.x, box.max.y - box.min.y, box.max.z - box.min.z};
147 if (s.x == 0 || s.y == 0 || s.z == 0)
return;
149 _scale.x = size.
x / s.x;
150 _scale.y = size.
y / s.y;
151 _scale.z = size.
z / s.z;
157 static int clamp(
int frame,
int frames) {
158 return frame < 0 ? 0 : (frame >= frames ? frames - 1 : frame);
162 raylib::UpdateModelAnimation(_mesh.
handle(), *(_animations->
handle() + _animId), _animFrame);
165 int frameCount()
const {
166 if (!_animations || _animId < 0 || _animId >= _animations->getSize())
168 return (_animations->handle() + _animId)->frameCount;
172 raylib::Vector3 _rotation;
173 raylib::Vector3 _position;
174 raylib::Vector3 _scale;
175 RayAnimationSet *_animations;
Raylib AnimationSet class - owns the loaded clips, independent of any RayModel bound to it.
Definition RayAnimationSet.hpp:26
raylib::ModelAnimation * handle() const
Definition RayAnimationSet.hpp:54
Raylib Mesh class - owns the loaded geometry (raylib's own Model struct is the mesh+material data,...
Definition RayMesh.hpp:26
raylib::Model & handle()
Definition RayMesh.hpp:42
int getAnimationsSize() const override
Definition RayModel.hpp:69
int getFirstFrame() const override
Definition RayModel.hpp:105
Vector3f getSize() const override
Definition RayModel.hpp:138
void setFrameRange(int first, int last) override
Restricts playback to [first, last] of the current clip.
Definition RayModel.hpp:93
void setAnimations(graphic::IAnimationSet *animations) override
Definition RayModel.hpp:64
void setTexture(graphic::ITexture *texture) override
Definition RayModel.hpp:56
Vector3f getPosition() const override
Definition RayModel.hpp:120
void setFrame(int frame) override
Definition RayModel.hpp:108
void setRotation(Vector3f rotation) override
Definition RayModel.hpp:132
friend class RayWindow
Definition RayModel.hpp:154
Vector3f getRotation() const override
Definition RayModel.hpp:128
void setPosition(Vector3f position) override
Definition RayModel.hpp:124
bool updateAnimation() override
Steps one frame forward inside the current range.
Definition RayModel.hpp:82
void setSize(Vector3f size) override
Definition RayModel.hpp:144
RayModel(RayMesh &mesh)
Definition RayModel.hpp:50
void setAnimation(int pos) override
Definition RayModel.hpp:72
int getFrame() const override
Definition RayModel.hpp:116
int getAnimation() const override
Definition RayModel.hpp:79
int getLastFrame() const override
Definition RayModel.hpp:106
Raylib Texture class - owns the GPU texture. RaySprite/RayModel only reference it,...
Definition RayTexture.hpp:26
raylib::Texture2D handle() const
Definition RayTexture.hpp:45
A file's loaded animation clips, independent of any IModel bound to it - deleting every bound IModel ...
Definition IAnimationSet.hpp:26
Model interface.
Definition IModel.hpp:27
Loaded pixel data, independent of any ISprite that references it. Deleting every ISprite built from a...
Definition ITexture.hpp:23
Vector3< double > Vector3f
Definition Vector3.hpp:121
Definition RayModel.hpp:16
T x
Definition Vector3.hpp:21
T y
Definition Vector3.hpp:21
T z
Definition Vector3.hpp:21