Following a bitmapped wall

I’m not sure where to put this exactly, but this forum seems to be the most appropriate.

I’m making a clone/update to the classic game Qix. The thing I’ve added is that when drawing, the player has simple verlet-based physics, so he slides around and makes curves and neat stuff like that. When not drawing however, the player is restricted to the outline of the shape he’s drawn. I keep the drawn area as a bitmap, so the more general problem is I want to keep the player in an area defined by a bitmap and allow for the player to slide along the edge of the area.

I’ve got an example below. The player - represented by the lovely Vanessa - moves downwards towards the black-off-limits area. She’s working under standard physics and accelerating as she goes (I’m still pushing the button). When she hits the black area, I want her to follow the curve (red arrow). I can get her to stop dead, but I can’t figure out how to get her to follow the curve.

Have any of you worked on a similar problem and can offer some help? This one puzzle’s had me stumped for a month or so.

Thanks,
Del.

an idea:

each frame or whatever
check the pixel underneatch the player to see if it is black, if is is then you need to check the height of the columns of pixels either side of that pixel, vannesa will follow the go onto the lowest collumn. And if both heights are the same either side then u need to take into account the current speed(veloctity) to see which direction to go in.

EDIT: i see the line goes up after it goes down :confused: well maybe just keep a pixel just beneath vannesa on black pixels but make sure it has a white pixel ontop of it and keep going in the current direction.

Well, I think there might some confusion in that I have no bounding box and it’s just one pixel in the middle of vanessa. Because of the verlet, that pixel can traverse through a lot of black in a single frame at top speed.

We want the pixel to stay in the white and keep spped when it hits a black region, changing direfction if necessary.

Theres no easy standard way of doing this. But the way I would handle it is by finding the nearest white pixel from the CM, create a virtual spring with enough dampness and a default length size of 0 between the current position and the white pixel. Solve that spring once. What that will do is create a big enough force to get the CM to the white pixel over a period of time (depends on dampness…etc).

But for this to work effectively, the collision detection and white pixel finding needs to happen at every step and preferably at a good FPS too.

DP

Hm. The collision detection can be done with the bresenham line algorithm… you just “plot” the pixels from start to end (this frame to next frame) and check those few pixels for a collision. Then you have to average the surrounding pixels somehow for determining the collision normal.

That “averaging” is a bit hard to explain… well, you can hit a pixel from left, top, right or bottom… and… well, just take a look…

http://kaioa.com/k/pixelavgnormal.png

Basically wall-follwoing. Going x to the left and x to the right… connecting those you get a plane, which normal you can use for the collision response.