frametime and character animation

Problems building or running the engine, queries about how to use features etc.
xantosbt
Gnoblar
Posts: 2
Joined: Sat Jul 19, 2025 11:50 am

frametime and character animation

Post by xantosbt »

Ogre Version: :14.3:
Operating System: :Win10:
Render System: :OpenGL:

Code: Select all

Ogre.log (optional)

Hi,
for learning purpose, I setup a simple Ogre Scene using the Application Skeleton (with OgreBites), as documented on the Site.
Right now, I'm experimenting a little bit with the animation system. Therefore, I succesfully imported a 3D character with an idle animation from Mixamo.
My character is rendered on the screen in Idle pose but fixed, without motion.
So, I'm stuck: how can I handle in code the elapsed frame time so the animation can be played continuously at runtime? Somewhere I red of a method called timesincelastframe but I don't undertand how it can be used.
Sorry for my lack of skills and I hope my explanation is stated the right way.
Thank in advance for you support, kindly regards.

paroj
OGRE Team Member
OGRE Team Member
Posts: 2238
Joined: Sun Mar 30, 2014 2:51 pm
x 1217

Re: frametime and character animation

Post by paroj »

xantosbt
Gnoblar
Posts: 2
Joined: Sat Jul 19, 2025 11:50 am

Re: frametime and character animation

Post by xantosbt »

Hi,
I found the tricks. I simply override FrameRenderingQueued class, as follows:

Code: Select all

class FrameRenderingQueued:public::Ogre::FrameListener
{

bool frameRenderingQueued(const Ogre::FrameEvent& fe) override
{
    anim_State->addTime(fe.timeSinceLastFrame);
    return true;
}

};

Now I have another question: is there in Ogre3d an input system? If I undestand correctly, OIS Api is no longer used.
I shoul'd like, for example, detect if W-key is pressed to trigger an action (run an animation or similar task).
I took a sneak peak in the API documentation, under OgreBites Keycode, but I didn't find what I mean.
Could you, please, point me in the right direction?
Thanks.

rpgplayerrobin
Orc Shaman
Posts: 788
Joined: Wed Mar 18, 2009 3:03 am
x 447

Re: frametime and character animation

Post by rpgplayerrobin »

It is now using SDL for input instead of OIS.

I agree that it is a bit more complex to set up (in my game I made an entire class for the SDL input in order to get it the way I want) but you can search for these places in the code:
keyPressed (especially things such as CameraMan::keyPressed or Sample_NewInstancing::keyPressed)
keyReleased
textInput

There is no function such as isKeyDown from what I can see (at least in my Ogre version), and in my own class I handle it myself from the keyPressed/keyReleased functions by setting the key state to true/false in my own hashmap variable, then I made my own isKeyDown function in order to be able to check if a key is currently down or not.

Here is my code for it (you can most likely just place it in the normal keyPressed/keyReleased/mousePressed/mouseReleased functions of a sample code):

Code: Select all

class CUnbufferedInputHashMapObject
{
public:
	CUnbufferedInputHashMapObject()
	{
		m_value = false;
		m_isEmpty = true;
	}

~CUnbufferedInputHashMapObject()
{
}

bool m_isEmpty;
bool m_value;
};
static std::unordered_map<CSDL_Keycode, CUnbufferedInputHashMapObject> m_unbufferedInputsHashMap;

class CUnbufferedInputHashMapObject_Mouse
{
public:
	CUnbufferedInputHashMapObject_Mouse()
	{
		m_value = false;
		m_isEmpty = true;
	}

~CUnbufferedInputHashMapObject_Mouse()
{
}

bool m_isEmpty;
bool m_value;
};
static std::unordered_map<int, CUnbufferedInputHashMapObject_Mouse> m_unbufferedInputsHashMap_Mouse;

typedef SDL_KeyCode CSDL_Keycode;

enum CSDL_MouseButton
{
	BUTTON_LEFT = 1,
	BUTTON_MIDDLE = 2,
	BUTTON_RIGHT = 3,
	BUTTON_X1 = 4,
	BUTTON_X2 = 5,
};

void CSDL::KeyPressed(const CSDL_KeyboardEvent& evt)
{
	CSDL_Keycode tmpKeyCode = (CSDL_Keycode)evt.keycode;
	CUnbufferedInputHashMapObject& tmpUnbufferedInputHashMapObject = m_unbufferedInputsHashMap[tmpKeyCode];
	tmpUnbufferedInputHashMapObject.m_isEmpty = false;
	tmpUnbufferedInputHashMapObject.m_value = true;

app->KeyPressed(evt);
}

void CSDL::KeyReleased(const CSDL_KeyboardEvent& evt)
{
	CSDL_Keycode tmpKeyCode = (CSDL_Keycode)evt.keycode;
	CUnbufferedInputHashMapObject& tmpUnbufferedInputHashMapObject = m_unbufferedInputsHashMap[tmpKeyCode];
	tmpUnbufferedInputHashMapObject.m_isEmpty = false;
	tmpUnbufferedInputHashMapObject.m_value = false;

app->KeyReleased(evt);
}

bool CSDL::IsKeyDown(CSDL_Keycode key)
{
	CUnbufferedInputHashMapObject& tmpUnbufferedInputHashMapObject = m_unbufferedInputsHashMap[key];

if (tmpUnbufferedInputHashMapObject.m_isEmpty)
	return false;

return tmpUnbufferedInputHashMapObject.m_value;
}

void CSDL::MousePressed(const CSDL_MouseButtonEvent& evt)
{
	CUnbufferedInputHashMapObject_Mouse& tmpUnbufferedInputHashMapObject_Mouse = m_unbufferedInputsHashMap_Mouse[(int)evt.button];
	tmpUnbufferedInputHashMapObject_Mouse.m_isEmpty = false;
	tmpUnbufferedInputHashMapObject_Mouse.m_value = true;

app->MousePressed(evt);
}

void CSDL::MouseReleased(const CSDL_MouseButtonEvent& evt)
{
	CUnbufferedInputHashMapObject_Mouse& tmpUnbufferedInputHashMapObject_Mouse = m_unbufferedInputsHashMap_Mouse[(int)evt.button];
	tmpUnbufferedInputHashMapObject_Mouse.m_isEmpty = false;
	tmpUnbufferedInputHashMapObject_Mouse.m_value = false;

app->MouseReleased(evt);
}

bool CSDL::IsMouseDown(CSDL_MouseButton mouseButton)
{
	CUnbufferedInputHashMapObject_Mouse& tmpUnbufferedInputHashMapObject_Mouse = m_unbufferedInputsHashMap_Mouse[(int)mouseButton];

if (tmpUnbufferedInputHashMapObject_Mouse.m_isEmpty)
	return false;

return tmpUnbufferedInputHashMapObject_Mouse.m_value;
}
paroj
OGRE Team Member
OGRE Team Member
Posts: 2238
Joined: Sun Mar 30, 2014 2:51 pm
x 1217

Re: frametime and character animation

Post by paroj »