(): Apply an impulse to the entity. The new impulse is
of the entity.....
previously applied to the entity.
i don't alleged i understand the Torque deeply since it is a mathematical issue. but in practice look this example. when you apply ApplyEntityTorqueImpulse by pressing
you see how rapidly the rotor rotate and draw the heavy big rectangular rod, while when apply ApplyEntityTorque by pressing 'Space' (rerun the example again for fair comparison) we see that it is very slowly rotate the rotor because the force here not accumulating
you may say okay remove the big weight and we will see the rotor accelerate in either cases, but i think the answer is that this is because there is no friction to stop the rotor and the newton law said that the continuous force accelerate the bodies and once it reaches a certain speed and we stop the force it will continue to move at the final speed unless there is a friction which is the usual case. so a better example than mine will be a heavy wheel rolling over a road, i choose my approach because it is easier to implement
surely there is much more to the subject, and it needs documentation. i just wish there is a friction to the Hinge Joint imagine it a rust on the joint axis.
Code: Select all
Enumeration
#LIGHT
#CAMERA
#mainwin
#Plane
#Joint
#cyl
EndEnumeration
Define.f KeyX, KeyY, MouseX, MouseY
ExamineDesktops()
If OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "Space: ApplyEntityTorque .....'Z': ApplyEntityTorqueImpulse, .. use mouse + Arrows to rotate + move Camera", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If InitEngine3D()
;Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Models", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts",#PB_3DArchive_FileSystem)
Parse3DScripts()
InitSprite()
InitKeyboard()
InitMouse()
OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
CreateMaterial(0, LoadTexture(0, "White.jpg"))
DisableMaterialLighting(0, #True)
MaterialShadingMode(0, #PB_Material_Wireframe )
MaterialCullingMode(0, #PB_Material_NoCulling)
CreateCamera(#camera, 0, 0, 100, 100)
MoveCamera(#camera, 20, 10, 20, #PB_Absolute)
CameraBackColor(#camera, RGB(255,200,200))
CameraLookAt(#camera,0,3,0)
CreateLight(0, RGB(255,255,255), 0, 20, 30)
AmbientColor(RGB(200, 200, 200))
CreateMaterial(3, LoadTexture(3, "ValetCoeur.jpg"))
DisableMaterialLighting(3, #False)
SetMaterialColor(3, #PB_Material_AmbientColor, RGB(250, 255, 0))
SetMaterialColor(3, #PB_Material_SpecularColor, RGB(255, 255, 0))
CreateMaterial(1, LoadTexture(1, "MRAMOR6X6.jpg"))
MaterialCullingMode(1, #PB_Material_NoCulling)
CreateMaterial(2, LoadTexture(2, "RustySteel.jpg"))
MaterialCullingMode(2, #PB_Material_NoCulling)
CreateMaterial(4, LoadTexture(4, "ground_diffuse.png"))
MaterialCullingMode(4, #PB_Material_NoCulling)
CreatePlane(500, 200, 200, 5, 5, 2, 2) ; the ground
CreateEntity(500, MeshID(500), MaterialID(4), 0,-5,0)
CreateEntityBody(500, #PB_Entity_StaticBody, 1, 0.0, 1)
CreateCube(0,1)
CreateEntity(0, MeshID(0), MaterialID(1), 0, 0, 0) ; the static cube
ScaleEntity(0, 3,3,3)
CreateCylinder(#cyl, 1, 5)
CreateEntity(#cyl, MeshID(#cyl), MaterialID(3), 0,5, 0)
ScaleEntity(#cyl, 1,0.5,1)
CreateEntityBody(0, #PB_Entity_StaticBody, 90, 0.1,10)
CreateEntityBody(#cyl, #PB_Entity_CylinderBody, 1000, 0.1, 2)
;hinge joint 0
HingeJoint(0, EntityID(0),
0, 5, 0,
0, 1, 0,
EntityID(#cyl),
0, 0, 0,
0, 1, 0)
RotateEntity(0, 0,0,90)
CreateEntity(2, MeshID(0), MaterialID(1), -5, 20, -50)
ScaleEntity(2, 3,1,100)
CreateEntityBody(2, #PB_Entity_BoxBody, 100, 0.1, 2)
CreateEntity(3, MeshID(0), MaterialID(1), -8, 0, 0) ; the static cube
ScaleEntity(3, 6,0.2,10)
RotateEntity(3,0,0,90)
CreateEntityBody(3, #PB_Entity_StaticBody, 1, 0.1, 2)
;-------------- not sleep ---------------------------------------
;SetEntityAttribute(0, #PB_Entity_LinearSleeping, 0)
SetEntityAttribute(#cyl, #PB_Entity_LinearSleeping, 0)
Repeat
Event = WindowEvent()
If ExamineMouse()
MouseX = -MouseDeltaX()/20
MouseY = -MouseDeltaY()/20
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -1
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = 1
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -1
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = 1
Else
KeyY = 0
EndIf
If KeyboardPushed(#PB_Key_Space)
;ApplyEntityForce(1, 0, 100, 0 , 0, 0, -6)
ApplyEntityTorque(#cyl, 500, 0, 0)
ElseIf KeyboardPushed(#PB_Key_Z)
;ApplyEntityImpulse(1, 0, 20, 0 , 0, 0, -6)
ApplyEntityTorqueImpulse(#cyl, 20, 0, 0)
EndIf
EndIf
RotateCamera(#Camera, MouseY, MouseX, 0, #PB_Relative)
MoveCamera(#Camera, KeyX, 0, KeyY)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End