3D 引擎在旋转时拉伸对象
3D Engine stretches objects out while rotating
我做了一个小的3D引擎。
但是我对旋转功能有一些问题。它们使物体不时伸展。这是数学:
this.rotateX = function(angle) {
var cos = Math.cos(angle);
var sin = Math.sin(angle);
for(var i = 0; i < this.points.length; i++) {
this.points[i].y = sin * this.points[i].z + cos * this.points[i].y;
this.points[i].z = -sin * this.points[i].y + cos * this.points[i].z;
}
}
this.rotateY = function(angle) {
var cos = Math.cos(angle);
var sin = Math.sin(angle);
for(var i = 0; i < this.points.length; i++) {
this.points[i].x = cos * this.points[i].x - sin * this.points[i].z;
this.points[i].z = sin * this.points[i].x + cos * this.points[i].z;
}
}
this.rotateZ = function(angle) {
var cos = Math.cos(angle);
var sin = Math.sin(angle);
for(var i = 0; i < this.points.length; i++) {
this.points[i].x = cos * this.points[i].x + sin * this.points[i].y;
this.points[i].y = -sin * this.points[i].x + cos * this.points[i].y;
}
}
this.points[i].y = sin * this.points[i].z + cos * this.points[i].y;
this.points[i].z = -sin * this.points[i].y + cos * this.points[i].z;
您正在计算y
并使用此新y
来计算z
。您可能应该使用旧y
(轮换之前):
var y = sin * this.points[i].z + cos * this.points[i].y;
var z = -sin * this.points[i].y + cos * this.points[i].z;
this.points[i].y = y;
this.points[i].z = z;
相关文章:
- 旋转后拖动对象
- 在JS中围绕旋转对象旋转对象
- Threejs-围绕中心旋转对象
- 如何在使用Kinetic拖动同一对象后,在旋转动画中保持先前的偏移
- 根据摄影机视图更改计算对象旋转
- 使用tween.js围绕世界轴旋转对象
- 在HTML5画布中,是否可以围绕旋转对象旋转对象
- 在拉斐尔中将对象作为一个组旋转
- 从对象旋转对象.带有自定义动画功能的trix.setrotationfromleuler
- 将一个对象自身旋转并围绕另一个中心对象旋转三.js
- 根据键盘 threejs 更改对象旋转动画方向
- WebGL在一个轴上围绕另一个对象旋转一个对象
- 使用Three.js围绕对象旋转相机
- SVG:反转父变换上的子对象旋转
- Three.js赢得't在对象旋转时渲染
- three.js面向对象旋转
- 如何在每次点击时用CSS转换/转换JS将对象旋转120度
- 对象旋转中的对象
- 获取对象旋转后的实际绑定区域
- HTML5 JavaScript-将对象旋转到目标