Is it possible to have 3D lines with MiniB3D? In would need them to show the vectors of a object.
3D lines
BlitzMax Modules Forums/MiniB3D/3D lines I found this code which works perfectly within B3D but converted to BMAX the lines aren't as nice anymore.
Any ideas why?
Any ideas why?
Import sidesign.minib3d Function createline(x1:Float, y1:Float, z1:Float, x2:Float, y2:Float, z2:Float, mesh = 0) If mesh = 0 Then mesh=CreateMesh() EntityFX(MESH, 1 + 4 + 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, x1:Float, y1:Float, z1:Float, 0, 0 ' or maybe change this to something like: AddVertex surf, x1:Float + 0.001, y1:Float + 0.001, z1:Float + 0.001, 0, 0 AddVertex surf,x2#,y2#,z2#,1,0 AddTriangle surf,verts,verts+2,verts+1 Return mesh End Function ' --- set graphics Graphics3D 640, 480, 32, 2 '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) EntityAlpha(cube, 0.5) cube2=CreateCube() ScaleMesh(cube2, 1.8,0.8,0.8) ' --- 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 (because freeEntity(lines) will only free the last line) ' 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 KeyDown(KEY_ESCAPE) ' --- 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) ShowEntity(cube2) RenderWorld() CameraClsMode(CAMERA, 0, 0) Wireframe(1) ShowEntity(lines) HideEntity(cube) HideEntity(cube2) RenderWorld() Flip() Wend End
Tried with 0.45 (after deleting all MouseYSpeed) but it's the same as in 0.42.
Is it fast enough to just use Max2D commands to draw lines connecting vertices? Y'know, using CameraProject to get 2D screen coordinates from the 3D coordinates of the vertices.
It's fast enough but 2d is drawn over the 3d, so it may not look right depending on what you are using it for. I often draw lines with Max2D to show vectors but only during debug.
I will introduce a 3d line type with the next extended release. I t will be easy to implement with the standard edition as well.
That will be very cool Klepto. Can we set line thickness too?
wow that would be cool, any idea when it'll be ready?
It's fast enough but 2d is drawn over the 3d, so it may not look right depending on what you are using it for. I often draw lines with Max2D to show vectors but only during debug.
Good point, you'd need to check the normals of vertices before drawing to make sure they are part of a polygon facing the camera. Only I'm not sure how to do that :P
hmm during debug would suffice, I'll try it.