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 / Reflecting a Laser Beam off a Mirror - Math Help?

Author
Message
JamesWalker101
16
Years of Service
User Offline
Joined: 14th Apr 2010
Location: England
Posted: 13th Jan 2013 15:56
I am making a 3d game, where you reflect laser beams off mirrors. I use reflection shading (there will be under 6 mirrors at one time) for them, and a plane for the mirror.
Can someone tell me which math I need to find the angle of incidence for Beam 1 and then reflect Beam 2 off it at the correct angle?

Thanks Guys
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 13th Jan 2013 19:04
I've just done a good long search on that subject because it is something I wanna faff about with soon. There's a bit of math to go with it but by the looks of it, it's not that hard to do, and there's a choice of methods too from vector math, matrices and quaternions.

I believe DBP Matrix maths commands are slow though but still very usable, They may be used to convert this math : http://www.euclideanspace.com/maths/geometry/affine/reflection/quaternion/index.htm (and they even advertise Dark Basic)

This one also I found useful though : http://higherorderfun.com/blog/2012/06/03/math-for-game-programmers-05-vector-cheat-sheet/

Hope this helps as I'll be needing it soon anyways...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Jan 2013 20:13 Edited at: 19th Jan 2013 20:20
I - Incoming source, vector to be reflected (normalized)
N - Normal of impacted surface (normalized)
R - Reflected vector

R = I - 2N*(N dot I)

edit
My equation was off slightly, fixed it.

"You're not going crazy. You're going sane in a crazy world!" ~Tick
MadBit
VIP Member
Gold Codemaster
17
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 13th Jan 2013 20:14
<advertising> For vector maths you can use my eXtendet Rotation .</advertising>

Share your knowledge. It's a way to achieve immortality. (Tenzin Gyatso)
Pixie-Particle-Engine
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 14th Jan 2013 00:46
Ahh Phaelax beat me to it
JamesWalker101
16
Years of Service
User Offline
Joined: 14th Apr 2010
Location: England
Posted: 18th Jan 2013 22:04
Can anyone convert this to an actual dark basic code? At least I am confused. I havn't used any of these "Matrix Maths" yet. I will post if I manage to make some code for it.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th Jan 2013 17:04 Edited at: 19th Jan 2013 20:21
You don't need matrices for reflection, I just gave you the equation you need. This is typically where I'd say the rest is up to you, otherwise we'd be doing all the work for you and you'll never learn.

I edited my post above. My equation was off slightly, it's been corrected.

However, as this gave me an idea for a neat little demo, I'll work on some code for you.

Check out this demo and see if it clears things up for ya.
http://forum.thegamecreators.com/?m=forum_view&t=203039&b=6

"You're not going crazy. You're going sane in a crazy world!" ~Tick

Login to post a reply

Server time is: 2026-07-07 00:48:44
Your offset time is: 2026-07-07 00:48:44