Page 1 of 1

Terrain dependent friction

Posted: Fri Jun 16, 2006 10:52 pm
by Hixxy
For my university project we're creating a bike simulator which is a cross between an arcade game and an exercise bike where you can steer through a 3d course but have to pedal to provide your speed along the way (uphill being harder and downhill freewheeling etc).

Having figured out the whole blender-Irrlicht .x export problems it's all going well except for one feature:

Terrain dependent friction.

Instead of using a TerrainSceneNode we're creating a mesh of a terrain in Blender and texturing different uv faces differently (ie road and grass). We're using a triangle selector to determine the angle of the ground the bike is on and hence the force (and acceleration) this creates. I was then hoping to use "GetMaterial" to determine the texture of the triangle and hence use it to alter our value for friction if it's on road or grass but it seems I misunderstood the function completely.

Having searched the forums I found a post from december:

(http://irrlicht.sourceforge.net/phpBB2/ ... ap+texture)

This asks about getting the texture of a whole terrainSceneNode but no answer was found and our problem is even more specific in needing to know which texture covers which triangle.

I can use

slope_node->getMaterial(1).Texture1 = driver->getTexture("../media/test2.bmp");
slope_node->getMaterial(2).Texture1 = driver->getTexture("../media/test3.bmp");

to change all the two individual textures so was wondering if it's in any way posible to determine which ones apply to which triangles? filenames aren't a problem, all we need is simply some kind of flag (number etc) to tell the difference between the two?

Thanks in advance,

Hixxy.

Posted: Sat Jun 17, 2006 1:25 am
by bitplane
unfortunatley, vertex and texture coordinate information is not stored within the triangles returned by a triangle selector.
I think your best option is to copy the code to the (oct-tree?) triangle selector and make a new one that stores a reference to the mesh buffer (sub-mesh) number, and the position (index of the vertex in the array) for each point added.
You can then use the mesh buffer number to check the material (and therefore texture layers), and the indices to get the texture coordinates, colour and alpha channel of each selected vertex. I would add this as an extra function rather than break the interface (for example an extra member function called getLastSelectedTriangleDetails which populates 4 integers)

I think a lot of people would find this very useful for games (different surfaces make different footstep sounds, different types of decals for bullet holes and scratches etc), so we'd be very grateful if you shared the source to such a handy new selector. :)

Posted: Sat Jun 17, 2006 3:18 pm
by TheGameMaker
maybe, if your terrain is a recagel, you can do a second image, whith different colors, get the relatif position on the terrain and projekt it onto the images and then read the next Pixel....

Code: Select all

^ Y
|*************   lets say this ist the terrain and the 8 is the bike.
|*************   then lets say the top left pos of the terrain lays at 0;0;0
|*************   ever dot is a step of 1
|********8****   that means the bike is at position 4;9 realativ to the 
|*************   terrain. The terrain is 5; 13 big. the relativ pos of the 
|------------------>X
bike is 4/5;9/13   the result is a nummer between 0 and 1 for X and Y.
now lets say our grafik is 400*900 pixel big, then multiply the Xvalue with the pixel hight of the img and the Y value with the widht of the img. The int of this numbers are the pixelcoordinates of the bike.. 
I think the rest is easy,
TGM

Posted: Sat Jun 17, 2006 10:07 pm
by Hixxy
I've only got til wednesday to finish the code so I think using a seperate image to look up friction values will be the best solution for now unless I can get anywhere with Bitplane's suggestion in the next day or so.

I hadn't considered that the same method could be used for sounds / decals so if I have time after it's due in I might try and implement it just for personal satisfaction and if I'm succesful the I'll post the code.

Any extra pointers on how to implement the modified triangle selector would be grately appreciated.

Cheers,

Hixxy.

Posted: Sun Jun 18, 2006 2:16 am
by bitplane
I've had a look at this and cant think of a clean way to do it without adapting the collision manager and triangle selectors, or introducing interface breaking changes. :?

Posted: Mon Jun 19, 2006 1:56 pm
by sudi
Use newton it already has a material system pluged in.

Posted: Fri Jul 14, 2006 5:03 am
by Shakira22
really ? :) :)