在Processing程序中,当按x的小写字母x表示x轴的逆时针方向,或按大写的X表示x轴的顺时针方向,并按小写的y表示y的逆时针方向时,我必须使一个多维数据集移动到该立方体移动的位置。轴,或按大写字母Y表示y轴的顺时针方向,按小写字母z表示z轴的逆时针方向,按大小写Z表示z轴的顺时针方向。问题在于多维数据集移出了位置,但确实旋转了。我如何旋转,但不会移动到不适当的位置?请帮助检查此代码。该代码有效,但是它移到了适当的位置。同样,它在第一次按下按钮时旋转。我该如何解决?
float theta = 0;
void setup() {
size(600, 600, P3D);
}
void draw() {
background(255);
fill(127, 127);
String s1 = "Press x for counterclockwise of x axis, X for clockwise of x axis";
String s2 = "Press y for counterclockwise of y axis, Y for clockwise of y axis ";
String s3 = "Press z for counterclockwise of z axis, Z for for clockwise for z axis";
text(s1, 0, width/2 + 100);
text(s2, 0, width/2 + 125);
text(s3, 0, width/2 + 150);
// if(pressLowX() == true)
// cubeBox(.5, .5, .5);
pressButtons();
pushMatrix();
translate(width/2, height/2);
cubeBox(.5, .5, .5);
popMatrix();
}
void cubeBox(float x, float y, float z) {
translate(x, y, z);
rotate(theta);
beginShape(QUADS);
fill(255, 0, 0);
vertex(100, 100, 100);
vertex(-100, 100, 100);
vertex(-100, -100, 100);
vertex(100, -100, 100);
fill(255, 255, 0);
vertex(-100, -100, -100);
vertex(100, -100, -100);
vertex(100, 100, -100);
vertex(-100, 100, -100);
fill(0, 255, 0);
vertex(100, 100, 100);
vertex(100, -100, 100);
vertex(100, -100, -100);
vertex(100, 100, -100);
fill(0, 255, 255);
vertex(-100, -100, 100);
vertex(-100, -100, -100);
vertex(-100, 100, -100);
vertex(-100, 100, 100);
fill(0, 0, 255);
vertex(-100, -100, 100);
vertex(-100, -100, -100);
vertex(100, -100, -100);
vertex(100, -100, 100);
fill(255, 0, 255);
vertex(100, 100, 100);
vertex(-100, 100, 100);
vertex(-100, 100, -100);
vertex(100, 100, -100);
// rotate(-theta);
// translate(-x, -y, -z);
endShape(CLOSE);
}
void pressButtons() {
if (key == 'x') {
theta = theta - .05;
rotateX(radians(0));
} else if (key == 'X') {
theta = theta + .05;
rotateX(radians(0));
} else if (key == 'y') {
theta = theta - .05;
rotateY(radians(90));
} else if (key == 'Y') {
theta = theta + .05;
rotateY(radians(90));
} else if (key == 'z') {
theta = theta - .05;
rotateZ(radians(60));
} else if (key == 'Z') {
theta = theta + .05;
rotateZ(radians(60));
}
}
答案 0 :(得分:1)
要在适当位置旋转几何图形,必须在平移之前将旋转应用于几何图形:
entity.Property(e => e.CreateDate).HasAnnotation("DisplayName", "Create Date");
这意味着您必须按照以下顺序进行操作:
例如
P' = translation * rotation * P
问题在于,在函数 translate(x, y, z);
rotateX(theta);
中,在theta
之前完成了角度translate
的旋转。
要解决您的问题,请创建一个全局变量,该变量会注意最后按下的键,并在函数pressButtons
pressButtons
创建一个新函数,该函数根据char actKey = 0;
void pressButtons() {
if (key == 'x' || key == 'X' || key == 'y' || key == 'Y' || key == 'z' || key == 'Z')
actKey= key;
}
的状态进行旋转
actKey
执行翻译,然后在void addRotation() {
if (actKey == 'x') {
theta = theta - .05;
rotateX(theta);
} else if (actKey == 'X') {
theta = theta + .05;
rotateX(theta);
} else if (actKey == 'y') {
theta = theta - .05;
rotateY(theta);
} else if (actKey == 'Y') {
theta = theta + .05;
rotateY(theta);
} else if (actKey == 'z') {
theta = theta - .05;
rotateZ(theta);
} else if (actKey == 'Z') {
theta = theta + .05;
rotateZ(theta);
}
}
的开头进行旋转:
cubeBox