diff --git a/index.htm b/index.htm
index e488493..e690de6 100644
--- a/index.htm
+++ b/index.htm
@@ -28,7 +28,6 @@
MINECRAFT ARMOR STAND
-
Please note: some rotation values do not work correctly.
diff --git a/js/main.js b/js/main.js
index 8fde7b5..606a6f7 100644
--- a/js/main.js
+++ b/js/main.js
@@ -358,12 +358,12 @@ function updateUI(){
// Rotate 3D Stuff
// y and z rotation needs to be inverted
- mBody.rotation.set(body.x * DEG2RAD, -body.y * DEG2RAD, -body.z * DEG2RAD);
- mHead.rotation.set(head.x * DEG2RAD, -head.y * DEG2RAD, -head.z * DEG2RAD);
- mLegLeft.rotation.set(leftLeg.x * DEG2RAD, -leftLeg.y * DEG2RAD, -leftLeg.z * DEG2RAD);
- mLegRight.rotation.set(rightLeg.x * DEG2RAD, -rightLeg.y * DEG2RAD, -rightLeg.z * DEG2RAD);
- mArmLeft.rotation.set(leftArm.x * DEG2RAD, -leftArm.y * DEG2RAD, -leftArm.z * DEG2RAD);
- mArmRight.rotation.set(rightArm.x * DEG2RAD, -rightArm.y * DEG2RAD, -rightArm.z * DEG2RAD);
+ setRotation(mBody, body);
+ setRotation(mHead, head);
+ setRotation(mLegLeft, leftLeg);
+ setRotation(mLegRight, rightLeg);
+ setRotation(mArmLeft, leftArm);
+ setRotation(mArmRight, rightArm);
armorstand.rotation.y = -rotation * DEG2RAD;
// Scale model, depending on small variable
@@ -624,3 +624,22 @@ function getLeatherColorString(element, condition){
}
return "";
}
+
+// Rotate three.js mesh to fit the minecraft rotation
+function setRotation(mesh, rotation){
+ rotateAroundWorldAxis(mesh, new THREE.Vector3(1,0,0), rotation.x * DEG2RAD, true);
+ rotateAroundWorldAxis(mesh, new THREE.Vector3(0,1,0), -rotation.y * DEG2RAD, false);
+ rotateAroundWorldAxis(mesh, new THREE.Vector3(0,0,1), -rotation.z * DEG2RAD, false);
+}
+
+// From here: http://stackoverflow.com/a/11124197/1456971
+var rotWorldMatrix;
+// Rotate an object around an arbitrary axis in world space
+function rotateAroundWorldAxis(object, axis, radians, reset) {
+ rotWorldMatrix = new THREE.Matrix4();
+ rotWorldMatrix.makeRotationAxis(axis.normalize(), radians);
+ if(!reset)
+ rotWorldMatrix.multiply(object.matrix); // pre-multiply
+ object.matrix = rotWorldMatrix;
+ object.rotation.setFromRotationMatrix(object.matrix);
+}