transfering force between two wheels

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

transfering force between two wheels

Post by applePi »

transfer force from a wheel to another bigger wheel, like Gears
press Z or X to operate the little wheel, if hanged with either keys press the other.
the wheels will adjust itself by itself by the wonderful engine, it needs fine tunning positioning to prevent this at the beginning.
i will post a request for the concave shapes, so we can make Gears.
Image

Code: Select all

Enumeration
   #MESH = 100
   #LIGHT
   #camera
   #mainwin
   #plane
   #node
   #wheel
   #wheel2
 EndEnumeration
Global width=20, length=20
Global zcam.f, xcam.f, ycam.f, rotate.b, camRo.f, camZ = 20



ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "Z for speed , X to slow down the wheel, arrows to Camera rotate/zoom. W for wire/solid frame", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-6, 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, 500, 500)
MoveCamera(#camera, 0, 2, 20)
CameraLookAt(#camera, 0, 2, 0)

EndIf

;SkyDome("clouds.jpg", 100) ;for blue color background
CreateMaterial(2, LoadTexture(2, "Geebee2.bmp"))
CreateSphere(3, 0.5)
CreateEntity(3, MeshID(3), MaterialID(2), -6,  6, 2)

CreateSphere(4, 0.5)
CreateEntity(4, MeshID(4), MaterialID(2), 1,  4, 0)
EntityPhysicBody(3, #PB_Entity_StaticBody)
EntityPhysicBody(4, #PB_Entity_StaticBody)

CreateMaterial(0, LoadTexture(0, "terrain_texture.jpg"))
DisableMaterialLighting(0, #True)
MaterialCullingMode(0, #PB_Material_NoCulling)

CreateCylinder(#wheel,2,1)
NormalizeMesh(#wheel)

CreateEntity(#wheel, MeshID(#wheel), MaterialID(0), -6.7,  4, -1) 
CreateEntity(#wheel, MeshID(#wheel), MaterialID(0), -6.7,  4, -1) 
RotateEntity(#wheel,0,90,0)
EntityPhysicBody(#wheel, #PB_Entity_CylinderBody    , 1.0)
EntityLinearFactor(#wheel, 0, 1, 0)
HingeJoint(1,EntityID(3),0,0,-0.2, 0,0,1, EntityID(#wheel),0,0,0, 0,1,0)
EnableHingeJointAngularMotor(1, #True, 2, 50)
;;;;;;;;;;;;;;
CreateCylinder(#wheel2,2,1)
NormalizeMesh(#wheel2)

CreateEntity(#wheel2, MeshID(#wheel2), MaterialID(0), -0.5,  4, -7) 
ScaleEntity(#wheel2,3,2,3)
EntityPhysicBody(#wheel2, #PB_Entity_CylinderBody  , 1.0)
HingeJoint(2,EntityID(4),0,0,-0.2, 0,0,1, EntityID(#wheel2),0,0,0, 0,1,0)
EnableHingeJointAngularMotor(2, #False, 2, 50) ; note that it is false

speed.f=2
;SetEntityAttribute(1, #PB_Entity_Friction , 10)
CreateMesh(#plane,#PB_Mesh_TriangleList ,#PB_Mesh_Static)
t=0
CreateNode(#node, 0,2,-3)
AttachNodeObject(#node, CameraID(#camera))
;WorldGravity(0)
;WorldDebug(#PB_World_DebugBody)
Repeat
  Event = WindowEvent()
  
  If stopFlag=1
    x + rotx
    y + roty
    z + rotz
  EndIf
   
   RenderWorld()
   FlipBuffers()

   ExamineKeyboard()
   If KeyboardPushed(#PB_Key_Z )
     ApplyEntityImpulse(#wheel,  10, 10, 10,  3,3,3)
     speed=speed+0.1
     If speed > 30: speed = 25:EndIf  
     EnableHingeJointAngularMotor(1, #True, speed, 50)
   ElseIf KeyboardPushed(#PB_Key_X)
     
     speed=speed-0.03
     ;If speed <0: speed=0:EndIf 
     EnableHingeJointAngularMotor(1, #True, speed, 50)
     
   EndIf
   
   If KeyboardReleased(#PB_Key_W) ; display wire frame for the material
      If wireFrame=0
      MaterialShadingMode(0, #PB_Material_Wireframe)
      wireFrame ! 1
         ElseIf wireFrame=1
           MaterialShadingMode(0, #PB_Material_Solid)
           wireFrame ! 1
      EndIf
    EndIf
           
    If KeyboardReleased(#PB_Key_Left)
      rotate ! 1
      camRo = -0.4
      ElseIf KeyboardReleased(#PB_Key_Right)
      rotate ! 1
      camRo = 0.4
    EndIf  
    If KeyboardPushed(#PB_Key_Down)
      camZ=camZ+1
      MoveCamera(#camera, 0, 2, camZ,#PB_Absolute)
      ElseIf KeyboardPushed(#PB_Key_Up)
      camZ=camZ-1
      MoveCamera(#camera, 0, 2, camZ,#PB_Absolute)
     EndIf 
      
    
    If rotate
      RotateNode(#node, 0, camRo, 0, #PB_Relative)
      Else
      RotateNode(#node, 0, 0, 0, #PB_Relative)
    EndIf 
    
    
            
Until KeyboardPushed(#PB_Key_Escape) Or Event = #PB_Event_CloseWindow
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: transfering force between two wheels

Post by DK_PETER »

applePi wrote:transfer force from a wheel to another bigger wheel, like Gears
press Z or X to operate the little wheel, if hanged with either keys press the other.
the wheels will adjust itself by itself by the wonderful engine, it needs fine tunning positioning to prevent this at the beginning.
i will post a request for the concave shapes, so we can make Gears.
Image
Thanks ApplePi. Great example as usual.
Yeah..I could go for concave shapes too.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Post Reply