How to create a triangle using a SMeshBuffer?

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
mitras1
Posts: 10
Joined: Mon Jan 29, 2024 8:02 am

How to create a triangle using a SMeshBuffer?

Post by mitras1 »

.
CuteAlien
Admin
Posts: 9644
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How to create a triangle using a SMeshBuffer?

Post by CuteAlien »

Maybe check example 23.MeshHandling. The part where it fills the meshbuffer is in the addstrip function.

But in short: Meshbuffers have Vertices, Indices and a Material and you need to set those all.

Vertices are usually in the S3DVertex format and set the 3 corners of your triangle. Or 4 corners of a quad, etc.
Indices are, as the name says, indices into your Vertex array. So they the give the order in which those vertices are used. For a triangle it's probably the number 0,1,2. For a quad - where you have 4 vertices you will probably use 2 triangles. So you need 6 indices (each triangle always as 3) which can be like: 0,1,2, 2,3,0. Note that the order matters to decide which side of the polygon is front and back. Irrlicht has clockwise ordering I think (and a left-handed coordinate sytem).

As for the Material - it often helps by starting with Lighting set to off. Then you don't have to worry if something is invisible because it's not in your light or because you messed up otherwise ;-)
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
Post Reply