zoukankan      html  css  js  c++  java
  • 图形学变换中的Homogenize方法_艾孜尔江撰

    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;
    	}
    




    作者:艾孜尔江·艾尔斯兰
  • 相关阅读:
    Nginx+Keepalived(双机热备)搭建高可用负载均衡环境(HA)
    库管理系统-- 后台管理开源啦,源码大放送
    .NET Core R2
    Linux gdb调试
    webpack React+ES6
    绿卡排队
    ABP分层设计
    vscode编写插件
    控制台程序的参数解析类库 CommandLine
    Net Core MVC6 RC2 启动过程分析
  • 原文地址:https://www.cnblogs.com/ezhar/p/14883392.html
Copyright © 2011-2022 走看看