look how to measure Coefficient of Friction with a Ramp http://www.school-for-champions.com/exp ... h_ramp.htm
note that in the article he doesn't care about the friction of the ramp itself, i have considered it in the program as 0.7 (just a choice), but how we calculate the total friction of the cube and the ramp i don't know, it may not be the total of the two. the friction subject are a too wide subject with complex calculus math.
in the following example press space to rotate the ramp slowly, until the cube moves, note the angle of sliding, change the friction from 0.4 to 1 and you will get another sliding angle, change the friction to 1.5 and the cube will fall down rolling and not sliding (the friction are too big)
change the friction to zero and the cube will slide easily
look for coefficients of friction for different materials here http://en.wikipedia.org/wiki/Coefficien ... f_friction

Code: Select all
Enumeration
#MESH
#LIGHT
#camera
#win
#plane
#node
#cube1
#cube2
#axis
#joint
EndEnumeration
Global width=20, length=20
Global zcam.f, xcam.f, ycam.f, rotate.b, camRo.f, camZ = 20
ExamineDesktops()
If OpenWindow(#win, 0, 0, DesktopWidth(0), DesktopHeight(0), "press space to move the slope , arrows to Camera rotate", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(#win), 0, 0, DesktopWidth(0), DesktopHeight(0)-60, 0, 0, 0)
TextGadget(23, 100, DesktopHeight(0)-55, 100, 25, "0")
StringGadget(24, 200, DesktopHeight(0)-55, 50, 20, "0.4")
TextGadget(25, 260, DesktopHeight(0)-55, 100, 25, "Friction")
InitKeyboard()
SetFrameRate(60)
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/Sources\Data", #PB_3DArchive_FileSystem)
CreateLight(#LIGHT,RGB(22,222,0),0,-4,0,#PB_Light_Directional )
LightLookAt(#LIGHT, 0, 4, -5)
CreateCamera(#camera, 0, 0, 100, 100)
MoveCamera(#camera, 0, 10, 20)
CameraLookAt(#camera, 0, 2, 0)
EndIf
CreateMaterial(2, LoadTexture(2, "Geebee2.bmp"))
CreateMaterial(1, LoadTexture(1, "wood.jpg"))
CreateMaterial(3, LoadTexture(3, "Caisse.png"))
CreateSphere(#axis, 0.5) ; the axis
CreateEntity(#axis, MeshID(#axis), MaterialID(2), -8.5, -2, 0)
EntityPhysicBody(#axis, #PB_Entity_StaticBody)
CreateCube(#cube1, 1) ; the weight at right
CreateEntity(#cube1, MeshID(#cube1), MaterialID(3), 6, -1.3, -3)
;ScaleEntity(#cube1,3,1,3)
CreateCube(#cube2, 1) ; the weight at left
CreateEntity(#cube2, MeshID(#cube1), MaterialID(3), -8.5, -1.3, -3)
CreateCube(#plane, 1) ; the slope
CreateEntity(#plane, MeshID(#plane), MaterialID(1), 0, -2, -5)
ScaleEntity(#plane,17,0.5,4)
MaterialCullingMode(1, #PB_Material_NoCulling)
MaterialBlendingMode(1, #PB_Material_Add )
EntityPhysicBody(#plane, #PB_Entity_BoxBody , 1,0,0.7)
HingeJoint(#joint,EntityID(#axis),0,0,0.15, #False,#False,#True, EntityID(#plane),-8,0,4, #False,#False,#True)
EnableHingeJointAngularMotor(#joint, #True, 0, 50)
EntityPhysicBody(#cube1, #PB_Entity_BoxBody , 2,0,1)
EntityPhysicBody(#cube2, #PB_Entity_BoxBody , 2,0,1)
CreateMesh(#plane,#PB_Mesh_TriangleList ,#PB_Mesh_Static)
SetMeshMaterial(#plane, MaterialID(1))
CreateNode(#node, 0,2,-3)
AttachNodeObject(#node, CameraID(#camera))
;WorldDebug(#PB_World_DebugBody)
friction.f = ValF(GetGadgetText(24))
SetEntityAttribute(#cube1, #PB_Entity_Friction , friction)
Repeat
Event = WindowEvent()
friction.f = ValF(GetGadgetText(24))
SetEntityAttribute(#cube1, #PB_Entity_Friction , friction)
RenderWorld()
FlipBuffers()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Space )
ApplyEntityImpulse(#plane, 0, 1, 0, 3,0,0)
EnableHingeJointAngularMotor(#joint, #True, -0.05, 10)
SetActiveGadget(23)
EndIf
If KeyboardPushed(#PB_Key_Left)
camRo = -0.4
RotateNode(#node, 0, camRo, 0, #PB_Relative)
ElseIf KeyboardPushed(#PB_Key_Right)
camRo = 0.4
RotateNode(#node, 0, camRo, 0, #PB_Relative)
EndIf
a.f = EntityRoll(#plane)
SetGadgetText(23, StrF(a))
Until KeyboardPushed(#PB_Key_Escape) Or Event = #PB_Event_CloseWindow
http://en.wikipedia.org/wiki/Radian_per_second
, look the following example , i use 1 unit for velocity in EnableHingeJointAngularMotor ,the timing for two virtual laser beams (RayCollide(...) ) on the opposite places of the plane edge show the time of about 6.2 seconds, and it is near the 360/57.3 = 6.28 (1 radian = 57.2957795 degree)
Code: Select all
Enumeration
#MESH
#LIGHT
#camera
#win
#plane
#node
#axis
#joint
EndEnumeration
Global width=20, length=20
Global zcam.f, xcam.f, ycam.f, rotate.b, camRo.f, camZ = 20
ExamineDesktops()
If OpenWindow(#win, 0, 0, DesktopWidth(0), DesktopHeight(0), "press space to move the slope , arrows to Camera rotate", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(#win), 0, 0, DesktopWidth(0), DesktopHeight(0)-60, 0, 0, 0)
InitKeyboard()
SetFrameRate(60)
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/Sources\Data", #PB_3DArchive_FileSystem)
CreateLight(#LIGHT,RGB(22,222,0),0,-4,0,#PB_Light_Directional )
LightLookAt(#LIGHT, 0, 4, -5)
CreateCamera(#camera, 0, 0, 100, 100)
MoveCamera(#camera, 0, 10, 20)
CameraLookAt(#camera, 0, 2, 0)
EndIf
CreateMaterial(2, LoadTexture(2, "Geebee2.bmp"))
CreateMaterial(1, LoadTexture(1, "wood.jpg"))
CreateMaterial(3, LoadTexture(3, "Caisse.png"))
CreateSphere(#axis, 0.5) ; the axis
CreateEntity(#axis, MeshID(#axis), MaterialID(2), -8.5, -2, 0)
EntityPhysicBody(#axis, #PB_Entity_StaticBody)
CreateCube(#plane, 1) ; the slope
CreateEntity(#plane, MeshID(#plane), MaterialID(1), 0, -2, -5)
ScaleEntity(#plane,17,0.5,4)
MaterialCullingMode(1, #PB_Material_NoCulling)
MaterialBlendingMode(1, #PB_Material_Add )
EntityPhysicBody(#plane, #PB_Entity_BoxBody , 1,0,0.7)
HingeJoint(#joint,EntityID(#axis),0,0,0.15, #False,#False,#True, EntityID(#plane),-8,0,4, #False,#False,#True)
EnableHingeJointAngularMotor(#joint, #True, 0, 50)
CreateMesh(#plane,#PB_Mesh_TriangleList ,#PB_Mesh_Static)
SetMeshMaterial(#plane, MaterialID(1))
CreateNode(#node, 0,2,-3)
AttachNodeObject(#node, CameraID(#camera))
Repeat
Event = WindowEvent()
RenderWorld()
FlipBuffers()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Space )
ApplyEntityImpulse(#plane, 0, 1, 0, 3,0,0)
EnableHingeJointAngularMotor(#joint, #True, -1, 10)
StartTime.f = ElapsedMilliseconds()
EndIf
re = RayCollide(7,-1.5,-7, 7,-1.5,0) ; detect the object pass through the laser beam
If re > 0 ; if it pass then do something
ElapsedTime.f = ElapsedMilliseconds()-StartTime
Debug StrF(ElapsedTime.f / 1000)+" seconds"
EndIf
Until KeyboardPushed(#PB_Key_Escape) Or Event = #PB_Event_CloseWindow