I made a reflection raycasting-thingy
everything works, exept when you raycast in a horizontal direction...
(change ray direction with 'a' and 'd', make mirrors with the mouse)
my .love and reflection formula in a .png, and 1 image that shows the problem
Reflection problems..
Reflection problems..
- Attachments
-
- Reflection.love
- (931 Bytes) Downloaded 207 times
Last edited by GijsB on Wed Sep 07, 2011 5:33 am, edited 1 time in total.
Re: Reflection problems..
I havn't worked out the solution yet, still reading through the code, but a couple of notes on efficiency:
If you only change the image data when the mouse/keyboard is pressed, then you only need to generate a new image after these events, rather than every frame.
In this case you need to move
to the end of Ray() instead of love.draw()
Also,
is fairly redundant, since you could just do
Less important, but still worth noting, is that if you define the map pixel function outside of Ray(), it will only be defined once, instead of every time Ray() is called, so its less work for GC.
Which bit do you think is calculating the horizontal mirror?
If you only change the image data when the mouse/keyboard is pressed, then you only need to generate a new image after these events, rather than every frame.
In this case you need to move
Code: Select all
DImage = love.graphics.newImage(ImageD)
DImage:setFilter("nearest","nearest")
Also,
Code: Select all
Ray(px,py,A)
local moved = 1
local ux = px
local uy = py
local ua = A
Code: Select all
Ray(ux, uy, ua)
Which bit do you think is calculating the horizontal mirror?
Re: Reflection problems..
it has to do with the collision detection :
1)get next position of the ray
2)check if a mirror, if so
2.1)calculate reflection =
angle mirror+(angle mirror-ray angle)
the angle of the mirror is detected like this :
every time you draw a mirror, the position of every pixel of the mirror is stored in Mirrors, with the angle like =
Mirrors[x..y] = angle
2.2)update the begin positions, and the moves to zero again.
3) if not keep on going with the ray
1)get next position of the ray
2)check if a mirror, if so
2.1)calculate reflection =
angle mirror+(angle mirror-ray angle)
the angle of the mirror is detected like this :
every time you draw a mirror, the position of every pixel of the mirror is stored in Mirrors, with the angle like =
Mirrors[x..y] = angle
2.2)update the begin positions, and the moves to zero again.
3) if not keep on going with the ray
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Reflection problems..
That's pretty awful. Your code can't distinguish between (23, 5) and (2, 35), for instance. At least do something like:GijsB wrote:every time you draw a mirror, the position of every pixel of the mirror is stored in Mirrors, with the angle like =
Mirrors[x..y] = angle
Code: Select all
Mirrors[x..':'..y] = angle
Help us help you: attach a .love.
Re: Reflection problems..
thanks, but it didnt do much, the reflection still glitchesRobin wrote:That's pretty awful. Your code can't distinguish between (23, 5) and (2, 35), for instance. At least do something like:GijsB wrote:every time you draw a mirror, the position of every pixel of the mirror is stored in Mirrors, with the angle like =
Mirrors[x..y] = angleCode: Select all
Mirrors[x..':'..y] = angle
Re: Reflection problems..
I must be missing something. This .love does nothing for me, just a white screen. Any ideas?
EDIT: seems to be due to using non-power-of-two image resolutions. I can make the code work on my machine if I change the resolution to use 512x512 instead.
Question: why are you not doing this by just creating a list of mirrors as startx,starty,endx,endy coordinates? Surely by trying to do the reflection on a pixel grid with a 1-pixel-wide mirror line means you're just going to get beams that 'pass through' the mirrors when the mirror pixels have gaps between them (i.e. on diagonals) and do completely weird things. Certainly that seems to happen with your current implementation. See bug illustrated below. The diagonal completely passes through the mirror.
Question2: Why does the line reflect if the mirror is horizontal, but 'pass through at a different angle' if the mirror is vertical? It looks like you're using degrees for the incident angle (A or ua) and radians for the mirror angle (OA or sa). You can't just add degrees to radians. If you put math.deg(sa) into Mirrors, or, alternatively, just use radians everywhere, it works fine. (above screenshot taken with that fix in place, and also the fix to use power-of-two imagedata)
EDIT: seems to be due to using non-power-of-two image resolutions. I can make the code work on my machine if I change the resolution to use 512x512 instead.
Question: why are you not doing this by just creating a list of mirrors as startx,starty,endx,endy coordinates? Surely by trying to do the reflection on a pixel grid with a 1-pixel-wide mirror line means you're just going to get beams that 'pass through' the mirrors when the mirror pixels have gaps between them (i.e. on diagonals) and do completely weird things. Certainly that seems to happen with your current implementation. See bug illustrated below. The diagonal completely passes through the mirror.
Question2: Why does the line reflect if the mirror is horizontal, but 'pass through at a different angle' if the mirror is vertical? It looks like you're using degrees for the incident angle (A or ua) and radians for the mirror angle (OA or sa). You can't just add degrees to radians. If you put math.deg(sa) into Mirrors, or, alternatively, just use radians everywhere, it works fine. (above screenshot taken with that fix in place, and also the fix to use power-of-two imagedata)
Re: Reflection problems..
wow thanks , and the problem is i dont know how radians work D:stripwax wrote:I must be missing something. This .love does nothing for me, just a white screen. Any ideas?
EDIT: seems to be due to using non-power-of-two image resolutions. I can make the code work on my machine if I change the resolution to use 512x512 instead.
Question: why are you not doing this by just creating a list of mirrors as startx,starty,endx,endy coordinates? Surely by trying to do the reflection on a pixel grid with a 1-pixel-wide mirror line means you're just going to get beams that 'pass through' the mirrors when the mirror pixels have gaps between them (i.e. on diagonals) and do completely weird things. Certainly that seems to happen with your current implementation. See bug illustrated below. The diagonal completely passes through the mirror.
Question2: Why does the line reflect if the mirror is horizontal, but 'pass through at a different angle' if the mirror is vertical? It looks like you're using degrees for the incident angle (A or ua) and radians for the mirror angle (OA or sa). You can't just add degrees to radians. If you put math.deg(sa) into Mirrors, or, alternatively, just use radians everywhere, it works fine. (above screenshot taken with that fix in place, and also the fix to use power-of-two imagedata)
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Reflection problems..
Radians on Dutch Wikipedia: Radiaal_(wiskunde).
0 radians = 0°
1 radian = 57.3° (not exactly, but something like that)
½ pi radians = 90°
pi radians = 180°
1½ pi radians = 270°
2 pi radians = 360°
As you will learn later in school, radians are very useful. If you start using them now, you'll have a head start on your classmates!
0 radians = 0°
1 radian = 57.3° (not exactly, but something like that)
½ pi radians = 90°
pi radians = 180°
1½ pi radians = 270°
2 pi radians = 360°
As you will learn later in school, radians are very useful. If you start using them now, you'll have a head start on your classmates!
Help us help you: attach a .love.
Re: Reflection problems..
ahaa...
so if i want to turn an image 180° i have to rotate it with math.pi?
so if i want to turn an image 180° i have to rotate it with math.pi?
Re: Reflection problems..
CorrectGijsB wrote:ahaa...
so if i want to turn an image 180° i have to rotate it with math.pi?
Who is online
Users browsing this forum: No registered users and 4 guests