Processing ';捕捉到';应用变换后的像素
您应该能够将值舍入为整数(整数) 最简单的是:Processing ';捕捉到';应用变换后的像素,processing,Processing,您应该能够将值舍入为整数(整数) 最简单的是: //given these coordinates for a rectangle (which I will draw with rectmode CORNER) float layerX = -50; float layerY = -50; float layerW = 100; float layerH = 100; //and these transformations translate( 300, 0 ); scale( 12, 1.
//given these coordinates for a rectangle (which I will draw with rectmode CORNER)
float layerX = -50;
float layerY = -50;
float layerW = 100;
float layerH = 100;
//and these transformations
translate( 300, 0 );
scale( 12, 1.5 );
scale( .5, .5 );
//which project those coordinates here.
float sx = screenX( layerX, layerY );
float sy = screenY( layerX, layerY );
float sw = screenX( layerX+layerW, layerY+layerH );
float sh = screenY( layerX+layerW, layerY+layerH );
//(this spits out 0, -37.5, 600, 37.5)
println( sx, sy, sw, sh );
//how do I modify the transformation to 'snap'
//the transformed values to [0, -38, 600, 38],
//effectively snapping to the pixel (and widening the rectangle)?
但使用将获得更准确的结果,因为强制转换为int
基本上会得到以下值:
int sx = (int)screenX( layerX, layerY );
int sy = (int)screenY( layerX, layerY );
int sw = (int)screenX( layerX+layerW, layerY+layerH );
int sh = (int)screenY( layerX+layerW, layerY+layerH );
int sx = (int)round(screenX( layerX, layerY ));
int sy = (int)round(screenY( layerX, layerY ));
int sw = (int)round(screenX( layerX+layerW, layerY+layerH ));
int sh = (int)round(screenY( layerX+layerW, layerY+layerH ));