Question about setTransform() method.
Question about setTransform() method.
The Irrlicht doc describes setTransform() method of IVideoDriver very shortly. Only the fact it sets some transformation matrices and their types. But it's quite unclear when and what those matrices are applied for. I guess it is similar with how setMaterial() works, i.e. it sets each type of matrix globally and apply it while working with vector3d/vector2ds, changing positions/rotations/scales of scene nodes. But it's also vague in which cases the world matrix, in which cases the projection matrix and also the view matrix are used. Can anybody please explain me thoroughly? Also, I don't understand what are texture matrices (ETS_TEXTURE_0, ETS_TEXTURE_1, ETS_TEXTURE_2, ETS_TEXTURE_3).
Re: Question about setTransform() method.
Those matrices are used when drivers (like OpenGL, D3D, Software) draw/render something. Then the active world/view/projection matrices are applied to the vertices send to the graphic card.
In Irrlicht, in most cases, the SceneManager cares about that for you and you don't have to set them yourself.
SceneNodes usually set the world-matrix (aka node position, how they are rotated/scaled).
CameraSceneNodes set the view matrix (camera position, where it looks at and which side is up)
And CameraSceneNodes also set the projection matrix (near/far planes, field of view, width/height aspect ratio... it's defining the so called frustum).
And in their render() functions the scenenodes then call driver->setTransform.
You do need to set matrices when you work with the IVideoDriver draw function directly. Like drawing 3d lines. Or writing your own SceneNodes. Otherwise whatever matrix is active at that point would be used by the draw functions. You can think of IVideoDriver as the lowest level wrapper in Irrlicht around the platform drivers (like OpenGL, Direct3D). Some people ignore nearly everything else (like everything in scene::) and just work with that.
The texture matrices come from the active material. So you don't set those directly, but call setMaterial() instead which creates them from the texture transformation matrix you have set (or not set in which case no special transformation is applied). And the draw functions will then use the active material to set ETS_TEXTURE_0-x.
Texture matrices are (in the fixed function pipeline) applied to the uv coordinates of your textures. In shaders you have to care yourself about them and can do whatever you want (but in generally you pass them to the shader and apply them to the uv coordinates again).
Another case where you need matrices is to read them out in shaders. Often you will get the current matrices (sometimes including texture matrices) in the OnRender function of the shader callback and pass it on to the shader code.
In Irrlicht, in most cases, the SceneManager cares about that for you and you don't have to set them yourself.
SceneNodes usually set the world-matrix (aka node position, how they are rotated/scaled).
CameraSceneNodes set the view matrix (camera position, where it looks at and which side is up)
And CameraSceneNodes also set the projection matrix (near/far planes, field of view, width/height aspect ratio... it's defining the so called frustum).
And in their render() functions the scenenodes then call driver->setTransform.
You do need to set matrices when you work with the IVideoDriver draw function directly. Like drawing 3d lines. Or writing your own SceneNodes. Otherwise whatever matrix is active at that point would be used by the draw functions. You can think of IVideoDriver as the lowest level wrapper in Irrlicht around the platform drivers (like OpenGL, Direct3D). Some people ignore nearly everything else (like everything in scene::) and just work with that.
The texture matrices come from the active material. So you don't set those directly, but call setMaterial() instead which creates them from the texture transformation matrix you have set (or not set in which case no special transformation is applied). And the draw functions will then use the active material to set ETS_TEXTURE_0-x.
Texture matrices are (in the fixed function pipeline) applied to the uv coordinates of your textures. In shaders you have to care yourself about them and can do whatever you want (but in generally you pass them to the shader and apply them to the uv coordinates again).
Another case where you need matrices is to read them out in shaders. Often you will get the current matrices (sometimes including texture matrices) in the OnRender function of the shader callback and pass it on to the shader code.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Question about setTransform() method.
Thanks for the detailed reply! Only I've not quite got about which matrices the draw functions use. As I understand only the world ones? Or in some cases still the view and projection?
Re: Question about setTransform() method.
All 3d drawing functions. Every vector send to the graphic-card will use the model-view-projection matrix. Every uv will use it's texture matrix. At least when using fixed function pipeline. If you code shaders you have to do it all yourself (but you can get them all from the Irrlicht driver). Note: With hardware drivers it's not Irrlicht doing the vector transformations - it's happening on the graphic card. Irrlicht says: "Use those matrices" and every vector send to the card will use those in it's build-in vector shaders (or however cards do that, maybe even in hardware?).
The 2d drawing functions will set other matrices which allow using 2d coordinates which correspond to pixels. And as far as I can see Irrlicht gives no way to access them (well, using OpenGL functions would get them, but Irrlicht matrices don't seem to be affected). Which I guess makes coding 2d material shaders a bit tricky (something I'm aware of, but very low on my todo list for now).
The 2d drawing functions will set other matrices which allow using 2d coordinates which correspond to pixels. And as far as I can see Irrlicht gives no way to access them (well, using OpenGL functions would get them, but Irrlicht matrices don't seem to be affected). Which I guess makes coding 2d material shaders a bit tricky (something I'm aware of, but very low on my todo list for now).
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm