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
World unit ?
Re: World unit ?
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).
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).
- pf shadoko
- Enthusiast
- Posts: 386
- Joined: Thu Jul 09, 2015 9:07 am
Re: World unit ?
it depends on the FOV
cameradistance.f=(cubesize/2)/Tan(Radian(FOV/2)) + cubesize/2
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 ?
Nice!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

-
- User
- Posts: 65
- Joined: Wed Jun 07, 2017 10:13 pm
Re: World unit ?
Thankspf shadoko wrote: Wed May 24, 2023 12:01 pm it depends on the FOV
cameradistance.f=(cubesize/2)/Tan(Radian(FOV/2)) + cubesize/2