Rotate the second object as well as the first

Everything related to 3D programming
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Rotate the second object as well as the first

Post by AndyLy »

How to turn a second object as well as the first.
I've tried different commands, different flags ..
Nothing turns out.

Code: Select all

InitEngine3D(): InitSprite(): InitKeyboard(): InitMouse(): InitSound()
 OpenWindow(0, 0, 0,1024,768,"PB 3D test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0,1024,768,0,0,0,#PB_Screen_WaitSynchronization)
EnableWorldPhysics(1): EnableWorldCollisions(1)

CreateLight(222,RGB(250,250,250),0,100,0,#PB_Light_Directional)
CreateCamera(1,0,0,100,100): MoveCamera(1,0,0,20)

CreatePlane(23,10,10,1,1,1,1)
CreateEntity(23,MeshID(23),#PB_Material_None,0,-3.5,0): EntityPhysicBody(23,#PB_Entity_StaticBody )

CreateCube(1,3): CreateEntity(1,MeshID(1),#PB_Material_None,0,0,0)
;EntityPhysicBody(1,#PB_Entity_BoxBody,10)

CreateCube(10,3): CreateEntity(10,MeshID(1),#PB_Material_None,0,5,0)

CameraSpeed.f=1: KeyX.f=0: KeyY.f=0

Repeat
Event = WindowEvent(): If Event=#PB_Event_CloseWindow: Quite = 1: EndIf
 ExamineMouse():  ExamineKeyboard()
     MouseX.f = -MouseDeltaX() * CameraSpeed * 0.05: MouseY.f = -MouseDeltaY() * CameraSpeed * 0.05
     If KeyboardPushed(#PB_Key_A): KeyX = -CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_D): KeyX = CameraSpeed: Else: KeyX = 0: EndIf
     If KeyboardPushed(#PB_Key_W): KeyY = -CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_S): KeyY = CameraSpeed: Else: KeyY = 0: EndIf    
     RotateCamera(1, MouseY, MouseX, 0, #PB_Relative): MoveCamera (1, KeyX, 0, KeyY)
     
RotateEntity(1,0.2,0.4,0.2,#PB_Relative)

     globppX.f=EntityPitch(1,#PB_Absolute | #PB_Engine3D_Adjusted)
     globppY.f=EntityYaw(1,#PB_Absolute | #PB_Engine3D_Adjusted)
     globppZ.f=EntityRoll(1,#PB_Absolute | #PB_Engine3D_Adjusted)

RotateEntity(10,globppX,globppY,globppZ,#PB_Absolute)

;RotateEntity(10,0,0,0,#PB_Absolute)
;Pitch(EntityID(10),globppX,#PB_World): Yaw(EntityID(10),globppY,#PB_World): Roll(EntityID(10),globppZ,#PB_World)

RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
End
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Rotate the second object as well as the first

Post by applePi »

from the example CopyAngle.pb in PB 3D section examples, just a small change.
press space to change the rotation of first cube, and the second cube will follow it.

Code: Select all

InitEngine3D(): InitSprite(): InitKeyboard(): InitMouse(): InitSound()
 OpenWindow(0, 0, 0,1024,768,"PB 3D test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0,1024,768,0,0,0,#PB_Screen_WaitSynchronization)
;EnableWorldPhysics(1): EnableWorldCollisions(1)

CreateLight(222,RGB(250,250,250),0,100,0,#PB_Light_Directional)
CreateCamera(1,0,0,100,100): MoveCamera(1,0,0,20)

CreatePlane(23,10,10,1,1,1,1)
CreateEntity(23,MeshID(23),#PB_Material_None,0,-3.5,0): EntityPhysicBody(23,#PB_Entity_StaticBody )

CreateCube(1,3): CreateEntity(1,MeshID(1),#PB_Material_None,0,0,0)
;EntityPhysicBody(1,#PB_Entity_BoxBody,10)

CreateCube(10,3): CreateEntity(10,MeshID(1),#PB_Material_None,0,5,0)

CameraSpeed.f=1: KeyX.f=0: KeyY.f=0
rot.f = 0
Repeat
Event = WindowEvent(): If Event=#PB_Event_CloseWindow: Quite = 1: EndIf
 ExamineMouse():  ExamineKeyboard()
     MouseX.f = -MouseDeltaX() * CameraSpeed * 0.05: MouseY.f = -MouseDeltaY() * CameraSpeed * 0.05
     If KeyboardPushed(#PB_Key_A): KeyX = -CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_D): KeyX = CameraSpeed: Else: KeyX = 0: EndIf
     If KeyboardPushed(#PB_Key_W): KeyY = -CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_S): KeyY = CameraSpeed: Else: KeyY = 0: EndIf    
     RotateCamera(1, MouseY, MouseX, 0, #PB_Relative): MoveCamera (1, KeyX, 0, KeyY)
     
RotateEntity(1,0.2+rot,0.4+rot,0.2+rot,#PB_Relative)

      If KeyboardReleased(#PB_Key_Space)
       If direction = 1
       rot = -0.4
       direction ! 1
     Else
       rot = 0.4
       direction ! 1
       EndIf
     EndIf  

     
      RotateEntity(10, EntityPitch(1,0), EntityYaw(1, 0), EntityRoll(1, 0))

RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
End
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Re: Rotate the second object as well as the first

Post by AndyLy »

Thank you applePi.

But :
#PB_Absolute: get the absolute pitch value, ignoring the current pitch of the parent (default).
#PB_Relative: get the pitch value relative to the current pitch of the parent.

combined with one of the following value:
#PB_Engine3D_Raw : the pitch is the raw value, but it can't be used in RotateEntity() to get back the same orientation (default).
#PB_Engine3D_Adjusted: the pitch is adjusted, so it can be put back in RotateEntity() to get back the same orientation.
flag 0 - its #PB_Absolute without #PB_Engine3D_Raw or #PB_Engine3D_Adjusted !
Is that an undocumented feature?
Or its a bug?
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Rotate the second object as well as the first

Post by applePi »

note that
Debug #PB_Relative = 1
Debug #PB_Absolute = 0

so i guess the default is the combination with #PB_Engine3D_Adjusted such as

Code: Select all

RotateEntity(10, EntityPitch(1,1 | #PB_Engine3D_Adjusted), EntityYaw(1, 1 | #PB_Engine3D_Adjusted ), EntityRoll(1, 1 | #PB_Engine3D_Adjusted ))
RotateEntity(10, EntityPitch(1,0 | #PB_Engine3D_Adjusted), EntityYaw(1, 0 | #PB_Engine3D_Adjusted ), EntityRoll(1, 0 | #PB_Engine3D_Adjusted ))
this is the same as

Code: Select all

RotateEntity(10, EntityPitch(1,1), EntityYaw(1, 1), EntityRoll(1, 1 ))
RotateEntity(10, EntityPitch(1,0), EntityYaw(1, 0), EntityRoll(1, 0 ))
all the above works in your example, since the #PB_Engine3D_Adjusted is what does the job

while this will not work: (like it is documented "#PB_Engine3D_Raw" will not work here:
(doc: but it can't be used in RotateEntity() to get back the same orientation (default)).
the default word may refer to the words "same orientation " and not the #PB_Engine3D_Raw since we can see that the #PB_Engine3D_Adjusted is the default

Code: Select all

RotateEntity(10, EntityPitch(1,#PB_Absolute | #PB_Engine3D_Raw), EntityYaw(1, #PB_Absolute | #PB_Engine3D_Raw ), EntityRoll(1, #PB_Absolute | #PB_Engine3D_Raw ))
RotateEntity(10, EntityPitch(1,1 | #PB_Engine3D_Raw), EntityYaw(1, 1 | #PB_Engine3D_Raw ), EntityRoll(1, 1 | #PB_Engine3D_Raw ))
RotateEntity(10, EntityPitch(1,0 | #PB_Engine3D_Raw), EntityYaw(1, 0 | #PB_Engine3D_Raw ), EntityRoll(1, 0 | #PB_Engine3D_Raw ))
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Re: Rotate the second object as well as the first

Post by AndyLy »

This kind of mysticism: put this code in a program-not working properly.
The second object twists inexplicably. :(

EntityPitch(1,1)....
Seems it works.

Thanks applePi.
So little by little I finish the game. Soon lay out a demo level.
You'll be amazed and shocked. Because I'm super cool. :)
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
Post Reply