يقوم المحرك ثلاثي الأبعاد بتمديد الأشياء أثناء الدوران
-
08-09-2020 - |
سؤال
لقد صنعت محركًا صغيرًا ثلاثي الأبعاد.
لكن لدي بعض المشاكل مع وظائف التدوير.أنها تجعل الكائن يمتد من وقت لآخر.وهنا الرياضيات:
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;
لا تنتمي إلى StackOverflow