Re: 3d world positionto 2d screen coordinates

#2
IRenderer interface has method GetCamera(). It returns CCamera, which has method Project(). Pointer to IRenderer is gEnv->pRenderer.
Although, I'm not particularly sure, when render camera is updated, especially considering multiple threads. I suspect it happens in C3DEngine::UpdateRenderingCamera(), which is called from C3DEngine::RenderWorld() - which might be too late for your game code, i.e. your game code will use camera from previous frame.
So maybe it would be better for your purposes to use ISystem::GetViewCamera(). Pointer to ISystem is gEnv->pSystem.

Re: 3d world positionto 2d screen coordinates

#4
I checked again, CRenderCamera::WorldToCam(), as name implies, just projects point into camera space, i.e. it multiplies point by view matrix. CCamera::Project() projects camera into screen space, i.e. it multiplies point by view-projection matrix. So which one do you want? The question in topic was about screen space - 2d coordinates.

In case you actually want camera space, you can do just the first part of what CCamera::Project() does:

Code: Select all

Matrix44A mView; mathMatrixLookAt(&mView, GetPosition(), GetPosition() + GetViewdir(), GetUp()); transformed = Vec4(p, 1) * mView;
Or if you would like to replicate exactly what CRenderView::SetCameras() does to initialize CRenderCamera:

Code: Select all

CRenderCamera rcam; Vec3 vEye = cam.GetPosition(); Vec3 vAt = vEye + cam.GetViewdir(); // GetViewdir() is same as Vec3((f32)mCam34(0, 1), (f32)mCam34(1, 1), (f32)mCam34(2, 1)) Vec3 vUp = cam.GetUp(); // GetUp() is same as Vec3((f32)mCam34(0, 2), (f32)mCam34(1, 2), (f32)mCam34(2, 2)) rcam.LookAt(vEye, vAt, vUp);
and then just call rcam.WorldToCam()

But I'm still confused - what do you mean by "screen size in meters"? Like, real meters of the monitor you draw on? I guess, there is some way to obtain DPI of screen and then convert pixels into real units. But that's definitely not related to camera space coordinates returned by WorldToCam().

Re: 3d world positionto 2d screen coordinates

#5
Sorry for confusing you, but I meant, that size of screen plane in game world space (because from the game's point of view our screen view is kind of flying plate plane) can help with my task.
And I just have thought, that WorldToCam() can help, but now, when it works, I see that it can't.
My major task is to obtain 2d coordinates on screen (in pixels or other units) of an entity from 3d world and I don't know how to make it.

Who is online

Users browsing this forum: No registered users and 1 guest

cron