It is currently Wed Oct 28, 2020 6:54 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: ConvertLocalToWorldPosition and ConvertWorldToLocalPosition
PostPosted: Fri Aug 14, 2020 4:05 pm 
Offline
User
User

Joined: Mon Nov 03, 2003 5:34 am
Posts: 32
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: ConvertLocalToWorldPosition and ConvertWorldToLocalPosit
PostPosted: Sun Oct 04, 2020 9:30 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4637
Location: Spa, relaxing and thinking, and learning...
Confirmed!
windows 8.1, PB5.72 (x64)

_________________
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend


Top
 Profile  
Reply with quote  
 Post subject: Re: ConvertLocalToWorldPosition and ConvertWorldToLocalPosit
PostPosted: Mon Oct 05, 2020 1:41 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 10:06 am
Posts: 871
Location: Denmark
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:
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

_________________
“Tell me and I forget. Teach me and I remember. Involve me and I learn.”
— Benjamin Franklin
Current configurations: Windows 10, Intel 6800K, GeForce Gtx 1060, 32 gb ram.


Last edited by DK_PETER on Tue Oct 06, 2020 12:06 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: ConvertLocalToWorldPosition and ConvertWorldToLocalPosit
PostPosted: Mon Oct 05, 2020 3:06 pm 
Offline
User
User

Joined: Mon Nov 03, 2003 5:34 am
Posts: 32
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: ConvertLocalToWorldPosition and ConvertWorldToLocalPosit
PostPosted: Mon Oct 05, 2020 6:19 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3754
Location: Utah, USA
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:
  If KeyboardReleased(#PB_Key_6)
    Test(6) ;Test(5)
  EndIf
  If KeyboardReleased(#PB_Key_7)
    Test(7) ;Test(5)
  EndIf

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: ConvertLocalToWorldPosition and ConvertWorldToLocalPosit
PostPosted: Tue Oct 06, 2020 12:12 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 10:06 am
Posts: 871
Location: Denmark
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:
  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.

_________________
“Tell me and I forget. Teach me and I remember. Involve me and I learn.”
— Benjamin Franklin
Current configurations: Windows 10, Intel 6800K, GeForce Gtx 1060, 32 gb ram.


Top
 Profile  
Reply with quote  
 Post subject: Re: ConvertLocalToWorldPosition and ConvertWorldToLocalPosit
PostPosted: Tue Oct 06, 2020 9:36 am 
Offline
Addict
Addict
User avatar

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4637
Location: Spa, relaxing and thinking, and learning...
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


Top
 Profile  
Reply with quote  
 Post subject: Re: ConvertLocalToWorldPosition and ConvertWorldToLocalPosit
PostPosted: Thu Oct 08, 2020 4:16 am 
Offline
User
User

Joined: Mon Nov 03, 2003 5:34 am
Posts: 32
Quote:
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: ConvertLocalToWorldPosition and ConvertWorldToLocalPosit
PostPosted: Tue Oct 13, 2020 8:39 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 19, 2003 11:36 am
Posts: 1419
Location: Doubs - France
Fixed for Node.
Camera, mesh and particle should be removed in doc. Use Node instead

_________________
Please correct my english
http://purebasic.developpez.com/


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye