1- wheel with a motor
2- the wheel have a hand attached to it by slider joint (with move freedom = zero so it is rigid and stable) and the hand allowed to go inside the wheel body with SetEntityCollisionFilter
3- another slider joint near the wheel
4- a spring near the the last slider joint
operations manual on the title bar
Code: Select all
Enumeration
#material = 10
#Joint
#axisCube
#Hand
#Joint2
#Joint3
#Joint4
EndEnumeration
#CameraSpeed = 0.1
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
;WorldDebug(#PB_World_DebugEntity)
;WorldDebug(#PB_World_DebugBody)
ExamineDesktops()
OpenWindow(0,0,0,DesktopWidth(0), DesktopHeight(0)," T: Energize the the motor...V: slower motor speed.....Mouse + arrows: for the Camera",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,DesktopWidth(0), DesktopHeight(0),1,0,0,#PB_Screen_WaitSynchronization)
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
;------------- Materials -----------------------------------------
CreateMaterial(0, LoadTexture(0, "Dirt.jpg"))
CreateMaterial(1, LoadTexture(1, "wood.jpg"))
CreateMaterial(3, LoadTexture(3, "ground_diffuse.png"))
CreateMaterial(2, LoadTexture(2, "Geebee2.bmp"))
;MaterialShadingMode(1, #PB_Material_Wireframe )
;-------------- Camera -----------------------------------------
#camera =0
CreateCamera(#Camera, 0, 0, 100, 100)
MoveCamera(#camera, 0.0254, 3.518, -4.5366, #PB_Absolute)
CameraLookAt(0, -1.5, 2, 0)
;- ------------- Light ---------------------------------------------
CreateLight(0, $FFFFFF, 1560, 900, 500)
AmbientColor(RGB(255,255,255))
;- ------------- World -------------------------------------------
WorldGravity(-9)
SkyBox("desert07.jpg")
;----------------- the big wheel-----------------------------------------
CreateCylinder(0, 1, 0.2)
CreateEntity(0, MeshID(0), MaterialID(1), 0, 2, 0)
;---------------- Hand on the wheel -----------------------------------
CreateEntityBody(0, #PB_Entity_CylinderBody, 1, 0.1,1)
CreateCylinder(#Hand,0.4, 0.2)
;TransformMesh(#Mesh, x, y, z, ScaleX, ScaleY, ScaleZ, RotateX, RotateY, RotateZ [, SubMesh])
TransformMesh(#Hand,0,0,0, 0.2, 5, 0.2, 0,0,0)
CreateEntity(#Hand, MeshID(#Hand), MaterialID(0), 0, 2, 0)
;CreateEntityBody(#Hand, #PB_Entity_CylinderBody, 1, 0.1,1)
;----------------- CollisionFilter between the wheel and its hand -----------------------------
;SetEntityCollisionFilter(#Entity, CollisionGroup, CollisionMask)
SetEntityCollisionFilter(0 , 4 , 2 )
SetEntityCollisionFilter(#Hand , 4 , 2 )
CreateEntityBody(#Hand, #PB_Entity_ConvexHullBody, 1, 0.1,1)
CreateCube(#axisCube, 0.5)
CreateEntity(#axisCube, MeshID(#axisCube), MaterialID(0) , 0, 0, 0)
CreateEntityBody(#axisCube, #PB_Entity_StaticBody)
;------------------joints ---------------------------------------------
;HingeJoint(#Joint, EntityID, PivotX, PivotY, PivotZ, AxisX, AxisY, AxisZ, EntityID2, PivotX2, PivotY2, PivotZ2, AxisX2, AxisY2, AxisZ2)
;SetJointAttribute(0, #PB_HingeJoint_LowerLimit, 0)
; the joint between the wheel EntityID(0) And the static cube on the ground EntityID(#axisCube)
HingeJoint(#Joint, EntityID(0),
0, 3, 0,
0, 1, 0,
EntityID(#axisCube),
-0.5, 0, 0,
1, 0, 0)
HingeJoint(#Joint, EntityID(0),
0, -1, 0,
0, 1, 0,
EntityID(#axisCube),
0, 1, 0,
0, 1, 0)
;;========================================================
SliderJoint(#Joint3, EntityID(0), -0.3, 0, 0, EntityID(#Hand),0.5, 0, 0)
SetJointAttribute(#Joint3, #PB_SliderJoint_LowerLimit, 0)
SetJointAttribute(#Joint3, #PB_SliderJoint_UpperLimit, 0)
;----------------- not sleep ---------------------------------------
SetEntityAttribute(0, #PB_Entity_LinearSleeping, 0)
;------------- ----------------------------------------------
CreateCube(3, 1) ; for the body of the slider
CreateEntity(6, MeshID(3), MaterialID(2) , -1.2, 2.4, 1.0) ; the moving slider
ScaleEntity(6, 1, 0.2, 0.2)
CreateEntityBody(6, #PB_Entity_BoxBody, 1)
CreateEntity(7, MeshID(3), MaterialID(0) , -1.3, 2.4, 1.5) ; fixed
ScaleEntity(7, 1, 0.1, 0.1)
CreateEntityBody(7, #PB_Entity_StaticBody, 1)
SliderJoint(#Joint4, EntityID(7), 0, 0, -1, EntityID(6),0, 0, 1)
SetJointAttribute(#Joint4, #PB_SliderJoint_LowerLimit, -1)
SetJointAttribute(#Joint4, #PB_SliderJoint_UpperLimit, 0)
Define.f KeyX, KeyY, MouseX, MouseY
CreateMaterial(#material, LoadTexture(#material, "MRAMOR6X6.jpg"))
CreatePlane(500, 30, 30, 5, 5, 2, 2)
CreateEntity(500, MeshID(500), MaterialID(#material), 0,-2.5,0.0)
CreateEntityBody(500, #PB_Entity_StaticBody, 1, 0.1, 1)
EnableHingeJointAngularMotor(#Joint,0,0.0,10)
CreateCube(50,0.1) ; static body connected with Hinge joint with 51
CreateEntity(50, MeshID(50), MaterialID(1), -2.35, 2.7, -0.5)
ScaleEntity(50, 3,3,2.5)
CreateEntity(51, MeshID(50), MaterialID(3), -5,0, 0) ; spring
ScaleEntity(51, 8,0.5,8)
RotateEntity(50, 0,0,-90)
CreateEntityBody(50, #PB_Entity_StaticBody, 90, 0.1,10)
CreateEntityBody(51, #PB_Entity_BoxBody, 1, 0.1, 1)
SetEntityCollisionFilter(6 , 5, 3 ) ; (the Hammer) ;slider
SetEntityCollisionFilter(51 , 5 , 3 ) ; spring block
SetEntityCollisionFilter(50 , 4, 3 ) ; static body connected with Hinge joint with 51
;HingeJoint(#Joint, EntityID, PivotX, PivotY, PivotZ, AxisX, AxisY, AxisZ, EntityID2, PivotX2, PivotY2, PivotZ2, AxisX2, AxisY2, AxisZ2)
;joints 60 and 61 just to fix entity 50 and entity 51 together
HingeJoint(60, EntityID(50), ;entity 50 are Static cube
0, 0.5, 0,
0, 0, 1,
EntityID(51), ; entity 51 is the spring
0, 0, 0,
0, 0, 1)
HingeJoint(61, EntityID(50),
-0.05, 0.5, 0,
0, 0, 1,
EntityID(51),
0.05, 0, 0,
0, 0, 1)
Repeat
Repeat
Event = WindowEvent()
Until Event = 0
If ExamineMouse()
MouseX = -MouseDeltaX() * #CameraSpeed * 0.2
MouseY = -MouseDeltaY() * #CameraSpeed * 0.2
EndIf
ShowCursor_(0)
ExamineKeyboard()
; Use arrow keys and mouse to rotate camera and fly in/out
If KeyboardPushed(#PB_Key_Left)
KeyX = -#CameraSpeed/2
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #CameraSpeed/2
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#CameraSpeed/2
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #CameraSpeed/2
Else
KeyY = 0
EndIf
If KeyboardPushed(#PB_Key_T) ; motor rotation
EnableHingeJointAngularMotor(#Joint,1,3,10)
EndIf
If KeyboardReleased(#PB_Key_V) ; slower motor rotation
EnableHingeJointAngularMotor(#Joint,1,0.5,10)
EndIf
If KeyboardReleased(#PB_Key_C) ; check camera position
Debug CameraX(0): Debug CameraY(0): Debug CameraZ(0)
EndIf
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
MoveCamera (0, KeyX, 0, KeyY)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or WindowEvent() = #PB_Event_CloseWindowthe first joint is at the center of springy block, the second joint at the left by -2
do this experiment:
change the second joint positions (they are relative to the center of objects)
Code: Select all
HingeJoint(1, EntityID(0),
-2, 5, 0,
0, 0, 1,
EntityID(1),
-2, 0, 0,
0, 0, 1) Code: Select all
HingeJoint(1, EntityID(0),
-0.1, 5, 0,
0, 0, 1,
EntityID(1),
-0.1, 0, 0,
0, 0, 1)
Code: Select all
Enumeration
#LIGHT
#CAMERA
#mainwin
#Plane
#Joint
EndEnumeration
Define.f KeyX, KeyY, MouseX, MouseY
ExamineDesktops()
If OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "press Space...to drop a cube, .. 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, 0, 10, 20, #PB_Absolute)
;CameraFOV(#camera, 70)
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, "snow_1024.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,-15,0)
CreateEntityBody(500, #PB_Entity_StaticBody, 1, 0.1, 1)
CreateCube(0,1)
CreateEntity(0, MeshID(0), MaterialID(1), 0, 0, 0) ; the static cube
ScaleEntity(0, 3,3,3)
CreateEntity(1, MeshID(0), MaterialID(3), 0,5, 0) ; the spring
ScaleEntity(1, 12,0.5,12)
CreateEntityBody(0, #PB_Entity_StaticBody, 90, 0.1,10)
CreateEntityBody(1, #PB_Entity_BoxBody, 1, 0.1, 1)
;joints 0 and 1 just to fix ent 0 and ent 1 together ;if the 2 joints are close they will show spring behaviour
HingeJoint(0, EntityID(0),
0, 5, 0,
0, 0, 1,
EntityID(1),
0, 0, 0,
0, 0, 1)
HingeJoint(1, EntityID(0),
-2, 5, 0,
0, 0, 1,
EntityID(1),
-2, 0, 0,
0, 0, 1)
;-------------- not sleep ---------------------------------------
SetEntityAttribute(0, #PB_Entity_LinearSleeping, 0)
SetEntityAttribute(1, #PB_Entity_LinearSleeping, 0)
;WorldGravity(-9)
Repeat
Repeat
Event = WindowEvent()
Until Event = 0
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_Space)
stone = CreateCube(#PB_Any , 1)
stone = CreateEntity(#PB_Any, MeshID(stone),MaterialID(2))
ScaleEntity(stone,2,0.7,2)
MoveEntity(stone, 4,8, 0)
CreateEntityBody(stone,#PB_Entity_BoxBody,20)
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




