2
votes

I'm trying to rotate three-faced object around its center via X axis. I'm building single face's center at 0,0. And I can rotate it around its center, but when I try to rotate the "whole" object, it doesn't work anymore. What should I do?

float a = 0;

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

void draw() {
  background(0);
  noStroke();
  lights();
  pushMatrix();
  translate(width/2, height/2, -100);
  a = a + 0.01;
  rotateX(a);
  beginShape(QUADS);

  vertex(-100, -100, 0);
  vertex(100, -100, 0);
  vertex(100, 100, 0);
  vertex(-100, 100, 0);

  vertex(-100, 100, 0);
  vertex(100, 100, 0);
  vertex(100, 0, - 170);
  vertex(-100, 0, - 170);

  vertex(-100, - 100, 0);
  vertex(100, - 100, 0);
  vertex(100, 0, - 170);
  vertex(-100, 0, - 170);

  endShape();
  popMatrix();
}
1

1 Answers

1
votes

If i understood correct, you need to draw the center of the object at origin also in z axis, see if is this that you want:

(only changes in z parameter of every vertex)

float a = 0;

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

void draw() {
  background(0);
  noStroke();
  lights();
  pushMatrix();
  translate(width/2, height/2, -100);
  a = a + 0.01;
  rotateX(a);
  beginShape(QUADS);

  vertex(-100, -100, 85);
  vertex(100, -100, 85);
  vertex(100, 100, 85);
  vertex(-100, 100, 85);


  vertex(-100, 100, 85);
  vertex(100, 100, 85);
  vertex(100, 0, - 85);
  vertex(-100, 0, - 85);

  vertex(-100, - 100, 85);
  vertex(100, - 100, 85);
  vertex(100, 0, - 85);
  vertex(-100, 0, - 85);

  endShape();

  popMatrix();
}