i thought of Psychophanta approach to delete triangles. but it seems not real hollow, the ball does not pass through with MP_EntityPhysicBody(shape, 1, 1) after removing the cylinder 2 sides triangles
Michael code tubes with physics:
(but why we can't see the ball pass through a supposed transparent tube with MP_CreateOpenCylinder.)
Code: Select all
Structure Vector3
x.f
y.f
z.f
EndStructure
Procedure Normalize(*V.Vector3)
Define.f magSq, oneOverMag
magSq = *V\x * *V\x + *V\y * *V\y + *V\z * *V\z
If magsq > 0
oneOverMag = 1.0 / Sqr(magSq)
*V\x * oneOverMag
*V\y * oneOverMag
*V\z * oneOverMag
EndIf
EndProcedure
Procedure CreateTube(outerRadius.f, innerRadius.f, height.f, numSegBase=16, numSegHeight=1)
Protected Normal.Vector3, returnMesh.i
Color.l = $FFFFFF
returnMesh = MP_CreateMesh()
If numSegBase < 1
numSegBase = 1
EndIf
If numSegHeight < 1
numSegHeight = 1
EndIf
deltaAngle.f = #PI*2 / numSegBase
deltaHeight.f = height / numSegHeight
height2.f = height / 2.0
offset = 0
For i = 0 To numSegHeight
For j = 0 To numSegBase
x0.f = outerRadius * Cos(j*deltaAngle)
z0.f = outerRadius * Sin(j*deltaAngle)
Normal\x = x0
Normal\y = 0
Normal\z = z0
Normalize(@Normal)
MP_AddVertex(returnMesh,x0, i*deltaHeight-height2, z0 , Color , j / numSegBase, i / numSegHeight, Normal\x, Normal\y, Normal\z)
If i <> numSegHeight
MP_AddTriangle(returnMesh,offset + numSegBase + 1,offset,offset + numSegBase)
MP_AddTriangle(returnMesh,offset + numSegBase + 1,offset + 1,offset)
EndIf
offset + 1
Next
Next
For i = 0 To numSegHeight
For j = 0 To numSegBase
x0.f = innerRadius * Cos(j*deltaAngle)
z0.f = innerRadius * Sin(j*deltaAngle)
Normal\x = x0
Normal\y = 0
Normal\z = z0
Normalize(@Normal)
MP_AddVertex(returnMesh,x0, i*deltaHeight-height2, z0 , Color , j / numSegBase, i / numSegHeight, Normal\x, Normal\y, Normal\z)
If i <> numSegHeight
MP_AddTriangle(returnMesh,offset + numSegBase + 1,offset + numSegBase,offset)
MP_AddTriangle(returnMesh,offset + numSegBase + 1,offset,offset + 1)
EndIf
offset + 1
Next
Next
For j = 0 To numSegBase
x0.f = innerRadius * Cos(j*deltaAngle)
z0.f = innerRadius * Sin(j*deltaAngle)
MP_AddVertex(returnMesh,x0, -height2, z0 , Color , j / numSegBase, 1, 0, -1, 0)
x0 = outerRadius * Cos(j*deltaAngle)
z0 = outerRadius * Sin(j*deltaAngle)
MP_AddVertex(returnMesh,x0, -height2, z0 , Color , j / numSegBase, 0, 0, -1, 0)
If j <> numSegBase
MP_AddTriangle(returnMesh,offset,offset + 1,offset + 3)
MP_AddTriangle(returnMesh,offset + 2,offset ,offset + 3)
EndIf
offset + 2
Next
For j = 0 To numSegBase
x0.f = innerRadius * Cos(j*deltaAngle)
z0.f = innerRadius * Sin(j*deltaAngle)
MP_AddVertex(returnMesh,x0, height2, z0 , Color , j / numSegBase, 0, 0, 1, 0)
x0 = outerRadius * Cos(j*deltaAngle)
z0 = outerRadius * Sin(j*deltaAngle)
MP_AddVertex(returnMesh,x0, height2, z0 , Color , j / numSegBase, 1, 0, 1, 0)
If j <> numSegBase
MP_AddTriangle(returnMesh,offset + 1,offset,offset + 3)
MP_AddTriangle(returnMesh,offset, offset +2,offset + 3)
EndIf
offset + 2
Next
ProcedureReturn returnMesh
EndProcedure
Procedure MP_CreateOpenCylinder(Radius.f, height.f, numSegBase=16, numSegHeight=1)
Protected Normal.Vector3, returnMesh.i
Color.l = $FFFFFF
returnMesh = MP_CreateMesh()
If numSegBase < 1
numSegBase = 1
EndIf
If numSegHeight < 1
numSegHeight = 1
EndIf
deltaAngle.f = #PI*2 / numSegBase
deltaHeight.f = height / numSegHeight
height2.f = height / 2.0
offset = 0
For i = 0 To numSegHeight
For j = 0 To numSegBase
x0.f = Radius * Cos(j*deltaAngle)
z0.f = Radius * Sin(j*deltaAngle)
Normal\x = x0
Normal\y = 0
Normal\z = z0
Normalize(@Normal)
MP_AddVertex(returnMesh,x0, i*deltaHeight-height2, z0 , Color , j / numSegBase, i / numSegHeight, Normal\x, Normal\y, Normal\z)
If i <> numSegHeight
MP_AddTriangle(returnMesh,offset + numSegBase + 1,offset,offset + numSegBase)
MP_AddTriangle(returnMesh,offset + numSegBase + 1,offset + 1,offset)
EndIf
offset + 1
Next
Next
ProcedureReturn returnMesh
EndProcedure
MP_Graphics3D (640,480,0,3) ; Create a Window with 3D function #Window = 0
SetWindowTitle(0, "3D with two cylinders")
camera=MP_CreateCamera() ; camera on
MP_PositionEntity(camera,4,6,-10)
MP_EntityLookAt(camera, 0, 3, 0)
light=MP_CreateLight(1) ; yes light
MP_PositionEntity (light,-6,10,-3)
MP_LightSetColor(light,RGB(255,255,255))
MP_EntityLookAt(light,0,0,0)
Mesh1=MP_CreateOpenCylinder(1.5, 6, 16, 1) ; my Cylinder normal
Mesh2=CreateTube(1.5, 1, 6, 16, 1)
MP_RotateMesh(Mesh2, 60,33,0)
MP_PositionEntity (Mesh1,-3,0,8) ; Position mesh1
MP_RotateMesh(Mesh1, 60,0,0)
MP_PositionEntity (Mesh2,3,0,8) ; Position mesh2
MP_PhysicInit()
MP_EntityPhysicBody(Mesh1, 1, 1)
MP_EntityPhysicBody(Mesh2, 1, 1)
tex2 = MP_LoadTexture(#PB_Compiler_Home + "Examples\3D\Data\Textures\MRAMOR6X6.jpg")
MP_EntitySetTexture(Mesh1, tex2)
MP_MeshSetAlpha (Mesh1,3)
MP_MaterialEmissiveColor (tex2,0,50,50,50)
MP_MaterialAmbientColor(tex2, 0, 255 ,200, 11)
MP_MeshSetBlendColor(Mesh1, MP_ARGB(100,255,255,255))
sphere = MP_CreateSphere(8)
MP_ScaleMesh(sphere, 0.3, 0.3, 0.3)
MP_PositionEntity(sphere,-3,3,10)
MP_EntityPhysicBody(sphere, 3, 1)
MP_EntitySetGravity(sphere, 0 , -1 ,0)
tex3 = MP_LoadTexture(#PB_Compiler_Home + "Examples\3D\Data\Textures\Geebee2.bmp")
MP_EntitySetTexture(sphere, tex3)
sphere2 = MP_CreateSphere(8)
MP_ScaleMesh(sphere2, 0.3, 0.3, 0.3)
MP_PositionEntity(sphere2, 4.5,4,10.0)
MP_EntityPhysicBody(sphere2, 3, 1)
MP_EntitySetGravity(sphere2, 0 , -1 ,0)
tex3 = MP_LoadTexture(#PB_Compiler_Home + "Examples\3D\Data\Textures\Geebee2.bmp")
MP_MaterialEmissiveColor (tex3,0,50,50,50)
MP_MaterialAmbientColor(tex3, 0, 255 ,200, 11)
MP_MeshSetBlendColor(Mesh1, MP_ARGB(100,255,255,255))
MP_MeshSetAlpha (Mesh2,1)
MP_EntitySetTexture(Mesh2, tex3)
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
;MP_TurnEntity (Mesh1,1,0.5,0.5) ; go to moving
;MP_TurnEntity (Mesh2,1,0.5,0.5) ; mee too
MP_PhysicUpdate()
MP_RenderWorld() ; render the world
MP_Flip () ; show me the world
Wend