c++ - HLSL的所有三角函数都使用弧度吗,如何旋转图像?
问题描述
我在所有可用文档中搜索了该问题的答案:Microsoft、wiki 和手册之外。
没有地方可以回答这个问题:“HLSL 的所有三角函数都使用弧度吗?”
我刚刚在微软发现函数的参数必须是:
每个分量都应该是 -1 到 1 范围内的浮点值。
但它并没有说,如果是弧度或渐变......
例如,我有顶点着色器和坐标。
我需要将图片旋转 10°。
我通过常量缓冲区将 10 作为参数传递:fzAngle
= 10。
我通过极坐标系使用变换。
下面的代码是否正确?
顶点着色器
float fzRadAngle = radians(fzAngle);
float2 ptPos = input.Pos.xy;
float polarAngle = atan(ptPos.y / ptPos.x);
float polarRadius = sqrt(pow(ptPos.x, 2) + pow(ptPos.y, 2));
polarAngle += fzRadAngle;
ptPos.x = polarRadius * cos(polarAngle);
ptPos.y = polarRadius * sin(polarAngle);
output.Pos.xy = ptPos.xy;
return output;
UPD那么旋转呢......即使我不旋转,只是在坐标系之间转移,我的图像超出范围(它从目标纹理中消失)
float fzRadAngle = radians(fzAngle);
float2 ptPos = input.Pos.xy;
float x = ptPos.x;
float y = ptPos.y;
float phita = atan(y / x);
float ro = sqrt(x * x + y * y);
x = ro * cos(phita);
y = ro * sin(phita);
ptPos.x = x;
ptPos.y = y;
output.Pos.xy = ptPos.xy;
return output;
正如我所看到的,半径计算中的问题,因此,如果我省略ro
,我会按原样返回图像:
float fzRadAngle = radians(fzAngle);
float2 ptPos = input.Pos.xy;
float x = ptPos.x;
float y = ptPos.y;
float phita = atan(y / x);
y = x * tan(phita);
ptPos.x = x;
ptPos.y = y;
output.Pos.xy = ptPos.xy;
return output;
UPD
我发现了一些有趣的事情。
坐标系:
[-1, 1, -1, 1]
在此代码的情况下,图片不会改变:
float2 ptPos = input.Pos.xy;
float x = ptPos.x;
float y = ptPos.y;
float phita = atan(y / x);
float ro = sqrt(pow(x, 2) + pow(y, 2));
y = x * tan(phita);
ptPos.x = x;
ptPos.y = y;
output.Pos.xy = ptPos.xy;
return output;
在这种情况下,它消失了:
float2 ptPos = input.Pos.xy;
float x = ptPos.x;
float y = ptPos.y;
float phita = atan(y / x);
float ro = sqrt(pow(x, 2) + pow(y, 2));
x = ro * cos(phita);
y = ro * sin(phita);
ptPos.x = x;
ptPos.y = y;
output.Pos.xy = ptPos.xy;
return output;
即使我尝试从最终值添加/子结构 1 或 0.5x
并且y
这不会将图像返回到视图字段。
在这里,我只是尝试从 Decart 系统转换为极地并返回。
解决方案
推荐阅读
- javascript - 为什么我的位置固定后背景图像消失了?
- python - 在不涉及数据帧的情况下按升序对条形图进行排序
- bash - 用于比较数组变量的 Bash If 语句
- haskell - 无论输入如何,程序都会不断进入边缘条件 - Haskell
- node.js - 在路由器中获取 req.param 未定义
- sharepoint - 如何将 > 100 万个项目加载到 SharePoint Online 列表
- python - 如何使用 BeautifulSoup 使用 txt 文件中的多个 URL
- sql - 我在 SQL 中遇到错误,无法修复此外键错误。有关详细信息,请参阅描述
- html - HTML:段落文本不堆叠成行。(所有的文字都在一行中并且在段落之外)
- continuous-integration - 如何并行运行 Travis CI 作业?