Latest incarnation. It loads up a heighmap and divides it up into the segments ok now. Placement works but needs to be redone.
Graphics3D 640,480,32,2 SetBuffer BackBuffer() width = GraphicsWidth() height = GraphicsHeight() ; make a var to hold the terrain segment info in ; 50,0 is where the actual mesh is stored ; 50,1 is the x position ; 50,2 is the y position ; 50,3 is the z position Dim Ter_Segment(50,3) camera = CreateCamera() PositionEntity camera,40,100,0 TurnEntity camera,90,0,0 light = CreateLight() ter = LoadSegTerrain("hmap2.bmp") MoveMouse width/2,height/2 While Not KeyHit(1) Cls mx=MouseX():my=MouseY() If KeyHit(17) w=1-w:WireFrame w mxs#=mxs-MouseXSpeed()*0.15 mys#=mys+MouseYSpeed()*0.3 MoveMouse mx,my mxd#=curvevalue(mxd,mxs,10) myd#=curvevalue(myd,mys,10) If myd=>90 myd=90:mys=90 If myd=<-90 myd=-90:mys=-90 RotateEntity camera,myd,mxd,0 If KeyDown(200) MoveEntity camera,0,0,0.25 If KeyDown(208) MoveEntity camera,0,0,-0.25 If KeyDown(203) MoveEntity camera,-0.15,0,0 If KeyDown(205) MoveEntity camera,0.15,0,0 MoveMouse width/2,height/2 UpdateWorld RenderWorld Text 5,5,"Tris: "+TrisRendered() Flip False Wend End ;============ ;=Curvevalue= ;============ Function curvevalue#(current#,destination#,curve) current#=current#+((destination#-current#)/curve) Return current# End Function ;============ ; Height Map Loader Function LoadSegTerrain (hmap$,seg=4);(hmap$,tmap$,lmap$,seg=4) h_map = LoadImage(hmap$) ; error trapping If Not h_map RuntimeError hmap$+" does not exist." Local h_width = ImageWidth(h_map) Local h_height = ImageHeight(h_map) ; error trapping If h_width <> h_height RuntimeError hmap$+" is not perfectly square." ; calc the total segments Local seg_total = seg * seg ; calc the quad dimensions for each segment Local seg_quads = h_width / seg ; now we build each segment individually For loop = 1 To seg_total s=0 ; create the mesh and surface mesh = CreateMesh() surf = CreateSurface(mesh) ; vertices For y = 0 To seg_quads For x = 0 To seg_quads AddVertex surf,x,0,y-1,0,x,-y VertexTexCoords surf,x+((seg_quads+1)*y),x,-y Next Next ; triangles For y = 0 To seg_quads-1 For x = 0 To seg_quads-1 v=x+s AddTriangle surf,v,v+seg_quads+1,v+seg_quads+2 AddTriangle surf,v,v+seg_quads+2,v+1 Next s=s+seg_quads+1 Next ; now to store the terrain segment and calc where it will be placed If z_count > seg-1 z_off = z_off + 1:z_count=0 ; color the segment to show it's actually working EntityColor mesh,Rand(50,255),Rand(50,255),Rand(50,255) Ter_Segment(loop,0)=mesh Ter_Segment(loop,1)=z_count*seg_quads Ter_Segment(loop,2)=0 Ter_Segment(loop,3)=z_off*seg_quads PositionEntity Ter_Segment(loop,0),Ter_Segment(loop,1),0,Ter_Segment(loop,3) z_count = z_count + 1 Next End Function