Page 1 of 1

Should 'Attach' like commands move the attached object?

Posted: Thu Mar 14, 2024 4:23 pm
by Psychophanta

Code: Select all

InitEngine3D(#PB_Engine3D_NoLog,#PB_Compiler_Home+"Compilers\Engine3d.dll")
InitSprite():InitKeyboard():InitMouse()
OpenWindow(0,0,0,800,600,"tip",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,800,600,0,0,0,#PB_Screen_WaitSynchronization)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
CreateLight(0,$EEEEEE,4,4,2,#PB_Light_Point)
CreateCamera(0,0,0,100,100):CameraProjectionMode(0,#PB_Camera_Perspective)
MoveCamera(0,0,0,3,#PB_Absolute)
CreateMaterial(0,LoadTexture(0,"soil_wall.jpg"))

CreateCube(0,0.3)
CreateEntity(0,MeshID(0),MaterialID(0),-0.5,0,0)
CreateSphere(1,0.2,5,5)
CreateEntity(1,MeshID(1),MaterialID(0),0.5,0,0)
CreateNode(0,-0.5,0,0)
Repeat
  While WindowEvent():Wend
  ExamineKeyboard()
  If KeyboardReleased(#PB_Key_1)
    If AttachedtoNode.b
      DetachNodeObject(0,EntityID(1))
      AttachedtoNode.b=0
    Else
      AttachNodeObject(0,EntityID(1)); <- should this command move the entity number 1 ???
      AttachedtoNode.b=1
    EndIf
  ElseIf KeyboardReleased(#PB_Key_2)
    If AttachedtoObject.b
      DetachEntityObject(0,EntityID(1))
      AttachedtoObject.b=0
    Else
      AttachEntityObject(0,"",EntityID(1)); <- should this command move the entity number 1 ???
      AttachedtoObject.b=1
    EndIf
  EndIf
  RenderWorld()
  FlipBuffers() 
Until KeyboardPushed(#PB_Key_Escape)

Re: Should 'Attach' like commands move the attached object?

Posted: Sat Mar 16, 2024 3:46 pm
by minimy
I think that the coordinates become relative to the parent object.
That's what I've deduced after doing some testing.
(because the manual is a bit gibberish)

Re: Should 'Attach' like commands move the attached object?

Posted: Sat Mar 16, 2024 3:59 pm
by minimy
With this you can see the two diferent coordinates based in relative and absolute. Is a start point.

If KeyboardReleased(#PB_Key_1)
If AttachedtoNode.b
DetachNodeObject(0,EntityID(1))
AttachedtoNode.b=0
Debug EntityX(1,#PB_Absolute)
Debug EntityX(1,#PB_Relative)
Else
AttachNodeObject(0,EntityID(1)); <- should this command move the entity number 1 ???
AttachedtoNode.b=1
Debug EntityX(1,#PB_Absolute)
Debug EntityX(1,#PB_Relative)
EndIf

Re: Should 'Attach' like commands move the attached object?

Posted: Sat Mar 16, 2024 6:41 pm
by Psychophanta
minimy wrote: Sat Mar 16, 2024 3:46 pm I think that the coordinates become relative to the parent object.
That is a fact.
The matter is that 'Attach' commands should get the current position and inclination of the attached object, and then make it attached without changing anything from it, whatever it be the orientation and position of both objects; the attached one , and the pivot.

Re: Should 'Attach' like commands move the attached object?

Posted: Sat Mar 16, 2024 9:16 pm
by DarkDragon
Often there are multiple modes to attach an object in an engine for putting it underneath some other object in the scene graph. Changing the coordinates has the same right to exist than not changing the coordinates.

E.g. putting an object into somebody's hand is changing coordinates. A person walking into a moving elevator is not changing coordinates.

It all depends on the situation.

Re: Should 'Attach' like commands move the attached object?

Posted: Sun Mar 17, 2024 5:08 pm
by Psychophanta
Darkdragon, that is a good answer. And that is because i posted the title with a :?:
My previous post was just my current opinion at that time, but opinions are subjects of change :D :)

Re: Should 'Attach' like commands move the attached object?

Posted: Mon Mar 18, 2024 2:38 pm
by minimy
Hello psychophanta. The only solution I can think of (the one I use) is to use a procedure or macro to control the relative and global position of each object before and after connecting to a node

Re: Should 'Attach' like commands move the attached object?

Posted: Mon Mar 18, 2024 6:24 pm
by Psychophanta
Dear minimy, don't worry, i already know many ways to deal with this from years ago.
Anyway thanks for your answer ;)

Re: Should 'Attach' like commands move the attached object?

Posted: Wed Mar 20, 2024 12:34 pm
by benubi
There was a bug with it in 5.22 - 5.73 when I tested and perhaps still exists.

When you attach a resized entity the scale modificators will be ignored. I tried to attach the rusty barrel to the robot in that code. When it did, the barrel shrunk in size (to the original size), but it would also remain attached as intended.

Re: Should 'Attach' like commands move the attached object?

Posted: Wed Mar 20, 2024 6:55 pm
by Psychophanta
@benubi, please post a short example