ConvertLocalToWorldPosition and ConvertWorldToLocalPosition

All bugs related to the 3D engine
Axeman
User
User
Posts: 89
Joined: Mon Nov 03, 2003 5:34 am

ConvertLocalToWorldPosition and ConvertWorldToLocalPosition

Post by Axeman »

I was going to title this "ConvertLocalToWorldPosition and ConvertWorldToLocalPosition don't seem to work with nodes" but that dumbarse character limit prevented me from writing a properly descriptive title. I'm fairly sure that I've customized phpBB to use longer titles in the past. A bit of basic research should show how to do it.

Both of these commands are throwing "Invalid memory access" errors for me when used with nodes. I've included some cut-down example code below.

This is on Windows 7 64 bit using PureBasic 5.72 (Windows - x86). EDIT: Also occurs with Windows 10 64 bit using PureBasic 5.72 (Windows - x86).

Code: Select all

InitEngine3D()
InitSprite()

#MAIN_WINDOW = 0

#PLAYER_NODE = 0

OpenWindow( #MAIN_WINDOW, 0, 0, 500, 500, "Test", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_Maximize )
OpenWindowedScreen( WindowID( #MAIN_WINDOW ), 0, 0, 500, 500, #True, 0, 0 )

CreateNode( #PLAYER_NODE )
RotateNode( #PLAYER_NODE, 45.0, 45.0, 45.0 )

ConvertLocalToWorldPosition( NodeID( #PLAYER_NODE ), 100.0, 100.0, 100.0 )
;ConvertWorldToLocalPosition( NodeID( #PLAYER_NODE ), 100.0, 100.0, 100.0 )

Debug GetX()
Debug GetY()
Debug GetZ()

End
User avatar
Psychophanta
Addict
Addict
Posts: 4996
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

Re: ConvertLocalToWorldPosition and ConvertWorldToLocalPosit

Post by Psychophanta »

Confirmed!
windows 8.1, PB5.72 (x64)
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: ConvertLocalToWorldPosition and ConvertWorldToLocalPosit

Post by DK_PETER »

Imho, I'm not so sure it's a bug. It's more an error in the documentation about ConvertLocalToWorldPosition() and its counterpart.
I believe that the functions are valid for 'physical objects in 3D space' only.
They don't work for Cameras, Nodes and mesh.
However...The errors thrown, when using invalid objects should be catched..

Code: Select all

EnableExplicit

InitEngine3D()
InitSprite()
InitKeyboard()

Global ret.i, ev.i

Declare.i Test(Index)

OpenWindow(0, 0, 0, 1024, 768, "Test", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768)
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 0, 2)
CreateLight(0, $FFFFFF, -10, -4, 0)
CreateCube(0, 0.1)
CreateTexture(0, 128, 128,"Cube")
StartDrawing(TextureOutput(0))
Box(0, 0, 128, 128, $26F522)
Box(5, 5, 118, 118, $0)
StopDrawing()
CreateMaterial(0, TextureID(0))
MaterialBlendingMode(0, #PB_Material_Add)
MaterialFilteringMode(0, #PB_Material_Anisotropic, 6)
CreateEntity(0, MeshID(0), MaterialID(0), 0, 0, 0)
CopyEntity(0, 1)
ScaleEntity(1, 0.5, 0.5, 0.5)
CreateNode(0, 0, 0, 0)
CreateNode(1, 1, 0, 0)
AttachNodeObject(0, NodeID(1))

CreateParticleEmitter(0, 5, 5, 5, #PB_Particle_Box, 0, 0, -5)
ParticleEmitterDirection(0, 0, 0, 1)
ParticleMaterial(0, MaterialID(0))
ParticleSize(0, 0.05, 0.05)
ParticleEmissionRate(0, 100)
ParticleVelocity(0, #PB_Particle_MinimumVelocity, 0.1)
ParticleVelocity(0, #PB_Particle_Velocity, 0.4)
ParticleVelocity(0, #PB_Particle_MaximumVelocity, 1)

CreateBillboardGroup(0, MaterialID(0), 1, 1, 0, 0, 0)
AddBillboard(0, -1, 1, -2)
AddBillboard(0, 1, 1, -2)
AddBillboard(0, 1, -1, -2)
AddBillboard(0, -1, -1, -2)



Repeat
  
  Repeat : ev = WindowEvent() : Until ev = 0
  
  RotateEntity(0, 0.1, -0.1, 0.1, #PB_Relative)
  RotateEntity(1, -0.1, 0.1, -0.1, #PB_Relative)
  RotateBillboardGroup(0, 0, 0, 0.03, #PB_Relative)
  
  RenderWorld()
  
  FlipBuffers()
 
  ExamineKeyboard()
  If KeyboardReleased(#PB_Key_1)
    Test(1)
  EndIf 
  If KeyboardReleased(#PB_Key_2)
    Test(2)
  EndIf 
  If KeyboardReleased(#PB_Key_3)
    Test(3)
  EndIf 
  If KeyboardReleased(#PB_Key_4)
    Test(4)
  EndIf 
  If KeyboardReleased(#PB_Key_5)
    Test(5)
  EndIf 
  If KeyboardReleased(#PB_Key_6)
    Test(6)
  EndIf 
  If KeyboardReleased(#PB_Key_7)
    Test(7)
  EndIf 
  
Until KeyboardPushed(#PB_Key_Escape)


Procedure.i Test(Index)
  Select Index
    Case 1
      Debug "Entity"
      ConvertLocalToWorldPosition(EntityID(0), 0, 0, 0) ; Works
      Debug GetX()
      Debug GetY()
      Debug GetZ()
    Case 2
      Debug "Mesh"
      ConvertLocalToWorldPosition(MeshID(0), 0, 0, 0) ; Fails
      Debug GetX()
      Debug GetY()
      Debug GetZ()
    Case 3
      Debug "BillBoard"
      ConvertLocalToWorldPosition(BillboardGroupID(0), 0, 0, 0) ; Works
      Debug GetX()
      Debug GetY()
      Debug GetZ()
    Case 4
      Debug "Camera"
      ConvertLocalToWorldPosition(CameraID(0), 0, 0, 0) ; Fails
      Debug GetX()
      Debug GetY()
      Debug GetZ()
    Case 5
      Debug "Light"
      ConvertLocalToWorldPosition(LightID(0), 0, 0, 0) ; Works
      Debug GetX()
      Debug GetY()
      Debug GetZ()
    Case 6
      Debug "Node"
      ConvertLocalToWorldPosition(NodeID(0), 0, 0, 0) ; Fails
      Debug GetX()
      Debug GetY()
      Debug GetZ()
    Case 7
      Debug "Particle"
      ConvertLocalToWorldPosition(ParticleEmitterID(0), 0, 0, 0) ; Fails
      Debug GetX()
      Debug GetY()
      Debug GetZ()
  EndSelect
  ProcedureReturn #True
EndProcedure
Last edited by DK_PETER on Tue Oct 06, 2020 12:06 am, edited 1 time in total.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Axeman
User
User
Posts: 89
Joined: Mon Nov 03, 2003 5:34 am

Re: ConvertLocalToWorldPosition and ConvertWorldToLocalPosit

Post by Axeman »

Nodes are listed as a valid ObjectID for both these commands. They need to work for anything that has a 3D position within the engine, and scene-graph nodes are the main thing that they will normally be used with.

Case in point, I needed these commands for a gimbal-based mouselook system involving a camera attached to a node that acts as the body of a character. The commands are used to ensure that the node the camera is attached to moves the same distance irregardless of which direction it is facing (otherwise it will move faster in diagonal directions). You can't really use anything other than a scene-graph node for this type of setup.
User avatar
Demivec
Addict
Addict
Posts: 4091
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: ConvertLocalToWorldPosition and ConvertWorldToLocalPosit

Post by Demivec »

DK_PETER wrote:Imho, I'm not so sure it's a bug. It's more an error in the documentation about ConvertLocalToWorldPosition() and its counterpart.
I believe that the functions are valid for 'physical objects in 3D space' only.
They don't work for Cameras, Nodes and mesh.
It also doesn't work for Particles. Your code example had some typos that didn't correctly test for those.

Corrected code segment

Code: Select all

  If KeyboardReleased(#PB_Key_6)
    Test(6) ;Test(5)
  EndIf 
  If KeyboardReleased(#PB_Key_7)
    Test(7) ;Test(5)
  EndIf 
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: ConvertLocalToWorldPosition and ConvertWorldToLocalPosit

Post by DK_PETER »

Demivec wrote:
DK_PETER wrote:Imho, I'm not so sure it's a bug. It's more an error in the documentation about ConvertLocalToWorldPosition() and its counterpart.
I believe that the functions are valid for 'physical objects in 3D space' only.
They don't work for Cameras, Nodes and mesh.
It also doesn't work for Particles. Your code example had some typos that didn't correctly test for those.

Corrected code segment

Code: Select all

  If KeyboardReleased(#PB_Key_6)
    Test(6) ;Test(5)
  EndIf 
  If KeyboardReleased(#PB_Key_7)
    Test(7) ;Test(5)
  EndIf 
Thanks Demivec. Please bare with me..I've been up for more than 32 hours. :-)
Code is fixed and yes - it doesn't work with Particles either.

@Axeman
Okay. I know what the docs says. If you say it should work, then it's all good.
I wouldn't mind at all, if they all worked. ;-)
Time to sleep.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
Psychophanta
Addict
Addict
Posts: 4996
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

Re: ConvertLocalToWorldPosition and ConvertWorldToLocalPosit

Post by Psychophanta »

Well @Axeman, may be you are right. So, in that case, you are agree that the doc should be fixed. :)
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
Axeman
User
User
Posts: 89
Joined: Mon Nov 03, 2003 5:34 am

Re: ConvertLocalToWorldPosition and ConvertWorldToLocalPosit

Post by Axeman »

Well @Axeman, may be you are right. So, in that case, you are agree that the doc should be fixed.
The docs are fine. It's the command that's faulty.
User avatar
Comtois
Addict
Addict
Posts: 1429
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: ConvertLocalToWorldPosition and ConvertWorldToLocalPosit

Post by Comtois »

Fixed for Node.
Camera, mesh and particle should be removed in doc. Use Node instead
Please correct my english
http://purebasic.developpez.com/
Post Reply