
Advertisement
This topic is 1242 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.
If you intended to correct an error in the post then please contact us.
Recommended Posts
ninnghazad 475
for 3, assuming ground behaves like function f(x) = y:
 have x evenly spaced, so all groundlinesegments span the same width (cyan lines)
 make arrays minHeight[x] and maxHeight[x] for all groundlinesegments (store y1 and y2 for all segments in xsorted arrays)
 also know min/max height of all ground. (gray lines)
 check if missileline hits ground at all or if it leaves screen above maxGroundHeight.
 clip missileline to min/max height of all ground. (yellow box)
 for remaining width of that missileline's segment check all entries in min/max groundHeight arrays per line/box intersection if there is a hit.
 as a bonus do the comparison in reverse if missileline goes from right to left and forward if from left to right, to find hit segment faster.

Advertisement
The ground surface  can you limit its shape to be a series of line segments ? (finer it is, the more seperate segments you have...)
I believe a game programming author (I once saw) used the term 'matchsticks' (segments laid head to tail) because that kind of set of data (a list of points) has some regularity you can use to optimize it (head point of one is tail point of adjacent segment).
That could allow something like a binary search based on the (head) points X poisition to minimize the detailed checking to a subset for intersection with the individual segments (Though you look to be doing intersection of entire trajectory 'ray' which lowers the potential savings a bit)

Also IF you have ALOT of memory and a largely static 'map', you might do an actual linpixel test for your ray intersection tests (indexed 'colors' to tell which object type (subset) to test in detail). Or even have the pixel 'colors' be the objects index ID.
Share this post
Link to post
Share on other sites