2010-01-10 159 views
2

矩陣轉換讓我頭腦轉動。我有一個dojox.gfx.group,我想用拖動器拖動它,然後可以在表面上的某個點上旋轉它。我的基本代碼如下所示:dojo.gfx矩陣轉換

this.m = dojox.gfx.matrix, 
. 
. 
. 

updateMatrix: function(){ 
    var mtx = this.group._getRealMatrix(); 
    var trans_m = this.m.translate(mtx.dx, mtx.dy); 
    this.group.setTransform([this.m.rotateAt(this.rotation, 0, 0), trans_m]); 
} 

旋轉點在(0,0)處,以保持簡單。我似乎不明白這個小組是如何輪換的。

任何有關矩陣轉換的簡單教程的參考也將有所幫助。我檢出的ones沒有太多幫助。

回答

0

官方文件是我的頭開始旋轉的地方。在相當長的一段時間裏,我一直盯着,因爲我無法知道如何將新的座標輸入到即將到來的矩陣變換中。

我終於設法弄清楚了這個問題。這是一個監聽器連接在動子觸發onMoveStop的問題:

dojo.connect(movable, "onMoveStop", map, "reposition"); 

我再拿到新的移動的距離和在我的圖形類它們送入任何旋轉或縮放矩陣譯文:

updateMatrix: function(){ 
    //So far it is the group which is being rotated 

    if (this.group) { 

     if(!this.curr_matrix){ 
      this.curr_matrix = this.initial_matrix; 
     } 
     this.group.setTransform([ 
      this.m.rotateAt(this.rotation, this.stage_w_2, this.stage_h_2), 
      this.m.scaleAt(this.scaling, this.stage_w_2, this.stage_h_2), 
      this.curr_matrix 
     ]); 

     //this.group.setTransform([ 
     // this.m.rotateAt(this.rotation, mid_x, mid_y), 
     // this.m.scaleAt(this.scaling, mid_x, mid_y), 
     // this.initial_matrix]); 
    } 
}, 
reposition: function(){ 
    mtx = this.group._getRealMatrix(); 
    this.curr_matrix = this.m.translate(mtx.dx, mtx.dy); 
}, 

生活的華麗再次。感謝尤金的建議。