【发布时间】:2018-07-08 09:29:47
【问题描述】:
由于我是 3D 世界和 3 JS 世界的新手,我了解了大部分内容,但在涉及矩阵时总是感到困惑。
我想要做的是我想将一个小对象拖到其他对象之上,并且小对象应该面向主要对象的相同方向(例如在墙上挂一个挂钟)。
为此,我首先尝试在旋转立方体的顶部放置一个轴助手并应用简单的逻辑,即相交点将给出放置小对象的位置,相交对象面法线将为小对象查看方向.我做了并找到了成功,但不合适。
然后我做了一些计算并搜索了一些计算相同事物的代码,我现在成功了。但不明白背后的整个逻辑,为什么我们这样做。
this.normalMatrix.getNormalMatrix(intersects[i].object.matrixWorld);
this.worldNormal.copy(intersects[i].face.normal).applyMatrix3(this.normalMatrix).normalize();
this.object.position.addVectors(intersects[i].point, this.worldNormal);
this.lookAtVec.addVectors(this.object.position,this.worldNormal.multiplyScalar(15));
this.object.lookAt(this.lookAtVec);
一个人实际上创造了一堵墙,并在上面放了一个小物件。他改变了这一行
this.object.position.addVectors(intersects[i].point, this.worldNormal);
到
this.object.position.copy(intersects[i].point);
它对他有用,但对我的轴助手来说同样的事情不起作用。
【问题讨论】:
-
我从事 3D 项目已有半年多的时间了,从那时起我就再也没有使用过矩阵。每当我必须移动/旋转/缩放对象时,我都会将对象变换矩阵拆分为位置/旋转/sclae 向量并使用它们,因为它明确地更容易理解向量的情况,而不是奇怪的矩阵运算。跨度>
-
什么代码用于定位/旋转/缩放轴助手?
-
仅将 this.object 视为轴助手,稍后我将其转换为挂钟。为了解释更多,这里是定义。
normalFinder = new normalController(meshes,clock,camera,renderer.domElement);.. 这里的网格是 raycaster 的对象数组。时钟是要放置的对象..等原型函数是:normalController = function(_meshes,_object, _camera,_dom){ this.meshes = _meshes; this.object = _object; this.camera = _camera;
标签: javascript three.js transformation coordinate-transformation normals