Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Lets say we have a laser beam emitter that has a position and an angle (in a 2D world to simplify things). The laser emitted from that emitter will start at that position, and continue heading in the direction of the angle until it intersects with an object (some arbitrary polygon). If that object is reflective, the laser should bounce off the surface that it first intersects. This continues until the laser hits a non-reflective surface.

I guess the problem here can be divided into two problems: finding the first intersection and calculating the new angle from that intersection. I'm not exactly sure how to solve the first problem, but I figure the second one can be solved by finding the angle between the laser and the normal vector (i think that's what it's called) and calculating the new angle using that.

share|improve this question
    
Your first question can't be answered, as you're not really specific about it. Maybe look into "Ray - Line intersection"? Your second question has been answered in this question: gamedev.stackexchange.com/questions/23672/… –  bummzack Feb 22 '12 at 14:08
    
I'm sorry, what additional information do I need to specify? I was looking for a general answer. –  Rahat Ahmed Feb 22 '12 at 14:13
    
I was thinking about something like your edit. It wasn't clear if this is 2D, 3D, if it's vs. lines, polygons, curves, metaballs or whatever :). But nevermind, your edit cleared things up a bit. –  bummzack Feb 22 '12 at 17:06
add comment

1 Answer

up vote 1 down vote accepted

I think this can be transfered to simple ray casting / ray tracing. You shoot ray, find hit, reflect, find other hit, etc.

The easiest way is brute force. You construct ray (position, direction) and calculate collision with all polygons (you should divide polygons on triangles) in scene. And find closest one. Of course you can't take collision behind rays origin, but only in front of it.

If you find closest intersection, look on material of polygon. If this is reflective, do whole procedure again. If it's not reflective, you are done.

If you have huge scene with lots of polygons and you need to shoot again and again, you can construct some kind of acceleration structure (kD-tree, BVH). But this is more complicated.

If you want more information, just google ray tracing or ray casting. You will find a lot of information.

share|improve this answer
    
Thanks, I'll look into it. –  Rahat Ahmed Feb 22 '12 at 15:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.