// Project: objectCollisionTest // Created: 20-05-03 // show all errors SetErrorMode(2) // set window properties SetWindowTitle( "objectCollisionTest" ) SetWindowSize( 1024, 768, 0 ) SetWindowAllowResize( 1 ) // allow the user to resize the window // set display properties SetVirtualResolution( 1024, 768 ) // doesn't have to match the window SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders UseNewDefaultFonts( 1 ) type myColor r as integer g as integer b as integer endtype global hangerSwing_colorOff as myColor hangerSwing_colorOff.r = 89 hangerSwing_colorOff.g = 100 hangerSwing_colorOff.b = 255 global hangerSwing_colorOn as myColor hangerSwing_colorOn.r = 89 hangerSwing_colorOn.g = 227 hangerSwing_colorOn.b = 255 setUpWorld() do if GetRawKeyState(39) moveDoor(5) endif if GetRawKeyState(37) moveDoor(-5) endif if GetRawKeyState(32) moveDoor(0) endif print("Left Arrow = Slide Door Left") print("Right Arrow = Slide Door Right") print("Spacebar = Stop Door Moving") if GetObject3DPhysicsFirstContact(hangerSwing) SetObjectColor(hangerSwing, hangerSwing_colorOn.r, hangerSwing_colorOn.g, hangerSwing_colorOn.b, 255) else SetObjectColor(hangerSwing, hangerSwing_colorOff.r, hangerSwing_colorOff.g, hangerSwing_colorOff.b, 255) endif Step3DPhysicsWorld() Sync() loop function moveDoor(getSpeed as float) Set3DPhysicsSliderJointTargetLinearMotorVelocity(sliderJoint, getSpeed) endfunction function setUpWorld() create3DPhysicsWorld(1) SetGlobal3DDepth(100) Set3DPhysicsGravity(0, -40, 0) SetAmbientColor(50, 50, 50) MoveCameraLocalY(1, 3) global sliderRail as integer sliderRail = CreateObjectBox(10, 0.5, 0.5) SetObjectPosition(sliderRail, 0, 6, 0) Create3DPhysicsStaticBody(sliderRail) SetObjectColor(sliderRail, 150, 150, 150, 255) global sliderDoor as integer sliderDoor = CreateObjectBox(5, 5, 0.5) SetObjectPosition(sliderDoor, -2.5, 3, 0) Create3DPhysicsDynamicBody(sliderDoor) SetObjectShapeBox(sliderDoor) SetObjectColor(sliderDoor, 150, 150, 150, 255) SetObject3DPhysicsCanSleep(sliderDoor, 0) global sliderJoint as integer sliderJoint = Create3DPhysicsSliderJoint(sliderRail, sliderDoor, CreateVector3(-3, 0, 0), CreateVector3(1, 0, 0)) Set3DPhysicsSliderJointPoweredLinearMotorIsEnabled(sliderJoint, 1) Set3DPhysicsJointSliderLinearLimits(sliderJoint, 0, 6.5) Set3DPhysicsSliderJointMaxLinearMotorForce(sliderJoint, 1) global hangerBlock as integer hangerBlock = CreateObjectBox(2, 2, 1) SetObjectPosition(hangerBlock, 6.5, 9, 0) Create3DPhysicsStaticBody(hangerBlock) SetObjectColor(hangerBlock, 0, 11, 178, 255) global hangerSwing as integer hangerSwing = CreateObjectBox(0.5, 4, 0.5) SetObjectPosition(hangerSwing, 6.5, 6.5, 0) Create3DPhysicsDynamicBody(hangerSwing) SetObjectShapeBox(hangerSwing) SetObject3DPhysicsCanSleep(hangerSwing, 0) SetObjectColor(hangerSwing, hangerSwing_colorOff.r, hangerSwing_colorOff.g, hangerSwing_colorOff.b, 255) global hingeJoint as integer positionVect = CreateVector3() rotationVect = CreateVector3(0,0,1.0) posVestStatus = GetObjects3DPhysicsContactPositionVector(hangerSwing, hangerBlock, positionVect) hingeJoint = Create3DPhysicsHingeJoint(hangerBlock, hangerSwing, positionVect, rotationVect, 1) Set3DPhysicsJointHingeLimits(hingeJoint, -90, 0) endfunction