I want to draw text over 3D point. The text request 2D points rect x y x1 y1
i use irrlight engine. But i need just formula.
i have:
core::vector3df point;
core::rect<s32> viewport = driver->getViewPort();
core::matrix4 matProj = driver->getTransform(video::ETS_PROJECTION);
core::matrix4 matView = driver->getTransform(video::ETS_VIEW);
core::matrix4 matWorld = driver->getTransform(video::ETS_WORLD);
core::quaternion point_qua(point.X ,point.Y , point.Z , 1);
// formula
point_qua = point_qua*(matWorld*matView*matProj);
std::cout << "\nX=" << point_qua.X;
std::cout << "\nY=" << point_qua.Y;
but x and y coord not correct. They give me negative y. And text drawing at top left. Is this formula correct?
Almost.
The formula you have gives you the position in OpenGL screenspace, which goes from [-1, -1] to [1, 1]. Positions in OpenGL screen space look like this:
To get it in pixels, transform as follows: