How to set up an angular velocity to an entity?
I only find EntityVelocity(#Entity, x, y, z) to set up a rectilinear velocity, but not angular velocity.
SetEntityAttribute() is not valid for this.
Entity angular velocity a.k.a. Omega
- Psychophanta
- Addict
- Posts: 4997
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Lípetsk, Russian Federation
- Contact:
Entity angular velocity a.k.a. Omega
http://www.zeitgeistmovie.com
While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB
While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB
Re: Entity angular velocity a.k.a. Omega
Hi Psychophanta
long time haven't done physics tests, i suggest:
EntityAngularFactor
i haven't used it for natural rotating things but for rotating things fixed to a joint:
GenericJoint with EntityAngularFactor and then use: ApplyEntityTorque
i have found this example: not optimized but works:
also hinge joint for the wheel to attach a motor to it (EnableHingeJointAngularMotor)
look Rotational to Linear movement
viewtopic.php?f=36&t=66458&p=493487#p493487
viewtopic.php?f=36&t=66458&p=493487#p493342
EntityLinearFactor and EntityAngularFactor to fix or relief the blocks ,
is used in old example by Kelebrindae, also it is used in a commercial Billiards Game posted here somewhere
long time haven't done physics tests, i suggest:
EntityAngularFactor
i haven't used it for natural rotating things but for rotating things fixed to a joint:
GenericJoint with EntityAngularFactor and then use: ApplyEntityTorque
i have found this example: not optimized but works:
Code: Select all
IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"
#CameraSpeed = 0.4
Define.f KeyX, KeyY, MouseX, MouseY
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
If Screen3DRequester()
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/" , #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)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/GUI" , #PB_3DArchive_FileSystem)
Parse3DScripts()
;WorldDebug(#PB_World_DebugBody)
;-------------------------------
; create material
CreateMaterial(1, LoadTexture(1, "Tire_tex.png"))
;RotateMaterial(1, -70, #PB_Material_Fixed)
SetMaterialColor(1, #PB_Material_AmbientColor, #PB_Material_AmbientColors)
;
CreateMaterial(2, LoadTexture(2, "snow_1024.jpg"))
SetMaterialColor(2, #PB_Material_AmbientColor, #PB_Material_AmbientColors)
CreateMaterial(3, LoadTexture(3, "Geebee2.bmp"))
SetMaterialColor(3, #PB_Material_AmbientColor, #PB_Material_AmbientColors)
CreateMaterial(4, LoadTexture(4, "Wood.jpg"))
;-------------------------------
CreateCylinder(50, 1, 0.5)
CreateEntity(50, MeshID(50),MaterialID(1), 0, 0, 0)
axis = CreateEntity(#PB_Any, MeshID(50),MaterialID(4), 0, 0, 0)
ScaleEntity(axis, 0.15, 3, 0.15)
;RotateEntity(50, 90,0, 0, #PB_Absolute)
CreateCube(1, 1)
Global Compound = CreateEntity(#PB_Any,0,0)
AddSubEntity(Compound, 50, #PB_Entity_StaticBody)
AddSubEntity(Compound, axis, #PB_Entity_StaticBody)
CreateEntityBody(Compound, #PB_Entity_CompoundBody, 1, 0.4, 0.5)
;-----------------------------------------
;Ground
;
Ground = CreateEntity(#PB_Any, MeshID(1), MaterialID(2), 0, -7, 0)
ScaleEntity(Ground, 40, 0.4, 40)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
GenericJoint(4,EntityID(Ground), 0, 5, 0,EntityID(Compound), 0, 0, 0)
;the following will make the wheel stop if we stop the angular force
SetJointAttribute(4, #PB_Joint_EnableSpring, #True, 4)
SetJointAttribute(4, #PB_Joint_Stiffness, 5, 4)
SetJointAttribute(4, #PB_Joint_Damping, 0.0, 4)
;SetJointAttribute(4, #PB_Joint_NoLimit, 0, 4)
EntityAngularFactor(Compound, 0, 1, 0)
;SetJointAttribute(4, #PB_Joint_LowerLimit, -70, 4)
;SetJointAttribute(4, #PB_Joint_UpperLimit, 70, 4)
; camera
CreateCamera(0, 0, 0, 100, 100, #True)
MoveCamera(0,0,0,2.5, #PB_Absolute)
CameraLookAt(0,0,-2,0)
; GUI
OpenWindow3D(0, 0, 0, 50 , 10 , "")
HideWindow3D(0,1)
ShowGUI(128, 1) ; Display the GUI, semi-transparent and display the mouse cursor
SetWindowTitle(0, "PureBasic-3D Demos ...Z/X apply torque to the Wheel,..'space':to drop Cubes..Mouse to Pick objects")
#stone = 30
Global Dim stone(1000)
CreateCube(#stone, 0.2)
For i = 1 To 1000
stone(i) = CreateEntity(#PB_Any, MeshID(#stone),MaterialID(3))
HideEntity(stone(i), #True)
Next
Repeat
Screen3DEvents()
If ExamineMouse()
MouseX = -MouseDeltaX() * #CameraSpeed * 0.1
MouseY = -MouseDeltaY() * #CameraSpeed * 0.1
InputEvent3D(MouseX(), MouseY(),0)
BodyPick(CameraID(0), MouseButton(#PB_MouseButton_Left), MouseX(), MouseY(), 1)
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Z)
ApplyEntityTorque(Compound, 0, 10, 0)
;ApplyEntityTorqueImpulse(Compound, 0, 0, 1)
ElseIf KeyboardPushed(#PB_Key_X)
ApplyEntityTorque(Compound, 0, -10, 0)
EndIf
If KeyboardReleased(#PB_Key_Space); throw cubes over the gear
stn+1
If stn > 1000: stn=1: EndIf
MoveEntity(stone(stn), 0.3,-1,0)
HideEntity(stone(stn), #False)
CreateEntityBody(stone(stn),#PB_Entity_BoxBody,2,0.1,4)
EndIf
If KeyboardPushed(#PB_Key_Left)
KeyX = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #CameraSpeed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #CameraSpeed
Else
KeyY = 0
EndIf
EndIf
MoveCamera (0, KeyX, 0, KeyY)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
End
look Rotational to Linear movement
viewtopic.php?f=36&t=66458&p=493487#p493487
viewtopic.php?f=36&t=66458&p=493487#p493342
EntityLinearFactor and EntityAngularFactor to fix or relief the blocks ,
is used in old example by Kelebrindae, also it is used in a commercial Billiards Game posted here somewhere
Code: Select all
;originally posted by Kelebrindae
; Window size
#SCREENWIDTH = 800
#SCREENHEIGHT = 500
Dim a(20)
;- initialization
InitEngine3D()
InitSprite()
InitKeyboard()
;- Window
OpenWindow(0, 0, 0, #SCREENWIDTH, #SCREENHEIGHT, "press space to move the hammer, press Z before space to free the cubes restrictions", #PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget)
OpenWindowedScreen(WindowID(0), 0, 0, #SCREENWIDTH,#SCREENHEIGHT, 0, 0, 0,#PB_Screen_SmartSynchronization)
;-Texture
Add3DArchive(".",#PB_3DArchive_FileSystem)
CreateImage(0,128, 128)
StartDrawing(ImageOutput(0))
Box(0, 0, 128, 128, $FFFFFF)
StopDrawing()
SaveImage(0,"temp.bmp")
FreeImage(0)
LoadTexture(0,"temp.bmp")
DeleteFile("temp.bmp")
;-Material
CreateMaterial(1,TextureID(0))
;MaterialAmbientColor(1,#PB_Material_AmbientColors)
SetMaterialColor(1, #PB_Material_AmbientColor, RGB(100,100,100))
CreateMaterial(2,TextureID(0))
;MaterialAmbientColor(2,$FFFF00)
SetMaterialColor(2, #PB_Material_AmbientColor, $FFFF00)
CreateMaterial(3,TextureID(0))
;MaterialAmbientColor(3,$0077FF)
SetMaterialColor(3, #PB_Material_AmbientColor, $0077FF)
CreateMaterial(4,TextureID(0))
;MaterialAmbientColor(4,$FF00FF)
SetMaterialColor(4, #PB_Material_AmbientColor, $FF00FF)
CreateMaterial(5,TextureID(0))
;MaterialAmbientColor(5,$0055BB)
SetMaterialColor(5, #PB_Material_AmbientColor, $FF00FF)
;- Entities
CreatePlane(1,30,30,20,20,1,1)
sol = CreateEntity(#PB_Any, MeshID(1), MaterialID(1))
CreateEntityBody(sol, #PB_Entity_StaticBody)
; Ball and tee
CreateCube(2, 1.0)
socle = CreateEntity(#PB_Any,MeshID(2), MaterialID(1))
ScaleEntity(socle,0.5,1,0.5)
MoveEntity(socle,2.6,0.5,0)
CreateEntityBody(socle, #PB_Entity_StaticBody)
CreateSphere(3,0.5)
ball = CreateEntity(#PB_Any, MeshID(3), MaterialID(3))
MoveEntity(ball,2.6,1.5,0)
CreateEntityBody(ball, #PB_Entity_SphereBody,1,4,1)
; Targets
For i = 1 To 4
temp = CreateEntity(#PB_Any, MeshID(2), MaterialID(4))
r+1
a(r) = temp ; store entities numbers
MoveEntity(temp,-10,0.5,(i*1.1)-2.8)
CreateEntityBody(temp, #PB_Entity_BoxBody, 0.25)
EntityLinearFactor(temp,0,0,0)
EntityAngularFactor(temp, 0, 0, 0)
Next i
For i = 1 To 3
temp = CreateEntity(#PB_Any, MeshID(2), MaterialID(4))
r+1
a(r) = temp
MoveEntity(temp,-10,1.5,(i*1.1)-2.3)
CreateEntityBody(temp, #PB_Entity_BoxBody, 0.25)
EntityLinearFactor(temp,0,0,0)
EntityAngularFactor(temp, 0, 0, 0)
Next i
For i = 1 To 2
temp = CreateEntity(#PB_Any, MeshID(2), MaterialID(4))
r+1
a(r) = temp
MoveEntity(temp,-10,2.5,(i*1.1)-1.8)
CreateEntityBody(temp, #PB_Entity_BoxBody, 0.25)
EntityLinearFactor(temp,0,0,0)
EntityAngularFactor(temp, 0, 0, 0)
Next i
; Mobile
Global hammerX.f = 5,hammerY.f = 8.5,hammerZ.f
CreateSphere(4,0.4)
axe = CreateEntity(#PB_Any, MeshID(4), MaterialID(2))
MoveEntity(axe,hammerX,hammerY,hammerZ)
CreateEntityBody(axe, #PB_Entity_StaticBody)
shaft = CreateEntity(#PB_Any, MeshID(2), MaterialID(5))
ScaleEntity(shaft,0.3,6,0.3)
MoveEntity(shaft,hammerX,hammerY - 3.5,hammerZ)
CreateEntityBody(shaft, #PB_Entity_BoxBody,0.1)
hammerhead = CreateEntity(#PB_Any,MeshID(2), MaterialID(2))
ScaleEntity(hammerhead,2,1,1)
MoveEntity(hammerhead,hammerX,hammerY - 7,hammerZ)
CreateEntityBody(hammerhead,#PB_Entity_BoxBody,20)
PointJoint(0,EntityID(shaft),0,-3.1 ,0, EntityID(hammerhead),0,0.5,0) ; Attach the hammerhead to the shaft
; Attach the hammer to axis.
HingeJoint(1,EntityID(axe),0,0,0, #False,#False,#True, EntityID(shaft),0,3.5,0, #False,#False,#True)
HingeJoint(2,EntityID(axe),0,0,0, #False,#False,#True, EntityID(hammerhead),0,7,0, #False,#False,#True)
;- Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0,-2,8,18)
CameraLookAt(0,-2,5,0)
;-Light
AmbientColor($666666)
CreateLight(0,RGB(160,160,255),200,400,200)
WorldShadows(#PB_Shadow_Additive)
KeyboardMode(#PB_Keyboard_International)
;- Main loop
Repeat
Delay(1)
While WindowEvent() : Wend
;- F1, F2, F3 : Change view
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_Z) ; to free cubes from restrictions
For i=1 To 9
EntityLinearFactor(a(i),1,1,1)
EntityAngularFactor(a(i), 1, 1, 1)
Next
EndIf
If KeyboardReleased(#PB_Key_F1)
MoveCamera(0,-18,2,0)
CameraLookAt(0,0,3,0)
EndIf
If KeyboardReleased(#PB_Key_F2)
MoveCamera(0,0,12,20)
CameraLookAt(0,0,5,0)
EndIf
If KeyboardReleased(#PB_Key_F3)
MoveCamera(0,1,5,10)
CameraLookAt(0,-3,3,0)
EndIf
;- [Space] : Throw hammer
If KeyboardPushed(#PB_Key_Space)
ApplyEntityImpulse(hammerhead, 5, 0, 0)
EndIf
;- R : Reset ball's position (doesn't work)
If KeyboardReleased(#PB_Key_R)
FreeEntity(ball)
EndIf
;- Return : Display FPS
If KeyboardReleased(#PB_Key_Return)
;MessageRequester("Infos","FPS = " + Str(Engine3DFrameRate(#PB_Engine3D_Average)))
MessageRequester("Infos","FPS = " + StrF(Engine3DStatus(#PB_Engine3D_CurrentFPS )))
EndIf
EndIf
; Render
RenderWorld()
FlipBuffers()
If Not IsEntity(ball)
ball = CreateEntity(#PB_Any, MeshID(3), MaterialID(3))
MoveEntity(ball,2.6,1.5,0)
CreateEntityBody(ball, #PB_Entity_SphereBody,1,4,1)
EndIf
Until KeyboardPushed(#PB_Key_Escape)
End
- Psychophanta
- Addict
- Posts: 4997
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Lípetsk, Russian Federation
- Contact:
Re: Entity angular velocity a.k.a. Omega
Hi applePi, long time.
Well, i have done the workaroud using ApplyEntityTorqueImpulse() , but that is not as it should be done, because there is needed a command to just set up an angular speed to a body.
GetEntityAttribute()
to setup a velocity vector there is:
EntityVelocity()
But in GetEntityAttribute() function this attribute is not called #PB_Entity_Velocity, but #PB_Entity_LinearVelocity. ??
Related to this issue, perhaps there is interesting to add this Structure native; as is now there it is PB_MeshVertex for example:
And then use GetEntityAttribute() and SetEntityAttribute() using a reference to it for some attributes like Velocity and also for AngularVelocity because an angular velocity is completely given with a vector.
Well, i have done the workaroud using ApplyEntityTorqueImpulse() , but that is not as it should be done, because there is needed a command to just set up an angular speed to a body.
GetEntityAttribute()
SetEntityAttribute()The attribute To get. The following attributes are available:
#PB_Entity_Friction : Get the friction value.
#PB_Entity_Restitution : Get the restitution value.
#PB_Entity_LinearVelocity : Get the current linear velocity (all axis).
#PB_Entity_LinearVelocityX : Get the current linear velocity on 'x' axis.
#PB_Entity_LinearVelocityY : Get the current linear velocity on 'y' axis.
#PB_Entity_LinearVelocityZ : Get the current linear velocity on 'z' axis.
#PB_Entity_MassCenterX : Get the mass center 'x' position.
#PB_Entity_MassCenterY : Get the mass center 'y' position.
#PB_Entity_MassCenterZ : Get the mass center 'z' position.
#PB_Entity_NbSubEntities : Get the number of sub-entities.
#PB_Entity_LinearSleeping : Get the minimum linear velocity value under which the entity will be sleeping.
#PB_Entity_AngularSleeping : Get the minimum angular velocity value under which the entity will be sleeping.
#PB_Entity_DeactivationTime: Get the time To wait (in milliseconds) before putting the entity in sleep mode when the above conditions are met.
#PB_Entity_IsActive : Get If an entity body is active (Not sleeping).
#PB_Entity_AngularVelocityX: Get the current angular velocity on 'x' axis.
#PB_Entity_AngularVelocityY: Get the current angular velocity on 'y' axis.
#PB_Entity_AngularVelocityZ: Get the current angular velocity on 'z' axis.
#PB_Entity_AngularVelocity : Get the current angular velocity (all axis).
#PB_Entity_HasContactResponse: Check If the entity body has contacts.
#PB_Entity_ScaleX : Get the current entity scale on 'x' axis.
#PB_Entity_ScaleY : Get the current entity scale on 'y' axis.
#PB_Entity_ScaleZ : Get the current entity scale on 'z' axis.
However,The attribute To set. The following attributes are available:
#PB_Entity_Friction : Change the friction value.
#PB_Entity_Restitution : Change the restitution value.
#PB_Entity_MinVelocity : Set the minimum linear velocity of the entity. As this value isn't stored,
it needs To be called every time the entity is moved.
#PB_Entity_MaxVelocity : Set the maximum linear velocity of the entity. As this value isn't stored,
it needs To be called every time the entity is moved.
#PB_Entity_ForceVelocity : Set the linear velocity of the entity. As this value isn't stored,
it needs To be called every time the entity is moved.
#PB_Entity_LinearSleeping : Change the minimum linear velocity value under which the entity will be sleeping.
#PB_Entity_AngularSleeping : Change the minimum angular velocity value under which the entity will be sleeping.
#PB_Entity_DeactivationTime: Time To wait (in milliseconds) before putting the entity in sleep mode when the above conditions are met.
#PB_Entity_DisableContactResponse: Disable Or enable the physic contacts For this entity. Value can be #True Or #False.
to setup a velocity vector there is:
EntityVelocity()
But in GetEntityAttribute() function this attribute is not called #PB_Entity_Velocity, but #PB_Entity_LinearVelocity. ??
Related to this issue, perhaps there is interesting to add this Structure native; as is now there it is PB_MeshVertex for example:
Code: Select all
Structure PB_3DVector
x.f
y.f
z.f
EndStructure
http://www.zeitgeistmovie.com
While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB
While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB