'Matrix'에 해당되는 글 1건

  1. 2010/04/28 Actionscript3 - Matrix3D 의 버그?? (5)
아래와 같이 내장 API인 Matrix3D 을 사용해서 객체를 X,Y,Z 축으로 로테이션 시켜보려하였습니다.

_mat = new Matrix3D();
_mat.identity();
_mat.appendRotation(1, Vector3D.Y_AXIS) ;

_vec = new Vector3D(100,0,0) ;

private function loop(e:Event):void
{
_vec = _mat.transformVector(_vec) ;

_obj.x = _vec.x ;
_obj.y = _vec.y ;
_obj.z = _vec.z ;
}

그런데 위와 같이 실행하면 _vec (Vector3D) 의 x,y,z 성분이 모두 0으로 수렴(?) 하게 되네요. 레퍼런스를 찾아보면 Matrix3D 의 transformVector 멤버함수는 매개변수로 넘어온 벡터에 변환을 적용한후 새로운 Vector3D 객체를 반환한다고 나오는데 해석을 잘못한건지 ..

그래서 일단 CustomMatrix3D 클레스를 만들어 보았습니다.

CustomMatrix3D 를 사용해서 위와 같은 시도를 해보았습니다.
package example.matrix {
   
    import flash.display.Shape;
    import flash.events.Event;
    import flash.geom.Vector3D;
   
    import flash.display.Sprite;

    /**
     * @author Lee
     * http://webnoon.net
     */
    public class MatrixMain extends Sprite {

       
       
       
        private var _vec : Vector3D;
        private var _ball : Shape;
        private var _mat : CustomMatrix3D;

        public function MatrixMain() {
           
           
           
           
            _vec = new Vector3D(100,0,0) ;
            _vec.w = 1 ;
            var rad : Number = Math.PI/180 ;
           
            _mat = new CustomMatrix3D() ;
            _mat.rotationY(rad) ;
            //_mat.rotationZ(rad) ;
            //_mat.rotationX(rad) ;
            //_mat.translation(0, 1, 0) ;
           
            _ball = new Shape();
            with(_ball.graphics)
            {
                beginFill(0xff0000) ;
                drawCircle(.0, .0, 10) ;
                endFill();
            }
            addChild(_ball) ;
           
            addEventListener(Event.ENTER_FRAME,loop);
        }
       
        private function loop(event : Event) : void {
           
            _mat.transformVector(_vec) ;
           
            _ball.x = _vec.x + stage.stageWidth/2;
            _ball.y = _vec.y + stage.stageHeight/2 ;
            _ball.z = _vec.z ;
           
        }
    }
}

[소스코드]

아래는 실행 결과...


rotationX,Y,Z , translation 모두 잘 적용됨을 알수 있습니다.

Flash Builder4 에서 실행결과 flash.geom.Matrix3D 사용에는 이상이 없었습니다.
오류(?) 가 발생한 환경은 FDT + Flash CS4(컴파일) 입니다.
개발 환경이 잘못된건지 제가 실수한건지 정확히 알수는 없지만 Flash Builder4 에서 실행한 코드는 같은 코드로 실행하였습니다.

저작자 표시 비영리 변경 금지
Posted by 웹눈