moving object with 3D view
in
Programming Questions
•
1 year ago
Hi everybody.
I am currently trying to write a script to draw an abstract stairs.
I am using rectangle as a step, this rectangle is moving in x or y.
Every step, the rectangle is tranlslated in z to climb.
It works fine when I look from the top (
example 01), but when i use something like
peasy cam to move around the stairs, the x,y,z system seems to be reboot for every view...
In the other hand, failed to replace the move with a translate (
example 02) ... any clue do use translate correctly ?
Thanks !
EXAMPLE 01 :
- int x = 100; // position en x de la marche
- int y = 100; // position en y de la marche
- int R = 20; // dimensions de la marche
- int m = R; //mouvement
- int mx; // mouvement en X
- int my; // mouvement en Y
- int cm = 10; //contremarche
- int mz; // mouvement en Z
- // ...
- void setup() {
- size (600, 600, P3D);
- background(0);
- frameRate(5);
- }
- void draw () {
- climb();
- display();
- //bounce();
- }
- void climb () {
- mx = m*round(random(0, 1));
- x = x + mx;
- if (mx > 0) {
- my = 0;
- }
- else {
- my = m;
- }
- y = y + my;
- }
- void display() {
- translate (0, 0, mz);
- mz = mz+cm;
- rect (x, y, R, R);
- }
EXAMPLE 02
- int x = 200; // position en x de la marche
- int y = 200; // position en y de la marche
- int R = 20; // dimensions de la marche
- int m = R; //mouvement
- int mx; // mouvement en X
- int my; // mouvement en Y
- int cm = 10; //contremarche
- int mz; // mouvement en Z
- // ...
- void setup() {
- size (600, 600, P3D);
- background(0);
- frameRate(5);
- }
- void draw () {
- climb();
- display();
- //bounce();
- }
- void climb () {
- mx = m*round(random(0, 1));
- if (mx > 0) {
- my = 0;
- }
- else {
- my = m;
- }
- pushMatrix();
- translate (mx,0,0);
- translate (0,my,0);
- translate (0,0,mz);
- mz = mz+cm;
- rect (x, y, R, R);
- popMatrix();
- }
- void display() {
- }
1