如何围绕其中心旋转 PShape? [英] How to rotate a PShape around its centre?
问题描述
处理手册(第二版)将此作为示例 17-10:
The Processing handbook (second edition) has this as example 17-10:
PShape zig;
void setup() {
size(100, 100);
zig = createShape();
zig.beginShape();
zig.fill(0);
zig.noStroke();
zig.vertex(10, 0);
zig.vertex(100, 30);
zig.vertex(90, 70);
zig.vertex(100, 70);
zig.vertex(10, 90);
zig.vertex(50, 40);
zig.endShape();
zig.scale(0.7);
zig.translate(-50, -50);
}
void draw() {
background(204);
shape(zig, 50, 50);
zig.rotate(0.01);
}
书中随附的图片显示了围绕画布中心旋转的形状.
And the images in the book that accompany this example show the shape rotating around the centre of the canvas.
然而,当我运行那个确切的代码时,形状会围绕画布左上角的 [0,0] 点旋转.
However when I run that exact code, the shape rotates around the [0,0] point at the top left of canvas.
-50, -50 平移和 50, 50 坐标对我来说似乎暗示(基于我有限的理解)旋转应该以 [50, 50] 点为中心,但这并不适用当我运行代码时?关于如何使形状围绕其中心旋转的任何想法?我的意思是专门使用 zig.rotate() 方法,我知道你可以翻译 &将画布作为一个整体旋转,但我想围绕其中心专门旋转这个形状.创建 PShapes 原点后可以更改它吗?谢谢!
The -50, -50 translation and 50, 50 co-ordinates do seem to imply to me (based on my limited understanding) that the rotation should be centred around the [50, 50] point but this doesn't bear out when I run the code? Any ideas as to how I can get the shape to rotate around its centre? I mean specifically using the zig.rotate() method, I know you can translate & rotate the canvas as a whole but I want to rotate specifically this shape around its centre. Can you change a PShapes origin point after creating it? Thanks!
推荐答案
我能够使用默认渲染器在 3.0a10 中重现这一点.如果我指定 P2D
作为渲染器 size(100,100,P2D)
,PShape
会按预期围绕中心点旋转.在 2.2.1 版本中指定 P2D 也有效.
I was able to reproduce this in 3.0a10 using the default renderer. If I specify P2D
as the renderer size(100,100,P2D)
, the PShape
rotates about the centre-point, as expected. Specifying P2D in version 2.2.1 also works.
所以我认为这看起来像是一个错误.也许值得在 Processing Github 上提出问题?
So I think this looks like a bug. Maybe it's worth opening an issue on the Processing Github?
更新:似乎已经有一个未解决的问题.
Update: there already seems to be an open issue for this.
这篇关于如何围绕其中心旋转 PShape?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!