SetJointAttribute(4, #PB_Joint_NoLimit, 0, 3)
to this
SetJointAttribute(4, #PB_Joint_NoLimit, 0, 5)
in line 74
shoot again and it will rotate correctly around Z.
now change it to
SetJointAttribute(4, #PB_Joint_NoLimit, 0, 4)
shoot it and it will rotate erratically around Y
so it works okay around X,Z but not around Y
tested with several objects, and different bodies
Code: Select all
;
; ------------------------------------------------------------
;
; PureBasic - GenericJoint
;
; (c) Fantaisie Software
;
; ------------------------------------------------------------
;
IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"
#Speed = 50
Define.f KeyX, KeyY, ex,ey
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
If Screen3DRequester()
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
CreateSprite(1, 200, 120, #PB_Sprite_AlphaBlending)
LoadFont(1, "Arial", 16, #PB_Font_Bold)
;====================== Materials/textures ========================
CreateMaterial(0, LoadTexture(0,"wood.jpg"))
GetScriptMaterial(1, "Examples/SphereMappedRustySteel")
GetScriptMaterial(2, "Color/Red")
GetScriptMaterial(3, "Color/Green")
CreateMaterial(4, LoadTexture(4, "Dirt.jpg"))
CreateMaterial(10, LoadTexture(10, "ground_diffuse.png")) : ScaleMaterial(10,1/8,1/8)
GetScriptMaterial(11, "Color/Yellow")
;- Aim
CreateSprite(0,256,256,#PB_Sprite_AlphaBlending )
StartDrawing(SpriteOutput(0))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0, 0, 256, 256, $0)
Circle(128, 128, 102, $ffffffff)
Circle(128, 128, 100, $77aaaaaa)
LineXY(128, 0, 128, 255, $ffffffff)
LineXY(0, 128, 255, 128, $ffffffff)
StopDrawing()
;====================== Meshes/Entities/bodies/joints ========================
; Ground
;
CreateCube(10, 2)
CreateEntity(10, MeshID(10), MaterialID(10), 0, -4.0, 0) : ScaleEntity(10, 20, 0.2, 20)
CreateEntityBody(10, #PB_Entity_StaticBody , 0,0.5,0.5)
; Shoot ball
;
CreateSphere(11, 1)
; turnstile - free x rotation
;
CreateCube(4, 4)
CreateEntity(4, MeshID(4), MaterialID(4), -12, 0.0, 0) : ScaleEntity(4, 1, 1, 0.2)
CreateEntityBody(4, #PB_Entity_BoxBody, 1, 0.5, 0.5)
GenericJoint(4,EntityID(10), 0, 10, 0,EntityID(4), 0, 0, 0)
SetJointAttribute(4, #PB_Joint_NoLimit, 0, 3)
; Camera
;
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, -1, 8, 25, #PB_Absolute)
CameraLookAt(0, -3, 0, 0)
; Light
;
CreateLight(0, RGB(255, 255, 255), 1560, 900, 500)
AmbientColor($777777)
WorldShadows(#PB_Shadow_Additive)
MouseLocate(ex/2, ey/2)
Repeat
Screen3DEvents()
If ExamineMouse()
If MouseButton(#PB_MouseButton_Left)
If Clic = 0
If PointPick(0, MouseX(), MouseY())
Clic = 1
Shoot = CreateEntity(#PB_Any, MeshID(11), MaterialID(11), CameraX(0), CameraY(0), CameraZ(0))
CreateEntityBody(Shoot, #PB_Entity_SphereBody, 1,0.5,0.5)
ApplyEntityImpulse(Shoot, PickX() * #Speed, PickY() * #Speed, PickZ() * #Speed)
EndIf
EndIf
Else
Clic = 0
EndIf
EndIf
If ExamineKeyboard()
keyy = -(Bool(KeyboardPushed(#PB_Key_Up)<>0)-Bool(KeyboardPushed(#PB_Key_Down)<>0))-MouseWheel()*5
keyx = -(Bool(KeyboardPushed(#PB_Key_Left)<>0)-Bool(KeyboardPushed(#PB_Key_Right)<>0))
EndIf
CameraLookAt(0, 0, 0, 0)
MoveCamera (0, KeyX, 0, KeyY)
RenderWorld()
DisplayTransparentSprite(0, MouseX()-SpriteWidth(0)/2, MouseY()-SpriteHeight(0)/2)
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
EndIf
