我做了一个小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;
}
}