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});
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};
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;
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
int getSize() const override
Definition RayAnimationSet.hpp:42
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
raylib::BoundingBox boundingBox() const
Definition RayMesh.hpp:46
Raylib Model class - references a RayMesh, does not own it.
Definition RayModel.hpp:47
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
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
Vector3f getRotation() const override
Definition RayModel.hpp:128
void setPosition(Vector3f position) override
Definition RayModel.hpp:124
bool updateAnimation() override
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 Window class - a single concrete class implementing IWindow3 fully (which already IS-A IWindow...
Definition RayWindow.hpp:37
Definition RayModel.hpp:16