How to flip an iBillboardSceneNode

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Markuss
Posts: 20
Joined: Tue May 02, 2023 4:48 pm

How to flip an iBillboardSceneNode

Post by Markuss »

Im animating a sprite on an iBillboardSceneNode. Id like to be able to flip it horizontally when moving left. I was hoping for a flip function but I cant seem to find one?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How to flip an iBillboardSceneNode

Post by CuteAlien »

Yeah, a bit tricky as meshbuffers are mostly rebuild each frame.
In Irrlicht svn trunk you can now go over uv coordinates, like:

Code: Select all

		// Flip upside-down
		scene::IMeshBuffer* mb = billboard->getMeshBuffer(0);
		video::S3DVertex* vertices = static_cast<video::S3DVertex*>(mb->getVertices());
		u32 vertCount = mb->getVertexCount();
		for ( u32 v=0; v < vertCount; ++v )
		{
			vertices[v].TCoords.Y = 1.f - vertices[v].TCoords.Y;
		}
In Irrlicht 1.8 getMeshBuffer did not exist yet. So the only clean option there is copying the CBillboardSceneNode code, renaming it and creating your own SceneNode that way. Then give yourself access to the video::S3DVertex vertices[4]; in there. And do as in code above.


edit: Argh, forget all I wrote - it's all horrible, horrible, horrible!!!

The real solution - which works in Irrlicht 1.8 as well:

Code: Select all

billboard->getMaterial(0).getTextureMatrix(0).setTextureScale(1.f, -1.f);
Yeah... I totally forgot (and not for the first time) we have texture matrices
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Markuss
Posts: 20
Joined: Tue May 02, 2023 4:48 pm

Re: How to flip an iBillboardSceneNode

Post by Markuss »

Thank you so much!
Post Reply