Semi Cylinder (PB 5.40 LTS)
Posted: Thu Oct 15, 2015 3:24 pm
the easiest way to create a semi Cylinder is to zeroing the z or x vertex coordinate in the left or right side. it is in fact deforming the cylinder
i think i like the new cylinder in which we have 2 open top and bottom so we have a free Tube, if we choose the CloseTop = 0, it should be CloseTop/Bottom = 0
CreateCylinder(#Mesh, Radius.f, Height.f [, NbBaseSegments, NbHeightSegments, CloseTop])
or a better choice is to have the ability to close/open one or the two sides. but if there is no choice i prefer the tube
the following half cylinder is suitable to make a truck, or a house, a garage,.... etc

5.40 beta 10
now change line 125 to :
and then you get a prism
i think i like the new cylinder in which we have 2 open top and bottom so we have a free Tube, if we choose the CloseTop = 0, it should be CloseTop/Bottom = 0
CreateCylinder(#Mesh, Radius.f, Height.f [, NbBaseSegments, NbHeightSegments, CloseTop])
or a better choice is to have the ability to close/open one or the two sides. but if there is no choice i prefer the tube
the following half cylinder is suitable to make a truck, or a house, a garage,.... etc

5.40 beta 10
Code: Select all
Enumeration
#camera
#Plane
EndEnumeration
#Radius = 6
#cyl = 40
Global Dim MeshData.PB_MeshVertex(0)
Global Dim MeshDataInd.PB_MeshFace(0)
Declare HalfCyl()
Define.f KeyX, KeyY, MouseX, MouseY
ExamineDesktops()
If OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "use arrow keys and mouse to move the camera,,...,,, pres 'W' for wire/solid frame", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
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(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
CreateCamera(#camera, 0, 0, 100, 100)
MoveCamera(#camera, 0, 20, 40, #PB_Absolute)
;CameraFOV(#camera, 70)
CameraBackColor(#camera, RGB(255,200,200))
CameraLookAt(#camera,0,5,0)
CreateLight(0, RGB(255,255,255), 0, 20, 30)
AmbientColor(RGB(200, 200, 200))
CreateMaterial(5, LoadTexture(5, "ValetCoeur.jpg")) ; ; Geebee2.bmp ;ValetCoeur.jpg
MaterialCullingMode(5, #PB_Material_NoCulling)
CreateMaterial(6, LoadTexture(6, "MRAMOR6X6.jpg"))
MaterialCullingMode(6, #PB_Material_NoCulling)
CreateMaterial(7, LoadTexture(7, "flare.png"))
MaterialShadingMode(7, #PB_Material_Wireframe)
MaterialCullingMode(7, #PB_Material_NoCulling)
CreatePlane(#Plane, 200, 200, 5, 5, 2, 2) ; the ground
CreateEntity(#Plane, MeshID(#Plane), MaterialID(6), 0,-15,0)
CreateCylinder(8, 10,40, 16,16,0)
CreateEntity(8, MeshID(8), MaterialID(5), -15,0,-20)
RotateEntity(8, 90,0,0)
HalfCyl() ; call the half cylinder procedure
FinishMesh(1)
CreateEntity(7, MeshID(7), MaterialID(5), 3,6,0)
RotateEntity(7, 90,0,0)
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 KeyboardReleased(#PB_Key_W)
If wire = 0
MaterialShadingMode(5, #PB_Material_Wireframe)
wire ! 1
Else
MaterialShadingMode(5, #PB_Material_Solid)
wire ! 1
EndIf
EndIf
EndIf
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 HalfCyl()
CreateMesh(7, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
CreateCylinder(#cyl,#Radius, 40, 16, 16, 0)
GetMeshData(#cyl,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate , 0, MeshVertexCount(#cyl)-1)
GetMeshData(#cyl,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(#cyl, 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
;Debug StrF(x)+" "+StrF(y)+" "+StrF(z)
If z > 0: z=0: EndIf
MeshVertexPosition(x,y,z)
MeshVertexTextureCoordinate(MeshData(c)\u, MeshData(c)\v)
MeshVertexNormal(MeshData(c)\NormalX, MeshData(c)\NormalY, MeshData(c)\NormalZ)
Next
ArrSizeInd = ArraySize(MeshDataInd())
For i=0 To ArrSizeInd Step 3
MeshFace(MeshDataInd(i)\Index, MeshDataInd(i+1)\Index,MeshDataInd(i+2)\Index)
Next
EndProcedureCode: Select all
CreateCylinder(#cyl,#Radius, 40, 4, 16, 0)