Turning my 2d raytracing engine into 3d and more
- 2 Devlogs
- 4 Total hours
So, I converted all the struct defs to 3d by adding the 3d coordinated.
So I had to figure out how I could draw a sphere to start off.
I had to consider that we now have 2 angles that we have to utilize.
I can get the three coordinates by doing:
x = r * cos(theta) * cos(phi)
y = r * cos(theta)
z = r * sin(phi) * cos(theta)
To do this we need to first calculate the two angles phi and theta:
theta = r( determined by loop) / rings * pi
phi = s(determined by loop) / sectors * 2 * pi
theta is the angle rotating in a motion containing the z axis
while phi is rotating around the z axis.
Added circle collisions and easier randomized shape generation. The circle collision functions by getting the discriminant of the equation obtained by inserting the definition of the ray into the definition of a circle.