I was wondering if anyone around here came up with any decent raytracing algorithms. The only one I'm aware of is the one in Shadowdarke's Pixel Projectiles library.
Right now, I've encountered a teensy problem with visual events in Haven's output system. The way it's set up, you can "see" things happening at a distance well beyond world.view, provided the event's visual strength is stronger than world.view. For instance, you might see someone attacking someone else even if it's well off screen -- your character isn't assumed to be so narrow minded that he suddenly loses track of someone just because they're no longer ten metres away. This appears in the form of a text message: "You see someone hit someone in the arm!"
However, the problem here is that view() fails completely at those ranges. My aim is to raytrace between an observer and the source for visual events that are larger than world.view, so that distant observers can still witness them. Obstructions that block line of sight at range will obviously prevent someone from "seeing" anything at range.
In the meantime, you can still "see" visual events at range, but they are visible through walls and the like, which is rather game-breaking to say the least...
ID:152427
Oct 31 2006, 3:12 pm
|
|
My Intercept() snippet in Post [link] may help. sgn() and sd_get_dist() are posted later on in the same thread, though you can probably figure them out for yourself. ;)
|
In case anyone was shy because they figured I'm just asking for code (heh heh), here's my own implementation of a raytracing system:
proc/ring(distance = 6, atom/centre) //Utility functions from my toolkit This system is designed with a maximum range in mind. I'm not sure how to go about a pure raytracing algorithm, so it seems as though I'll need to do some reading... I imagine it's exceedingly inefficient, but that's what you get from a programmer who hasn't had one iota of education for optimisation. This is why I was asking to see if anyone had anything better. =) [edit]Oops, forgot get_line(). //This returns a precise list of turfs in a near-perfect |
In response to Jtgibson
|
|
Try to set things up so you can drop the sqrt in get2Ddist - that is, compare it to squared values where applicable, etc. etc. Maybe create a get2Ddistsquare() proc, that returns the squared value of the distance to the object. sqrt() is slow.
And, of course, avoid ** like the plague - multiply the number by itself. I think you're already doing that, from what I looked at. Store values that you're going to be looking at instead of creating them in if()s, etc. If they're going to be constant, that is. For example: var/dup=distance+0.5 Those are my two cents on optimisation. I'm not sure about how to build a better LOS algorithm, though. |
In response to Jp
|
|
Jp wrote:
Those are my two cents on optimisation. I'm not sure about how to build a better LOS algorithm, though. I know about all of those, although for the most part I wrote that proc as a fire-and-forget sort of thing. It worked for my purposes and I wasn't trying to heavily optimise it (it was being called for bullets only, so it wasn't being used as much as a line-of-sight algorithm would be). I'm talking more about the heavier-duty optimisations, like the ones that Lummox JR does. For instance, compare: //My version: //Lummox JR's version: =P |
These may help:
[link]
http://sc.tri-bit.com/Computing_LOS_for_Large_Areas
http://www-cs-students.stanford.edu/~amitp/Articles/ LineOfSight.html
http://roguelikedevelopment.org/php/category/ showCategory.php?path=development/&category=LOS