December 03, 2020, 07:50:56 PM

### Author Topic: [bb] triangle - box intersection by elias_t [ 1+ years ago ]  (Read 695 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] triangle - box intersection by elias_t [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : triangle - box intersection
Author : elias_t
Posted : 1+ years ago

Description : A dll that allows intersection between a triangle and a box.
Get it from here:
<a href="http://telias.free.fr/3d_blitz3d.html" target="_blank">http://telias.free.fr/3d_blitz3d.html[/url]

Original code is by Tomas Moller.

Code :
Code: BlitzBasic
1. ;USE tribox2.cpp !!!!
2.
3. ;EXAMPLE
4.
5. Graphics3D 640,480,32,2
6.
7. cam=CreateCamera()
8. PositionEntity cam,0,5,-10
9. li=CreateLight()
10.
11.
12.
13.
14.
15.
16. ;the bounding box
17. bx#=1 ; box x min
18. by#=2 ; box y min
19. bz#=3 ; box z min
20.
21. bw#=3 ; box width
22. bh#=4 ; box height
23. bd#=5 ; box depth
24.
25.
26.
27.
28. box=CreateCube()
29. EntityColor box,0,255,100
30. EntityFX box,16
31. EntityAlpha box,.7
32.
33. FitMesh box, bx,by,bz, bw,bh,bd
34.
35.
36.
37.
38. ;tri visualization
39. p0x#=6:p0y#=10:p0z#=-10
40. p1x#=-8:p1y#=-5:p1z#=45;movable
41. p2x#=8:p2y#=10:p2z#=-10
42.
43. m=CreateMesh()
44. s=CreateSurface(m)
49. EntityColor m,255,255,0
50. EntityFX m,16
51. VertexCoords(s,0,p0x,p0y,p0z)
52. VertexCoords(s,1,p1x,p1y,p1z)
53. VertexCoords(s,2,p2x,p2y,p2z)
54. UpdateNormals m
55.
56. PositionEntity cam,10,15,-10
57. PointEntity cam ,m
58.
59.
60.
61. ;the bank we need to pass to the dll
62. bank=CreateBank(15*4)
63.
64. ;box center
65. PokeFloat bank,0,bx+bw/2.0
66. PokeFloat bank,4,by+bh/2.0
67. PokeFloat bank,8,bz+bd/2.0
68. ;box halfsize
69. PokeFloat bank,12,bw/2.0
70. PokeFloat bank,16,bh/2.0
71. PokeFloat bank,20,bd/2.0
72. ;triangle vertices
73. ;v0
74. PokeFloat bank,24,p0x
75. PokeFloat bank,28,p0y
76. PokeFloat bank,32,p0z
77. ;v1
78. PokeFloat bank,36,p1x
79. PokeFloat bank,40,p1y
80. PokeFloat bank,44,p1z
81. ;v2
82. PokeFloat bank,48,p2x
83. PokeFloat bank,52,p2y
84. PokeFloat bank,56,p2z
85.
86.
87. While Not KeyHit(1)
88.
89. RenderWorld()
90.
91. If KeyDown(200) VertexCoords(s,1,VertexX(s,1),VertexY(s,1)+.1,VertexZ(s,1))
92. If KeyDown(208) VertexCoords(s,1,VertexX(s,1),VertexY(s,1)-.1,VertexZ(s,1))
93.
94. If KeyDown(203) VertexCoords(s,1,VertexX(s,1)-.1,VertexY(s,1),VertexZ(s,1))
95. If KeyDown(205) VertexCoords(s,1,VertexX(s,1)+.1,VertexY(s,1),VertexZ(s,1))
96.
97.
98. ;update the bank for v1
99. PokeFloat bank,36,VertexX(s,1)
100. PokeFloat bank,40,VertexY(s,1)
101. PokeFloat bank,44,VertexZ(s,1)
102.
103. res=triBox(bank)
104.
105. Text 10,10,res
106.
107. Flip
108.
109. Wend
110.
111. End

aab(Posted 1+ years ago)

Usefullsimple to useThanku

elias_t(Posted 1+ years ago)

Sorry I putted a wrong title for this.It is actually a triangle-box intersection algorithm instead of 3d line segment - box intersection.I confused it with some other code I am working on.

aab(Posted 1+ years ago)

*noticed earlier.I bet it'llget more attention written as 'Tri' in the title, it makes it 10x More usefull!

Santiworld(Posted 1+ years ago)

how use this?

Kryzon(Posted 1+ years ago)

yeah, just having "bank*" as argument doesn't really explain how to use this DLL...