Question

J'ai fait un petit moteur 3d.

Mais j'ai quelques problèmes avec la rotation des fonctions.Ils font l'objet d'étirer de temps en temps.Voici le calcul:

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;
    }
}
Était-ce utile?

La solution

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;

Vous êtes le calcul de y et à l'aide de cette nouvelle y pour calculer z.Vous devriez probablement utiliser de vieux y (avant rotation):

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;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top