有没有办法在不使用transform.set
的情况下重置模型实例的比例或设置modelInstances位置?我正在制作一个3D怪物制造器,当一个部件被选中时,一组3D箭头移动到该部件上,并变得可见,允许该部件被拖动。我注意到,无论出于什么原因,在缩放时设置箭头的位置都会使箭头严重变形。这是一个巨大的问题,因为我需要的箭头是不同的大小取决于零件的大小。Without setting position,with setting position.在未缩放的ModelInstance (或按1缩放的a)上使用transform.set
可以很好地工作。
我认为一个解决方案是在移动箭头之前重新设置箭头的大小,然后在移动之后重新缩放它,但是似乎没有任何方法可以做到这一点,使用transform.scale(-currentScale, -currentScale, -currentScale)
来反转箭头并增加它的大小而不是减小它。
下面是我如何更改箭头的位置:arrow[j].transform.set(modelInstance[i].transform.getTranslation(new Vector3(), arrow[j].transform.getRotation(new Quaternion());
发布于 2020-01-10 08:44:52
好的,我做了一些日志记录,发现缩放会改变matrix4中的所有值,而不仅仅是modelInstance的大小。我没有找到一种只缩放旋转的方法,但我想出了一种方法:我创建了一个空的Matrix4,并在缩放之前将其设置为箭头矩阵的副本。当需要将箭头定位在某个部分时,我将箭头的矩阵设置为baseMatrix,使用transform.set更改箭头的位置,然后重新缩放箭头。
if(Intersector.intersectRayBoundsFast(pickRay, modelInstance[i].boundingBox)) {
modelInstance[i].transform.getTranslation(modelInstance[i].position);//get the part's position and store it
for(int j = 0 ; j < 3 ; j++) {
arrow[j].transform = arrow[j].baseTransform.cpy();//reset the arrows transform
arrow[j].transform.getRotation(arrow[j].rotation);//get the arrow's (unscaled) rotation and store it
arrow[j].transform.set(modelInstance[i].position, arrow[j].rotation);//set the arrow's position and rotation
arrow[j].changeSize('S');//rescale the arrow
}
break;
}
发布于 2021-01-08 14:40:05
您可以使用transform.scale(1f/currentScale,1f/currentScale,1f/currentScale)或函数ModelInstance.calculateTransforms()来恢复缩放。
https://stackoverflow.com/questions/59665561
复制相似问题