hi,
a while ago somebody posted something about lines in 3d. i also wanted to do those but i never found a satisfying answer untill this idea suddenly sprang into my mind (while walking home from the supermarket). it's a bit messy, since it's the frist thing that sprang into my mind, but i hope it can be of use for somebody out there (except me, because i am a very happy man at the moment).
here goes:
a while ago somebody posted something about lines in 3d. i also wanted to do those but i never found a satisfying answer untill this idea suddenly sprang into my mind (while walking home from the supermarket). it's a bit messy, since it's the frist thing that sprang into my mind, but i hope it can be of use for somebody out there (except me, because i am a very happy man at the moment).
here goes:
Function createline(x1#,y1#,z1#, x2#,y2#,z2#, mesh=0) If mesh = 0 Then mesh=CreateMesh() EntityFX(mesh,16) surf=CreateSurface(mesh) verts = 0 AddVertex surf,x1#,y1#,z1#,0,0 Else surf = GetSurface(mesh,1) verts = CountVertices(surf)-1 End If AddVertex surf,x2#,y2#,z2#,1,0 AddTriangle surf,verts,verts+1,verts Return mesh End Function ; --- set graphics Graphics3D 640,480,32,0 SetBuffer(BackBuffer()) ; --- create scene setup camPiv = CreatePivot() camera = CreateCamera(camPiv) PositionEntity(camera, 0,0,-10) light=CreateLight(2) PositionEntity(light,4,10,0) LightRange(light,10) ; --- create test cube cube=CreateCube() ScaleMesh(cube, 2,1,1) ; --- create lines lines = createLine(2,1,1, 1,2,1) lines = createLine(1,2,1, 0,2.3,1, lines) lines = createLine(0,2.3,1, -1,2,1, lines) lines = createLine(-1,2,1, -2,1,1, lines) EntityColor(lines, 255,0,0) ; okay, this is a bit cheating and very wrong/memory leak prone and shouldn't be used this way ; but i wanted To make more than one Line ; and not bother with typing even more hide- and showentity or rewriting the createline function:) ; ; yes, i am lazy ;) lines = createLine(2,1,-1, 1,2,-1) lines = createLine(1,2,-1, 0,2.3,-1, lines) lines = createLine(0,2.3,-1, -1,2,-1, lines) lines = createLine(-1,2,-1, -2,1,-1, lines) EntityColor(lines, 255,0,0) lines = createLine(-3,1,1, 3,1,1) EntityColor(lines, 255,0,0) lines = createLine(-5,1,-1, 4,1,-1) EntityColor(lines, 255,0,0) lines = createLine(-4,-1,1, 3,-1,1) EntityColor(lines, 255,0,0) lines = createLine(-3,-1,-1, 5,-1,-1) EntityColor(lines, 255,0,0) TurnEntity(campiv, 35,35,35) While Not KeyHit(1) ; --- camera controls scrollwheel = MouseZSpeed() If MouseDown(1) Then TurnEntity(camPiv, MouseYSpeed(),-MouseXSpeed(),0) Else If scrollwheel <> 0 Then MoveEntity(camera, 0,0,scrollwheel*3) Else dummy = MouseYSpeed():dummy = MouseXSpeed():dummy = MouseZSpeed() ; prevent mousepeed blips. End If ; --- rendering CameraClsMode(camera, 1, 1) WireFrame(0) HideEntity(lines) ShowEntity(cube) RenderWorld() CameraClsMode(camera, 0, 0) WireFrame(1) ShowEntity(lines) HideEntity(cube) RenderWorld() Flip() Wend End
