Page 1 of 1

PB6.02final; issue with ConvertWorldToLocalPosition()

Posted: Sat Apr 29, 2023 11:14 am
by Psychophanta
There was hard to find it, and it is harder to explain, but this single word will be enough to cure it: :)

In my experience here , as long as the 'angulo' surpasses 90 or -90 degrees, then ConvertWorldToLocalPosition() returns crazy values and the Entity rotates crazyful:

Code: Select all

InitEngine3D(#PB_Engine3D_NoLog,#PB_Compiler_Home+"Compilers\Engine3d.dll")
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/fonts", #PB_3DArchive_FileSystem)
Parse3DScripts()
InitSprite():InitKeyboard():InitMouse()
OpenWindowedScreen(OpenWindow(0,0,0,1024,768,"title",#PB_Window_BorderLess|#PB_Window_ScreenCentered),0,0,1024,768,1,0,0,#PB_Screen_WaitSynchronization)
CreateLight(0,$EEEEEE,-1,1,6,#PB_Light_Point)
CreateCamera(0,0,0,100,100)
MoveCamera(0,0,0,4,#PB_Absolute)
CreateMaterial(0,0,$55DDEE)
CreateSphere(0,1,4,2)
          
CreateEntity(0,MeshID(0),MaterialID(0),0,0,0)
CreateText3D(0,"csgf","BlueHighway-8",0.5,$aa9999bb):MoveText3D(0,0,1.4,0):CreateNode(0):AttachNodeObject(0,Text3DID(0))

Repeat:While WindowEvent()<>#PB_Event_None:Wend
  ExamineMouse():ExamineKeyboard()
  angulo.f+Degree(MouseDeltaX()/200):angulo-360*Round(angulo/360,#PB_Round_Nearest)
  Text3DCaption(0,StrF(angulo,0))
  ConvertWorldToLocalPosition(EntityID(0),10,20,-0.2)
  x.f=GetX():y.f=GetY():z.f=GetZ()
  m.f=Sqr(Pow(x,2)+Pow(y,2)+Pow(z,2))
  EntityFixedYawAxis(0,#True,x/m,y/m,z/m)
  Yaw(EntityID(0),angulo,#PB_Local)
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)

Re: PB6.02final; issue with ConvertWorldToLocalPosition()

Posted: Tue Jan 02, 2024 8:51 pm
by minimy
Hi Psychophanta, yes.
Angles are a nightmare!! LOL

I did this to lock pitch when rotate yaw. Is bad code but work for me. (Good for FPS games)
If you can improve are wellcome :)
Happy 2024!

Code: Select all

      pitch.f= EntityPitch(entity,#PB_Engine3D_Adjusted)
      If pitch>=90 Or pitch<=-90: pitch-180:EndIf
      If pitch<=-300: pitch+360:EndIf

Re: PB6.02final; issue with ConvertWorldToLocalPosition()

Posted: Wed Jan 03, 2024 10:20 am
by Psychophanta
This thread is a nonsense, even it is useful to understand some things.
I have to say it has nothing to do with angles, but with the understanding of global coordenates while converting it to local, and viceversa.
About your requirement, when you want to wrap a value inside a fringe, can be used something like this:

Code: Select all

Procedure.d Envolver(valor.d,m.d)
  ;wrap inside (-m,+m)
  m*2
  ProcedureReturn valor-m*Round(valor/m,#PB_Round_Nearest)
EndProcedure

Re: PB6.02final; issue with ConvertWorldToLocalPosition()

Posted: Wed Jan 03, 2024 3:36 pm
by minimy
Hi Psychophanta, sorry for my ignorance. What does the function do? What is valor and M?.
Is it to adjust Pitch with Yaw?
No entiendo muy bien el proposito, disculpa.

Re: PB6.02final; issue with ConvertWorldToLocalPosition()

Posted: Wed Jan 03, 2024 4:35 pm
by Psychophanta
Use it like this (following your example):
pitch.f=Envolver(EntityPitch(entity,#PB_Engine3D_Adjusted),90)
so that you will get a pitch value always inside (-90,90)

Re: PB6.02final; issue with ConvertWorldToLocalPosition()

Posted: Wed Jan 03, 2024 4:46 pm
by minimy
Wow!! work really good!
Many thanks Psychophanta!
Nice code for my 'cutre' FPS! :D
Happy 2024!! and thanks again!