long columns of spheres

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

long columns of spheres

Post by applePi »

while trying to put blocks over each other i have found by chance that spheres are too stable if they are given a Restitution of zero or very small value in the EntityPhysicBody(...), even they behave like a spring. but i can't apply the same thing to rectangular blocks.
the following 2 programs are nothing more than arrange spheres over each other, the first one are rectangles which are given the physics of spheres, they still spheres but with a shape of a rectangle, it behaves like a spring, but don't expect to put a block over it other than a suitable sphere else it will collapse
Image

Code: Select all

Enumeration
 #plane
 #cube
 #ball
 #Cone
 #Tube_extension
EndEnumeration

Quit.b = #False
ExamineDesktops()
OpenWindow(3, 0, 0, DesktopWidth(0), DesktopHeight(0), "Arrow keys and mouse to move/rotate .... Space ...to push the spring ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(3), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
InitKeyboard()
InitMouse()
SetFrameRate(60)
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)

CreateMaterial(1, LoadTexture(1, "clouds.jpg"))
CreatePlane(#plane, 20, 20, 1, 1, 1, 1)
CreateEntity (#plane, MeshID(#plane), MaterialID(1))
MoveEntity(#plane,0,-6,0)
EntityPhysicBody(#plane, #PB_Entity_StaticBody)

CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))

CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 4, 12)
MoveCamera(0, 7, -5, 0)
;RotateCamera(0, -60,90,0)
CameraLookAt(0, 0, -5, 0)

CreateMaterial(0, LoadTexture(0, "wood.jpg"))
CreateMaterial(1, LoadTexture(1, "wood.jpg"))
MaterialCullingMode(0, #PB_Material_NoCulling)
;MaterialBlendingMode(0, #PB_Material_AlphaBlend )

MaterialShadingMode(0, #PB_Material_Wireframe)
DisableMaterialLighting(0, 1)
CreateMesh(1, #PB_Mesh_TriangleList, #PB_Mesh_Static )
SetMeshMaterial(1, MaterialID(0))

CreateMaterial(3, LoadTexture(3, "white.jpg"))
SetMaterialColor(3, #PB_Material_SelfIlluminationColor, RGB(255,0,0))
CreateCube(#cube,1)
Global r
y.f = -5.9
For i=0 To 6
OneBlock = CreateEntity(#PB_Any, MeshID(#cube), MaterialID(3))
ScaleEntity(OneBlock, 0.5, 0.2, 3)
y = y + 0.2
MoveEntity(OneBlock, 2.0, y, -1.5, #PB_Absolute)
SetMaterialColor(3, #PB_Material_SelfIlluminationColor, RGB(255,0,0))
EntityPhysicBody(OneBlock, #PB_Entity_SphereBody, 1,0,10)
Next
;Last block
OneBlock = CreateEntity(#PB_Any, MeshID(#cube), MaterialID(3))
ScaleEntity(OneBlock, 0.5, 0.2, 6)
y = y + 0.2

MoveEntity(OneBlock, 2.0, y, -1.5, #PB_Absolute)
EntityPhysicBody(OneBlock, #PB_Entity_SphereBody, 50,0,10)

WorldDebug(#PB_World_DebugBody)
ExamineKeyboard()
Global.f keyX, ketY, MouseY, MouseX
EntityPhysicBody(#ball, #PB_Entity_SphereBody, 22,3,1)

Repeat
  Event = WindowEvent()
  

  If KeyboardPushed(#PB_Key_Space)
    
    ApplyEntityImpulse(OneBlock, 0,  -15,  0)
    
  EndIf
  
  

  If ExamineMouse()
        MouseX = -MouseDeltaX()/10
        MouseY = -MouseDeltaY()/10
      EndIf
      
      
      If ExamineKeyboard()
                
        If KeyboardPushed(#PB_Key_Left)
          KeyX.f = -0.2
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX.f = 0.2
        Else
          KeyX.f = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY.f = -0.2
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY.f = 0.2
        Else
          KeyY.f = 0
        EndIf
        
      EndIf
      
      RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera  (0, KeyX.f, 0, KeyY.f)
  
  
    
  RenderWorld()
  FlipBuffers()
   
   ExamineKeyboard()
   If KeyboardPushed(#PB_Key_Escape)
      Quit = #True
    EndIf
Until Quit = #True Or Event = #PB_Event_CloseWindow
16 columns of sphere (every one have 46 spheres) press space key to Push the Big sphere, don't try more spheres or your system may halt.
Image

Code: Select all

Enumeration
 #plane
 #Ball
 #BigBall
 #Cone
 #Tube_extension
EndEnumeration

Quit.b = #False
ExamineDesktops()
OpenWindow(3, 0, 0, DesktopWidth(0), DesktopHeight(0), "Arrow keys and mouse to move/rotate .... Space .to push the ball ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(3), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
InitKeyboard()
InitMouse()
SetFrameRate(60)
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)

CreateMaterial(1, LoadTexture(1, "clouds.jpg"))
CreateCube(#plane, 1)
CreateEntity (#plane, MeshID(#plane), MaterialID(1))
ScaleEntity(#plane, 50,0.2,50)
MoveEntity(#plane,0,0,0)
EntityPhysicBody(#plane, #PB_Entity_StaticBody)

CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))

CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 4, 12)
MoveCamera(0, 35, 30, 130)
;RotateCamera(0, -60,90,0)
CameraLookAt(0, 0, 40, 0)

;CreateMaterial(0, LoadTexture(0, "terrain_texture.jpg"))
CreateMaterial(0, LoadTexture(0, "wood.jpg"))
CreateMaterial(1, LoadTexture(1, "wood.jpg"))
MaterialCullingMode(0, #PB_Material_NoCulling)
;MaterialBlendingMode(0, #PB_Material_AlphaBlend )

MaterialShadingMode(0, #PB_Material_Wireframe)
DisableMaterialLighting(0, 1)
CreateMesh(1, #PB_Mesh_TriangleList, #PB_Mesh_Static )
SetMeshMaterial(1, MaterialID(0))

CreateMaterial(3, LoadTexture(3, "white.jpg"))
SetMaterialColor(3, #PB_Material_SelfIlluminationColor, RGB(255,0,0))
CreateSphere(#BigBall, 2)
CreateEntity(#BigBall, MeshID(#BigBall), MaterialID(3), 22,10,12)
CreateSphere(#Ball,1)

xdisp.f = -16
For c = 0 To 3
  z.f + 3 : xdisp=0
For j = 0 To 3
y.f = 0.0
xdisp.f + 3
For i=0 To 45
OneBlock = CreateEntity(#PB_Any, MeshID(#Ball), MaterialID(3))
y = y + 2
MoveEntity(OneBlock, xdisp, y, -1.5+z, #PB_Absolute)
SetMaterialColor(3, #PB_Material_SelfIlluminationColor, RGB(255,0,0))
EntityPhysicBody(OneBlock, #PB_Entity_SphereBody, 1,0,10)
Next
Next
Next

;WorldDebug(#PB_World_DebugBody)
ExamineKeyboard()
Global.f keyX, ketY, MouseY, MouseX
EntityPhysicBody(#BigBall, #PB_Entity_SphereBody, 22,3,1)

Repeat
  Event = WindowEvent()
  

  If KeyboardPushed(#PB_Key_Space)
   ApplyEntityImpulse(#BigBall, -20, 0,0)  
    ;Debug r
  EndIf
  
  If ExamineMouse()
        MouseX = -MouseDeltaX()/10
        MouseY = -MouseDeltaY()/10
      EndIf
      
      
      If ExamineKeyboard()
        If KeyboardPushed(#PB_Key_X)
          MessageRequester("", Str(meshesNum) + "=== "+Str(sss))
          EndIf
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -0.5
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = 0.5
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -0.5
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = 0.5
        Else
          KeyY = 0
        EndIf
        
      EndIf
      
      RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera  (0, KeyX, 0, KeyY)
  
  
    
  RenderWorld()
  FlipBuffers()
   
   ExamineKeyboard()
   If KeyboardPushed(#PB_Key_Escape)
      Quit = #True
    EndIf
  Until Quit = #True Or Event = #PB_Event_CloseWindow
  
  
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: long columns of spheres

Post by IdeasVacuum »

the first one are rectangles which are given the physics of spheres
Confused.com :?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: long columns of spheres

Post by applePi »

IdeasVacuum writes :
Confused.com
ie in geometry it is cubes made with CreateCube(#cube,1)
but in its collision behavior it is spheres because it is given this with the line EntityPhysicBody(OneBlock, #PB_Entity_SphereBody, 1,0,10)
only the tiny sphere in the middle of the block can make collision while all the rest of the rectangular block are transparent to physical actions
a proof this example which i was testing before posting the above spherical piles (and not corrected nor optimized but it is funny)
wait after the collapse of all rectangular blocks and you will see some of the block sink in the plane up to its center. also while falling it is rotating like balls.

Code: Select all

Enumeration
 #plane
 #cube
 #ball
 #Cone
 #Tube_extension
EndEnumeration

Quit.b = #False
ExamineDesktops()
OpenWindow(3, 0, 0, DesktopWidth(0), DesktopHeight(0), "use arrow keys and mouse to move/rotate the camera..... press Space key to move the big ball ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(3), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
InitKeyboard()
InitMouse()
SetFrameRate(60)
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)

CreateMaterial(1, LoadTexture(1, "clouds.jpg"))
CreatePlane(#plane, 20, 20, 1, 1, 1, 1)
CreateEntity (#plane, MeshID(#plane), MaterialID(1))
MoveEntity(#plane,0,-6,0)
EntityPhysicBody(#plane, #PB_Entity_StaticBody)

CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))

CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 4, 12)
MoveCamera(0, 5, -5, 0)
;RotateCamera(0, -60,90,0)
CameraLookAt(0, 0, -5, 0)

;RotateCamera(0, -15, 0, 0)
;CreateMaterial(0, LoadTexture(0, "terrain_texture.jpg"))
CreateMaterial(0, LoadTexture(0, "wood.jpg"))
CreateMaterial(1, LoadTexture(1, "wood.jpg"))
MaterialCullingMode(0, #PB_Material_NoCulling)
;MaterialBlendingMode(0, #PB_Material_AlphaBlend )

MaterialShadingMode(0, #PB_Material_Wireframe)
DisableMaterialLighting(0, 1)
CreateMesh(1, #PB_Mesh_TriangleList, #PB_Mesh_Static )
SetMeshMaterial(1, MaterialID(0))

CreateMaterial(3, LoadTexture(3, "white.jpg"))
SetMaterialColor(3, #PB_Material_SelfIlluminationColor, RGB(255,0,0))
CreateSphere(#ball, 2)
CreateEntity(#ball, MeshID(#ball), MaterialID(3), 8,10,0)
CreateCube(#cube,1)

Global r
y.f = -5.9
For i=0 To 300
OneBlock = CreateEntity(#PB_Any, MeshID(#cube), MaterialID(3))
ScaleEntity(OneBlock, 0.65, 0.2, 3)
  
If flg = 1
  xdisp.f = -2
  flg=0
Else
  xdisp.f = 2
  flg=1
EndIf 
 
y = y + 0.2
MoveEntity(OneBlock, xdisp, y, -1.5, #PB_Absolute)

SetMaterialColor(3, #PB_Material_SelfIlluminationColor, RGB(255,0,0))
EntityPhysicBody(OneBlock, #PB_Entity_SphereBody, 1,0,10)
Next

For i=0 To 300
OneBlock = CreateEntity(#PB_Any, MeshID(#cube), MaterialID(3))
ScaleEntity(OneBlock, 0.65, 0.2, 3)
RotateEntity(OneBlock, 0, 90, 0)
 
If flg = 1
  zdisp.f = -3
  flg=0
Else
  zdisp.f = 0
  flg=1
EndIf 
 
y = y + 0.2
MoveEntity(OneBlock, 0, y, zdisp, #PB_Absolute)
SetMaterialColor(3, #PB_Material_SelfIlluminationColor, RGB(255,0,0))
EntityPhysicBody(OneBlock, #PB_Entity_SphereBody, 1,0,10)
Next

OneBlock = CreateEntity(#PB_Any, MeshID(#cube), MaterialID(3))
ScaleEntity(OneBlock, 0.5, 0.2, 5)
y = y + 0.2

MoveEntity(OneBlock, 2.0, y, zdisp, #PB_Absolute)
EntityPhysicBody(OneBlock, #PB_Entity_SphereBody, 50,0,10)

WorldDebug(#PB_World_DebugBody)
ExamineKeyboard()
Global.f keyX, ketY, MouseY, MouseX
EntityPhysicBody(#ball, #PB_Entity_SphereBody, 22,3,1)

Repeat
  Event = WindowEvent()
  

  If KeyboardPushed(#PB_Key_Space)
   ApplyEntityImpulse(#ball, -20, 0,0)  
    
  EndIf
  
 
  If ExamineMouse()
        MouseX = -MouseDeltaX()/10
        MouseY = -MouseDeltaY()/10
      EndIf
      
      
      If ExamineKeyboard()
        If KeyboardPushed(#PB_Key_X)
          MessageRequester("", Str(meshesNum) + "=== "+Str(sss))
          EndIf
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -0.5
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = 0.5
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -0.5
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = 0.5
        Else
          KeyY = 0
        EndIf
        
      EndIf
      
      RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera  (0, KeyX, 0, KeyY)
  
  
    
  RenderWorld()
  FlipBuffers()
   
   ExamineKeyboard()
   If KeyboardPushed(#PB_Key_Escape)
      Quit = #True
    EndIf
Until Quit = #True Or Event = #PB_Event_CloseWindow
Post Reply