accurate surface detection

Blitz3D Forums/Blitz3D Programming/accurate surface detection

Slomas(Posted 2011) [#1]
Here’s a problem I’ve been wrestling with for hours- I’m usually determined to figure it out myself but have found that humbly admitting defeat by asking for help here can be very educational!


I’m writing a ‘stunt car racer’ game- if anyone knows the old PC game where a car makes ridiculous jumps etc on a roller coaster race track- great fun but I wanted to make a better higher performance version.

I’m trying to get a really nice realistic interaction between the four wheels and the track surface- with independent suspension etc- which I have achieved before on a terrain- but I can’t use a terrain for nice sharp complex shapes like loops etc- so I’m using a .3ds mesh for the track…

Re. surface detection; The Blitz collision detection is too crude- and the MeshsIntersect far too slow-

So what I have is a camera parented to each wheel- they point downwards at small yellow cube entities which are also parented to the wheels and positioned/offset to where the rubber should meet the road. Using ReadPixelFast- the cameras can detect whether the yellow cube-and hence wheel, has sunk below the road surface.

Using a very small viewport for each camera- this is a very fast method, but I really need a way to return HOW FAR the cube has sunk. I can make an estimate based on speed/rate of fall of the car to get a reasonable result-
but that’s just a little messy and unsatisfying, and does not allow for precise detection/ accurate interaction with irregular shapes on the mesh.

Basically - is there any way for a camera to detect the distance to the closest surface in front of it?-
Sorry- I guess I could have just put the question that way instead!!

Any help much appreciated!

Steve


Rroff(Posted 2011) [#2]
I'd have thought you'd be better off looking at physics engines, tho JVODE is one of teh better ones for Blitz its default vehicle model is a bit clunky, tho I'm pretty sure with a bit of work its possible to get something decent out of it.


Warner(Posted 2011) [#3]
If you want to get the z-value of a certain pixel, you could enable fog mode on a camera. The further away something is, the darker it gets.
But then again, it might be better to use the picking commands. There is a command, called PickedTime which returns the distance to the closest triangle.

That said, I agree with Rroff, physics engine might be easier for creating car physics.


Slomas(Posted 2011) [#4]
Thanks- I was wondering about the picking commands but there wasn't any description for them in command references-

and since some of the triangles are quite large- e.g. on a flat piece of track- I'm not sure if it'll be accurate enough but I'll give it a try-

I'll try the fog too- enabled just for the wheel cams, but is there a way to convert the 'readpixelfast' code into a nice usable scale like the RGB info that GetColor? returns (the latter being too slow to use)


I enjoy working on the physics parts- gives me better control, just the surface detection has me stumped-

Thanks


Slomas(Posted 2011) [#5]
Just to follow up-

After a quick test, the LinePick / PickedTime method looks like it will work beautifully- does exactly what I need & doesn't seem to cost anything in frame rate- and I can loose the wheel cams (thought I was being clever with those!)

never would have stumbled on that- many thanks


Rroff(Posted 2011) [#6]
Function rgb2int(r,g,b,a=255)
	Return b Or (g Shl 8) Or (r Shl 16) Or (a Shl 24)
End Function

Function int2r(in)
	Return (in Shr 16) And $ff
End Function

Function int2g(in)
	Return (in Shr 8) And $ff
End Function

Function int2b(in)
	Return in And $ff
End Function


For converting long int color values to rgb and vice versa (origins of this code were by someone else forgotten who tho its been so long).

Last edited 2011


Slomas(Posted 2011) [#7]
Saved it thanks

That's going to come in very handy for speeding up an image processing program I was working on for Astrophotography-

Right now I'm having way too much fun with the car suspension-
a rare moment of programming gratification..

I should really come here more often!