【发布时间】:2019-06-04 12:19:45
【问题描述】:
几天前,我向question 询问了有关处理中的平移和旋转的问题。
我想:
- 多次平移、反转和旋转单个四边形(PShape 对象)
- 然后更改其 2 个顶部顶点之一的高度
所以整个东西就像一个关节臂,可以向右或向左弯曲。
感谢@Rabbid76 的帮助,我能够实现此效果,但我现在面临另一个问题在翻译最后 5 个顶部水平倒置四边形时。
弯曲对象时,前 3 个四边形与后 5 个四边形分开。而且弯曲的腿越弯曲,它们之间的距离就越远。
如果有人能帮我修复 translation 部分(从第 65 行到第 68 行),我将不胜感激,这样无论弯曲强度如何,四边形都保持相互连接。
任何关于这个问题的建议也将不胜感激。
脚本
int W = 40;
int H = 40;
int nQuads = 8;
int xOffset = 27;
float[] p0 = {-W/2 + xOffset, -H/2};
float[] p1 = {-W/2, H/2};
float[] p2 = {W/2, H/2};
float[] p3 = {W/2, -H/2};
PShape object;
void setup(){
size(600, 600, P2D);
smooth(8);
}
void draw(){
background(255);
// Bending to the left
float bending = sin(frameCount*.05) * .1;
p0[1] -= bending;
pushMatrix();
translate(width/2, height/2);
float minX = min( min(p0[0], p3[0]), min(p2[0], p1[0]) );
float maxX = max( max(p0[0], p3[0]), max(p2[0], p1[0]) );
float cptX = (minX+maxX)/2;
//Rotation Angle
float angle = atan2(p3[1]-p0[1], p3[0]-p0[0]);
//Pivot Height
float PH = p0[1] + (p3[1]-p0[1]) * (cptX-p0[0])/(p3[0]-p0[0]);
for (int i = 0; i < nQuads; i++){
float PivotHeight = (i % 2 == 1) ? PH : H/2;
//Height translation
if (i > 0){
translate(0, PivotHeight);
}
//Rotate once every 2 quads
if (i%2 == 1){
rotate(angle*2);
}
//Height translation
//Flip all quads except 1st one
if (i > 0){
translate(0, PivotHeight);
scale(1, -1);
}
//NOT working --> Flipping horizontally the last 5 top QUADS
if (i == 3){
scale(-1, 1);
translate(- xOffset, 0); //trying to align the quads on the X axis. Y translation is missing
rotate(-angle*2);
}
object();
}
popMatrix();
}
void object() {
beginShape(QUADS);
vertex(p0[0], p0[1]);
vertex(p1[0], p1[1]);
vertex(p2[0], p2[1]);
vertex(p3[0], p3[1]);
endShape();
}
【问题讨论】:
-
@KevinWorkman 在挖掘和查找交叉帖子方面,您似乎非常活跃,但如果您能提供帮助,我将不胜感激
-
请记住,帮助您的人在他们的私人时间免费提供帮助。老实说,我希望你能找到答案,但请尊重其他人的时间。发布到多个站点是可以的,但请在帖子之间建立链接,这样我们就不会重复您已经收到的建议。祝你好运。
-
translation-tag 专门用于语言翻译,例如从英语到德语。不适用于图像,因此在标签中进行了编辑。请不要再次回滚。
-
@Adriaan 我明白了。但是我认为“翻译”是指处理的一个非常具体的功能(如“旋转”),并且“翻译动画”具有误导性和混淆性:它不是动画并且该术语不属于使用的术语由处理社区提供。
标签: rotation processing translate-animation