2012-05-23 67 views
1

我想在3D點上繪製文字。文本請求2D點rect x y x1 y1如何在3D點上繪製文字?

我使用irrlight引擎。 但我只需要公式。

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; 

但是x和y座標不正確。他們給我消極的y。並在左上方繪製文字。 這個公式是否正確?

+0

我的意思並不是要諷刺,但你怎麼畫的東西在一個點(這應該是adimensional)? :) –

+0

我有框 - vector3d 8分。 並計算所有8點? – manking

回答

2

差不多。

這個公式給你在OpenGL屏幕空間中的位置,它從[-1,-1]到[1,1]。在OpenGL屏幕空間位置是這樣的:

[-1, 1]-----------------------------------------[1, 1] 
    |            | 
    |            | 
    |            | 
    |            | 
    |            | 
    |     [0, 0]      | 
    |            | 
    |            | 
    |            | 
    |            | 
    |            | 
[-1, -1]----------------------------------------[1, -1] 

爲了得到它以像素爲單位,變換如下:

pixelsX = (1 + point.X) * Viewport.Width/2; 
pixelsY = (1 - point.Y) * Viewport.Height/2;