02-09-2025, 09:12 AM
Another interesting glitch which I made trying to rotate a sphere:
You can see the actual working version in the Works in Progress topic, but this one was rather neat as it was a screw up I generated on the way to the other. LOL!
This might could be used to generate a planet going through a black hole or some such, I guess.
Code: (Select All)
_Title "Rotating Sphere in QB64PE"
Screen _NewImage(800, 600, 32)
Dim Shared sphere(360, 360) As _Unsigned Long
Dim Shared rotationX, rotationY As Single
' Initialize the sphere
For phi = 0 To 359
For theta = 0 To 359
x = Cos(_D2R(phi)) * Sin(_D2R(theta))
y = Sin(_D2R(phi)) * Sin(_D2R(theta))
z = Cos(_D2R(theta))
sphere(phi, theta) = _RGB32(Cos(_D2R(phi)) * 127 + 128, Sin(_D2R(phi)) * 127 + 128, z * 127 + 128)
Next
Next
' Main loop
Do
If _KeyDown(18432) Then rotationX = rotationX - 5
If _KeyDown(20480) Then rotationX = rotationX + 5
If _KeyDown(19200) Then rotationY = rotationY - 5
If _KeyDown(19712) Then rotationY = rotationY + 5
Cls , 0
_PrintString (0, 0), "Rotating Rainbow Sphere"
_PrintString (0, 16), "Use arrow keys to rotate"
' Draw the sphere
For phi = 0 To 359 Step .25
For theta = 0 To 359 Step .25
x = Cos(_D2R(phi)) * Sin(_D2R(theta))
y = Sin(_D2R(phi)) * Sin(_D2R(theta))
z = Cos(_D2R(theta))
' Rotate around X axis
y = y * Cos(_D2R(rotationX)) - z * Sin(_D2R(rotationX))
z = y * Sin(_D2R(rotationX)) + z * Cos(_D2R(rotationX))
'y = y1
'z = z1
' Rotate around Y axis
x = x * Cos(_D2R(rotationY)) + z * Sin(_D2R(rotationY))
z = -x * Sin(_D2R(rotationY)) + z * Cos(_D2R(rotationY))
'x = x1
'z = z1
' Project to 2D
screenX = 400 + x * 200
screenY = 300 - y * 200
PSet (screenX, screenY), sphere(phi, theta)
Next
Next
_Display
_Limit 60
Loop Until _KeyDown(27)
You can see the actual working version in the Works in Progress topic, but this one was rather neat as it was a screw up I generated on the way to the other. LOL!
This might could be used to generate a planet going through a black hole or some such, I guess.
