i have found a work around the problem described by falsam here
http://forums.purebasic.fr/english/view ... 36&t=56083
in concise there is a table (ground) and added to it 4 walls (all made from scaled cubes) with AttachEntityObject(...) function. and we enable physics to the all objects. when we rotate the table we see that the sphere with enough speed will go through the walls.
several users have reported this phenomena.
there is a solution even it needs a more coding, but it is automatic.
i will construct the same table and walls like this:
1-
CreateMesh(0, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
CreateCube(30,10)
CopyMesh(30,31) ; make a copy of the original cube mesh
2- scale the mesh as you want with TransformMesh: such as:
TransformMesh(31,0,0,0, 7.6,1,7.6,0,0,0)
from doc: TransformMesh(#Mesh, x, y, z, ScaleX, ScaleY, ScaleZ, RotateX, RotateY, RotateZ [, SubMesh])
3- GetMeshData into the Arrays MeshData and MeshDataInd (created previously)
and don't forget to use the switch #PB_Mesh_UVCoordinate
4- to make the ground, use this:
Code: Select all
ArrSize = ArraySize(MeshData())
;main mesh: the ground or the Table
For c=0 To ArrSize
x.f = MeshData(c)\x
y.f = MeshData(c)\y
z.f = MeshData(c)\z
MeshVertexPosition(x,y,z)
MeshVertexTextureCoordinate(MeshData(c)\u, MeshData(c)\v)
Next
ArrSizeInd = ArraySize(MeshDataInd())
For i=0 To ArrSizeInd Step 3
MeshFace(MeshDataInd(i)\Index, MeshDataInd(i+1)\Index,MeshDataInd(i+2)\Index)
Next
AddSubMesh(#PB_Mesh_TriangleList)
5- continue to the next Left wall and any object you want, and finally use FinishMesh(#True)
and CreateEntity(...)
and so you have in reality a One Mesh with strong physics if enabled.
note that AddSubMesh(#PB_Mesh_TriangleList) will add submesh with a number above the the parent mesh 0 so here the last submesh is the big sphere sticky on the ground and its number is 5. the texturing can be made for every submesh alone such as SetEntityMaterial(0,MaterialID(3),2) ;will texture the submesh 2 Right Wall with materialId 3
Note: don't choose very small sphere since it will penetrate the other objects whether it is made using this method or not.
also it is necessary to add:
DisableEntityBody(#sphere, #False)
ApplyEntityImpulse(#sphere, 0, 0, 0 )
at the moment when you rotate the table, to keep the sphere alive
Note: now when you save the Mesh you will save all the compound structure, press 'S' to save the mesh to "compound.mesh", look at it in a mesh viewer and you will see it like what you have already designed.
workes only in PB 5.50 beta 1 and later , will work in 5.42 but with one texture for all
Code: Select all
Enumeration
#LIGHT
#CAMERA
#mainwin
#Plane
#sphere
EndEnumeration
Structure vector3d
x.f
y.f
z.f
EndStructure
Structure vertex
x.f
y.f
z.f
EndStructure
Define.f KeyX, KeyY, MouseX, MouseY
Global Dim MeshData.PB_MeshVertex(0)
Global Dim MeshDataInd.PB_MeshFace(0)
Global Dim MeshData2.PB_MeshVertex(0)
Global Dim MeshDataInd2.PB_MeshFace(0)
ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "press Z / X to rotate Ground left/Right, ... use mouse + Arrows to rotate + move Camera", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Define.f KeyX, KeyY
Declare CreateMatrix()
If InitEngine3D()
Add3DArchive("\", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Models", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts",#PB_3DArchive_FileSystem)
Parse3DScripts()
InitSprite()
InitKeyboard()
InitMouse()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
CreateMaterial(0, LoadTexture(0, "White.jpg"))
DisableMaterialLighting(0, #True)
MaterialShadingMode(0, #PB_Material_Wireframe )
MaterialCullingMode(0, #PB_Material_NoCulling)
CreateCamera(#camera, 0, 0, 100, 100)
MoveCamera(#camera, 0, 70, 80, #PB_Absolute)
CameraFOV(#camera, 70)
CameraBackColor(#camera, RGB(255,200,200))
CameraLookAt(#camera,0,0,0)
CreateLight(0, RGB(255,255,255), 0, 20, 30)
AmbientColor(RGB(200, 200, 200))
CreateMaterial(3, LoadTexture(3, "snow_1024.jpg"))
DisableMaterialLighting(3, #False)
SetMaterialColor(3, #PB_Material_AmbientColor, RGB(250, 255, 0))
SetMaterialColor(3, #PB_Material_SpecularColor, RGB(255, 255, 0))
CreateMaterial(1, LoadTexture(1, "MRAMOR6X6.jpg"))
MaterialCullingMode(1, #PB_Material_NoCulling)
CreateMaterial(2, LoadTexture(2, "RustySteel.jpg"))
MaterialCullingMode(2, #PB_Material_NoCulling)
CreateMaterial(4, LoadTexture(4, "ground_diffuse.png"))
MaterialCullingMode(4, #PB_Material_NoCulling)
CreateMaterial(5, LoadTexture(5, "Geebee2.bmp"))
MaterialCullingMode(5, #PB_Material_NoCulling)
CreateMatrix()
SetEntityMaterial(0,MaterialID(5),5) ;the sphere sticky on the ground
SetEntityMaterial(0,MaterialID(1),0) ;Ground
SetEntityMaterial(0,MaterialID(3),1) ;Left wall
SetEntityMaterial(0,MaterialID(3),2) ;Right wall
WorldGravity(-20)
CreateSphere(#sphere, 3)
CreateEntity(#sphere, MeshID(#sphere), MaterialID(5), 0, 60, 4)
CreateEntityBody(#sphere, #PB_Entity_SphereBody, 0.5,0.5,0.2)
Repeat
Event = WindowEvent()
If ExamineMouse()
MouseX = -MouseDeltaX()/20
MouseY = -MouseDeltaY()/20
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -1
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = 1
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -1
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = 1
Else
KeyY = 0
EndIf
If KeyboardPushed(#PB_Key_Z)
DisableEntityBody(#sphere, #False)
ApplyEntityImpulse(#sphere, 0, 0, 0 )
RotateEntity(0,0,0,0.5, #PB_Relative)
ElseIf KeyboardPushed(#PB_Key_X)
DisableEntityBody(#sphere, #False)
ApplyEntityImpulse(#sphere, 0, 0, 0 )
RotateEntity(0,0,0,-0.5, #PB_Relative)
EndIf
If KeyboardPushed(#PB_Key_S)
SaveMesh(0, "Compound.mesh")
EndIf
EndIf
rot.f+0.6
RotateCamera(#Camera, MouseY, MouseX, 0, #PB_Relative)
MoveCamera(#Camera, KeyX, 0, KeyY)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
Procedure CreateMatrix()
CreateMesh(0, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
CreateCube(30,10)
CopyMesh(30,31)
;TransformMesh(#Mesh, x, y, z, ScaleX, ScaleY, ScaleZ, RotateX, RotateY, RotateZ [, SubMesh])
TransformMesh(31,0,0,0, 7.6,1,7.6,0,0,0)
GetMeshData(31,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate , 0, MeshVertexCount(31)-1)
GetMeshData(31,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(31, 0)-1)
ArrSize = ArraySize(MeshData())
;main mesh: the ground or the Table
For c=0 To ArrSize
x.f = MeshData(c)\x
y.f = MeshData(c)\y
z.f = MeshData(c)\z
MeshVertexPosition(x,y,z)
MeshVertexTextureCoordinate(MeshData(c)\u, MeshData(c)\v)
Next
ArrSizeInd = ArraySize(MeshDataInd())
For i=0 To ArrSizeInd Step 3
MeshFace(MeshDataInd(i)\Index, MeshDataInd(i+1)\Index,MeshDataInd(i+2)\Index)
Next
AddSubMesh(#PB_Mesh_TriangleList)
;left wall
CopyMesh(30,31)
TransformMesh(31,-35,15,0, 0.5,2,7.6,0,0,0)
GetMeshData(31,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate, 0, MeshVertexCount(31)-1)
GetMeshData(31,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(31, 0)-1)
ArrSize = ArraySize(MeshData())
For c=0 To ArrSize
x.f = MeshData(c)\x
y.f = MeshData(c)\y
z.f = MeshData(c)\z
MeshVertexPosition(x,y,z)
MeshVertexTextureCoordinate(MeshData(c)\u, MeshData(c)\v)
Next
ArrSizeInd = ArraySize(MeshDataInd())
For i=0 To ArrSizeInd Step 3
MeshFace(MeshDataInd(i)\Index, MeshDataInd(i+1)\Index,MeshDataInd(i+2)\Index)
Next
AddSubMesh(#PB_Mesh_TriangleList)
;right wall
CopyMesh(30,31)
TransformMesh(31, 35,15,0, 0.5,2,7.6,0,0,0)
GetMeshData(31,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate, 0, MeshVertexCount(31)-1)
GetMeshData(31,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(31, 0)-1)
ArrSize = ArraySize(MeshData())
For c=0 To ArrSize
x.f = MeshData(c)\x
y.f = MeshData(c)\y
z.f = MeshData(c)\z
MeshVertexPosition(x,y,z)
MeshVertexTextureCoordinate(MeshData(c)\u, MeshData(c)\v)
Next
ArrSizeInd = ArraySize(MeshDataInd())
For i=0 To ArrSizeInd Step 3
MeshFace(MeshDataInd(i)\Index, MeshDataInd(i+1)\Index,MeshDataInd(i+2)\Index)
Next
AddSubMesh(#PB_Mesh_TriangleList)
; front wall
CopyMesh(30,31)
TransformMesh(31,0,11,38, 6.5,1,0.2,0,0,0)
GetMeshData(31,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate, 0, MeshVertexCount(31)-1)
GetMeshData(31,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(31, 0)-1)
ArrSize = ArraySize(MeshData())
For c=0 To ArrSize
x.f = MeshData(c)\x
y.f = MeshData(c)\y
z.f = MeshData(c)\z
MeshVertexPosition(x,y,z)
MeshVertexTextureCoordinate(MeshData(c)\u, MeshData(c)\v)
Next
ArrSizeInd = ArraySize(MeshDataInd())
For i=0 To ArrSizeInd Step 3
MeshFace(MeshDataInd(i)\Index, MeshDataInd(i+1)\Index,MeshDataInd(i+2)\Index)
Next
AddSubMesh(#PB_Mesh_TriangleList)
; back wall
CopyMesh(30,31)
TransformMesh(31,0,11,-38, 6.5,1,0.2,0,0,0)
GetMeshData(31,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate, 0, MeshVertexCount(31)-1)
GetMeshData(31,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(31, 0)-1)
ArrSize = ArraySize(MeshData())
For c=0 To ArrSize
x.f = MeshData(c)\x
y.f = MeshData(c)\y
z.f = MeshData(c)\z
MeshVertexPosition(x,y,z)
MeshVertexTextureCoordinate(MeshData(c)\u, MeshData(c)\v)
Next
ArrSizeInd = ArraySize(MeshDataInd())
For i=0 To ArrSizeInd Step 3
MeshFace(MeshDataInd(i)\Index, MeshDataInd(i+1)\Index,MeshDataInd(i+2)\Index)
Next
;just extra sphere
AddSubMesh(#PB_Mesh_TriangleList)
CreateSphere(31,10)
TransformMesh(31,0,11,-20, 1,1,1,0,0,0)
GetMeshData(31,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate , 0, MeshVertexCount(31)-1)
GetMeshData(31,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(31, 0)-1)
ArrSize = ArraySize(MeshData())
For c=0 To ArrSize
x.f = MeshData(c)\x
y.f = MeshData(c)\y
z.f = MeshData(c)\z
MeshVertexPosition(x,y,z)
MeshVertexTextureCoordinate(MeshData(c)\u, MeshData(c)\v)
Next
ArrSizeInd = ArraySize(MeshDataInd())
For i=0 To ArrSizeInd Step 3
MeshFace(MeshDataInd(i)\Index, MeshDataInd(i+1)\Index,MeshDataInd(i+2)\Index)
Next
FinishMesh(#True)
SetMeshMaterial(0, MaterialID(0))
CreateEntity(0, MeshID(0), MaterialID(2), 0,-10,0)
CreateEntityBody(0, #PB_Entity_StaticBody, 1, 0.2, 1)
EndProcedure
Note:note that i have used #PB_Entity_ConvexHullBody in EntityPhysicBody(#sphere2, #PB_Entity_ConvexHullBody, 1,0.2,1) for the big sphere over the cone opening, else if we use #PB_Entity_SphereBody it will go through the cone opening. thats something to consider, sometimes #PB_Entity_ConvexHullBody are better to use
Code: Select all
Enumeration
#MESH = 970
#LIGHT
#CAMERA
#mainwin
#Window
#Plane
#sphere
#sphere2
EndEnumeration
Structure vector3d
x.f
y.f
z.f
EndStructure
Structure vertex
x.f
y.f
z.f
EndStructure
Define.f KeyX, KeyY, MouseX, MouseY
Global Dim MeshData.PB_MeshVertex(0)
Global Dim MeshDataInd.PB_MeshFace(0)
ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "press Z / X to rotate Ground left/Right, ... use mouse + Arrows to rotate + move Camera", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Define.f KeyX, KeyY
Declare DrawTube (x.f, y.f,z.f, x2.f, y2.f, z2.f, RadiusS.f, RadiusE.f, TubeShape)
Declare TubeXYZ (tube, x.f, y.f, z.f, x2.f, y2.f, z2.f, RadiusS.f, RadiusE.f, TubeShape, Material)
Declare CreateMatrix()
Declare DrawMatrix()
Declare Ground()
Declare Wall_Left()
Declare Wall_Right()
Declare Wall_Back()
Declare Wall_Front()
If InitEngine3D()
Add3DArchive("\", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Models", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts",#PB_3DArchive_FileSystem)
Parse3DScripts()
InitSprite()
InitKeyboard()
InitMouse()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
CreateMaterial(0, LoadTexture(0, "White.jpg"))
DisableMaterialLighting(0, #True)
MaterialShadingMode(0, #PB_Material_Wireframe )
MaterialCullingMode(0, #PB_Material_NoCulling)
CreateCamera(#camera, 0, 0, 100, 100)
MoveCamera(#camera, 0, 70, 80, #PB_Absolute)
CameraFOV(#camera, 70)
CameraBackColor(#camera, RGB(255,200,200))
CameraLookAt(#camera,0,0,0)
CreateLight(0, RGB(255,255,255), 0, 20, 30)
AmbientColor(RGB(200, 200, 200))
CreateMaterial(3, LoadTexture(3, "snow_1024.jpg"))
DisableMaterialLighting(3, #False)
SetMaterialColor(3, #PB_Material_AmbientColor, RGB(250, 255, 0))
SetMaterialColor(3, #PB_Material_SpecularColor, RGB(255, 255, 0))
CreateMaterial(1, LoadTexture(1, "MRAMOR6X6.jpg"))
MaterialCullingMode(1, #PB_Material_NoCulling)
CreateMaterial(2, LoadTexture(2, "RustySteel.jpg"))
MaterialCullingMode(2, #PB_Material_NoCulling)
CreateMaterial(4, LoadTexture(4, "ground_diffuse.png"))
MaterialCullingMode(4, #PB_Material_NoCulling)
CreateMaterial(5, LoadTexture(5, "Geebee2.bmp"))
MaterialCullingMode(5, #PB_Material_NoCulling)
CreateMatrix()
;WorldDebug(#PB_World_DebugEntity)
;WorldDebug(#PB_World_DebugBody )
;RotateEntity(0, 0,0,150)
;RotateMaterial(1, 20, #PB_Material_Fixed )
SetEntityMaterial(0,MaterialID(4),5)
SetEntityMaterial(0,MaterialID(1),0)
SetEntityMaterial(0,MaterialID(3),1)
SetEntityMaterial(0,MaterialID(3),2)
WorldGravity(-20)
CreateSphere(#sphere2, 4)
CreateEntity(#sphere2, MeshID(#sphere2), MaterialID(5), 0, 200, 0)
EntityPhysicBody(#sphere2, #PB_Entity_ConvexHullBody, 1,0.2,1)
CreateSphere(#sphere, 3)
CreateEntity(#sphere, MeshID(#sphere), MaterialID(5), 0, 70, 4)
EntityPhysicBody(#sphere, #PB_Entity_SphereBody, 0.5,0.5,0.2)
Repeat
Event = WindowEvent()
If ExamineMouse()
MouseX = -MouseDeltaX()/20
MouseY = -MouseDeltaY()/20
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -1
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = 1
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -1
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = 1
Else
KeyY = 0
EndIf
If KeyboardPushed(#PB_Key_Z)
DisableEntityBody(#sphere, #False)
ApplyEntityImpulse(#sphere, 0, 0, 0 )
DisableEntityBody(#sphere2, #False)
ApplyEntityImpulse(#sphere2, 0, 0, 0 )
RotateEntity(0,0,0,0.5, #PB_Relative)
ElseIf KeyboardPushed(#PB_Key_X)
DisableEntityBody(#sphere, #False)
ApplyEntityImpulse(#sphere, 0, 0, 0 )
DisableEntityBody(#sphere2, #False)
ApplyEntityImpulse(#sphere2, 0, 0, 0 )
RotateEntity(0,0,0,-0.5, #PB_Relative)
EndIf
EndIf
rot.f+0.6
RotateCamera(#Camera, MouseY, MouseX, 0, #PB_Relative)
MoveCamera(#Camera, KeyX, 0, KeyY)
;RotateEntity(0,0,rot,0)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
Procedure DrawMatrix()
Ground()
AddSubMesh(#PB_Mesh_TriangleList)
Wall_Left()
AddSubMesh(#PB_Mesh_TriangleList)
Wall_Right()
AddSubMesh(#PB_Mesh_TriangleList)
Wall_Back()
AddSubMesh(#PB_Mesh_TriangleList)
Wall_Front()
AddSubMesh(#PB_Mesh_TriangleList)
tube = 200
;TubeXYZ (tube, x.f, y.f, z.f, x2.f, y2.f, z2.f, RadiusS.f, RadiusE.f, TubeShape, Material)
TubeXYZ (tube, 0, 6,0, 0, 40,0, 20, 3, 8, 1) ; call the tube making function
EndProcedure
Procedure CreateMatrix()
CreateMesh(0, #PB_Mesh_TriangleList, #True)
DrawMatrix()
FinishMesh(#True)
SetMeshMaterial(0, MaterialID(0))
CreateEntity(0, MeshID(0), MaterialID(2), 0,-10,0)
;EntityPhysicBody(0, #PB_Entity_ConvexHullBody, 1, 0.2, 1)
EntityPhysicBody(0, #PB_Entity_StaticBody, 1, 0.2, 1)
;ScaleEntity(0, 20, 4, 20)
GetMeshData(0,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(0)-1)
GetMeshData(0,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(0, 0)-1)
EndProcedure
;beginning of frenet sqaure approximation 5 procedures
Procedure vector_cross(*v1.vector3d, *v2.vector3d, *vout.vector3d)
*vout\x = (*v1\y * *v2\z) - (*v2\y * *v1\z)
*vout\y = (*v1\z * *v2\x) - (*v2\z * *v1\x)
*vout\z = (*v1\x * *v2\y) - (*v2\x * *v1\y)
EndProcedure
Procedure.f vector_magnitude(*v.vector3d)
mag.f
mag = Sqr(*v\x * *v\x + *v\y * *v\y + *v\z * *v\z)
If mag = 0:mag = 1:EndIf
ProcedureReturn mag
EndProcedure
Procedure vector_normalize (*v.vector3d)
mag.f
mag = vector_magnitude(*v)
*v\x = *v\x / mag
*v\y = *v\y / mag
*v\z = *v\z / mag
EndProcedure
Procedure vector_add (*v1.vector3d, *v2.vector3d, *vout.vector3d)
*vout\x = *v1\x + *v2\x
*vout\y = *v1\y + *v2\y
*vout\z = *v1\z + *v2\z
EndProcedure
Procedure vector_sub (*v1.vector3d, *v2.vector3d, *vout.vector3d)
*vout\x = *v1\x - *v2\x
*vout\y = *v1\y - *v2\y
*vout\z = *v1\z - *v2\z
EndProcedure
;end of frenet sqaure approximation 5 procedures
Procedure DrawTube (x.f, y.f,z.f, x2.f, y2.f,z2.f, RadiusS.f, RadiusE.f, TubeShape)
#Rings = 2
Dim vertx.vertex(2)
lineVec.vector3d
u.f: r.f
txu.f : txv.f
x1.f = x
y1.f = y
z1.f = z
bands = TubeShape ; 2 flat tube, 3 triangular tube, 4 rectangular, 8 almost cylindrical tube
;vector of the line between start vertex and the end vertex
lineVec\x = x2 - x1
lineVec\y = y2 - y1
lineVec\z = z2 - z1
tt.f = 0
For i=0 To 2
x = x1 + lineVec\x * tt
y = y1 + lineVec\y * tt
z = z1 + lineVec\z * tt
tt + 1
vertx(i)\x = x
vertx(i)\y = y
vertx(i)\z = z
Next
current_point.vector3d
next_point.vector3d
T.vector3d
B.vector3d
N.vector3d
p.f
For i = 0 To 1
If i=0 ; to manage the radius of tube start and tube end
Radius.f = RadiusS
Else
Radius.f=RadiusE
EndIf
;center point
current_point\x = vertx(i)\x
current_point\y = vertx(i)\y
current_point\z = vertx(i)\z
;next point For Frenet square
next_point\x = vertx(i+1)\x
next_point\y = vertx(i+1)\y
next_point\z = vertx(i+1)\z
;T = P' - P
vector_sub(next_point, current_point, T)
;N = P' + P
vector_add(next_point, current_point, N)
;B = T x N
vector_cross(T, N, B)
;N = B x T
vector_cross(B, T, N)
;Normalize vectors Or Else it won't work
vector_normalize(B)
vector_normalize(N)
For j = 0 To bands
new_point_x.f
new_point_y.f
;rotate around the current point using normal rotation makes bands
new_point_x = Sin(j * (#PI*2) / bands) * Radius
new_point_y = Cos(j * (#PI*2) / bands) * Radius
;this is the coordinates of our point along the curve
x = N\x * new_point_x + B\x * new_point_y + current_point\x
y = N\y * new_point_x + B\y * new_point_y + current_point\y
z = N\z * new_point_x + B\z * new_point_y + current_point\z
MeshVertexPosition(x, y, z)
MeshVertexTextureCoordinate(txu, txv)
MeshVertexNormal(x, y, z)
txv = txv + 1/#Rings
Next
txv = 0
txu = txu + 1/bands
Next
v.l
For j = 0 To bands -1
MeshFace(v,v+1,v + bands+1)
MeshFace(v + bands+1,v + bands+2,v+1 )
v + 1
Next
EndProcedure
Procedure TubeXYZ (tube, x.f, y.f,z.f, x2.f, y2.f,z2.f, RadiusS.f, RadiusE.f, TubeShape, Material)
x.f+0.00001 : y.f+0.00001 : z.f+0.00001 ; +0.00001 necessary if x,y,z or x2,y2,z2 are zero !!!
x2.f+0.00001 : y2.f+0.00001 : z2.f+0.00001
;CreateMesh(tube , #PB_Mesh_TriangleList, #PB_Mesh_Dynamic )
DrawTube (x, y, z, x2, y2, z2, RadiusS, RadiusE, TubeShape)
;FinishMesh(tube)
;NormalizeMesh(tube)
;BuildMeshTangents(tube)
;CreateEntity(tube,MeshID(tube),MaterialID(Material))
EndProcedure
Procedure Ground()
txu.f: txv.f
MeshVertexPosition(40,2,40)
MeshVertexTextureCoordinate(txu.f, txv.f)
MeshVertexNormal(40,2,40)
txv.f + 1/1
MeshVertexPosition(40,-2,40)
;MeshVertexTextureCoordinate(txu, txv)
MeshVertexNormal(40,-2,40)
;txv = 0
;txu+1/2
MeshVertexPosition(-40,-2,40)
;MeshVertexTextureCoordinate(txu, txv)
MeshVertexNormal(-40,-2,40)
;txv + 1/1
MeshVertexPosition(-40,2,40)
MeshVertexTextureCoordinate(txu, txv)
MeshVertexNormal(-40,2,40)
txv = 0
txu + 1/1
MeshVertexPosition(40,2,-40)
MeshVertexTextureCoordinate(txu, txv)
MeshVertexNormal(40,2,-40)
txv + 1/1
MeshVertexPosition(40,-2,-40)
;MeshVertexTextureCoordinate(txu, txv)
MeshVertexNormal(40,-2,-40)
;txv = 0
;txu + 1/2
MeshVertexPosition(-40,-2,-40)
;MeshVertexTextureCoordinate(txu, txv)
MeshVertexNormal(-40,-2,-40)
;txv + 1/1
MeshVertexPosition(-40,2,-40)
MeshVertexTextureCoordinate(txu, txv)
MeshVertexNormal(-40,2,-40)
MeshFace(0,2,1)
MeshFace(0,3,2)
MeshFace(4,5,6)
MeshFace(4,6,7)
MeshFace(0,1,4)
MeshFace(1,5,4)
MeshFace(2,3,6)
MeshFace(3,7,6)
MeshFace(0,4,3)
MeshFace(3,4,7)
MeshFace(1,2,5)
MeshFace(2,6,5)
EndProcedure
Procedure Wall_Left()
MeshVertexPosition(-38, 8,40)
MeshVertexPosition(-38, 2,40)
MeshVertexPosition(-40, 2,40)
MeshVertexPosition(-40,8,40)
MeshVertexPosition(-38,8,-40)
MeshVertexPosition(-38,2,-40)
MeshVertexPosition(-40,2,-40)
MeshVertexPosition(-40,8,-40)
MeshFace(0,2,1)
MeshFace(0,3,2)
MeshFace(4,5,6)
MeshFace(4,6,7)
MeshFace(0,1,4)
MeshFace(1,5,4)
MeshFace(2,3,6)
MeshFace(3,7,6)
MeshFace(0,4,3)
MeshFace(3,4,7)
MeshFace(1,2,5)
MeshFace(2,6,5)
EndProcedure
Procedure Wall_Right()
MeshVertexPosition(40,8,40)
MeshVertexPosition(40,2,40)
MeshVertexPosition(38,2,40)
MeshVertexPosition(38,8,40)
MeshVertexPosition(40,8,-40)
MeshVertexPosition(40,2,-40)
MeshVertexPosition(38,2,-40)
MeshVertexPosition(38,8,-40)
MeshFace(0,2,1)
MeshFace(0,3,2)
MeshFace(4,5,6)
MeshFace(4,6,7)
MeshFace(0,1,4)
MeshFace(1,5,4)
MeshFace(2,3,6)
MeshFace(3,7,6)
MeshFace(0,4,3)
MeshFace(3,4,7)
MeshFace(1,2,5)
MeshFace(2,6,5)
EndProcedure
Procedure Wall_Back()
MeshVertexPosition(38,8,-38)
MeshVertexPosition(38,2,-38)
MeshVertexPosition(-38,2,-38)
MeshVertexPosition(-38,8,-38)
MeshVertexPosition(38,8,-40)
MeshVertexPosition(38,2,-40)
MeshVertexPosition(-38,2,-40)
MeshVertexPosition(-38,8,-40)
MeshFace(0,2,1)
MeshFace(0,3,2)
MeshFace(4,5,6)
MeshFace(4,6,7)
MeshFace(0,1,4)
MeshFace(1,5,4)
MeshFace(2,3,6)
MeshFace(3,7,6)
MeshFace(0,4,3)
MeshFace(3,4,7)
MeshFace(1,2,5)
MeshFace(2,6,5)
EndProcedure
Procedure Wall_Front()
MeshVertexPosition(38,8,40)
MeshVertexPosition(38,2,40)
MeshVertexPosition(-38,2,40)
MeshVertexPosition(-38,8,40)
MeshVertexPosition(38,8,38)
MeshVertexPosition(38,2,38)
MeshVertexPosition(-38,2,38)
MeshVertexPosition(-38,8,38)
MeshFace(0,2,1)
MeshFace(0,3,2)
MeshFace(4,5,6)
MeshFace(4,6,7)
MeshFace(0,1,4)
MeshFace(1,5,4)
MeshFace(2,3,6)
MeshFace(3,7,6)
MeshFace(0,4,3)
MeshFace(3,4,7)
MeshFace(1,2,5)
MeshFace(2,6,5)
EndProcedure