在当前坐标系

时间:2017-03-17 21:04:19

标签: processing

如何在当前坐标系中获取鼠标坐标,即在由变换矩阵确定的坐标系中?

mouseX和mouseY在未转换的屏幕空间中返回坐标。

2 个答案:

答案 0 :(得分:1)

一种选择是手动跟踪变换矩阵,并使用逆变换在本地坐标系和全局坐标系之间进行转换。

要从全局坐标系转换为局部坐标系,请将全局位置乘以局部坐标系的倒数。这是一个非常基本的例子:

//local coordinate system
PMatrix2D coordinateSystem;
//ineverse local coordinate system
PMatrix2D inverseCoordinateSystem;

PVector global = new PVector();
PVector local = new PVector();

void setup(){
  size(400,400);

  coordinateSystem = new PMatrix2D();
  //move to centre
  coordinateSystem.translate(width * .5, height * .5);
  //rotate 45 degrees
  coordinateSystem.rotate(HALF_PI * .5);

  //inverse coordinate system - clone the regular one, then simply invert it
  inverseCoordinateSystem = coordinateSystem.get(); 
  inverseCoordinateSystem.invert();

  fill(128);
}

void draw(){
  background(255);

  pushMatrix();
  applyMatrix(coordinateSystem);
  rect(0,0,100,100);
  popMatrix();

  //set global coordinates
  global.set(mouseX,mouseY);
  //compute local coordinates by multiplying the global coordinates to the inverse local coordinate system (transformation matrix)
  inverseCoordinateSystem.mult(global,local);

  text("global coordinates:" + global+
      "\nlocal coordinates:" + local,15,10);
}

请注意,当光标位于菱形顶部时,本地坐标为0,0。

同样的原则适用于3D,只需要使用PMatrix3D代替

答案 1 :(得分:0)

通过仔细阅读the Processing reference可以最好地回答这样的问题。具体来说,<?php WCVendors_Pro_Product_Form::form_data( $object_id, $post_status ); ?> <?php WCVendors_Pro_Product_Form::save_button( $title ); ?> example.com/profile函数完全符合您的要求:它们从屏幕坐标转换为变换后的坐标。

相关问题