大家好,欢迎来到IT知识分享网。
Vector4 Transform::Homogenize(Vector4& result, const Vector4& vec4ToBeHomogenized)
{
if (vec4ToBeHomogenized.getW() == 0.f) {
return Vector4();
}
float rhw = 1 / vec4ToBeHomogenized.getW();
result.setX((1.f + vec4ToBeHomogenized.getX() * rhw) * canvasWidth * 0.5f); // screen coordinate
result.setY((1.f - vec4ToBeHomogenized.getY() * rhw) * canvasHeight * 0.5f); //screen coordinate ---> top down
result.setZ(vec4ToBeHomogenized.getZ() * rhw);
result.setW(rhw);
return result;
}
它的逆变换如下(逆变换主要用于求阴影时候的反求过程):
Vector4 Transform::HomogenizeInvertion(Vector4 & result, const Vector4 & vec4ToBeInverted)
{
if (vec4ToBeInverted.getW() == 0.f) {
return Vector4();
}
float rhw = 1.f / vec4ToBeInverted.getW();
float reciprocalOfCanvasHeight = 1.f / canvasHeight;
float reciprocalOfCanvasWidth = 1.f / canvasWidth;
result.setX(((2 * vec4ToBeInverted.getX() * reciprocalOfCanvasWidth) - 1.f) * rhw);
result.setY((1.f - (2 * vec4ToBeInverted.getY() * reciprocalOfCanvasHeight)) * rhw);
result.setZ(vec4ToBeInverted.getZ() * rhw);
result.setW(rhw);
return result;
}
作者:艾孜尔江·艾尔斯兰
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/28095.html