Page 1 of 1

World unit ?

Posted: Wed May 24, 2023 2:02 am
by williamvanhoecke
Hello,
I have a screenwidth() = 500 and a screenheight() = 500
I want to create a mesh with CreateCube(#Mesh, Size) that initialy exactly fits that screen
CreateCube(#Mesh, Size) however uses 'world unit' for setting the size.
Since one does not know many pixels a 'world unit' is. what value should i use for Size

Re: World unit ?

Posted: Wed May 24, 2023 9:28 am
by Caronte3D
One way, is progressively bring te cube close to the camera until it cover the whole surface, then remember the position to the camera to use it directly.
The other way is to translate the cube wold coordinates to screen space coordinates until it fits (but I don't know if PB have such function).

Re: World unit ?

Posted: Wed May 24, 2023 12:01 pm
by pf shadoko
it depends on the FOV

cameradistance.f=(cubesize/2)/Tan(Radian(FOV/2)) + cubesize/2

Code: Select all

InitEngine3D():InitSprite():InitKeyboard():InitMouse()

ExamineDesktops()
OpenWindow(0, 0,0, 500,500, "",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)

CreateCamera(0, 0, 0, 100, 100)
CreateLight(0,$ffffff, 0, 10000, -10000)
AmbientColor($111111*3)
CameraBackColor(0,$444488)

fov.f=45
cubesize.f=10
cameradistance.f=(cubesize/2)/Tan(Radian(fov/2)) + cubesize/2

CameraFOV(0,fov)
CreateCube(0,cubesize);:TransformMesh(0,0,0,0,1,1,0.01,0,0,0)
CreateMaterial(0,0,$ff)
CreateEntity(0,MeshID(0),MaterialID(0))
MoveCamera(0,0,0,-cameradistance):CameraLookAt(0,0,0,0)

Define.f MouseX,Mousey,depx,depz,dist,val,blend

Repeat
	While WindowEvent():Wend
	ExamineKeyboard()
	ExamineMouse()	
	RotateEntity(0,0.2,0.2,0.2, #PB_Relative)
	RenderWorld()
	FlipBuffers()    
Until KeyboardReleased(#PB_Key_Escape) Or MouseButton(3)

Re: World unit ?

Posted: Wed May 24, 2023 1:02 pm
by Caronte3D
pf shadoko wrote: Wed May 24, 2023 12:01 pm it depends on the FOV
cameradistance.f=(cubesize/2)/Tan(Radian(FOV/2)) + cubesize/2
Nice! :D

Re: World unit ?

Posted: Wed May 24, 2023 10:08 pm
by williamvanhoecke
pf shadoko wrote: Wed May 24, 2023 12:01 pm it depends on the FOV
cameradistance.f=(cubesize/2)/Tan(Radian(FOV/2)) + cubesize/2
Thanks