Page 1 of 3

Skidmarks

Posted: Mon Sep 25, 2006 6:43 pm
by kallaspriit
I'm trying to implement skidmarks into my little racing-game but I'm having problems. I can determine tire contacts and store them when the currect wheel is skidding but I don't know how to continue. I can also add these point after a relatively similar distance - if the contact is too near to the last one, it wont be added. I have read about decals but haven't had much success implementing them or maby there are some other methods for dealing this.

Some screenshots from the debug display (even Chuck got onto the picture :lol:):
Image
Image


Any help is very welcome :)

Posted: Mon Sep 25, 2006 7:37 pm
by omaremad
wow nice phsics and car model. also store the wheel rotation at that moment of time at every "skid node" then add a rectangular mesh (planar) in that position with that rotaion with the same normal as the ground. if these skid nodes are equidistant as you have already programmed them to be, you wont have to link each skid rectangle(ie join their vertices up)

You have done most of the hard stuff, for aligning to the normal look at the tech demo source, look at how the particle for the impacts is aligned to the normal of the collided triangle.

Posted: Tue Sep 26, 2006 7:52 pm
by kallaspriit
I am having problems with the math. First of all arranging the decals by wheel positions wouldnt work - if your wheels are turned out but the car is going straight, the decals would not be rotated correctly. I'm thinking of calculating the angle by the previous decal position, so they would face each other, but I haven't succeded to do it even in 2d as if the ground was always even. I was thinking something like this:
Image
But this wouldn't apply in 3d anyway. I know I suck with 3d math :oops:

Any ideas? :P

Posted: Tue Sep 26, 2006 8:43 pm
by andrei25ni
kallaspriit,

That is my map and that is the vehicle I used in my game. I guess part of the code it's mine too.

I'm intending to make this project ( Supremacy Errands) commercial in the future, so please DO NOT distribute your game with my map.

You can use it for testing purposes though. I just wanted to make these things clear.

Thank you.

Posted: Wed Sep 27, 2006 4:27 am
by kallaspriit
I found both models in google and I'm sorry if it is yours. It is just a testing platform and used for learning purposes only. If anyone knows a good public city or racetrack model in a reasonable format, then I would be happy to switch :P

Anyone has ideas about the topic? :(

Posted: Wed Sep 27, 2006 5:51 am
by vitek
Assuming you can easily get the normal of the terrain and the direction that the tire was sliding, you should be able to easily orient a decal to line up correctly.

Code: Select all

// parameter is the position of the start of the skid mark
const core::vector3df pos1;

// parameter is the position at the end of the skid mark
const core::vector3df pos2;

// parameter is the normalized normal of the plane the skid mark is on
const core::vector3df normal;

// parameter is the width scale factor to apply to each decal
const f32 width;

// direction of the skid
core::vector3df direction(pos2 - pos1);
direction.normalize();

// vector from pos1 to side of decal
core::vector3df side = normal.crossProduct(direction);

// scale the width vector to make decal wider/narrower
side *= width;

// you could set A and B to be the last to coordinates of the previous skid mark section.
// that would avoid splitting or overlap when a skid section is rotated. it also complicates the code a little.
const core::vector3df A = pos1 - side;
const core::vector3df B = pos1 + side;
const core::vector3df C = pos2 + side;
const core::vector3df D = pos2 - side;

const video::SColor color(255, 255, 255, 255);

Vertices[0] = video::S3DVertex(A.X, A.Y, A.Z, normal.X, normal.Y, normal.Z, color, 0.f, 1.f);
Vertices[1] = video::S3DVertex(B.X, B.Y, B.Z, normal.X, normal.Y, normal.Z, color, 1.f, 1.f);
Vertices[2] = video::S3DVertex(C.X, C.Y, C.Z, normal.X, normal.Y, normal.Z, color, 1.f, 0.f);
Vertices[3] = video::S3DVertex(D.X, D.Y, D.Z, normal.X, normal.Y, normal.Z, color, 0.f, 0.f);
For efficiency you will probably want to make one scene node that has a mesh buffer that is used to manage the skid marks. Once the vertices are setup you don't need to touch them. After some time, or maybe after so many decals are laid out, you will need to start recycling vertices in the mesh buffer.

Posted: Wed Sep 27, 2006 11:13 am
by ProSoft
I have made a similar scenenode, but never finished it coz i have a math problem i cannot solve. I need to store a new point only if the angle btw the last two points and the current tire position is greater than, lets say, 5 degrees. This way, stored points become near when turning a curve and far when car dont steer. Currently, stored points is all the same distance. This makes storing a great number of points if you choose a near distance or a poor quality decal if you choose a far distance.

Image

If you interested, i can share my code.

Posted: Wed Sep 27, 2006 8:23 pm
by kallaspriit
Thanks for the tips. I would like to see your code too ProSoft, maby someone else can learn from it too. I'm going to try vitek's code tomorrow and let you know how it goes :P

Posted: Thu Sep 28, 2006 12:50 pm
by ProSoft
I solved all ( known ) problems i got. You can download RibbonTrailSceneNode here

http://br.geocities.com/paulo_cmv/

You can find a lot of info at top of .h file. Feel free to test others scenenodes i have written. CLODSceneNode, CQuadTreeSceneNode, CLensFlareSceneNode.

Posted: Thu Sep 28, 2006 6:11 pm
by kallaspriit
Tried to download it but there is an error:
Desculpe, este site estА temporariamente indisponМvel!
Cant really understand a word of this language but maby you could host the RibbonTrailSceneNode somewhere else :wink:

Posted: Sat Sep 30, 2006 9:55 am
by kallaspriit
I'm unable to get it to work :(

I have tried several ways but nothing seems to work. At best I got it to display a debug line between the points added but no textures. This is basicly the demo shown in the header file that does not work for me (skid.jpg is a 64x64 image of skidmark):

Code: Select all

RibbonTrailSceneNode* skid = new RibbonTrailSceneNode(iDevice, sManager->getRootSceneNode());
	
	skid->setMaterialTexture(0, vDriver->getTexture("textures/skid.jpg"));
	skid->setPoint1(core::vector3df(5, 0, 0));
	skid->setPoint2(core::vector3df(-5, 0, 0));
	skid->setMaxDistance(3);
	skid->setStartingAlpha(0);
	skid->setShowDebug(true);
    skid->setEnabled(true);
I must be missing something :cry:

Posted: Sat Sep 30, 2006 3:19 pm
by jimowns
wow cool kallaspriit :)
nice screens .

but what illricht version you use for that game ?


jim

Posted: Sat Sep 30, 2006 5:13 pm
by kallaspriit
I'm using the latest version of irrlicht and the textures and everything are very low quality because my pc is a piece of **** :lol:

Anyway I posted a working demo of it in NGD forums in this thread

Or if you don't want to register to see it, then it went like this:

During my testing with newton and the vehicle component, I made a small application simulating a vehicle. Basicly you can just drive around a small city . It features a well-tuned car with simulated manual gearbox including torque curve, automatic clutch, optional traction control and so on. It's just 5,52 MB so give it a try and tell me what do you think :P

The controls are:

ESC - exit

C - toggle follow camera
R - reset car position
P - place car at the start pos
T - toggle traction control
N - make a new vehicle

F1 - toggle show collisions
F2 - toggle show contacts
F3 - toggle show data
F4 - make a pile of boxes
F5 - throw a box
F6 - create a big terrain under the city (take a while)

wheel mouse - change car power (press F3 to see the percent)
arrows - steer and accelerate/brake the car
A - shift up
Z - shift down
ENTER - change drive type (4WD/FWD/RWD) (press F3 to see current)
SPACE - handbrake

Download | 5,52MB

ImageImage

Enjoy

Posted: Sat Sep 30, 2006 8:54 pm
by jimowns
its realy nice game you maked :)

its realy cool but i like race games :p

Posted: Sat Sep 30, 2006 10:43 pm
by ProSoft
kallaspriit:

Code: Select all

skid->setStartingAlpha(0); 
means you using our alpha at startup with value 0 ( completely transparent ).

you can use a starting alpha greather then 0, i sugest 100..200
also, i only tested it in DirectX, but i guess it will work well in OpenGL