piotr.karkocha Posted October 31, 2019 Posted October 31, 2019 Hi, following some of the tutorials, like using custom component system, I made a property for animating a rotation of an object. Unfortunatelly it does not work at all. Could you please have a look at the code: Rotator.h #pragma once #include <UnigineNode.h> #include <UniginePhysics.h> #include "../../ComponentSystem/ComponentSystem.h" #include "Players/VRPlayer.h" class Rotator : public ComponentBase { public: COMPONENT(Rotator, ComponentBase); COMPONENT_INIT(init); COMPONENT_UPDATE(update); // property PROP_NAME("Rotator"); PROP_AUTOSAVE(0); PROP_PARAM(Float, animation_speed, 0.5f); PROP_PARAM(Float, turn_speed, 30.0f); PROP_PARAM(Float, acceleration, 5.0f); protected: void init(); void update(); private: float start_turn_speed = 10; }; Rotator.cpp #include "Rotator.h" #include <UnigineGame.h> #include <UnigineEditor.h> REGISTER_COMPONENT(Rotator); using namespace Unigine; using namespace Math; void Rotator::init() { start_turn_speed = turn_speed; } void Rotator::update() { float ifps = Game::get()->getIFps(); turn_speed = turn_speed + acceleration * ifps; node->setRotation(node->getRotation() * quat(0, 0, turn_speed * ifps)); } What am I doing wrong? Best pio The object i´m trying to animate is a dynamic mesh.
fox Posted November 1, 2019 Posted November 1, 2019 Hi Piotr, Perhaps you've forgotten to initialize the Component System by adding the following code to the AppSystemLogic.cpp: int AppSystemLogic::init() { // ... // initialize ComponentSystem and register all components ComponentSystem::get()->initialize(); return 1; } As the Component System is initialized, you can add the Rotator component to your node via code like this: int AppWorldLogic::init() { //... // get your node by name - e.g. "DynamicMesh" NodePtr node = Editor::get()->getNodeByName("DynamicMesh"); // add the Rotator component to your node ComponentSystem::get()->addComponent<Rotator>(node->getNode()); return 1; } And your code should work fine. Hope this helps! Thanks!
piotr.karkocha Posted November 5, 2019 Author Posted November 5, 2019 Hi Fox, my project is based on the VR Sample, so the component system is already initialized. I also have assigned the property to the node in the editor, so this should work too. But the object does not rotate. So I guess the problem must be somewhere else....
fox Posted November 7, 2019 Posted November 7, 2019 Glad to hear that, Piotr! Just wanted to ask you for a small sample, cause in case of using the VR Sample I've got everything working fine )) Thanks!
Recommended Posts