- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要使节点层次结构中的一个节点面向相机,或者换句话说,成为一个广告牌。对于每个节点,我将其世界矩阵和世界旋转存储为四元数。根据我对四元数的了解,我想要的操作是获取相机四元数和节点的旋转四元数之间的差值,然后简单地旋转节点该差值。
我的相机存储为欧拉 Angular ,因此我通过首先创建 X 轴旋转,然后创建 Z 轴旋转(我没有 Y 轴旋转)并将它们相乘来构造相机四元数。
从这里开始,只需进行一些数学运算即可获得差异,最后从中创建一个旋转矩阵,并将节点的世界矩阵与其相乘。
然而,这最终导致节点像疯狂的暴徒一样旋转,并且绝不面向相机。
以下是相关的 JavaScript 代码:
// If there is a parent, multiply both world matrix and rotation by it
// localMatrix here is the current local matrix of the node
// rotation here is the local rotation quaternion
if (node.parent) {
math.Mat4.multMat(node.parent.worldMatrix, localMatrix, node.worldMatrix);
math.Quaternion.concat(node.parent.worldRotation, rotation, node.worldRotation);
} else {
node.worldMatrix = localMatrix;
node.worldRotation = rotation.copy();
}
// And here the mess begins
if (node.billboarded) {
var cameraX = [];
var cameraZ = [];
var camera = [];
// transform.rotation is my camera's rotation stored as 3 euler angles,
// but I am not using the Y-axis for now
math.Quaternion.setFromAxisAngle([1, 0, 0], transform.rotation[0], cameraX);
math.Quaternion.setFromAxisAngle([0, 0, 1], transform.rotation[2], cameraZ);
math.Quaternion.concat(cameraX, cameraZ, camera);
// The current rotation on the node
var initial = node.worldRotation.copy();
// Need to reverse it, since the difference is camera * -initial
math.Quaternion.conjugate(initial, initial);
var difference = [];
math.Quaternion.concat(camera, initial, difference);
var rotationMatrix = [];
math.Quaternion.toRotationMatrix4(difference, rotationMatrix);
var finalMatrix = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
// pivot is the node's position, need to keep the rotation in local space
math.Mat4.translate(finalMatrix, pivot[0], pivot[1], pivot[2]);
math.Mat4.multMat(finalMatrix, rotationMatrix, finalMatrix);
math.Mat4.translate(finalMatrix, -pivot[0], -pivot[1], -pivot[2]);
// And finally actually rotate the node
math.Mat4.multMat(node.worldMatrix, finalMatrix, node.worldMatrix);
}
我犯了一些明显的错误吗?
最佳答案
你的假设是错误的:
the operation I want is to get the difference between the camera quaternion and the rotation quaternion of a node, and simply rotate the node by said difference.
如果你这样做正确,它应该会导致你的节点面向与相机面向相同的方向。这与实际面对相机有很大不同。
您需要找到面向世界空间中相机位置的变换。您可能会受益于对 gluLookAt() 的一些快速研究。
关于javascript - 获取节点层次结构中的节点面向相机(广告牌),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17258087/
我从我的老师那里得到了一个代码,目前显示了一个 3D 地球和一个 2D 粒子系统。摄像机绕圈移动。粒子系统应该面向相机。 根据我的讲义,我必须将广告牌乘以相机 View 矩阵的逆矩阵。我很想尝试一下,
我需要使节点层次结构中的一个节点面向相机,或者换句话说,成为一个广告牌。对于每个节点,我将其世界矩阵和世界旋转存储为四元数。根据我对四元数的了解,我想要的操作是获取相机四元数和节点的旋转四元数之间的差
我希望能够创建一个 div 并为其指定高度、宽度和类。然后将 div 添加到 Cesium map 作为广告牌。 我可以创建带有图像和标签的广告牌并且还找到了 this有关如何使用 svg 的链接,但
每个人, 我正在尝试对基于Canvas的纹理进行动画处理,该纹理映射到平面上,如广告牌。我已经指出要包括 material.needsUpdate 和 texture.needsUpdate ,但是我
我创建了一个小应用程序来显示单个粒子: 当我围绕场景旋转时,光照发生变化,粒子几乎变得不可见: 是否可以在整个旋转过程中强制设置光照? 相关代码: // init glClear(GL_COLOR_B
我正在使用 LibGDX 博客中描述的 3d 粒子系统(Billboards ar 粒子):https://github.com/libgdx/libgdx/wiki/3D-Particle-Effe
我是一名优秀的程序员,十分优秀!