ok, I got it to work as I wanted it to. The texture and height-field match up quite nicely. All I did was change the HeightMap(128, 64) to HeightMap(129, 65) and reversed how the HeightMap() x-value Array was loaded.
Here's the code:
SetupDisplay()
SetupCamera()
SetupLightSources()
load image "SkySphere.png", 1
load image "Star_Glare.bmp", 2
load image "PlanetHeightMap.png", 3
make object sphere 1, -50000, 10, 20 `Make Starry Backdrop
set object light 1, 0
texture object 1, 1
make object sphere 2, 300 `Make Sun
set object light 2, 0
position object 2, 0, 0, -5000
make object cube 3, 1800 `Make Sun Glare
texture object 3, 2
set object transparency 3, 2
set alpha mapping on 3, 80
set object light 3, 0
position object 3, 0, 0, -5000
Dim HeightMap(129,65)
DIM VertexX(8500) as float
DIM VertexY(8500) as float
DIM VertexZ(8500) as float
DIM VertexD(8500) as float
DIM VertexALT(8500) as float
global PlanetID = 10
global PlanetRows = 64
global PlanetColumns = 128
global PlanetRadius = 250
global XAng as float
global YAng as float
global CameraDist as float
global mx
global my
global xpos#
global ypos#
global zpos#
global mmx as float
global mmy as float
global mmz as float
global mmzr as float
mmzr = .025
global smmx as float
global smmy as float
global rmmx as float
global rmmy as float
global dXAng as float
global dYAng as float
global CullState = 1
global num_objects = 20
global lmb
global CameraTickRate = 0
global tag_state = 0
global tempmousex as float
global tempmousey as float
global tempmousez as float
global xposdiff# as float
global yposdiff# as float
global OriginalZPos#
dXAng = 0
global ssnvx# as float
global ssnvy# as float
global ssnvz# as float
global ssvx# as float
global ssvy# as float
global ssvz# as float
global ssvl# as float
global ssZoomLevel as float
global ssp#
make object sphere PlanetID, PlanetRadius, PlanetRows, PlanetColumns
texture object PlanetID, 3
CameraDist = -(PlanetRadius)
`Start Main Program - ************************************************************************************
SetTerrainHeight()
while escapekey() = 0
mx = mousex()
my = mousey()
`PlaceItemsOnSphere()
ControlCamera()
if rightkey()=1 then sot#=sot#+.0001
if leftkey()=1 then sot#=sot#-.0001
scroll object texture PlanetID, sot#, 0
text 0, 0, "screen fps: " + str$(screen fps())
text 0, 15, "CameraTickRate: " + str$(CameraTickRate)
text 0, 30, "Cursor Y: " + str$(my)
text 0, 45, "sot#: " + str$(sot#)
text 0, 60, "dYAng: " + str$(dYAng)
text 0, 75, "70, 30 height: " + str$(HeightMap(70, 30))
endwhile
`End of Main Program - ************************************************************************************
function EditTerrain()
endfunction
function SetTerrainHeight()
for y=1 to 64 `Load Height Array Backwards
for x=1 to 128
paste image 3, 1, 1
HeightMap(x,y)=rgbr(point(x,y))
next x
next y
vv=1
lock vertexdata for limb PlanetID, 0
x=128
y=1
for vv=1 to (127*63)+1
VertexALT(vv)=(HeightMap(x,y)*.035)
ssvx#=get vertexdata position x(vv)
ssvy#=get vertexdata position y(vv)
ssvz#=get vertexdata position z(vv)
`Get the vector length
ssvl#=sqrt((ssvx#*ssvx#)+(ssvy#*ssvy#)+(ssvz#*ssvz#))
`Normalise the vector
ssnvx#=ssvx#/ssvl#
ssnvy#=ssvy#/ssvl#
ssnvz#=ssvz#/ssvl#
ssvx#=ssnvx#*((PlanetRadius/2) + VertexALT(vv))
ssvy#=ssnvy#*((PlanetRadius/2) + VertexALT(vv))
ssvz#=ssnvz#*((PlanetRadius/2) + VertexALT(vv))
VertexX(vv) = ssvx#
VertexY(vv) = ssvy#
VertexZ(vv) = ssvz#
set vertexdata position vv, ssvx#, ssvy#, ssvz#
x=x-1
if x=0
x=129
y=y+1
if y>64 then y=64
endif
next vv
unlock vertexdata
endfunction
function PlaceItemsOnSphere()
mx = mousex()
my = mousey()
if lmb = 0
if mouseclick() = 4
lmb = 0
if pick object(mx,my,10,10) = PlanetID
`calculate the 3D coordinates of the cursor projected onto the sphere
xpos# = get pick vector x() + camera position x()
ypos# = get pick vector y() + camera position y()
zpos# = get pick vector z() + camera position z()
`create a cube object, position it and point it at the centre of the sphere
`inc num_objects
`make object cube num_objects, .2
`color object num_objects, rgb(255,90,90)
`position object num_objects, xpos#, ypos#, zpos#
`point object num_objects, object position x(PlanetID), object position y(PlanetID), object position z(PlanetID)
endif
endif
endif
if mouseclick() = 0 then lmb = 0
endfunction
function ControlCamera()
mmx = MouseMoveX()
mmy = MouseMoveY()
mmz = MouseMoveZ() * mmzr
xpos# = get pick vector x() + camera position x()
ypos# = get pick vector y() + camera position y()
zpos# = get pick vector z() + camera position z()
`if CameraDist<-14 then mmzr=.005
`if CameraDist>-14 and CameraDist<-12 then mmzr=.000625
`if CameraDist>-12 and CameraDist<-10.03 then mmzr=.0003125
`if CameraDist>-10.026 then CameraDist=-10.026
if MouseClick() = 4 and tag_state=0
`Take a snapshot of initial mouse cursor click location on the planet
if pick object(mx,my,10,10) = PlanetID
tempmousex = xpos#
tempmousey = ypos#
tempmousez = zpos#
OriginalZPos# = zpos#
tag_state=1
endif
endif
If MouseClick()=4 and ControlKey()=0 and ShiftKey()=0 and tag_state=1 and pick object(mx,my,10,10) = PlanetID
xposdiff# = (xpos# - tempmousex)*.01
yposdiff# = (ypos# - tempmousey)*.01
endif
`Outside of previous if-loop to allow for free-rolling of planet
if OriginalZPos#>0 then XAng = XAng - (xposdiff#)
if OriginalZPos#<0 then XAng = XAng + (xposdiff#)
YAng = YAng - yposdiff#
Position Camera 0, 0, 0, 0
Rotate Camera 0, YAng, XAng, 0.0
Move Camera 0, CameraDist
CameraDist = CameraDist + mmz
if MouseClick()=4 and ControlKey()=1 and ShiftKey()=0 `Skew Camera Right or Left
dXAng=dXAng+(mmx*.1)
dYAng=dYAng+(mmy*.1)
endif
turn camera right 0, dXAng
pitch camera down 0, dYang
If MouseClick()=4 and ControlKey()=0 and ShiftKey()=1
rmmx=rmmx-(mmx*.1)
endif
roll camera right 0, rmmx
if spacekey()=1
rmmx=0
dXAng=0
dYAng=0
yposdiff#=0
xposdiff#=0
point camera 0, 0, 0, 0
endif
`point Object 5, camera position x(0), camera position y(0), camera position z(0)
smmx=0
smmy=0
mmx=0
mmy=0
mmz=0
if MouseCLick() = 0 then tag_state = 0
`point object 5, camera position x(0), camera position y(0), camera position z(0)
endfunction
function SetupDisplay()
set display mode desktop width(), desktop height(), 32 : set window off
autocam off : backdrop on : color backdrop rgb(0,0,0) : set ambient light 5
endfunction
function SetupCamera()
position camera 0, 0, 0, -25
set camera range 0, .125, 51000
point camera 0, 0, 0, 0
endfunction
function SetupLightSources()
hide light 0
make light 1
position light 1, 0, 0, -5000
set light range 1, 35000
make light 2
position light 2, 0, 0, -5000
set light range 2, 35000
make light 3
position light 3, 0, 0, -5000
set light range 3, 35000
endfunction
it should work and you'll see what I mean. Use the camera controls to move around the planet. Use the Middle Mouse button to pan around the camera, the mouse wheel to zoom in and out. Use the ControlKey+mouse buttom to skew the camera around.
If you get disorientated use the space bar to straighten you out. The current camera controls are not perfect, but that can be remedied soon enough.
Home is where my souped-up computer is...
