I think I know what Psychophanta is talking about.
The object should attach itself at the current location - no matter the rotation performed of the node.
As it is you must recalculate the position to attach an object at a specific location - regardless of the node rotation or reset the node before attaching it.
Wrong behaviour:
Code: Select all
InitEngine3D()
InitSprite()
InitKeyboard()
Structure Object
id.i
ma.i
ms.i
tx.i
EndStructure
Global o.Object, node.i, no.Object, ret.i, ev.i, Attached.i = #False, Quit.i = #False
Declare.i CreateObjects()
OpenWindow(0, 0, 0, 1024, 768, "Node detach/attach", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768)
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 0, 5)
ret = CreateObjects()
Repeat
Repeat : ev = WindowEvent() : If ev = #PB_Event3D_CloseWindow : Quit = #True : EndIf : Until ev = 0
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
RotateNode(node, 0, 0, 0.2, #PB_Relative)
ElseIf KeyboardPushed(#PB_Key_Right)
RotateNode(node, 0, 0, -0.2, #PB_Relative)
EndIf
If KeyboardReleased(#PB_Key_A)
If Attached = #False
AttachNodeObject(node, EntityID(o\id))
Attached = #True
EndIf
ElseIf KeyboardReleased(#PB_Key_D)
If Attached = #True
DetachNodeObject(node, EntityID(o\id))
Attached = #False
EndIf
EndIf
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = #True
Procedure.i CreateObjects()
node = CreateNode(#PB_Any, 0, 0, 0)
no\ms = CreateCube(#PB_Any, 0.3)
no\tx = CreateTexture(#PB_Any, 100, 100, "GradBox")
StartDrawing(TextureOutput(no\tx))
DrawingMode(#PB_2DDrawing_Gradient)
FrontColor($00FF31) : BackColor($00B431)
LinearGradient(50, 0, 50, 50)
Box(0, 0, 100, 50)
LinearGradient(50, 100, 50, 50)
Box(0, 50, 100, 50)
StopDrawing()
no\ma = CreateMaterial(#PB_Any, TextureID(no\tx))
MaterialBlendingMode(no\ma, #PB_Material_Color)
no\id = CreateEntity(#PB_Any, MeshID(no\ms), MaterialID(no\ma))
AttachNodeObject(node, EntityID(no\id))
o\ms = CreateCone(#PB_Any, 0.3, 0.2, 16, 16)
o\tx = CreateTexture(#PB_Any, 10, 10)
StartDrawing(TextureOutput(o\tx))
Box(0, 0, 10, 10, $00FFFF)
StopDrawing()
o\ma = CreateMaterial(#PB_Any, TextureID(o\tx))
MaterialBlendingMode(o\ma, #PB_Material_Add)
o\id = CreateEntity(#PB_Any, MeshID(o\ms), MaterialID(o\ma), -1, 0, 0)
EndProcedure
EDIT: Same wrong behaviour goes for AttachEntityObject()/DetachEntityObject()
The object should simply attach itself at current angle and position - regardless of parent rotation/position.
Code: Select all
InitEngine3D()
InitSprite()
InitKeyboard()
Structure Object
id.i
ma.i
ms.i
tx.i
EndStructure
Global o.Object, node.i, no.Object, ret.i, ev.i, Attached.i = #False, Quit.i = #False
Declare.i CreateObjects()
OpenWindow(0, 0, 0, 1024, 768, "Node detach/attach", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768)
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 0, 5)
ret = CreateObjects()
Repeat
Repeat : ev = WindowEvent() : If ev = #PB_Event3D_CloseWindow : Quit = #True : EndIf : Until ev = 0
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
RotateNode(node, 0, 0, 0.2, #PB_Relative)
ElseIf KeyboardPushed(#PB_Key_Right)
RotateNode(node, 0, 0, -0.2, #PB_Relative)
EndIf
If KeyboardReleased(#PB_Key_A)
If Attached = #False
;AttachNodeObject(node, EntityID(o\id))
AttachEntityObject(no\id, "", EntityID(o\id))
Attached = #True
EndIf
ElseIf KeyboardReleased(#PB_Key_D)
If Attached = #True
;DetachNodeObject(node, EntityID(o\id))
DetachEntityObject(no\id, EntityID(o\id))
Attached = #False
EndIf
EndIf
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = #True
Procedure.i CreateObjects()
node = CreateNode(#PB_Any, 0, 0, 0)
no\ms = CreateCube(#PB_Any, 0.3)
no\tx = CreateTexture(#PB_Any, 100, 100, "GradBox")
StartDrawing(TextureOutput(no\tx))
DrawingMode(#PB_2DDrawing_Gradient)
FrontColor($00FF31) : BackColor($00B431)
LinearGradient(50, 0, 50, 50)
Box(0, 0, 100, 50)
LinearGradient(50, 100, 50, 50)
Box(0, 50, 100, 50)
StopDrawing()
no\ma = CreateMaterial(#PB_Any, TextureID(no\tx))
MaterialBlendingMode(no\ma, #PB_Material_Color)
no\id = CreateEntity(#PB_Any, MeshID(no\ms), MaterialID(no\ma))
AttachNodeObject(node, EntityID(no\id))
o\ms = CreateCone(#PB_Any, 0.3, 0.2, 16, 16)
o\tx = CreateTexture(#PB_Any, 10, 10)
StartDrawing(TextureOutput(o\tx))
Box(0, 0, 10, 10, $00FFFF)
StopDrawing()
o\ma = CreateMaterial(#PB_Any, TextureID(o\tx))
MaterialBlendingMode(o\ma, #PB_Material_Add)
o\id = CreateEntity(#PB_Any, MeshID(o\ms), MaterialID(o\ma), -1, 0, 0)
EndProcedure