Estoy tratando de rotar un Sprite en tres dimensiones alrededor de su punto central, y estoy luchando por comprender algo del comportamiento de matrix3D.cómo hacer rotación 3D alrededor del centro en AS3 usando matrix3D?
he anulado los métodos establecidos rotationX, rotationY y rotationZ del Sprite de la siguiente manera:
override public function set rotationX (_rotationX:Number) : void {
this.transform.matrix3D.prependTranslation(this.width/2.0, this.height/2.0, 0);
this.transform.matrix3D.prependRotation(-this.rotationX, Vector3D.X_AXIS);
this.transform.matrix3D.prependRotation(_rotationX, Vector3D.X_AXIS);
this.transform.matrix3D.prependTranslation(-(this.width/2.0), -(this.height/2.0), 0);
}
override public function set rotationY (_rotationY:Number) : void {
this.transform.matrix3D.prependTranslation(this.width/2.0, this.height/2.0, 0);
this.transform.matrix3D.prependRotation(-this.rotationY, Vector3D.Y_AXIS);
this.transform.matrix3D.prependRotation(_rotationY, Vector3D.Y_AXIS);
this.transform.matrix3D.prependTranslation(-(this.width/2.0), -(this.height/2.0), 0);
}
override public function set rotationZ (_rotationZ:Number) : void {
this.transform.matrix3D.prependTranslation(this.width/2.0, this.height/2.0, 0);
this.transform.matrix3D.prependRotation(-this.rotationZ, Vector3D.Z_AXIS);
this.transform.matrix3D.prependRotation(_rotationZ, Vector3D.Z_AXIS);
this.transform.matrix3D.prependTranslation(-(this.width/2.0), -(this.height/2.0), 0);
}
estoy usando prependTranslation para corregir el punto central de la rotación, y la primera prependRotation para anular cualquier anteriormente- rotación aplicada
Probándolo, rotationX funciona exactamente como se esperaba, y el Sprite gira alrededor de su eje horizontal.
rotationY y rotationZ también parecen funcionar bien. Sin embargo, hay un problema: cuando se establecen rotationY o rotationZ, también cambian todos los otros valores de rotación. Esto no es un problema con rotationX - si configuro rotationX, nada más cambia. Pero si configuro rotationY o rotationZ cambian todos los valores de rotación, lo cual es un problema para mi aplicación (que está tratando de guardar y restaurar valores).
Creo que me falta cierto conocimiento sobre lo que está pasando con matrix3D. ¿Cómo puedo implementar esto para que no haya interdependencia entre los valores?
Lo mejor es consultar [UIComponent # transformAround] (http://opensource.adobe.com/svn/opensource/flex/sdk/trunk/frameworks/projects/framework/src/mx/core/UIComponent.as) y la implementación relacionada de AdvancedLayout.as. Hacen exactamente eso, envolviendo Matrix3D. –
No revisando su código, pero ¿está experimentando Gimbal Lock? http://en.wikipedia.org/wiki/Gimbal_lock –