문제

약 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;
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top