Page 1 of 1

Updating physics parameters?

Posted: Mon Aug 19, 2013 8:46 am
by DK_PETER
Greetings good folks..
Edit: Tired of fiddling!!! :?

Edit 2: You have GOT to be kidding!!!
It seems like Bullet physics has problems, when static objects touch eachother....
Don't let them touch one another and the physics starts to behave a little bit differently.
(Damn...Now I have to test some more.... :| )

Edit 3: Nope. Done testing...ApplePi, your idea using a mesh with falsam's example is for now the best example I have seen.

I was just fiddling with physics to explore the 'inner workings' in details.
If entities change positions on the x, y and z axis, the physics
parameters are altered. Guess you have to (edit: somehow) change the physics parameters
manually or do we have the equivalent of UpdatePhysics()..?

Try this example: (Example updated) and updated again to reflect new findings...

Code: Select all

;Welcome to a nightmare in bullet physics. (maby)...Testing again... :shock: 
;This is test number 28837384773!!!!!!!!!!!!!!!!!!

;I've cleaned this up in the hopes, that
;someone can figure this out.
;I KNOW it can be done, but right now I'm quite disgusted
;at trying thirty millions ways to make it work as expected.
;This should have been a test, which should have resulted
;in an example of how to do the game: 'Labyrinth'.. You know...The ball, holes and two knobs..
;According to Bullet Physics forum, rigid objects are disabled after a certain
;amount of time, du to performance reasons. This 'feature' can be deactivated
;
;using the following command: body->setActivationState(DISABLE_DEACTIVATION);
;
;Whether that would do any different or not is totally unknown to me, but it would certainly
;be worth a try.
;I know, I know...Looks like a jumping pacman :-)
;PLEASE, let me know if you find a solution.
;Best regards
;Peter PB-Forum nickname DK_PETER
;
;NOTE: move the ball using WSAD immediately...or it remains stationary.

InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()

DeclareModule _3D_Labyrinth
	
	#CamSpeed = 5
	
	Structure _3D_Mesh_Data
		ID.i
		Mesh.i
		Texture.i
		Material.i
		x.i
		y.i
		z.i
	EndStructure
	
	Global Win.i, Cam.i, Lgt.i, node.i, NotThere.i, NotThereID.i
	Global Dim Boxes._3D_Mesh_Data(20)
	Global Dim Walls._3D_Mesh_Data(3)
	Global Ground._3D_Mesh_Data
	Global Ball._3D_Mesh_Data
	Global FakeGround.i, motor.i, Sphere.i, SphereID.i, joint.i
	
	Declare SetUpScreen(Width.i, Height.i, Title.s)
	Declare CreateGround()
	Declare CreateBoxes()
	Declare CreateWalls()
	Declare CreateBall()
	Declare GetRandom()
	
EndDeclareModule

Module _3D_Labyrinth
	
	Procedure SetUpScreen(Width.i, Height.i, Title.s)
		Win = OpenWindow(#PB_Any,0, 0, Width, Height, Title, #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
		OpenWindowedScreen(WindowID(Win),0,0,Width, Height, 0, 0, 0, #PB_Screen_SmartSynchronization)
		Cam = CreateCamera(#PB_Any, 0, 0, 100, 100)
		MoveCamera(Cam,0,10,100, #PB_Absolute)
		RotateCamera(Cam, 0, 0, 0)
		Lgt	= CreateLight(#PB_Any, $FFF7B6, 100,100,0)
		WorldShadows(#True)
; 		node = CreateNode(#PB_Any, 0, 0, 0)
;  		MoveNode(node,0,10,100)
;  		AttachNodeObject(node, CameraID(Cam))
	EndProcedure
	
	Procedure CreateGround()
		Protected Texture.i, faker.i

		Texture = CreateTexture(#PB_Any, 64, 64)
		StartDrawing(TextureOutput(Texture))
		Box(0, 0, 64, 64, $786B3C)
		StopDrawing()
		
		With Ground
			\Texture  = CopyTexture(Texture, #PB_Any)
			\Material = CreateMaterial(#PB_Any, TextureID(\Texture))
			\Mesh     = CreatePlane(#PB_Any, 100, 100, 100, 100, 10, 10)
			\ID       = CreateEntity(#PB_Any, MeshID(\Mesh), MaterialID(\Material))
			\x				= 0
			\y				= 0
			\z        = 0
			MoveEntity(\ID, \x, \y, \z, #PB_Absolute)
		  EntityPhysicBody(\ID, #PB_Entity_StaticBody, 1, 0.9, 1.8)
		EndWith
		;Encapsulating the entire board in a Staticbody....
		NotThere = CreateCube(#PB_Any,10)
		NotThereID = CreateEntity(#PB_Any, MeshID(NotThere),#PB_Material_None)
		ScaleEntity(NotThereID, 10,3,10)
		MoveEntity(NotThereID,0,0,0)
		EntityPhysicBody(NotThereID, #PB_Entity_StaticBody)
		HideEntity(NotThereID,1)
	EndProcedure
	
	Procedure CreateBoxes()
		Protected texture.i
		
		texture = CreateTexture(#PB_Any, 64, 64)
		StartDrawing(TextureOutput(texture))
		Box(0, 0, 64, 64, $C6855E)
		StopDrawing()
		
		For x = 0 To ArraySize(Boxes())-1
			With Boxes(x)
				\Mesh 		= CreateCube(#PB_Any, 2)    ;Let's keep everything small
				\Texture 	= CopyTexture(texture,#PB_Any)
				\Material = CreateMaterial(#PB_Any, TextureID(\Texture))
				\ID     	= CreateEntity(#PB_Any, MeshID(\Mesh), MaterialID(\Material))
				\x				= GetRandom()
				\y 				= 1.2
				\z        = GetRandom()
				MoveEntity(\ID, \x, \y, \z, #PB_Absolute)
				EntityPhysicBody(\ID, #PB_Entity_StaticBody, 1, 0.5, 1) 
				AttachEntityObject(Ground\ID, "", EntityID(\ID))
			EndWith
		Next x
	EndProcedure
	
	Procedure GetRandom()
		Protected NewVal.i, WhatDirection.i
		NewVal = Random(40,1)
		WhatDirection = Random(1000,1)
		Select WhatDirection
			Case 0 To 500
				ProcedureReturn  0 - NewVal
			Default
				ProcedureReturn NewVal
		EndSelect
	EndProcedure
	
	Procedure CreateBall()
		Protected texture.i
		
		texture = CreateTexture(#PB_Any, 64, 64)
		StartDrawing(TextureOutput(texture))
		Box(0, 0, 64, 64, $7BFFFC)
		StopDrawing()
		
		With Ball
			\Texture	= CopyTexture(texture, #PB_Any)
			\Material = CreateMaterial(#PB_Any, TextureID(Texture))
			\Mesh			= CreateSphere(#PB_Any, 2, 20, 20)
			\ID 			= CreateEntity(#PB_Any, MeshID(\Mesh), MaterialID(\Material))
			RotateEntity(\ID , 0, 0, 0)
			\x				= 0
			\y				= 10
			\z				= 0
			MoveEntity(\ID, \x, \y, \z, #PB_Absolute)	
			EntityPhysicBody(\ID, #PB_Entity_CapsuleBody, 1, 0.5, 9)
		EndWith
	EndProcedure
	
	Procedure CreateWalls()
		Protected texture.i
		
		texture = CreateTexture(#PB_Any, 64, 64)
		StartDrawing(TextureOutput(texture))
		Box(0, 0, 64, 64, $C6855E)
		StopDrawing()
		
			With Walls(0)
				\Mesh 		= CreateCube(#PB_Any, 1)    ;Let's keep everything small
				\Texture 	= CopyTexture(texture,#PB_Any)
				\Material = CreateMaterial(#PB_Any, TextureID(\Texture))
				\ID     	= CreateEntity(#PB_Any, MeshID(\Mesh), MaterialID(\Material))
				ScaleEntity(\ID, 100,50,1)
				\x				= 0
				\y 				= 5
				\z        = 58
				MoveEntity(\ID, \x, \y, \z, #PB_Absolute)
				EntityPhysicBody(\ID, #PB_Entity_StaticBody)
				HideEntity(\ID,1)
				;AttachEntityObject(Ground\ID, "", EntityID(\ID))
			EndWith
			With Walls(1)
				\Mesh 		= CreateCube(#PB_Any, 1)    ;Let's keep everything small
				\Texture 	= CopyTexture(texture,#PB_Any)
				\Material = CreateMaterial(#PB_Any, TextureID(\Texture))
				\ID     	= CreateEntity(#PB_Any, MeshID(\Mesh), MaterialID(\Material))
				ScaleEntity(\ID, 100,50,1)
				\x				= 0
				\y 				= 2
				\z        = -58
				MoveEntity(\ID, \x, \y, \z, #PB_Absolute)
				EntityPhysicBody(\ID, #PB_Entity_StaticBody)
				HideEntity(\ID,1)
				;AttachEntityObject(Ground\ID, "", EntityID(\ID))
			EndWith
			With Walls(2)
				\Mesh 		= CreateCube(#PB_Any, 1)    ;Let's keep everything small
				\Texture 	= CopyTexture(texture,#PB_Any)
				\Material = CreateMaterial(#PB_Any, TextureID(\Texture))
				\ID     	= CreateEntity(#PB_Any, MeshID(\Mesh), MaterialID(\Material))
				ScaleEntity(\ID, 1,50,100)
				\x				= 58
				\y 				= 2
				\z        = 0
				MoveEntity(\ID, \x, \y, \z, #PB_Absolute)
				EntityPhysicBody(\ID, #PB_Entity_StaticBody)
				HideEntity(\ID,1)
				;AttachEntityObject(Ground\ID, "", EntityID(\ID))
			EndWith
			With Walls(3)
				\Mesh 		= CreateCube(#PB_Any, 1)    ;Let's keep everything small
				\Texture 	= CopyTexture(texture,#PB_Any)
				\Material = CreateMaterial(#PB_Any, TextureID(\Texture))
				\ID     	= CreateEntity(#PB_Any, MeshID(\Mesh), MaterialID(\Material))
				ScaleEntity(\ID, 1,50,100)
				\x				= -58
				\y 				= 2
				\z        = 0
				MoveEntity(\ID, \x, \y, \z, #PB_Absolute)
				EntityPhysicBody(\ID, #PB_Entity_StaticBody)
				HideEntity(\ID,1)
				;AttachEntityObject(Ground\ID, "", EntityID(\ID))
			EndWith
		
	EndProcedure

EndModule

_3D_Labyrinth::SetUpScreen(1024, 768, "Physics - the roasted ball version")
_3D_Labyrinth::CreateGround()
_3D_Labyrinth::CreateBoxes()
_3D_Labyrinth::CreateBall()
_3D_Labyrinth::CreateWalls()

EnableWorldPhysics(#True)


X = 1 ;Start the spin - must start in motion
dx = 0 : dy = 0 : dz = 0
Repeat
	
	ev = WindowEvent()
	
	ExamineKeyboard()
	EntityMove = #False
	
	If KeyboardPushed(#PB_Key_W)
		EntityMove = #True
		X = 2
		Z = 0
		X1 = 0.5
	EndIf
	
	If KeyboardPushed(#PB_Key_S)
		EntityMove = #True

		X = -2
		Z = 0
		X1 = -0.5
	EndIf
	
	If KeyboardPushed(#PB_Key_A)
		EntityMove = #True
		Z = -2
		X = 0
		Z1 = 0.5
	EndIf
	
	If KeyboardPushed(#PB_Key_D)
		EntityMove = #True
		Z = 1
		X = 0
		Z1 = -0.5
	EndIf
	
  RotateEntity(_3D_Labyrinth::Ground\ID, x1, 0, z1, #PB_Relative)

 	If KeyboardReleased(#PB_Key_All)
 		Z1 = 0 : X1 = 0
 	EndIf
 	
	elaps = RenderWorld()
	
	
	FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)


Best regards
Peter

Re: Updating physics parameters?

Posted: Mon Aug 19, 2013 9:02 am
by falsam
[PB 5.20]
Thanks for sharing :)
Waiting for the ball to be fixed and tries to move the tray. The ball does not move.

Re: Updating physics parameters?

Posted: Mon Aug 19, 2013 9:26 am
by DK_PETER
falsam wrote:[PB 5.20]
Thanks for sharing :)
Hi falsam
Contribution to the forum is vital, so I'm more than happy to share. :wink:
falsam wrote:[PB 5.20]
Waiting for the ball to be fixed and tries to move the tray. The ball does not move.
Yeah...It's frustrating, right? :lol:

Re: Updating physics parameters?

Posted: Mon Aug 19, 2013 11:24 am
by applePi
Hi Peter
i have noticed previously that the Ogre rotations and move commands contradicts the physics because it is designed as a subject of geometry and graphics and not physics, so there is a more need for the Bullet physics functions to be integrated with Ogre. this is why i have used in my demo the inclined plane , friction and weight http://www.purebasic.fr/english/viewtop ... 36&t=54556& the joint and motor attached to a plane so when we press space the motor begins to rotate rotating also the inclined plane. if we use rotateEntity sometimes the cube will go through the plane, but with a motor it will not since the physics here are on always. i am trying to see where to put the axis , joint for your plain to motorize it, if possible. until now i have failed.

Re: Updating physics parameters?

Posted: Mon Aug 19, 2013 3:01 pm
by DK_PETER
applePi wrote:Hi Peter
i have noticed previously that the Ogre rotations and move commands contradicts the physics because it is designed as a subject of geometry and graphics and not physics, so there is a more need for the Bullet physics functions to be integrated with Ogre. this is why i have used in my demo the inclined plane , friction and weight http://www.purebasic.fr/english/viewtop ... 36&t=54556& the joint and motor attached to a plane so when we press space the motor begins to rotate rotating also the inclined plane. if we use rotateEntity sometimes the cube will go through the plane, but with a motor it will not since the physics here are on always. i am trying to see where to put the axis , joint for your plain to motorize it, if possible. until now i have failed.
Thanks for the link ApplePi. Had not seen that example before now.
I see, what you mean about adding a continous 'rotation' - engine and keeping the object(s) in motion.
I too believe, that a better integration could solve the issue...
Oh, well...Back to the 'drawing-board'. :-)

Re: Updating physics parameters?

Posted: Tue Aug 20, 2013 8:07 pm
by DK_PETER
First post updated...