Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

When I turn the 3D space, I want an object remains in place: how to do ?

$
0
0

Hello,

I wrote a small P5 code to explain my problem. In P3D, there are 2 cubes : white cube and red cube. I want to rotate the white cube in the 3 dimensions without rotate the red cube. I use a very simple Max standalone control (rotateX, rotateY, rotateZ) to rotate the white cube (OSC). You can download this standalone here : https://dl.dropboxusercontent.com/u/83095197/Rotation.zip

This work fine if I rotate only one variable (rotateX with rotateY = 0 et rotateZ = 0; rotateY with rotateX = 0 et rotateZ = 0; rotateZ with rotateX = 0 et rotateY = 0). On the other side, it doesn't work if I rotate 2, 3 variables in the same time : the red cube move. How to maintain the red cube in place by modifying several parameters at once ?

Here, my P5 code :

                        // OSC
                        import oscP5.*;
                        import netP5.*;
                        OscP5 oscP5;
                        NetAddress myRemoteLocation;

                        // VARIABLES
                        int DIMX, DIMY, DIMZ;
                        float translateX, translateY, translateZ;
                        float rotateX, rotateY, rotateZ;


                        void setup() {
                          size(600, 600, P3D);
                          DIMX = width/2;
                          DIMY = height/2;
                          DIMZ = 300;

                          // OSC
                          oscP5 = new OscP5(this, 12000);
                          myRemoteLocation = new NetAddress("127.0.0.1", 12000);

                          // VARIABLES
                          translateX = width/2;
                          translateY = height/2;
                          translateZ = -height*2;
                          rotateX = 0;
                          rotateY = 0;
                          rotateZ = 0;
                        }


                        void draw() {
                          background(0);

                          // WHITE CUBE
                          translate(translateX, translateY, translateZ);
                          rotateX(radians(rotateX));
                          rotateY(radians(rotateY));
                          rotateZ(radians(rotateZ));
                          noFill();
                          stroke(255);
                          box(DIMX*2, DIMY*2, DIMZ*2);

                          // RED CUBE
                          pushMatrix();
                          rotateX(radians(rotateX * -1));
                          rotateY(radians(rotateY * -1));
                          rotateZ(radians(rotateZ * -1));
                          noFill();
                          stroke(255, 0, 0);
                          box(DIMX, DIMY, DIMZ);
                          popMatrix();
                        }


                        void oscEvent(OscMessage theOscMessage) {

                          // ROTATE X
                          if (theOscMessage.checkAddrPattern("/max2P5/rotateX")==true) {
                            rotateX=theOscMessage.get(0).floatValue();
                          }

                          // ROTATE Y
                          if (theOscMessage.checkAddrPattern("/max2P5/rotateY")==true) {
                            rotateY=theOscMessage.get(0).floatValue();
                          }

                          // ROTATE Z
                          if (theOscMessage.checkAddrPattern("/max2P5/rotateZ")==true) {
                            rotateZ=theOscMessage.get(0).floatValue();
                          }
                        }

Thank you :) Best, Alex


Viewing all articles
Browse latest Browse all 2896

Trending Articles