5 glasses and a bottle
Posted: Tue Dec 10, 2013 3:04 pm
the following glasses

are made from circle which moves up in time , increasing or decreasing size as demand and with a rate of radius change determined by Zincr in (z.f + Zincr). this is like Pottery making which are rotating on table and you shape it with hand.
sorry for the Spaghetti code in cone() procedure but i want to make 5 glasses from the same procedure so it becomes misleading.
note that we begins from ( Nozzle.f = -15 ) ie from the bigger side of the cone then we decrease down. try changing Nozzle.f = -20 and you will have larger glass base like this:

comment line 304 (z + Zincr) and the Z dimension will diappear and all glasses are flattened into a 2D world

remember that the ball go through a glass mouth which have static physics, it can't go if the object have dynamic physics like the wood textured glasses
use the mouse and keys to fly around the scene. press space to stop rotation of some glasses.

are made from circle which moves up in time , increasing or decreasing size as demand and with a rate of radius change determined by Zincr in (z.f + Zincr). this is like Pottery making which are rotating on table and you shape it with hand.
sorry for the Spaghetti code in cone() procedure but i want to make 5 glasses from the same procedure so it becomes misleading.
note that we begins from ( Nozzle.f = -15 ) ie from the bigger side of the cone then we decrease down. try changing Nozzle.f = -20 and you will have larger glass base like this:

comment line 304 (z + Zincr) and the Z dimension will diappear and all glasses are flattened into a 2D world

remember that the ball go through a glass mouth which have static physics, it can't go if the object have dynamic physics like the wood textured glasses
use the mouse and keys to fly around the scene. press space to stop rotation of some glasses.
Code: Select all
Declare cone(r.f, m.f)
Declare Table()
Declare Bottle(r.f)
Define.f MouseX,MouseY,KeyX,KeyY
Global choice = 8
Global Mat
;IncludeFile("curves.pbi")
#PB_Shadow_TextureModulative = 5
#CameraSpeed = 2
Enumeration
#mainwin = 100
#mesh
#entity
#tex
#tex2
#tex3
#light
#camera
#mat
#table
#leg1
#leg2
#leg3
#leg4
#tableMaterial
EndEnumeration
InitEngine3D(#PB_Engine3D_DebugLog)
InitSprite()
InitKeyboard()
InitMouse()
ExamineDesktops()
OpenWindow(0,0,0,DesktopWidth(0), DesktopHeight(0),"use the mouse and keys to fly around the scene. press space to stop rotation of some glasses",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
;OpenWindow(0,0,0,DesktopWidth(0), DesktopHeight(0),"use the mouse and keys to fly around the scene. press space to stop rotation of some glasses",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,DesktopWidth(0), DesktopHeight(0)-5,1,0,0,#PB_Screen_WaitSynchronization)
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures/nvidia", #PB_3DArchive_FileSystem)
KeyboardMode(#PB_Keyboard_AllowSystemKeys)
;WorldShadows(#PB_Shadow_Modulative , -1, RGB(100, 100, 10))
Table() ; call the Table building procedure
;Create Light
CreateLight(0,RGB(245,245,205),190,230,0)
;Create Camera
CreateCamera(0,0,0,100,100)
MoveCamera(0,-150,120,120,#PB_Absolute)
CameraLookAt(0, 0, 50, 0)
AmbientColor(RGB(255,255,255))
CreateMaterial(#tex3, LoadTexture(#tex3, "growth_weirdfungus-03_normalheight.jpg"))
CreateMaterial(#tex, LoadTexture(#tex, "wood.jpg"))
MaterialCullingMode(#tex, #PB_Material_NoCulling)
MaterialBlendingMode(#tex, #PB_Material_AlphaBlend)
SetMaterialColor(#tex, #PB_Material_DiffuseColor, RGBA(255, 255, 0, 150))
MaterialCullingMode(#tex3, #PB_Material_NoCulling)
MaterialBlendingMode(#tex3, #PB_Material_AlphaBlend)
SetMaterialColor(#tex3, #PB_Material_DiffuseColor, RGBA(255, 255, 0, 150))
CreateMaterial(#tex2, LoadTexture(#tex2, "grass.jpg"))
MaterialCullingMode(#tex2, #PB_Material_NoCulling)
MaterialBlendingMode(#tex2, #PB_Material_AlphaBlend)
SetMaterialColor(#tex2, #PB_Material_DiffuseColor, RGBA(255, 255, 0, 150))
CreateSphere(33, 2)
CreateEntity(33,MeshID(33), #PB_Material_None, 0,110,-10 )
EntityPhysicBody(33, #PB_Entity_SphereBody , 1,1,1)
CopyEntity(33,34)
MoveEntity(34, 0,110,50 )
EntityPhysicBody(34, #PB_Entity_SphereBody , 1,1,1)
CopyEntity(33,35)
MoveEntity(35, 0,110,-80 )
EntityPhysicBody(35, #PB_Entity_SphereBody , 1,0.5,1)
CreateMesh(1, #PB_Mesh_TriangleList, #PB_Mesh_Static)
Global cup = 1
cone(0.4, 2) ; Blue cup
CreateEntity(1, MeshID(1), MaterialID(Mat))
ScaleEntity(1,0.6, 0.6, 0.6)
MoveEntity(1,0,42,50,#PB_Absolute)
RotateEntity(1,-90,0,0,#PB_Relative)
EntityPhysicBody(1, #PB_Entity_StaticBody , 4,0.3,1)
cup = 0
FreeMesh(1) ; woody octal cup
CreateMesh(1, #PB_Mesh_TriangleList, #PB_Mesh_Static)
cone(0.5, 5)
CreateEntity(2, MeshID(1), MaterialID(#tex))
ScaleEntity(2,0.6, 0.6, 0.6)
MoveEntity(2,0,42,80,#PB_Absolute)
RotateEntity(2,-90,0,0,#PB_Relative)
EntityPhysicBody(2, #PB_Entity_ConvexHullBody , 4,0,1)
FreeMesh(1)
CreateMesh(1, #PB_Mesh_TriangleList, #PB_Mesh_Static)
cone(0.5, 14)
CreateEntity(3, MeshID(1), MaterialID(#tex))
ScaleEntity(3,0.6, 0.6, 0.6)
MoveEntity(3,0,42,20,#PB_Absolute)
RotateEntity(3,-90,0,0,#PB_Relative)
EntityPhysicBody(3, #PB_Entity_ConvexHullBody , 4,0,1)
FreeMesh(1)
CreateMesh(1, #PB_Mesh_TriangleList, #PB_Mesh_Static)
cup = 4 ; for cup 4 we want to bypass closing the cup handle ie to continue to cup major cone
cone(0.5, 2) ; Green cup
CreateEntity(4, MeshID(1), MaterialID(#tex2))
ScaleEntity(4,0.6, 0.6, 0.6)
MoveEntity(4,0,42,-10,#PB_Absolute)
RotateEntity(4,-90,0,0,#PB_Relative)
EntityPhysicBody(4, #PB_Entity_StaticBody , 4,0.6,1)
FreeMesh(1)
CreateMesh(1, #PB_Mesh_TriangleList, #PB_Mesh_Static)
cup = 5 ; for cup 4 we want to bypass closing the cup handle ie to continue to cup major cone
cone(0.5, 2) ; Green cup
CreateEntity(5, MeshID(1), MaterialID(#tex3))
ScaleEntity(5,0.6, 0.6, 0.6)
MoveEntity(5,0,42,-50,#PB_Absolute)
RotateEntity(5,-90,0,0,#PB_Relative)
EntityPhysicBody(5, #PB_Entity_StaticBody , 4,0.6,1)
FreeMesh(1)
CreateMesh(1, #PB_Mesh_TriangleList, #PB_Mesh_Static)
;creating the Bottle
Bottle(0.3)
CreateEntity(6, MeshID(1), MaterialID(#tex2))
ScaleEntity(6,0.6, 0.6, 0.6)
MoveEntity(6,0,90,-80,#PB_Absolute)
RotateEntity(6,90,0,0)
EntityPhysicBody(6, #PB_Entity_StaticBody , 4,1,1)
x = 180: y=0: z=0 : h.f
rotx=-90
temp=1
Repeat
WindowEvent()
If ExamineMouse()
MouseX = -MouseDeltaX() * #CameraSpeed * 0.02
MouseY = -MouseDeltaY() * #CameraSpeed * 0.02
EndIf
ShowCursor_(0)
; Use arrow keys and mouse to rotate and fly in/out
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #CameraSpeed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #CameraSpeed
Else
KeyY = 0
EndIf
If KeyboardPushed(#PB_Key_Z)
z = 0
EndIf
If KeyboardReleased(#PB_Key_Space) ;press key to toggle the rotation of the object
temp ! 1
EndIf
rotz - temp : ;roty-temp: roty-temp
RotateEntity(1, rotx, roty, rotz/3,#PB_Absolute)
RotateEntity(2, rotx, roty, rotz/3,#PB_Absolute)
RotateEntity(3, rotx, roty, rotz/3,#PB_Absolute)
RotateEntity(4, rotx, roty, rotz/3,#PB_Absolute)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
MoveCamera (0, KeyX, 0, KeyY)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or WindowEvent() = #PB_Event_CloseWindow
;creating the Table furniture
Procedure Table()
CreateMaterial(3, LoadTexture(3, "MRAMOR6X6.jpg"))
MaterialCullingMode(3, #PB_Material_NoCulling )
CreatePlane(11,1000,1000,1,1,8,8)
CreateEntity(11,MeshID(11),MaterialID(3),0,0,0)
EntityPhysicBody(11, #PB_Entity_StaticBody,1,0.3,1)
CreateMaterial(#tableMaterial, LoadTexture(#tex , "Wood.jpg"))
CreateCube(#table, 10)
CreateEntity(#table,MeshID(#table), MaterialID(#tableMaterial),0,35,0)
ScaleEntity(#table,10,1,20)
EntityPhysicBody(#table, #PB_Entity_ConvexHullBody , 100,1,1)
CopyEntity(#table, #leg1)
ScaleEntity(#leg1, 0.3,1,0.05)
RotateEntity(#leg1, 0,0,90)
MoveEntity(#leg1, 40, 16,90)
EntityPhysicBody(#leg1, #PB_Entity_ConvexHullBody , 4,0,100)
CopyEntity(#leg1, #leg2)
RotateEntity(#leg2, 0,0,90)
MoveEntity(#leg2, -40, 16,90)
EntityPhysicBody(#leg2, #PB_Entity_ConvexHullBody , 4,0,100)
CopyEntity(#leg1, #leg3)
RotateEntity(#leg3, 0,0,90)
MoveEntity(#leg3, -40, 16,-90)
EntityPhysicBody(#leg3, #PB_Entity_ConvexHullBody , 4,0,100)
CopyEntity(#leg1, #leg4)
RotateEntity(#leg4, 0,0,90)
MoveEntity(#leg4, 40, 16,-90)
EntityPhysicBody(#leg4, #PB_Entity_ConvexHullBody , 4,0,100)
EndProcedure
Procedure cone(incr.f, minorSt.f)
Tex = LoadTexture(#PB_Any, "clouds.jpg")
Mat = CreateMaterial(#PB_Any, TextureID(Tex))
MaterialBlendingMode(Mat, #PB_Material_AlphaBlend)
SetMaterialColor(Mat, #PB_Material_DiffuseColor, RGBA(255, 255, 255, 150))
MaterialCullingMode(Mat, #PB_Material_NoCulling)
x.f: y.f :z.f : u.f: v.f: r.f
majorOrbit.l = 100 : minorOrbit.l = 20
majorStep.f = 2 * #PI / majorOrbit
minorStep.f = minorSt.f * #PI / minorOrbit
i.l: j.l: txu.f : txv.f
Zincr.f
Nozzle.f = -15 ; determine the radius of the smaller nozzle of the funnel
Nozzle2.f = 4
For i = 0 To majorOrbit
If i <= 20
Nozzle.f + incr
Zincr = 0.3 ; Zincr determine the rate of increase/decrease the circles radius over time
EndIf
If i <= 60 And i > 20
Zincr = 0.45
Nozzle = 4
EndIf
If cup < 4
If i = 61 ; to close the tube mouth
Nozzle = 0 ; to close the tube mouth
EndIf
EndIf
If i > 61 ; the beginning point of the wider circles than the tube circles
If cup = 1 :Zincr = 0.8 ;make the blue cup cone only taller
Else
Zincr = 0.45
EndIf
Nozzle2.f + incr ; incr determines the radius of the bigger nozzle
Nozzle = Nozzle2
If cup = 5: Nozzle = 15: Zincr = 0.8: EndIf ; to keep the cup cylindrical and not conical we stabilize Nozzle
EndIf
v = i * majorStep
For j = 0 To minorOrbit
u = j * minorStep
x = Cos(u)*Nozzle
y = Sin(u)*Nozzle
;===========================================
MeshVertexPosition(x, y, z);
MeshVertexTextureCoordinate(txu, txv)
MeshVertexNormal(x, y, z)
; texture the whole mesh with one picture stretched
txv = txv + 1/minorOrbit ; texture coordinates
Next
z + Zincr
txv = 0
txu = txu + 1/majorOrbit
Next
For i = 0 To majorOrbit-1
For j = 0 To minorOrbit
MeshFace(t,t + minorOrbit+1,t+1)
MeshFace(t + minorOrbit+1,t + minorOrbit+2,t+1 )
If i=majorOrbit-1 And j=minorOrbit-1 ;bypass the last triangle
minorOrbit-1
EndIf
t + 1
Next
Next
NormalizeMesh(1)
FinishMesh(#True)
EndProcedure
Procedure Bottle(incr.f)
x.f: y.f :z.f : u.f: v.f: r.f
majorOrbit.l = 100 : minorOrbit.l = 20
majorStep.f = 10 * #PI / majorOrbit
minorStep.f = 2 * #PI / minorOrbit
i.l: j.l: txu.f : txv.f
Nozzle.f = 5 ; determine the radius of the smaller nozzle of the funnel
Nozzle2.f = 5
For i = 0 To majorOrbit
If i <= 5 ; to make a small Bulge before the bottle mouth
Nozzle2.f + Pow(incr,2 )
Nozzle = Nozzle2
EndIf
If i <= 30 And i > 5 ; to make the bottle neck
Nozzle.f = 5
EndIf
If i < 50 And i > 30 ; to make the small conic shape before the main bottle body
Nozzle.f + incr
EndIf
;the rest 50 is for the cylindrical bottle body in which Nozzle does not change
If i = 100; to close the main bottle body, and we are finished
Nozzle.f = 0
EndIf
v = i * majorStep
For j = 0 To minorOrbit
u = j * minorStep
x = Cos(u)*Nozzle
y = Sin(u)*Nozzle
;z+0.04
;MP_AddVertex (Mesh, x, y,z,0,txu,txv)
MeshVertexPosition(x, y, z);
MeshVertexTextureCoordinate(txu, txv)
MeshVertexNormal(x, y, z)
; texture the whole mesh with one picture stretched
txv = txv + 1/minorOrbit ; texture coordinates
Next
z + 0.8
txv = 0
txu = txu + 1/majorOrbit
Next
For i = 0 To majorOrbit-1
For j = 0 To minorOrbit
MeshFace(t,t + minorOrbit+1,t+1)
MeshFace(t + minorOrbit+1,t + minorOrbit+2,t+1 )
t + 1
Next
Next
NormalizeMesh(1)
FinishMesh(#True)
EndProcedure

