赞
踩
https://stackoverflow.com/questions/52339320/unity-shader-hlsl-equivalent-of-vector3-projectonplane
a 在 b 上的投影
感觉向量还是这样写好看
mathmatica
Dot[{1,0} , {-1,0}] // 点乘 是一个数
{1,0} x {-1,0} // 叉乘 是一个向量
// If your plane normal vector is normalized: inline float3 projectOnPlane( float3 vec, float3 normal ) { return vec - normal * dot( vec, normal ); } // If it's not: inline float3 projectOnPlane( float3 vec, float3 normal ) { return vec - normal * ( dot( vec, normal ) / dot( normal, normal ) ); } // Same formula, depending on GPU model & driver version can be either faster or slower: inline float3 projectOnPlane( float3 v, float3 n ) { float3 r; r.x = n.y * n.y * v.x + n.z * n.z * v.x - n.x * n.y * v.y - n.x * n.z * v.z; r.y = n.x * n.x * v.y - n.x * n.y * v.x - n.y * n.z * v.z + n.z * n.z * v.y; r.z = n.x * n.x * v.z - n.x * n.z * v.x + n.y * n.y * v.z - n.y * n.z * v.y; return r / dot(n, n); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。