Here it is, X,Y,Z rotations are supported.
rem -----------------------------------------------------------------------------
rem Convert 3D coordinates to UV coordinates on a sphere
rem
rem this is purely mathematical and assumes the object is using the default
rem UV mapping of a sphere primitive
rem -----------------------------------------------------------------------------
rem by TheComet
rem -----------------------------------------------------------------------------
rem setup screen
sync on
sync rate 60
backdrop on
color backdrop 0
show mouse
rem UDTs
type vec3
x# as float
y# as float
z# as float
endtype
rem global variables
global Collision as vec3
rem create an emtpy white texture for every planet/star
create bitmap 1 , 256 , 256
ink 0xFFFFFFFF , 0
box 0 , 0 , 256 , 256
get image 1 , 0 , 0 , 256 , 256
get image 2 , 0 , 0 , 256 , 256
delete bitmap 1
rem convert images to memblock so it can be edited faster
make memblock from image 1 , 1
make memblock from image 2 , 2
rem create a sun
make object sphere 1 , 50
texture object 1 , 1
rotate object 1 , 70 , 20 , 30
rem create a planet (half the size of the sun is about right, yes? xD)
make object sphere 2 , 25
texture object 2 , 2
rem create grid texture
create bitmap 1 , 512 , 512
ink 0xFF303030
for n = 0 to 511 step 10
line n , 0 , n , 511
line 0 , n , 511 , n
next n
ink 0xFF0080FF , 0
circle 255 , 255 , 255
line 255 , 255 , 255 , 0
line 0 , 255 , 20 , 255
line 255 , 491 , 255 , 511
line 491 , 255 , 511 , 255
text 258 , 20 , "0°"
text 22 , 250 , "90°"
text 250 , 480 , "180°"
text 460 , 250 , "270°"
get image 3 , 0 , 0 , 512 , 512
delete bitmap 1
rem create grid object
make object plain 3 , 400 , 400
rotate object 3 , 270 , 270 , 0
texture object 3 , 3
set object transparency 3 , 2
rem main loop
camdist# = 320
do
rem user info
center text 512 , 10 , "Right-Click and move mouse to look around"
center text 512 , 25 , "Left-Click on an object to draw on it"
center text 512 , 40 , "Move mouse over an object to get the current colour: " + hex$(GetColour)
center text 512 , 55 , "Press Space to change colour. Currently: " + hex$(colour)
rem zoom
if upkey() then dec camdist# , 5
if downkey() then inc camdist# , 5
rem change colour
if spacekey()
colour = 0xFF000000 || (rnd(255)<<16) || (rnd(255)<<8) || rnd(255)
endif
rem control planet
inc a# , 0.08
position object 2 , cos(a#)*200 , 0 , sin(a#)*200
rotate object 2 , 40 , wrapvalue( a# * 4.5 ) , 0
rem control camera
if mouseclick() = 2
angle# = wrapvalue( angle# + (mousemovex()*0.8) )
inc height# , mousemovey() * 4
else
null = mousemovex()
null = mousemovey()
endif
set camera to follow 0 , 0 , 0 , angle# , camdist# , height# , 3 , 0
point camera 0 , 0 , 0
rem get collision
Obj = pick object( mousex() , mousey() , 1 , 2 )
if Obj > 0
rem get collision point
x# = get pick vector x() + camera position x()
y# = get pick vector y() + camera position y()
z# = get pick vector z() + camera position z()
rem all further operations are performed around point of origin
dec x# , object position x(Obj)
dec y# , object position y(Obj)
dec z# , object position z(Obj)
rem normalize (so size doesn't matter)
dist# = (x#^2 + y#^2 + z#^2)^0.5
Collision.x# = x# / dist#
Collision.y# = y# / dist#
Collision.z# = z# / dist#
rem rotate back to point of origin
MatrixRotateZ( Collision , 0-object angle z(Obj) )
MatrixRotateY( Collision , object angle y(Obj) )
MatrixRotateX( Collision , 0-object angle x(Obj) )
rem get the Y angle between 0° and collision point
ay# = 180 - atan( Collision.x#/Collision.z# )
rem wrap to 360°
if Collision.z# > 0 then ay# = wrapvalue( ay# + 180 )
rem get the X angle between 0° and collision ponit
ax# = 90 - asin( Collision.y# )
rem calculate UV
u# = ay# / 360.0
v# = ax# / 180.0
rem convert UV coordinates to pixel offset
x = u#*256
y = v#*256
offset = (y*256) + x
offset = offset*4 + 12
rem if mouse is clicking, draw at those UV coordinates
if mouseclick() = 1
rem update image
write memblock dword Obj , offset , colour
make image from memblock Obj , Obj
endif
rem get colour at that position
GetColour = memblock dword( Obj , offset )
endif
rem refresh screen
sync
rem end of main loop
loop
rem end
end
remstart
/ 1 0 0 \
Rx(a) = | 0 cos(a) -sin(a) |
\ 0 sin(a) cos(a) /
/ cos(a) 0 -sin(a) \
Ry(a) = | 0 1 0 |
\ sin(a) 0 cos(a) /
/ cos(a) -sin(a) 0 \
Rz(a) = | sin(a) cos(a) 0 |
\ 0 0 1 /
remend
function MatrixRotateX( IN as vec3 , angle# )
rem rotate
Collision.y# = (IN.y#*cos(angle#)) - (IN.z#*sin(angle#))
Collision.z# = (IN.y#*sin(angle#)) + (IN.z#*cos(angle#))
endfunction
function MatrixRotateY( IN as vec3 , angle# )
rem rotate
Collision.x# = (IN.x#*cos(angle#)) - (IN.z#*sin(angle#))
Collision.z# = (IN.x#*sin(angle#)) + (IN.z#*cos(angle#))
endfunction
function MatrixRotateZ( IN as vec3 , angle# )
rem rotate
Collision.x# = (IN.x#*cos(angle#)) - (IN.y#*sin(angle#))
Collision.y# = (IN.x#*sin(angle#)) + (IN.y#*cos(angle#))
endfunction
TheComet