It is currently Mon Jul 06, 2020 6:29 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Problem with TransformMesh using Physics
PostPosted: Sat May 02, 2020 3:07 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4625
Location: Spa, relaxing and thinking, and learning...
Hi.
The code says it all.
When turning entity without touching the mes, all is ok, but when transform the mesh , it does not transform its bounding shape.
Code:
InitEngine3D():InitSprite():InitKeyboard()
RX.u=1280:RY.u=720
OpenWindow(0,0,0,RX,RY,"",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,RX,RY,1,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):SetLightColor(0,#PB_Light_DiffuseColor,$EEEEEE):MoveLight(0,4,4,2,#PB_Absolute):AmbientColor($FFFFFF)
LoadTexture(0,"wood.jpg"):CreateMaterial(0,TextureID(0))
CreateCube(0,10):TransformMesh(0,0,0,0,2,0.01,2,0,0,0,0):UpdateMeshBoundingBox(0)
CreateEntity(0,MeshID(0),MaterialID(0),0,-0.05,0)
CreateEntityBody(0,#PB_Entity_StaticBody,1.0,0.8,0.3)
CreateCamera(0,0,0,100,100)
MoveCamera(0,0,3,5)
Cameralookat(0,0,1,0)
LoadTexture(1,"RustySteel.jpg")
CreateMaterial(1,TextureID(1))
WorldDebug(#PB_World_DebugBody)
Repeat
  ExamineKeyboard()
  WindowEvent()
  If KeyboardReleased(#PB_Key_Space):way.b!1
    If IsEntity(1):FreeEntityBody(1):FreeEntity(1):EndIf
    If IsMesh(1):FreeMesh(1):EndIf
    CreateCone(1,0.2,1,16,8)
    If way
      UpdateMeshBoundingBox(1)
      CreateEntity(1,MeshID(1),MaterialID(1),0,0.5,0)
      RotateEntity(1,0,0,180)
    Else
      ; This way does not work!!: ?
      TransformMesh(1,0,0,0,1,1,1,0,0,180):UpdateMeshBoundingBox(1)
      CreateEntity(1,MeshID(1),MaterialID(1),0,0.5,0)
    EndIf
    CreateEntityBody(1,#PB_Entity_ConeBody,1,0.4,0.2):SetEntityAttribute(1,#PB_Entity_LinearSleeping,0.01):SetEntityAttribute(1,#PB_Entity_AngularSleeping,2.2)
  EndIf
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)


EDITED to minimize code amount.

_________________
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend


Last edited by Psychophanta on Sun May 03, 2020 3:36 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with TransformMesh using Physics
PostPosted: Sat May 02, 2020 3:46 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 10:06 am
Posts: 853
Location: Denmark
Nice find.
The UpdateMeshBoundingBox() should recalculate the boundingBox to the fit the shape of the object.
It doesn't....

_________________
“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: Problem with TransformMesh using Physics
PostPosted: Sat May 02, 2020 5:26 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4625
Location: Spa, relaxing and thinking, and learning...
DK_PETER wrote:
Nice find.
The UpdateMeshBoundingBox() should recalculate the boundingBox to the fit the shape of the object.
It doesn't....

Indeed, that's the reason of the post.
May be a bug !

_________________
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with TransformMesh using Physics
PostPosted: Wed May 20, 2020 12:19 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Mar 04, 2014 4:15 pm
Posts: 113
Location: Netherlands
I want to share my 2 cents here, and maybe iam toally wrong:

I dont think theres a bug at all, what i see is that youre the first time rotate the entity, and the second time only the mesh.
With both times you use the command: UpdateMeshBoundingBox, but thats doing nothing, even with the first time. Clearly not needed at all.

What i think happens is, that you must rotate at all times only the boundingbox and not the mesh itself (its like a parent -> child), that way all works fine, try the following code:

in the docs it says by: UpdateMeshBoundingBox(): " If a mesh has been manually modified"
And thats what youre not doing. So my guess your using a command at the wrong place.

Code:
Enumeration
  #BoundingBox = 10 ; Entity
  #ConeObject ; mesh
EndEnumeration


InitEngine3D():InitSprite():InitKeyboard()
RX.u=1280:RY.u=720
OpenWindow(0,0,0,RX,RY,"",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,RX,RY,1,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):SetLightColor(0,#PB_Light_DiffuseColor,$EEEEEE):MoveLight(0,4,4,2,#PB_Absolute):AmbientColor($FFFFFF)
LoadTexture(0,"wood.jpg"):CreateMaterial(0,TextureID(0))
CreateCube(0,10):TransformMesh(0,0,0,0,2,0.01,2,0,0,0,0):;UpdateMeshBoundingBox(0)
CreateEntity(0,MeshID(0),MaterialID(0),0,-0.05,0)
CreateEntityBody(0,#PB_Entity_StaticBody,1.0,0.8,0.3)
CreateCamera(0,0,0,100,100)
MoveCamera(0,0,3,5)
CameraLookAt(0,0,1,0)
LoadTexture(1,"RustySteel.jpg")
CreateMaterial(1,TextureID(1))
WorldDebug(#PB_World_DebugBody)




Repeat
  ExamineKeyboard()
  WindowEvent()
  If KeyboardReleased(#PB_Key_Space)
   
    way.b!1
   
    If IsEntity(#BoundingBox)
      FreeEntityBody(#BoundingBox)
      FreeEntity(#BoundingBox)
    EndIf
   
    If IsMesh(#ConeObject)
      FreeMesh(#ConeObject)
    EndIf
   
    CreateCone(#ConeObject,0.2,1,16,8)

   
    If way
      CreateEntity(#BoundingBox,MeshID(#ConeObject),MaterialID(1),0,0.5,0)
      RotateEntity(#BoundingBox,0,0,150)
    Else
      CreateEntity(#BoundingBox,MeshID(#ConeObject),MaterialID(1),0,0.5,0)
      RotateEntity(#BoundingBox,0,0,210)
    EndIf
   
    CreateEntityBody(#BoundingBox,#PB_Entity_ConeBody,1,0.4,0.2)
    SetEntityAttribute(#BoundingBox,#PB_Entity_LinearSleeping,0.01)
    SetEntityAttribute(#BoundingBox,#PB_Entity_AngularSleeping,2.2)
   
   
   
  EndIf
 
  RenderWorld()
  FlipBuffers()
 
Until KeyboardPushed(#PB_Key_Escape)


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with TransformMesh using Physics
PostPosted: Thu Jun 18, 2020 10:28 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4625
Location: Spa, relaxing and thinking, and learning...
The point is that the wanted thing to do is to rotate the mesh in one of the both cases, and leave it untouched in the other case, to see the difference.

What you do is to perform the SAME in both cases, what is nonsense.

My tip is a demonstration about the fact that there seems not to exist a clean and direct way to just update the bounding box after altering the mesh.
So that, the UpdateMeshBoundingBox() is failing in its task.

_________________
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 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