Page 1 of 1

Problem with pitching on Staticgeometry

Posted: Fri Sep 12, 2014 4:31 pm
by Bananenfreak
Hiho,

I´m not sure whether this is normal for EntityYaw() or not, so first I post my code here before I do a bugreport.
I discovered something, hmm, unnormal. Just run the code below.
Keep in mind: Adjusted is the value you can use a second time for same orientation of both entities.
So, what we expect: All 3 cubes get a different angle. Now look at them; All 3 got a different direction/angle.
But what we get with EntityYaw(cubeEnt, #PB_Absolute | #PB_Engine3D_Adjusted) is that cube No.1 and No.3 have the same directionangle.
As I said, I´m not sure, but for me #PB_Engine3D_Adjusted is a thing we should not use...
Because I only get the same direction with the #PB_Engine3D_Raw angle.

So, what do you think about it? Is this normal or bugrelated?

Greets,

Bananenfreak

Code: Select all

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>                             >>
;>>  Name: Staticgeometryversuch>>
;>>                             >>
;>>  Author: (c) Bananenfreak  >>
;>>                             >>
;>>  Date: 12.09.2014           >>
;>>                             >>
;>>  OS: Windows                >>
;>>                             >>
;>>         >>
;>>                             >>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
EnableExplicit


Define.f KeyX, KeyY, MouseX, MouseY
Define nx.f, nz.f, Boost.f = 1, Yaw.f, Pitch.f
Define.i Quit, boden, cube, cubeEnt, cubeEnt1, cubeEnt2
#kam_0 = 0
#window = 0
#plane = 0
#planent = 0

If InitEngine3D()
  
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  OpenWindow(#window, 0, 0, 1800, 1000, "3D-Template", #PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(#window), 10, 10, 2000, 2000, 0, 10, 10, #PB_Screen_SmartSynchronization)
  
  WorldShadows(#PB_Shadow_TextureAdditive, 200, RGB(255 * 0.2, 255 * 0.2, 255 * 0.2), 4096)
  
  AmbientColor(RGB(255 * 0.2, 255 * 0.2, 255 * 0.2))
  
  CreatePlane(#plane, 100, 100, 100, 100, 100, 100)
  boden = GetScriptMaterial(#PB_Any, "Scene/GroundBlend")
  CreateEntity(#planent, MeshID(#plane), MaterialID(boden), 0, 0, 0)
  
  cube = CreateCube(#PB_Any, 2.0)
  cubeEnt = CreateEntity(#PB_Any, MeshID(cube), #PB_Material_None, 0, 1, 0)
  RotateEntity(cubeEnt, 0, 60, 0, #PB_Relative)
  cubeEnt1 = CreateEntity(#PB_Any, MeshID(cube), #PB_Material_None, 5, 1, 0)
  RotateEntity(cubeEnt1, 0, 90, 0, #PB_Relative)
  cubeEnt2 = CreateEntity(#PB_Any, MeshID(cube), #PB_Material_None, 10, 1, 0)
  RotateEntity(cubeEnt2, 0, 120, 0, #PB_Relative)
  
  Debug "Cube1, Adjusted: " + EntityYaw(cubeEnt, #PB_Absolute | #PB_Engine3D_Adjusted)
  Debug "Cube2, Adjusted: " + EntityYaw(cubeEnt1, #PB_Absolute | #PB_Engine3D_Adjusted)
  Debug "Cube3, Adjusted: " + EntityYaw(cubeEnt2, #PB_Absolute | #PB_Engine3D_Adjusted)
  Debug "Cube3, Raw: " + EntityYaw(cubeEnt2, #PB_Absolute | #PB_Engine3D_Raw)
  
  ;-Camera
  CreateCamera(#kam_0, 0, 0, 100, 100)
  MoveCamera(#kam_0, 0, 20, 0, #PB_Absolute)
  CameraLookAt(#kam_0, 20, 0, 20)
  CameraRange (#kam_0, 2, 5000)
  CameraFOV   (#kam_0, 90)
  CameraBackColor(#kam_0, RGB(0, 0, 0))
  
  Repeat
    Repeat
    Until WindowEvent() = 0
    
    If ExamineMouse()
      Yaw   = -MouseDeltaX() * 0.05
      Pitch = -MouseDeltaY() * 0.05
    EndIf
    
    If ExamineKeyboard()
      
      If KeyboardPushed(#PB_Key_Up)    
        MoveCamera(0,  0, 0, -1 * Boost)
      ElseIf KeyboardPushed(#PB_Key_Down)
        MoveCamera(0,  0, 0,  1 * Boost)
      EndIf 
      
      If KeyboardPushed(#PB_Key_Left)  
        MoveCamera(0, -1 * Boost, 0, 0) 
      ElseIf KeyboardPushed(#PB_Key_Right)
        MoveCamera(0,  1 * Boost, 0, 0)
      EndIf 
      
    EndIf
    
    RotateCamera(0, Pitch, Yaw, 0, #PB_Relative)
    
    RenderWorld()
    FlipBuffers()
  Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End

Re: Problem with EntityYaw() (and -Roll(), -Pitch())

Posted: Sat Sep 13, 2014 10:03 am
by Comtois
not a bug.
The problem is that there are multiple combinations of pitch/yaw/roll which result in the same quaternion.
When you try to convert a quaternion to euler, the algorithm has no way of knowing which combination of values you wanted from the many valid possibilities.

For example, think of a spaceship facing forwards. Now pitch the ship 180 degrees. It is now upside down facing backwards.
Now think of a second spaceship facing forwards. Don't pitch it, instead yaw it 180 degrees and roll it 90 degrees. It's now upside down facing backwards.
Two different combinations of euler angles, with the same end result. Both would generate the quaternion <0,1,0,0> (off the top of my very tired head).
The quaternion doesn't care how the spaceship got to being upside down and backwards, it just knows that's how it's facing, and that's all it stores.
When converting back to euler from the quaternion, which result should it tell you: P=180,Y=0,R=0 or P=0,Y=180,R=90?

The moral of the story is: going from a quaternion to a euler combination will always give a correct result, but maybe not the one you wanted. If you want consistant eulers, you need to store them as eulers.
Entity 1 & 3 dont have same pitch/roll

Code: Select all

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>                             >>
;>>  Name: Staticgeometryversuch>>
;>>                             >>
;>>  Author: (c) Bananenfreak  >>
;>>                             >>
;>>  Date: 12.09.2014           >>
;>>                             >>
;>>  OS: Windows                >>
;>>                             >>
;>>         >>
;>>                             >>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
EnableExplicit


Define.f KeyX, KeyY, MouseX, MouseY
Define nx.f, nz.f, Boost.f = 1, Yaw.f, Pitch.f
Define.i Quit, boden, cube, cubeEnt0, cubeEnt1, cubeEnt2
#kam_0 = 0
#window = 0
#plane = 0
#planent = 0

If InitEngine3D()
  
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  OpenWindow(#window, 0, 0, 1800, 1000, "3D-Template", #PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(#window), 10, 10, 2000, 2000, 0, 10, 10, #PB_Screen_SmartSynchronization)
  
  WorldShadows(#PB_Shadow_TextureAdditive, 200, RGB(255 * 0.2, 255 * 0.2, 255 * 0.2), 4096)
  
  AmbientColor(RGB(255 * 0.2, 255 * 0.2, 255 * 0.2))
  
  CreatePlane(#plane, 100, 100, 100, 100, 100, 100)
  boden = GetScriptMaterial(#PB_Any, "Scene/GroundBlend")
  CreateEntity(#planent, MeshID(#plane), MaterialID(boden), 0, 0, 0)
  
  cube = CreateCube(#PB_Any, 2.0)
  cubeEnt0 = CreateEntity(#PB_Any, MeshID(cube), #PB_Material_None, 0, 1, 0)
  RotateEntity(cubeEnt0, 0, 60, 0, #PB_Relative)
  cubeEnt1 = CreateEntity(#PB_Any, MeshID(cube), #PB_Material_None, 5, 1, 0)
  RotateEntity(cubeEnt1, 0, 90, 0, #PB_Relative)
  cubeEnt2 = CreateEntity(#PB_Any, MeshID(cube), #PB_Material_None, 10, 1, 0)
  RotateEntity(cubeEnt2, 0, 120, 0, #PB_Relative)
  
  Debug "Cube1, Pitch Adjusted: " + EntityPitch(cubeEnt0, #PB_Engine3D_Adjusted)
  Debug "Cube2, Pitch Adjusted: " + EntityPitch(cubeEnt1, #PB_Engine3D_Adjusted)
  Debug "Cube3, Pitch Adjusted: " + EntityPitch(cubeEnt2, #PB_Engine3D_Adjusted)
  Debug "Cube1, Yaw Adjusted: " + EntityYaw(cubeEnt0, #PB_Engine3D_Adjusted)
  Debug "Cube2, Yaw Adjusted: " + EntityYaw(cubeEnt1, #PB_Engine3D_Adjusted)
  Debug "Cube3, Yaw Adjusted: " + EntityYaw(cubeEnt2, #PB_Engine3D_Adjusted)
  Debug "Cube1, Roll Adjusted: " + EntityRoll(cubeEnt0, #PB_Engine3D_Adjusted)
  Debug "Cube2, Roll Adjusted: " + EntityRoll(cubeEnt1, #PB_Engine3D_Adjusted)
  Debug "Cube3, Roll Adjusted: " + EntityRoll(cubeEnt2, #PB_Engine3D_Adjusted)
  
  ;-Camera
  CreateCamera(#kam_0, 0, 0, 100, 100)
  MoveCamera(#kam_0, 0, 20, 0, #PB_Absolute)
  CameraLookAt(#kam_0, 20, 0, 20)
  CameraRange (#kam_0, 2, 5000)
  CameraFOV   (#kam_0, 90)
  CameraBackColor(#kam_0, RGB(0, 0, 0))
  
  Repeat
    Repeat
    Until WindowEvent() = 0
    
    If ExamineMouse()
      Yaw   = -MouseDeltaX() * 0.05
      Pitch = -MouseDeltaY() * 0.05
    EndIf
    
    If ExamineKeyboard()
      
      If KeyboardPushed(#PB_Key_Up)   
        MoveCamera(0,  0, 0, -1 * Boost)
      ElseIf KeyboardPushed(#PB_Key_Down)
        MoveCamera(0,  0, 0,  1 * Boost)
      EndIf
      
      If KeyboardPushed(#PB_Key_Left) 
        MoveCamera(0, -1 * Boost, 0, 0)
      ElseIf KeyboardPushed(#PB_Key_Right)
        MoveCamera(0,  1 * Boost, 0, 0)
      EndIf
      
    EndIf
    
    RotateCamera(0, Pitch, Yaw, 0, #PB_Relative)
    
    RenderWorld()
    FlipBuffers()
  Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End

Re: Problem with EntityYaw() (and -Roll(), -Pitch())

Posted: Sat Sep 13, 2014 11:33 am
by Bananenfreak
Ah, thank you comtois for the Explanation.
So, I have to search for the bug somewhere else in my Project ^^

Here I found something... I think this is my problem:
What am I doing wrong? Why the first staticgeometry-cube gets a wrong direction?!

Code: Select all

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>                             >>
;>>  Name: Entityangle() 2.     >>
;>>                             >>
;>>  Author: (c) Bananenfreak   >>
;>>                             >>
;>>  Date: 12.09.2014           >>
;>>                             >>
;>>  OS: Windows                >>
;>>                             >>
;>>                             >>
;>>                             >>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
EnableExplicit


Define.f KeyX, KeyY, MouseX, MouseY
Define nx.f, nz.f, Boost.f = 1, Yaw.f, Pitch.f
Define.i Quit, boden, cube, cubeEnt, statik, ent2
#kam_0 = 0
#window = 0
#plane = 0
#planent = 0

If InitEngine3D()
  
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  OpenWindow(#window, 0, 0, 1800, 1000, "3D-Angle-2", #PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(#window), 10, 10, 2000, 2000, 0, 10, 10, #PB_Screen_SmartSynchronization)
  
  WorldShadows(#PB_Shadow_TextureAdditive, 200, RGB(255 * 0.2, 255 * 0.2, 255 * 0.2), 4096)
  
  AmbientColor(RGB(255 * 0.2, 255 * 0.2, 255 * 0.2))
  
  CreatePlane(#plane, 100, 100, 100, 100, 100, 100)
  boden = GetScriptMaterial(#PB_Any, "Scene/GroundBlend")
  CreateEntity(#planent, MeshID(#plane), MaterialID(boden), 0, 0, 0)
  
  cube = CreateCube(#PB_Any, 2.0)
  cubeEnt = CreateEntity(#PB_Any, MeshID(cube), #PB_Material_None, 0, 1, 0)
  RotateEntity(cubeEnt, 0, -120, 0, #PB_Relative)
  
  statik = CreateStaticGeometry(#PB_Any, 1000, 1000, 1000, #True)
  AddStaticGeometryEntity(statik, EntityID(cubeEnt), 5, 1, 0, 1, 1, 1, EntityPitch(cubeEnt, #PB_Engine3D_Adjusted), EntityYaw(cubeEnt, #PB_Engine3D_Adjusted), EntityRoll(cubeEnt, #PB_Engine3D_Adjusted))
  AddStaticGeometryEntity(statik, EntityID(cubeEnt), 5, 1, 5, 1, 1, 1, 0, -120, 0)
  AddStaticGeometryEntity(statik, EntityID(cubeEnt), 5, 1, 10, 1, 1, 1, EntityPitch(cubeEnt, #PB_Engine3D_Raw), EntityYaw(cubeEnt, #PB_Engine3D_Raw), EntityRoll(cubeEnt, #PB_Engine3D_Raw))
  BuildStaticGeometry(statik)
  
  ent2 = CreateEntity(#PB_Any, MeshID(cube), MaterialID(boden), 10, 1, 0)
  RotateEntity(ent2, EntityPitch(cubeEnt, #PB_Engine3D_Adjusted), EntityYaw(cubeEnt, #PB_Engine3D_Adjusted), EntityRoll(cubeEnt, #PB_Engine3D_Adjusted))
  
  Debug "Cube1, Pitch Adjusted: " + EntityPitch(cubeEnt, #PB_Engine3D_Adjusted)
  Debug "Cube2, Pitch raw: " + EntityPitch(cubeEnt, #PB_Engine3D_Raw)
  Debug "Cube1, Yaw Adjusted: " + EntityYaw(cubeEnt, #PB_Engine3D_Adjusted)
  Debug "Cube2, Yaw raw: " + EntityYaw(cubeEnt, #PB_Engine3D_Raw)
  Debug "Cube1, Roll Adjusted: " + EntityRoll(cubeEnt, #PB_Engine3D_Adjusted)
  Debug "Cube2, Roll raw: " + EntityRoll(cubeEnt, #PB_Engine3D_Raw)
  
  ;-Camera
  CreateCamera(#kam_0, 0, 0, 100, 100)
  MoveCamera(#kam_0, 0, 20, 0, #PB_Absolute)
  CameraLookAt(#kam_0, 20, 0, 20)
  CameraRange (#kam_0, 2, 5000)
  CameraFOV   (#kam_0, 90)
  CameraBackColor(#kam_0, RGB(0, 0, 0))
  
  Repeat
    Repeat
    Until WindowEvent() = 0
    
    If ExamineMouse()
      Yaw   = -MouseDeltaX() * 0.05
      Pitch = -MouseDeltaY() * 0.05
    EndIf
    
    If ExamineKeyboard()
      
      If KeyboardPushed(#PB_Key_Up)    
        MoveCamera(0,  0, 0, -1 * Boost)
      ElseIf KeyboardPushed(#PB_Key_Down)
        MoveCamera(0,  0, 0,  1 * Boost)
      EndIf 
      
      If KeyboardPushed(#PB_Key_Left)  
        MoveCamera(0, -1 * Boost, 0, 0) 
      ElseIf KeyboardPushed(#PB_Key_Right)
        MoveCamera(0,  1 * Boost, 0, 0)
      EndIf 
      
    EndIf
    
    RotateCamera(0, Pitch, Yaw, 0, #PB_Relative)
    
    RenderWorld()
    FlipBuffers()
  Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End

Re: Problem with EntityYaw() (and -Roll(), -Pitch())

Posted: Sun Sep 14, 2014 10:30 am
by Bananenfreak
Hey,

I localized the Problem to z-angle in Staticgeometry.
Whenever you try to rotate an entityentry in a staticgeometry across z-axis, it rotates the "entity" by the same value, but negative...

Code: Select all

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>                             >>
;>>  Name: Entityangle() 2.     >>
;>>                             >>
;>>  Author: (c) Bananenfreak   >>
;>>                             >>
;>>  Date: 12.09.2014           >>
;>>                             >>
;>>  OS: Windows                >>
;>>                             >>
;>>                             >>
;>>                             >>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
EnableExplicit


Define.f KeyX, KeyY, MouseX, MouseY
Define nx.f, nz.f, Boost.f = 1, Yaw.f, Pitch.f
Define.i Quit, boden, cube, ent1, statik, ent2, ent3
#kam_0 = 0
#window = 0
#plane = 0
#planent = 0

If InitEngine3D()
  
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  OpenWindow(#window, 0, 0, 1800, 1000, "3D-Angle-2", #PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(#window), 10, 10, 2000, 2000, 0, 10, 10, #PB_Screen_SmartSynchronization)
  
  WorldShadows(#PB_Shadow_TextureAdditive, 200, RGB(255 * 0.2, 255 * 0.2, 255 * 0.2), 4096)
  
  AmbientColor(RGB(255 * 0.2, 255 * 0.2, 255 * 0.2))
  
  CreatePlane(#plane, 100, 100, 100, 100, 100, 100)
  boden = GetScriptMaterial(#PB_Any, "Scene/GroundBlend")
  CreateEntity(#planent, MeshID(#plane), MaterialID(boden), 0, 0, 0)
  
  cube = CreateCube(#PB_Any, 2.0)
  Ent1 = CreateEntity(#PB_Any, MeshID(cube), #PB_Material_None, 0, 1, 0)
  RotateEntity(Ent1, -120, 0, 0, #PB_Relative)
  ent2 = CreateEntity(#PB_Any, MeshID(cube), #PB_Material_None, 0, 1, 5)
  RotateEntity(ent2, 0, -120, 0, #PB_Relative)
  ent3 = CreateEntity(#PB_Any, MeshID(cube), #PB_Material_None, 0, 1, 10)
  RotateEntity(ent3, 0, 0, -120, #PB_Relative)
  SetEntityMaterial(ent3, MaterialID(boden))
  
  statik = CreateStaticGeometry(#PB_Any, 1000, 1000, 1000, #True)
  AddStaticGeometryEntity(statik, EntityID(Ent1), 5, 1, 0, 1, 1, 1, -120, 0, 0)
  AddStaticGeometryEntity(statik, EntityID(ent2), 5, 1, 5, 1, 1, 1, 0, -120, 0)
  AddStaticGeometryEntity(statik, EntityID(ent3), 5, 1, 10, 1, 1, 1, 0, 0, -120)
  BuildStaticGeometry(statik)
  
  
;   Debug "Cube1, Pitch Adjusted: " + EntityPitch(cubeEnt, #PB_Engine3D_Adjusted)
;   Debug "Cube2, Pitch raw: " + EntityPitch(cubeEnt, #PB_Engine3D_Raw)
;   Debug "Cube1, Yaw Adjusted: " + EntityYaw(cubeEnt, #PB_Engine3D_Adjusted)
;   Debug "Cube2, Yaw raw: " + EntityYaw(cubeEnt, #PB_Engine3D_Raw)
;   Debug "Cube1, Roll Adjusted: " + EntityRoll(cubeEnt, #PB_Engine3D_Adjusted)
;   Debug "Cube2, Roll raw: " + EntityRoll(cubeEnt, #PB_Engine3D_Raw)
  
  ;-Camera
  CreateCamera(#kam_0, 0, 0, 100, 100)
  MoveCamera(#kam_0, 0, 20, 0, #PB_Absolute)
  CameraLookAt(#kam_0, 20, 0, 20)
  CameraRange (#kam_0, 2, 5000)
  CameraFOV   (#kam_0, 90)
  CameraBackColor(#kam_0, RGB(0, 0, 0))
  
  Repeat
    Repeat
    Until WindowEvent() = 0
    
    If ExamineMouse()
      Yaw   = -MouseDeltaX() * 0.05
      Pitch = -MouseDeltaY() * 0.05
    EndIf
    
    If ExamineKeyboard()
      
      If KeyboardPushed(#PB_Key_Up)    
        MoveCamera(0,  0, 0, -1 * Boost)
      ElseIf KeyboardPushed(#PB_Key_Down)
        MoveCamera(0,  0, 0,  1 * Boost)
      EndIf 
      
      If KeyboardPushed(#PB_Key_Left)  
        MoveCamera(0, -1 * Boost, 0, 0) 
      ElseIf KeyboardPushed(#PB_Key_Right)
        MoveCamera(0,  1 * Boost, 0, 0)
      EndIf 
      
    EndIf
    
    RotateCamera(0, Pitch, Yaw, 0, #PB_Relative)
    
    RenderWorld()
    FlipBuffers()
  Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End