January 21, 2021, 05:39:20 AM

### Author Topic: 3D Lines  (Read 492 times)

#### JBR

• Full Member
• Posts: 123
##### 3D Lines
« on: April 23, 2020, 01:32:15 AM »
Is it possible to use a scaled cylinder and AlignToVector?

Can't get it to work.

Any ideas?

Jim

#### JBR

• Full Member
• Posts: 123
##### Re: 3D Lines
« Reply #1 on: April 24, 2020, 10:54:46 PM »
Ok I've got it to work! I was using some ones BB code but it used pivots & extra sphere but gave me some ideas.

The code is simple enough, build the cylinder in code as CreateCylinder() is slow and uses 2 surfaces.

(Line_Scale is the width of the line, try 0.015 but you can always ScaleEntity the line after it has been made to match distance from camera)

Code: [Select]
`Function Make_Line:TEntity(Surf:TSurface, vert_1%, vert_2%) Local x1# = VertexX#(Surf, vert_1) Local y1# = VertexY#(Surf, vert_1) Local z1# = VertexZ#(Surf, vert_1) Local x2# = VertexX#(Surf, vert_2) Local y2# = VertexY#(Surf, vert_2) Local z2# = VertexZ#(Surf, vert_2) Local le# = Sqr( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1) ) / 2.0  Local c3:TMesh = CreateMesh() Local ssss:TSurface = CreateSurface(c3) For Local v% = 0 To 6-1 AddVertex ssss, Cos(v*60), -1, Sin(v*60) Next For Local v% = 0 To 6-1 AddVertex ssss, Cos(v*60), +1, Sin(v*60) Next For Local t% = 0 To 6-1 AddTriangle ssss, t, t+6, 6+((t+1) Mod 6) AddTriangle ssss, t, 6+(t+1) Mod 6, (t+1) Mod 6 Next For Local i% = 0 To 5-2 AddTriangle  ssss, 0,i%+1,i%+2 Next For Local i% = 6 To 11-2 AddTriangle  ssss, 6,i%+2,i%+1 Next ScaleEntity c3, Line_scale, le, Line_scale PositionEntity c3, (x1+x2)/2.0, (y1+y2)/2.0, (z1+z2)/2.0 AlignToVector c3, x2-x1, y2-y1, z2-z1, 2, 1 Return(c3)End Function`