Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Custom Sphere to Landscape collision - Help please

Author
Message
Avan Madisen
22
Years of Service
User Offline
Joined: 12th Sep 2002
Location: The Castle Anthrax
Posted: 29th Sep 2004 01:00
The title only explains half my problem, so let me explain in a little detail.

My current 3d RPG project is using a lot of custom written functions. Such as a fractal landscape generator, a function to shift a mesh around and deform it to the landscape shape to create the illusion of a massive rolling landscape, a function to find the height of the ground at a given x/z co-ordinate and a function to find the intersection point of a straight line with the landscape, all using a custom written heightmap.

My problem is that I want to do collision between a sphere and the landscape to find not only whether a collision has occured, but approximately where it occured so I can consider collision response. Now, since the actual mesh only exists infront of the camera, I want to work it out from the heightmap data I'm using.

I realise that the simplest solution might be to transform the heightmap data into a mesh and use something like Nuclear Glory. Two problems are there:

1) It defeats the object of having a dynamic mesh to trick you into thinking the landscape is bigger then it really is.
2) Turning it into a mesh would result in over 8 million polys, calculating collision with that many polys is just a bit silly.

Now, since the entire landscape is basically a huge grid, I can work out exactly which grid squares the sphere is within the boundaries of, and I want to work the collisions from that. But I'm completely stuck as to how to perform the checks. I can work out a set of 9 squares totally 18 polys around the sphere that I could collide with but that leaves me with the original problem. I don't know how to work out the collision.

I've searched with google and found nothing but either useless pages, pages that require paid logins, or pages full of more mathmatical jargon then you could find in David Brabbem's note-book, oh and the odd porn page that google throws in for some reason.

I've also searched the cobebase here and found only some source code that unforunately uses DBPro's built in mesh collision functions, which requires a mesh to be setup.

If anyone can help, I'd appreciate it.

Thanks

Avan

I don't suffer from insanity:

I enjoy every minute of it!
mm0zct
21
Years of Service
User Offline
Joined: 18th Nov 2003
Location: scotland-uk
Posted: 29th Sep 2004 01:15
i have an idea but i'm not sure if it will work for you...

you know where the sphere is on the heightmap yes?

i asume you can work out the height of the landscape at that point using the colour of the pixel bellow the sphere

use the sphere's radius to see whether the bottom edge is below the landscape

http://www.larinar.tk
AMD athlon thoroughbred 2200, 512Mb ram, 40Gb HD, ati saphire radeon 9600 atlantis w/128mb ddr ram, good creative-labs soundcard, cd-rw + dvd drives.
Avan Madisen
22
Years of Service
User Offline
Joined: 12th Sep 2002
Location: The Castle Anthrax
Posted: 29th Sep 2004 06:35
Not that simple, mm0zct, because a sphere colliding with a slope is different to colliding with a level surface.

But "Sod's Law" attacked me, not long after I posted that message I came up with a possible solution. But I haven't tried it just yet.

Any further help will be appreciated though.

Avan

I don't suffer from insanity:

I enjoy every minute of it!
mm0zct
21
Years of Service
User Offline
Joined: 18th Nov 2003
Location: scotland-uk
Posted: 29th Sep 2004 08:37 Edited at: 29th Sep 2004 08:47
you'd have to do several checks at different points on the sphere,


tank a certain pont on the sphere, use it's x,z displacement from the centre of the sphere to find the pixel on the heightmap and then use maths to find the height of that point on the sphere, i'll draw a diagram to show you how

horizontal=sqrt(z^2+x^2)

height=sqrt(radius^2-horizontal^2)
http://www.lochviewwest.plus.com/likethis.JPG

http://www.larinar.tk
AMD athlon thoroughbred 2200, 512Mb ram, 40Gb HD, ati saphire radeon 9600 atlantis w/128mb ddr ram, good creative-labs soundcard, cd-rw + dvd drives.
Avan Madisen
22
Years of Service
User Offline
Joined: 12th Sep 2002
Location: The Castle Anthrax
Posted: 29th Sep 2004 20:33
My method of working out the collision was going to be to working out the normals of the land surface and use those to calculate the closest point of the sphere to the landscape and see if that has gone below the surface. It works but I've hit a major problem.

I'm using a fixed update speed that works independant to the frame rate using the timer. It's updating 100 times a second (originally 1000 but I quickly found that to be too slow) and the collision checks are being performed twice per update along with the other constraints. Now, since I'm going to have a lot of particles, about 256 at the moment, it works out that I'm performing the collision checks possibly more then 50 thousand times per second.

Without any collision checks, my system runs the game at 120fps.

Now, using a simple height check with the landscape (not very accurate) and the system went down to 80fps, a drop of 40fps which is about 33%, nasty in my opinion.

But using the more complicated method of using the normals, it shot down to 4 fps!

I'm going to rework the variable handling so it's all managed from memblocks rather then arrays to see how much extra speed that can give me, but I'm not banking on much!

Again, suggestions and ideas will be appreciated.

Avan

I don't suffer from insanity:

I enjoy every minute of it!

Login to post a reply

Server time is: 2025-05-31 01:41:38
Your offset time is: 2025-05-31 01:41:38