if we want to change the orientation of the rotor then the same x,y,z values will not work as we naturally wants for the rotor. ie we should then change the values as in the example below.
what if there is a local or global flag ??
of course for the rotors we can use EnableHingeJointAngularMotor as demonstrated by example carPhysics.pb in the PB examples\Demos
in the following the default torque is
ApplyEntityTorque(#cyl, 1000, 0, 0)
ApplyEntityTorque(#cyl2, 1000, 0, 0)
and due to imperfections in the wheel cylinder body the car will turn to the opposite direction and when it is almost stop press '2' to change torque to:
ApplyEntityTorque(#cyl, -1000, 0, 0)
ApplyEntityTorque(#cyl2, -1000, 0, 0)
Code: Select all
Enumeration
#camera
#Plane
#cyl
#cyl2
EndEnumeration
Define.f KeyX, KeyY, MouseX, MouseY
ExamineDesktops()
If OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "change with 1, 2, ... use mouse + Arrows to rotate + move Camera", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If InitEngine3D()
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #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)
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(4, LoadTexture(4, "ground_diffuse.png"))
MaterialCullingMode(4, #PB_Material_NoCulling)
CreatePlane(500, 450, 400, 5, 5, 2, 2) ; the ground
CreateEntity(500, MeshID(500), MaterialID(4), 0,-4,0)
CreateEntityBody(500, #PB_Entity_StaticBody, 1, 0.1, 2)
CreateCube(0,1)
CreateEntity(0, MeshID(0), MaterialID(1), 0, 0, 0) ; car body
ScaleEntity(0, 3,3,6)
CreateCylinder(#cyl, 1, 5)
CreateEntity(#cyl, MeshID(#cyl), MaterialID(3), -5,0, 0)
RotateEntity(#cyl,0,0,90)
ScaleEntity(#cyl, 3,0.5,3)
CreateEntity(#cyl2, MeshID(#cyl), MaterialID(3), 5,0, 0)
RotateEntity(#cyl2,0,0,90)
ScaleEntity(#cyl2, 3,0.5,3)
CreateEntityBody(0, #PB_Entity_BoxBody, 90, 0.1,10)
CreateEntityBody(#cyl, #PB_Entity_CylinderBody, 100, 0.1, 4)
CreateEntityBody(#cyl2,#PB_Entity_CylinderBody, 100, 0.1, 4)
HingeJoint(0, EntityID(0),
-2, 0, 0,
1, 0, 0,
EntityID(#cyl),
0, -2, 0,
0, -1, 0)
HingeJoint(1, EntityID(0),
2, 0, 0,
-1, 0, 0,
EntityID(#cyl2),
0, 2, 0,
0, 1, 0)
autoGear = 1
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 KeyboardReleased(#PB_Key_1)
autoGear = 1
ElseIf KeyboardReleased(#PB_Key_2)
autoGear = 2
EndIf
Select autoGear
Case 1
ApplyEntityTorque(#cyl, 1000, 0, 0)
ApplyEntityTorque(#cyl2, 1000, 0, 0)
Case 2
ApplyEntityTorque(#cyl, -1000, 0, 0)
ApplyEntityTorque(#cyl2, -1000, 0, 0)
EndSelect
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