dojo.gfx 矩阵变换

发布于 2024-08-17 13:23:27 字数 526 浏览 8 评论 0原文

矩阵变换让我头晕目眩。我有一个 dojox.gfx.group,我想用 Mover 拖动它,然后能够围绕表面上的某个点旋转它。我的基本代码如下所示:

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) 只是为了简单起见。我似乎不明白这个小组是如何轮换的。

任何有关矩阵变换的简单教程的参考也会有所帮助。我检查过的那些并没有太大帮助。

Matrix transformations has got my head spinning. I've got a dojox.gfx.group which I want to be draggable with Mover and then be able to rotate it around a certain point on the surface. My basic code looks like this:

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]); 
}

The rotation point is at (0,0) just to keep things simple. I don't seem to understand how the group is being rotated.

Any reference to simplistic tutorial on matrix transformations would also help. The ones I've checked out haven't help too much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼眸里的快感 2024-08-24 13:23:27

官方文档是我开始旋转的地方。我已经盯着这个问题很长一段时间了,因为我不知道如何将新坐标输入到即将到来的矩阵转换中。

我终于设法找出问题所在。这是一个将监听器连接到 Mover 何时触发 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);
},

Life's dandy Again。感谢尤金的建议。

The official documentation is where my head started spinning. Been staring at that for quite a long time because I couldn't make out how to feed the new coordinates into upcoming matrix transformations.

I've finally managed to figure out the problem though. It was a matter of connecting a listener to when the Mover triggers onMoveStop:

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

I then get the new moved distances and feed them into any rotation or scaling matrix translations in my graphic class:

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);
},

Life's dandy again. Thanks Eugene for the suggestions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文