There were various errors. The first one, which caused the strange line was due to
Set Object Normals, which seems to dislike spheres.
The most important problem couldn't be seen on your demo, but actually, the vertex data uses local coordinate. This means that for all your calculation, it was assumed that your planet was placed on the sun and not rotated. I fixed that using some matrix calculation to turn a local space coordinate into a world space one. However, it requires the IanM plugins :
http://forum.thegamecreators.com/?m=forum_view&t=85209&b=18 (I strongly recommend them, there are a lot of useful functions).
Set display mode desktop width(), desktop height(),32
Autocam off
Sync on : Sync Rate 60
`planet
Make object sphere 1,120,20,20
//Set object normals 1
set object cull 1,0
convert object fvf 1,338
Set Object Light 1,0
`sun
make object sphere 2,500,30,30
Position Object 2, 0,0,0
Set object ambient 2,0
Set object light 2,0
Make Light 1
Hide light 0
color light 1,255,255,255
Set light Range 1,150000
Set ambient light 10
Set camera range 1,200000
m = Make Matrix4(1)
v = Make Vector4(2)
v = Make Vector4(3)
v = Make Vector3(4)
v = Make Vector3(5)
Dist=480
CangA#=0
CangB#=0
CangC#=0
Pang#=0
Do
`planet distance and rotation updated before calculations
sdist#=(4500+(px#/3))
Object Matrix4 1, 1
`We now have to update the calculation of light and shadow, so the vectorIII "set commands" will be called each time.
Lock VertexData For Limb 1,0
Vcount = Get VertexData Vertex Count()
For Rays=0 to Vcount
`position
VX#=Get vertexdata position X(rays)
VY#=Get Vertexdata position Y(rays)
VZ#=Get vertexdata position Z(rays)
`normals
NX#=Get Vertexdata Normals X(Rays)
NY#=Get Vertexdata Normals Y(Rays)
NZ#=Get Vertexdata Normals Z(Rays)
// Find the World Space normal
Set Vector4 2,NX#,NY#,NZ#,0
Transform Vector4 2,2,1
// Find the World Space position
Set Vector4 3,vx#,vy#,vz#,1
Transform Vector4 3,3,1
// Turn the normal back to a vector3
Set Vector3 4, X Vector4(2), Y Vector4(2), Z Vector4(2)
// Calculate the vector sun-vertex in a vector3
Set Vector3 5, Object position X(2)-X Vector4(3), Object position Y(2)-Y Vector4(3), Object position Z(2)-Z Vector4(3)
// Normalize the vectors
NORMALIZE VECTOR3 4,4
NORMALIZE VECTOR3 5,5
// And dot product them
Heat#=Dot Product Vector3 (4,5)
if heat#>0
heated = rgb( heat#*255,32,0)
Else
heated = rgb( 0,32, 255-(1+heat#)*255 )
EndIf
SET VERTEXDATA DIFFUSE Rays,Heated
Next Rays
UnLock VertexData
`Orbital Tilt
Tilt#=Pang#*24
Orb#=(0+(SIN(Tilt#)))
Axis#=(Orb#/2)/(SIN(TILT#)*360)
pitch object up 1,Axis#
Roll Object right 1,Axis#
Turn Object LEft 2,0.2
//turn object left 1,0.188
cx#=Newxvalue(object position x(1),CAngA#,dist#)
cy#=Newyvalue(object position Y(1),CAngB#,dist#)
cz#= Newzvalue (Object Position z(1),CangC#,Dist#)
PX#=Newxvalue(object position x(2), Pang#,sDIST#)
PZ#=NewZvalue (Object position Z(2), Pang#, sDIST#)
SET LIGHT TO OBJECT ORIENTATION 1,2
position light 1,object position x(2),Object position Y(2),object position z(2)
Point Light 1,Object position X(1),Object position Y(1), Object position Z(1)
Position camera cX#,cy#,cZ#
Position Object 1,px#,0,Pz#
Point Camera object position X(1), Object Position Y(1), Object position Z(1)
If mouseclick()=2
Newang#=MousemoveX()
If oldang# <> NEWANG#
If Oldang# < Newang# then Mousexx#=5
If oldang# > Newang# then Mousexx#=-5
Oldang#=MousemoveX()
CangA#=Mousexx#+CangA#
CAngc#=MouseXX#+CAngc#
else
MouseXX#=0
endif
endif
If mouseclick()=1
Newangy#=Mousemovey()
If oldangy# <> NEWANGy#
If Oldangy# < Newangy# then Mouseyy#=5
If oldangy# > Newangy# then Mouseyy#=-5
Oldangy#=Mousemovey()
Angb#=MouseYY#+AngB#
Cangc#=mouseYY#+CANGc#
ELSE
MOUSEYY#=0
Endif
endif
Newmousez = MousemoveZ()
If oldmousez <> newmousez
If oldmousez < newmousez then mousezz=-25
If oldmousez > newmousez then mousezz=25
Oldmousez =Mousemovez()
Dist#=Dist#+MouseZz
else
Mousezz=0
endif
CAngA#=Wrapvalue(CAngA#+0.0)
CAngb#=Wrapvalue(CAngb#+0.0)
CAngC#=Wrapvalue(CAngC#+0.0)
Pang#=Wrapvalue( Pang# +0.108897)
Sync
Loop
Don't worry if you don't really understand all this matrix stuff. What you have to remember:
- for changing a coordinate (e.g. the vertex position) from local to world space, you need to make a vector4 with the positions in the 3 first components and a 1 in the last one, to get the object matrix (which holds the positions, rotations and scale), and finally, you have to transform the vector with the matrix.
- for changing a vector (e.g. the vertex normal), you need to do the same but with a 0 in the last component of your vector.
- for changing a vector or a coordinate from world to local space, do the same but inverse the matrix.