Page 1 of 1

[PB 5.11] EntityRoll() returns wrong values.

Posted: Sat Aug 24, 2013 10:57 am
by Bananenfreak
Heyho,

this is a modified Entity.pb from the Examples\3D Folder. Please try this code.

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Entity
;
;    (c) 2002 - Fantaisie Software
;
; ------------------------------------------------------------
;

#CameraSpeed = 1

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY, RollZ


If InitEngine3D()
  
  Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Models", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Packs/skybox.zip", #PB_3DArchive_Zip)
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    LoadMesh(0, "robot.mesh")
    
    CreateMaterial(0, LoadTexture(0, "clouds.jpg"))
    CopyMaterial(0, 1)
    CreateMaterial(2, LoadTexture(2, "r2skin.jpg"))
    MaterialShadingMode(0, #PB_Material_Wireframe)
    
    CreateEntity(0, MeshID(0), MaterialID(0))
    CreateEntity(1, MeshID(0), MaterialID(1), -60, 0, 0)
    CreateEntity(2, MeshID(0), MaterialID(2),  60, 0, 0)
    
    StartEntityAnimation(0, "Walk")
    
    EntityRenderMode(0, #PB_Entity_DisplaySkeleton)
    
    SkyBox("stevecube.jpg")
    Debug EntityRoll(0, #True)
    RotateEntity(0, 0, 90, 0, #PB_Relative)
    Debug EntityRoll(0, #True)
    
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0, 40, 150, #PB_Absolute)
    
    Repeat
      Screen3DEvents()
      
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf
      
      If ExamineKeyboard()
        
        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
      
      RotateEntity(1, 0, 1, 0, #PB_Relative)
      RotateEntity(2, 0, 1, 0, #PB_Relative)
      
      RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera  (0, KeyX, 0, KeyY)
      
      RenderWorld()
      Screen3DStats()
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf

End
The entity is rotated over the Y-Axis. If the angle is between 90 to 270 degree, EntityRoll() Returns 180°. In my mind a wrong result.

Re: [PB 5.11] EntityRoll() returns wrong values.

Posted: Sat Aug 24, 2013 11:38 am
by STARGÅTE
You have written EntityRoll(0, #True), so you get the raw data, not the "real" rotation like RotateEntity().
False gives: (Pitch, Yaw, Roll) = (0, 90, 0)

But note: euler angles are ambiguous!
Rotate (90, 90, 0) and back (-90, -90, 0) gives not the start rotation!

Re: [PB 5.11] EntityRoll() returns wrong values.

Posted: Sat Aug 24, 2013 12:13 pm
by Bananenfreak
:oops: Sorry, I thought #true is the cleaned value :oops: