matrix and shader question (demo example code)

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
RobinvK
Posts: 12
Joined: Thu Mar 10, 2011 1:22 pm

matrix and shader question (demo example code)

Post by RobinvK »

Hello everyone, I just went through all the code of the ‘Demo’ file included in the irrLicht examples and I have a few questions about it.
In the loadSceneData function there is the following bit of code:

Code: Select all

 core::matrix4 m;
		m.setTranslation(core::vector3df(-1300,-70,-1249));

		for ( i = 0; i!= scene::quake3::E_Q3_MESH_SIZE; ++i )
			sm->getMeshManipulator()->transform(quakeLevelMesh->getMesh(i), m);
 
I’m not sure what a ‘matrix4’ really is, but I do understand what this bit of code does. However, what is the advantage of doing this over doing the following?:

Code: Select all

 quakeLevelNode->setPosition(core::vector3df(-1300,-70,-1249)); 
The result seems the same, the only thing that changes is that the position of the node changes instead of the position of the mesh. Is there an advantage of using one thing over the other?


Later on in the function there is this bit of code:

Code: Select all

scene::IMesh * additional_mesh = quakeLevelMesh->getMesh ( scene::quake3::E_Q3_MESH_ITEMS );

		for ( i = 0; i!= additional_mesh->getMeshBufferCount (); ++i )
		{
			scene::IMeshBuffer *meshBuffer = additional_mesh->getMeshBuffer ( i );
			const video::SMaterial &material = meshBuffer->getMaterial();

			//! The ShaderIndex is stored in the material parameter
			s32 shaderIndex = (s32) material.MaterialTypeParam2;

			// the meshbuffer can be rendered without additional support, or it has no shader
			const scene::quake3::IShader *shader = quakeLevelMesh->getShader ( shaderIndex );
			if ( 0 == shader )
			{
				continue;
			}
			// Now add the MeshBuffer(s) with the current Shader to the Manager
			sm->addQuake3SceneNode ( meshBuffer, shader );
		}
It is clear what this does, it puts the flames and lava on the scene. But I don’t really understand why it works. So I guess that .bsp files are files that include several meshes. Accessing the fire and lava in this file is done with getMesh ( scene::quake3::E_Q3_MESH_ITEMS );. But what are they exactly, are the fire and lava animated meshes?
I guess every fire and lava mesh has it’s own buffer so that is where the for loop comes into place. (is this true?)
I have no idea what the code after that does though. All I know is that if I mess with it the flames and lava don’t get rendered. shaderIndex stores a value (the shader ID?) from ‘material’, but why is MaterialTypeParam2 used instead of MaterialTypeParam? Or better, how do I know which one to use?

After that shader is made. But what does it do? I know that the highlights on the walls in the map are done with the editing of the texture, so the shader doesn’t do anything there. I’ve searched around on the internet and I found this: http://www.heppler.com/shader/, but that doesn’t really clear things up for me either. Do shaders simply say how the device should render the fire and lava meshes?

Any help is appreciated! :)
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

the difference in the first case is that with the current code, the actual mesh's vertices are changed. That is, the object coord system's values are altered. With setPosition, the vertices are kept at their original places (usually centered around 0,0,0) and are only rendered at a different place (using the world matrix). Here, the mesh is moved to some other place, and you can render it at location 0,0,0 while it's not shown at the wrold center anymore.
The second part is basically correct as you got it. There are several meshes, which are loaded and kept in memory for q3 maps. There are some specific ways to access them, which are shown here and in example 16 and 21. If you want to use q3 maps, you should read that code in some detail, otherwise it's completely useless for you.
RobinvK
Posts: 12
Joined: Thu Mar 10, 2011 1:22 pm

Post by RobinvK »

Thanks! I got it now :)
I guess I'll first decide what modeller and world editor I am going to use before I delve into the details of Quake 3 maps.
Fabio451
Posts: 17
Joined: Sun Nov 08, 2015 4:50 pm

Re: matrix and shader question (demo example code)

Post by Fabio451 »

Hi.
How additional meshes and shaders, for example the flames in the demo, can be added to a bsp map?
Can GtkRadiant/NetRadiant do that?
Post Reply