I've written this code to emulate the 2d Line function using single surface triangles. The code works great as long as the origin of the line is 0,0. If I change the origin it all goes a bit "Pete Tong".
Can anyone help? I also want the origin to map on to the normal 2d co-ords, ie. 0,0 = Top Left.
Thanks in advance.
Can anyone help? I also want the origin to map on to the normal 2d co-ords, ie. 0,0 = Top Left.
Thanks in advance.
Graphics3D 800,600,32,2 texsize = 64 LineTex = CreateTexture(texsize,texsize,2) SetBuffer TextureBuffer(LineTex) Line 0,0,0,texsize-1 SetBuffer BackBuffer() cam = CreateCamera() CameraProjMode cam,2 CameraZoom cam,0.1 SeedRnd MilliSecs() blob = line3d(0,0,0,30,30,1) EntityColor blob,0,255,255 EntityBlend blob,3 EntityTexture blob,LineTex For x = 0 To 100 blob = line3d(blob,0,0,Rnd(-400,400),Rnd(-300,300),Rnd(0.1,0.9)) Next ;WireFrame 1 While Not KeyHit(1) If Not MouseDown(1) Then TurnEntity blob,0,0,.1 RenderWorld Text 0,0,TrisRendered() Flip ;False Wend Function Line3D(Mesh,x0#,y0#,x1#,y1#,thickness#=0.5) pivot = CreatePivot() PositionEntity pivot,x0,y0,10 rot# = ATan2(y1-y0,x1-x0) ; how much to rotate the quad to get the right angle. TurnEntity pivot,0,0,rot If Mesh = 0 Mesh = CreateMesh() surf = CreateSurface(Mesh) EntityFX Mesh,1+16 Else lastsurf = CountSurfaces(Mesh) surf = GetSurface(Mesh,lastsurf) If CountVertices(surf)>30000 surf = CreateSurface(Mesh) EndIf End If dx# = Abs(x1-x0) dy# = Abs(y1-y0) length# = Sqr((dx*dx)+(dy*dy)) sizex# = length/120 : sizeY# = thickness TFormPoint 0,0,0,Pivot,0 V = AddVertex(Surf,TFormedX(),TFormedY(),TFormedZ(),0,0) TFormPoint SizeX*3,0,0,Pivot,0 AddVertex(Surf,TFormedX(),TFormedY(),TFormedZ(),0,0.9) TFormPoint 0,-SizeY*3,0,Pivot,0 AddVertex(Surf,TFormedX(),TFormedY(),TFormedZ(),0.9,0.9) AddTriangle Surf,V,V+1,V+2 FreeEntity pivot Return Mesh End Function