Ooops
January 26, 2021, 10:54:44 AM

### Author Topic: [bb] Wire Primitives and Drawing by N [ 1+ years ago ]  (Read 599 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] Wire Primitives and Drawing by N [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Wire Primitives and Drawing
Author : N
Posted : 1+ years ago

Description : Functions to create wireframe primitives and draw them

Code :
Code: BlitzBasic
1. Graphics3D 800,600,32,2
2.
3. C = CreateCamera()
4. CameraClsColor C,240,255,215
5.
6. WireCylinder = CreateWireCylinder(8)
7. EntityColor WireCylinder,0,0,0
8. ScaleEntity WireCylinder,1.05,1.05,1.05
9. Cylinder = CreateCylinder(8)
10. EntityColor Cylinder,235,255,110
11. EntityAlpha Cylinder,.7
12. EntityParent Cylinder,WireCylinder
13.
14.
15. Cube = CreateCube()
16. WireCube = CreateWireCube()
17. ScaleEntity WireCube,1.05,1.05,1.05
18. EntityAlpha Cube,.7
19. EntityColor Cube,235,255,110
20. EntityColor WireCube,0,0,0
21. EntityParent Cube,WireCube
22.
23. Sphere = CreateSphere(4)
24. WireSphere = CreateWireSphere(4)
25. ScaleEntity WireSphere,1.05,1.05,1.05
26. EntityAlpha Sphere,.7
27. EntityColor Sphere,235,255,110
28. EntityColor WireSphere,0,0,0
29. EntityParent Sphere,WireSphere
30.
31. PositionEntity WireCube,3,0,-3
32. PositionEntity WireSphere,-3,0,3
33.
34. PositionEntity C,4,4,4
35. PointEntity C,Cylinder
36.
37. L = CreateLight(2)
38. PositionEntity L,4,4,4
39. LightRange L,4
40.
41. Repeat
42.         HideEntity Cylinder
43.         HideEntity Cube
44.         HideEntity Sphere
45.
46.         TurnEntity WireCylinder,.5,.6,.7
47.         TurnEntity WireCube,.5,.6,.7
48.         TurnEntity WireSphere,.5,.6,.7
49.
50.         DrawWireMeshes(C)
51.
52.         ShowEntity Cylinder
53.         ShowEntity Cube
54.         ShowEntity Sphere
55.
56.         RenderWorld
57.
58.         Flip
59.
60. Until KeyHit(1)
61.
62.
63.
64. Type WireMesh
65.         Field Entity
66. End Type
67.
68. Function DrawWireMeshes(Camera,Tween#=-1)
69.         For W.WireMesh = Each WireMesh
70.                 EntityAlpha WEntity,1
71.         Next
72.
73.         CameraClsMode Camera,1,1
74.         WireFrame True
75.
76.         If Tween Then
77.                 RenderWorld Tween
78.         Else
79.                 RenderWorld
80.         EndIf
81.
82.         WireFrame False
83.         CameraClsMode Camera,0,0
84.
85.         For W.WireMesh = Each WireMesh
86.                 EntityAlpha WEntity,0
87.         Next
88. End Function
89.
90. Function CreateWireCube()
91.         M=CreateMesh()
92.         S = CreateSurface(M)
93.         ;outer edges
94.         WireLine3D S,-1,-1,-1,-1,1,-1
95.         WireLine3D S,1,-1,-1,1,1,-1
96.         WireLine3D S,1,-1,1,1,1,1
97.         WireLine3D S,-1,-1,1,-1,1,1
98.
99.         ;top edges
100.         WireLine3D S,1,1,1,-1,1,1
101.         WireLine3D S,1,1,-1,-1,1,-1
102.         WireLine3D S,-1,1,-1,-1,1,1
103.         WireLine3D S,1,1,-1,1,1,1
104.
105.         ; bottom edges
106.         WireLine3D S,1,-1,1,-1,-1,1
107.         WireLine3D S,1,-1,-1,-1,-1,-1
108.         WireLine3D S,-1,-1,-1,-1,-1,1
109.         WireLine3D S,1,-1,-1,1,-1,1
110.
111.         EntityFX M,1+16
112.         EntityAlpha M,0
113.         W.WireMesh = New WireMesh
114.         WEntity = M
115.         Return M
116. End Function
117.
118. Function CreateWireSphere(Segments=8)
119.         M = CreateMesh()
120.         S = CreateSurface(M)
121.         Dummy = CreateSphere(Segments)
122.         DS = GetSurface(Dummy,1)
123.         For N = 0 To CountTriangles(DS)-1
124.                 V1 = TriangleVertex(DS,N,0)
125.                 V2 = TriangleVertex(DS,N,1)
126.                 V3 = TriangleVertex(DS,N,2)
127.                 If V1 < Segments*2 Then WireLine3D S,VertexX(DS,V1),VertexY(DS,V1),VertexZ(DS,V1),VertexX(DS,V2),VertexY(DS,V2),VertexZ(DS,V2)
128.                 WireLine3D S,VertexX(DS,V2),VertexY(DS,V2),VertexZ(DS,V2),VertexX(DS,V3),VertexY(DS,V3),VertexZ(DS,V3)
129.         Next
130.         FreeEntity Dummy
131.         EntityFX M,1+16
132.         EntityAlpha M,0
133.         W.WireMesh = New WireMesh
134.         WEntity = M
135.         Return M
136. End Function
137.
138. Function CreateWireCylinder(Segments=8)
139.         M = CreateMesh()
140.         S = CreateSurface(M)
141.         AngleStep# = 360.0/Segments
142.         While N < 360
143.                 WireLine3D S,Sin(N),1,Cos(N),Sin(N),-1,Cos(N)
144.                 WireLine3D S,Sin(N),1,Cos(N),Sin(N+AngleStep),1,Cos(N+AngleStep)
145.                 WireLine3D S,Sin(N),-1,Cos(N),Sin(N+AngleStep),-1,Cos(N+AngleStep)
146.                 N = N + AngleStep
147.         Wend
148.         EntityFX M,1+16
149.         EntityAlpha M,0
150.         W.WireMesh = New WireMesh
151.         WEntity = M
152.         Return M
153. End Function
154.
155. Function CreateWireRing(Segments=8)
156.         M = CreateMesh()
157.         S = CreateSurface(M)
158.         AngleStep# = 360.0/Segments
159.         While N < 360
160.                 WireLine3D S,Sin(N),0,Cos(N),Sin(N+AngleStep),0,Cos(N+AngleStep)
161.                 N = N + AngleStep
162.         Wend
163.         EntityFX M,1+16
164.         EntityAlpha M,0
165.         W.WireMesh = New WireMesh
166.         WEntity = M
167.         Return M
168. End Function
169.
170. Function WireLine3D(S,X#,Y#,Z#,X2#,Y2#,Z2#)
175. End Function

WildStorm(Posted 1+ years ago)

wow, very nice!

Filax(Posted 1+ years ago)

Great !!

puki(Posted 1+ years ago)

Actually that is a nice visual effect - kind of pleasing on the eye - in a way - difficult to describe, but I like it.

N(Posted 1+ years ago)

Glad to hear you liked it.

puki(Posted 1+ years ago)

Hey "Pigeon" has nicked "Noel Cower's" sig - not sure if that will go down too well around here - best you delete it before someone sees it.

N(Posted 1+ years ago)

That's right, I nicked that awesome man's signature so I can be as cool as him.

puki(Posted 1+ years ago)

Well, I'll just have to grass - this might be my ticket back into IRC.

Mikel(Posted 1+ years ago)

Most excellent! Very clean looking. Thanks!