5 glasses and a bottle

Everything related to 3D programming
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

5 glasses and a bottle

Post by applePi »

the following glasses
Image
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:
Image

comment line 304 (z + Zincr) and the Z dimension will diappear and all glasses are flattened into a 2D world
Image
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
  
  
  
  
Last edited by applePi on Wed Dec 11, 2013 7:36 am, edited 1 time in total.
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: 5 glasses and a bottle

Post by DK_PETER »

Hi Applepi.

That's a really nice example.
Thanks. ;-)
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: 5 glasses and a bottle

Post by applePi »

Thanks DK_PETER and Alexi
sorry Alexi, i wish i can, too much problems in my way .
i want to add that to make the blue glass have a parabola shape we change z + Zincr to

Code: Select all

If cup = 1 And i > 61
            y2.f = 0.25 * x * x - 1.5 * x + 0.25 ;parabola curve
            Zincr = y2/50
          EndIf
        z + Zincr
Image

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
          If cup = 1
            ;y2.f = 0.25 * y * y*x*x - 1.5 * y*x + 0.25
            ;Zincr = y2
          EndIf
            ;y2.f = 0.25 * x*x - 1.5 * x + 0.25
            ;z + y2/50
        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
        
        If cup = 1 And i > 61
            y2.f = 0.25 * x * x - 1.5 * x + 0.25 ;parabola curve
            Zincr = y2/50
          EndIf
        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
  
  
  
  
Last edited by applePi on Wed Dec 11, 2013 7:30 am, edited 1 time in total.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: 5 glasses and a bottle

Post by davido »

Hi applePi,

In the past I have really enjoyed the lovely examples you have crafted.

Unfortunately the current code crashes within a few seconds of running.

What version of PureBasic are you using? I am using 5.21 LTS 64 bit with Windows 7.
DE AA EB
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 756
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: 5 glasses and a bottle

Post by Samuel »

Good job ApplePi.

I made a few small changes. For me it seemed the camera movement was a little jumpy and fast.
Here's the changes I made in case you are interested.

Code: Select all

Define.f MouseX,MouseY,KeyX,KeyY
Defining them as floats makes the camera movement smoother.

Code: Select all

  If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.02
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.02
  EndIf
Made the mouse rotation a little slower by changing 0.2 to 0.02.

davido wrote: Unfortunately the current code crashes within a few seconds of running.
What version of PureBasic are you using? I am using 5.21 LTS 64 bit with Windows 7.
Runs on 5.2 LTS 64 bit Windows 7 with no problems for me.

Did Purebasic give you an error message?
If not you could post your Ogre log file.
We might be able to find something in there.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: 5 glasses and a bottle

Post by applePi »

Thanks davido and Samuel
@Samuel you are right the mouse and key variables should be float, i have updated the example
@davido i use the latest 5.21 LTS 32 bit version , i run windows xp 32 bit. the card is Geforce GT 520 . may be the error with the graphics card, try changing the subsys to opengl
i have added the following code just One parabolic glass and a bowl only with 2 separated procedures to enable the users to carve their Glasses as they want, for the blue glass note that its bowl are closed and there is no hole in its bottom because we have closed its handle abruptly:

Code: Select all

If i = 61
Nozzle = 0
EndIf 
the Ogre secret way of doing things manage connecting the closing triangles
so there is a tiny gap , but Comment Nozzle = 0 at line 227 below and we will get a hole in the glass bowl bottom and the ball will pass through it, and there is a smooth continuation and there is no gap
i have made a lot of experiments, it is a kind of simple experimental math and we can get good Art scenes.
Image

Code: Select all

Declare cone(r.f) 
Declare bowl(r.f) 
Declare Table() 

Define.f MouseX,MouseY,KeyX,KeyY
Global choice = 8
Global Mat
#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,0.5,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) ; 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)

FreeMesh(1)
CreateMesh(1, #PB_Mesh_TriangleList, #PB_Mesh_Static)

bowl(0.6) ; Green cup
CreateEntity(2, MeshID(1), MaterialID(mat))  
ScaleEntity(2,0.6, 0.6, 0.6)
MoveEntity(2,0,56,10,#PB_Absolute)
RotateEntity(2,90,0,0,#PB_Relative)
ScaleEntity(2, 2,2,2)
EntityPhysicBody(2, #PB_Entity_StaticBody  , 4,0.6,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)
  
      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)
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   = 2 * #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 i = 61     ; the end of the cup handle and the begening of its big cone (which contains the Liquid)
           
              Nozzle = 0  ; to close the cup handle, it will close the big cone bottom
            EndIf 
       
        If i > 61  ; the begening of the big cone (which contains the Liquid)
          
         ; Zincr = 0.45
                     
          Nozzle2.f  + incr  ; incr determines the radius of the bigger nozzle
          Nozzle = Nozzle2
        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
        
        If i > 61
            y2.f = 0.25 * x * x - 1.5 * x + 0.25 ;parabola curve
            Zincr = y2/40
          EndIf
        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 bowl(incr.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   = 2 * #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 = 20     ; the end of the cup handle and the begening of its big cone (which contains the Liquid)
           
              Nozzle = 0  ; to close the cup handle, it will close the big cone bottom
            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
        
        
        y2.f = 0.25 * x * x - 1.5 * x + 0.25 ;parabola curve
        Zincr = y2/60
         
        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
  
  
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: 5 glasses and a bottle

Post by davido »

@applePi
Decided to try it on my other machine with 32 bit Windows 7 installed. Glad to say it works just fine. Another wonderful example. Thank you very much. :D

@Samuel
Thank you for your comments and offer of assistance. :D
I'm quite happy knowing it works on one of my machines. I suspect it may be a machine related problem.
I am listing the contents of the ogre.log file, should it be of interest. Please don't spend your valuable time on this unless you wish to.
09:16:16: Creating resource group General
09:16:16: Creating resource group Internal
09:16:16: Creating resource group Autodetect
09:16:16: SceneManagerFactory for type 'DefaultSceneManager' registered.
09:16:16: Registering ResourceManager for type Material
09:16:16: Registering ResourceManager for type Mesh
09:16:16: Registering ResourceManager for type Skeleton
09:16:16: MovableObjectFactory for type 'ParticleSystem' registered.
09:16:16: OverlayElementFactory for type Panel registered.
09:16:16: OverlayElementFactory for type BorderPanel registered.
09:16:16: OverlayElementFactory for type TextArea registered.
09:16:16: Registering ResourceManager for type Font
09:16:16: ArchiveFactory for archive type FileSystem registered.
09:16:16: ArchiveFactory for archive type Zip registered.
09:16:16: ArchiveFactory for archive type EmbeddedZip registered.
09:16:16: DDS codec registering
09:16:16: FreeImage version: 3.10.0
09:16:16: This program uses FreeImage, a free, open source image library supporting all common bitmap formats. See http://freeimage.sourceforge.net for details
09:16:16: Supported formats: bmp,ico,jpg,jif,jpeg,jpe,koa,iff,lbm,pbm,pbm,pcd,pcx,pgm,pgm,png,ppm,ppm,ras,tga,targa,tif,tiff,wap,wbmp,wbm,psd,cut,xbm,xpm,dds,gif,g3,sgi,j2k,j2c,jp2
09:16:16: PVRTC codec registering
09:16:16: Registering ResourceManager for type HighLevelGpuProgram
09:16:16: Registering ResourceManager for type Compositor
09:16:16: MovableObjectFactory for type 'Entity' registered.
09:16:16: MovableObjectFactory for type 'Light' registered.
09:16:16: MovableObjectFactory for type 'BillboardSet' registered.
09:16:16: MovableObjectFactory for type 'ManualObject' registered.
09:16:16: MovableObjectFactory for type 'BillboardChain' registered.
09:16:16: MovableObjectFactory for type 'RibbonTrail' registered.
09:16:16: *-*-* OGRE Initialising
09:16:16: *-*-* Version 1.8.2 (Byatis)
09:16:16: D3D9 : Direct3D9 Rendering Subsystem created.
09:16:16: D3D9: Driver Detection Starts
09:16:16: D3D9: Driver Detection Ends
09:16:16: Particle Emitter Type 'Point' registered
09:16:16: Particle Emitter Type 'Box' registered
09:16:16: Particle Emitter Type 'Ellipsoid' registered
09:16:16: Particle Emitter Type 'Cylinder' registered
09:16:16: Particle Emitter Type 'Ring' registered
09:16:16: Particle Emitter Type 'HollowEllipsoid' registered
09:16:16: Particle Affector Type 'LinearForce' registered
09:16:16: Particle Affector Type 'ColourFader' registered
09:16:16: Particle Affector Type 'ColourFader2' registered
09:16:16: Particle Affector Type 'ColourImage' registered
09:16:16: Particle Affector Type 'ColourInterpolator' registered
09:16:16: Particle Affector Type 'Scaler' registered
09:16:16: Particle Affector Type 'Rotator' registered
09:16:16: Particle Affector Type 'DirectionRandomiser' registered
09:16:16: Particle Affector Type 'DeflectorPlane' registered
09:16:16: PCZone Factory Type 'ZoneType_Default' registered
09:16:16: CPU Identifier & Features
09:16:16: -------------------------
09:16:16: * CPU ID: GenuineIntel: Intel(R) Core(TM) i3 CPU 540 @ 3.07GHz
09:16:16: * SSE: yes
09:16:16: * SSE2: yes
09:16:16: * SSE3: yes
09:16:16: * MMX: yes
09:16:16: * MMXEXT: yes
09:16:16: * 3DNOW: no
09:16:16: * 3DNOWEXT: no
09:16:16: * CMOV: yes
09:16:16: * TSC: yes
09:16:16: * FPU: yes
09:16:16: * PRO: yes
09:16:16: * HT: no
09:16:16: -------------------------
09:16:16: D3D9 : Subsystem Initialising
09:16:16: Registering ResourceManager for type Texture
09:16:16: Registering ResourceManager for type GpuProgram
09:16:16: ***************************************
09:16:16: *** D3D9 : Subsystem Initialised OK ***
09:16:16: ***************************************
09:16:16: SceneManagerFactory for type 'OctreeSceneManager' registered.
09:16:16: SceneManagerFactory for type 'BspSceneManager' registered.
09:16:16: Registering ResourceManager for type BspLevel
09:16:16: D3D9RenderSystem::_createRenderWindow "PureBasic Ogre", 2560x1435 windowed miscParams: FSAA=0 displayFrequency=0 externalWindowHandle=3084106 vsync=true
09:16:16: D3D9 : Created D3D9 Rendering Window 'PureBasic Ogre' : 2560x1440, 32bpp
09:16:18: OGRE EXCEPTION(3:RenderingAPIException): Cannot create device! in D3D9Device::createD3D9Device at OgreD3D9Device.cpp (line 729)
09:16:18: Added resource location './.' of type 'FileSystem' to resource group 'General'
09:16:18: Added resource location 'C:\Program Files\PureBasic\Examples/3D/Data/Textures' of type 'FileSystem' to resource group 'General'
09:16:18: Added resource location 'C:\Program Files\PureBasic\Examples/3D/Data/Textures/nvidia' of type 'FileSystem' to resource group 'General'
DE AA EB
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 756
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: 5 glasses and a bottle

Post by Samuel »

09:16:16: D3D9 : Direct3D9 Rendering Subsystem created.
09:16:16: D3D9: Driver Detection Starts
09:16:16: D3D9: Driver Detection Ends
Your computer found Direct3D9, but then failed here.
09:16:18: OGRE EXCEPTION(3:RenderingAPIException): Cannot create device! in D3D9Device::createD3D9Device at OgreD3D9Device.cpp (line 729)
There's a few things you can do.
First you could make sure you have the required version of DirectX9 installed.
http://www.microsoft.com/en-us/download ... aspx?id=35

If it still doesn't work. Then it's possible that you have an older graphics card that doesn't support Direct3D9 completely.
Looking at your CPU and window size though. I'm assuming you have a fairly nice GPU.
So, you most likely just have an older version of DirectX9.

If you want to avoid all this DirectX hassle then you could just set your compiler to use OpenGL instead.

I believe your issue isn't related to ApplePi's example. So, if your still having trouble after trying these things.
It may be better to discuss this through PMs instead of taking over ApplePi's thread.
Just let me know if your still having problems.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: 5 glasses and a bottle

Post by PMV »

i guess it has more to do with the resolution and dimension of the window and render window. Just play a little bit around with the window width and window height until OpenWindow() and OpenWindowedScreen() will not fail. :wink:

MFG PMV
Post Reply