- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 CATransformLayer 构建了一个 6 面 3D 骰子,将其用作容器层,将 6 个变换后的图层固定为可以在空间中旋转的 3D 对象。 I got the idea from here 。它运行良好,我可以在顶层调用 CATransform3DMakeRotation 旋转“骰子”,骰子旋转并且运行良好。
下一步是将“子弹物理”插入到程序中。我已经可以工作了,但是我被卡住了,因为我不知道如何将物理世界中骰子的“子弹物理‘四元数’方向”转换为可以传递给容器 CALayer 方法的旋转角度。
这就是我正在做的事情:
1) 调用“子弹物理”来获取骰子的方向:
// QUATERNION: Get the orientation
btQuaternion quatO = TObject->getOrientation();
2)将四元数转换为欧拉(大量时间谷歌搜索答案找到了下面复制的方法来执行此操作) qW = quatO.getW(); qX = quatO.getX(); qY = quatO.getY(); qZ = quatO.getZ(); [自四元数到欧拉];
3) 将新的欧拉角应用到我的 CALayer (sCtrl)
[sCtrl rotaX:eX rotaY:eY rotaZ:eZ];
注1:这是用于旋转我的日历的方法
- (CATransform3D) rotaX:(CGFloat) anguloX rotaY:(CGFloat) anguloY rotaZ:(CGFloat) anguloZ
{
CATransform3D rX;
CATransform3D rY;
CATransform3D rZ;
CATransform3D ret;
// Apply all the rotations in order (x, y, z)
rX = CATransform3DMakeRotation([self gradosARadianes:(anguloX)], 1.0f, 0.0f, 0.0f);
ret = CATransform3DConcat(baseTransform, rX);
rY = CATransform3DMakeRotation([self gradosARadianes:(anguloY)], 0.0f, 1.0f, 0.0f);
ret = CATransform3DConcat(rX, rY);
rZ = CATransform3DMakeRotation([self gradosARadianes:(anguloZ)], 0.0f, 0.0f, 1.0f);
ret = CATransform3DConcat(rY, rZ);
// Store finished result for next time start from there...
baseTransform = ret;
return ret;
}
注2:这是我发现的将四元数转换为欧拉的方法。
-(void) quaternionToEuler
{
float matrix[3][3];
float cx,sx;
float cy,sy,yr;
float cz,sz;
matrix[0][0] = 1.0f - 2.0f * (qY * qY + qZ * qZ);
matrix[0][1] = (2.0f * qX * qY) - (2.0f * qW * qZ);
matrix[1][0] = 2.0f * (qX * qY + qW * qZ);
matrix[1][1] = 1.0f - (2.0f * qX * qX) - (2.0f * qZ * qZ);
matrix[2][0] = 2.0f * (qX * qZ - qW * qY);
matrix[2][1] = 2.0f * (qY * qZ + qW * qX);
matrix[2][2] = 1.0f - 2.0f * (qX * qX - qY * qY);
sy = -matrix[2][0];
cy = sqrt(1 - (sy * sy));
yr = (float)atan2(sy,cy);
eY = (yr * 180.0f) / (float)M_PI;
if (sy != 1.0f && sy != -1.0f)
{
cx = matrix[2][2] / cy;
sx = matrix[2][1] / cy;
eX = ((float)atan2(sx,cx) * 180.0f) / (float)M_PI; // RAD TO DEG
cz = matrix[0][0] / cy;
sz = matrix[1][0] / cy;
eZ = ((float)atan2(sz,cz) * 180.0f) / (float)M_PI; // RAD TO DEG
}
else
{
cx = matrix[1][1];
sx = -matrix[1][2];
eX = ((float)atan2(sx,cx) * 180.0f) / (float)M_PI; // RAD TO DEG
cz = 1.0f;
sz = 0.0f;
eZ = ((float)atan2(sz,cz) * 180.0f) / (float)M_PI; // RAD TO DEG
}
}
总之,我的目标:使用 CALayer(不是 OpenGL)在我的程序中表示“子弹物理”盒子(骰子)。为此,我使用 CATransformLayer 作为 6 个转换层到 3D 对象的容器。
--我现在得到的结果不好,图形骰子旋转但显然不正确......所以我在这里做了完全错误的事情......
问题是:鉴于我可以获得子弹物理世界中盒子的“方向或旋转”,我如何将返回的四元数转换为可用于 CATransform3DMakeRotation 的东西(角度)。
提前非常感谢,
路易斯
最佳答案
这是一个糟糕的方法。您从一个矩阵开始,将其转换为四元数,将其转换为欧拉角,然后将其转换为矩阵。
调用 getCenterOfMassTransform().getBasis()
来获取 btMatrix3x3
,而不是 getOrientation()
。将其打包到 CATransform3D
的左上角,并用零填充其余部分(m44
除外,它应该是 1)。
关于objective-c - 从子弹物理四元数转换为角度以与 CATransform3DMakeRotation 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9557966/
对于游戏,我正在尝试计算我正在看的位置与场景中另一个对象的位置之间的角度。我通过使用以下代码获得了角度: Vec3 out_sub; Math.Subtract(pEnt->vOrigin, pLoc
我还是 Firebase 的新手。有什么方法可以使用 Firebase 性能监控从控制台自动逐屏监控我们的 Web 应用程序?我检查了文档,它说我们需要在代码中添加一些跟踪来跟踪(如果我弄错了,请纠正
我正在使用 angular-material2 的复选框。目前复选框的默认颜色为紫色。 看起来他们已将复选框的默认颜色从“主要”更改为重音。 有没有办法在不覆盖 css 的情况下获得“主要”(绿色)颜
Angular-Material 中是否有任何分页指令可与 md-list 一起使用? 这些确实有效,但不是基于 Material 设计的。 https://github.com/brantwills
所以我有一个configmap config.json { "apiUrl": "http://application.cloudapp.net/", "test": "1232" } 称为“连续部署
我可以成功对图像进行阈值处理并找到图像的边缘。我正在努力尝试的是准确地提取黑色边缘的 Angular 。 我目前正在使用黑色边缘的极端点,并使用atan2函数计算 Angular ,但是由于混叠,根据
我需要一些帮助来计算点的角度: 我需要计算从点 (0,0) 到从图像中提取的点的角度。 1 将是 0*,2 大约是 40-44* 等。 我的问题是 atan2 显示的值不正确。atan2 的当前输出是
好的,所以我有一个运动场 512x512环绕,-32变成 512对于x和 y . 现在我需要计算两个实体之间的角度,我有以下代码作为一种解决方法,它在大多数时间都有效,但有时仍然会失败: Shoote
我有一个组件,它有一个子组件。子组件有一个按钮,可以打开一个 Material 对话框。 在对话框中,我们有表单、用户名和密码以及提交按钮。当我提交时,我正在调用后端 REST api。 这在子组件中
我一直在试图找到2之间的差异,但是要减去这个就没有运气了 The primary diff erence between the two representations is that a quate
我在 Angular Material Expansion 面板中遇到了这个问题。部分分页下拉菜单被切断。如何使下拉菜单与扩展面板的末端重叠?我尝试了 z-index 但没有成功。 Material
我正在创建一个PapperSoccer项目,但是在寻找运动/线条的方向时遇到了问题。我正在使用HoughLinesP来检测行,并且效果尽可能好。 我使用ROI,在其中寻找一行,然后相应地移动它。 到目
我正在寻找修改构建函数输出的方法 ng build --prod 想添加一些引导CSS文件到index.html的head部分,更改名称index.html => index.php等 怎么做? 最佳
如何获得两个单位向量之间的 x、y 和 z 旋转值?我不能使用点积,因为它只给我一个值。我想使用旋转矩阵在每个轴上旋转,对于那些我需要每个轴上的角度差。我尝试了仅两个组件的点积,但我有点困惑。有没有一
我必须计算图像中每条可检测线的斜率(或角度)。如果可能的话,甚至可以检测直线斜率的变化。我已经执行了 2D 傅立叶并且我知道每个区域的邻域平均角度(64x64px 的集合)。我什至尝试了 Hough
我正在使用Tiled map 编辑器创建简单的平铺 map 。在我的 map 中,我有几个矩形,如果我创建一个宽度为 50、高度为 10 的矩形并将其精确旋转 90°,则保存 map 并将其加载到我的
我计算了一个三角形的角度,但我不明白为什么我得到一些锐角的负角。例如: var sin = Math.Sin(4.45); var radians = Math.Atan(sin); var
我正在开发一个机器学习项目,其中使用 TensorFlow(和 DNNRegressor)。我想预测范围在 -pi 和 pi 之间的模算术值(角度)。当我尝试“正常方式”执行此操作时,模型不是很好,因
我有一个包含 40 个旋转图像的图像。 图像索引实际上从 0. 0-39 开始。 这是将 0-39 转换为度数的代码 int image_direction = 0; //Can be 0-39 in
在 PostGIS/PostgreSQL 中,是否有一个函数可以给出给定点所在的线串的线段的角度? 最佳答案 在 PostGIS 版本 1.5.3 上 ST_Azimuth()需要两点作为输入——据我
我是一名优秀的程序员,十分优秀!