I want to publish two 3D graphs on one segmented window but the problems is that the end sketch seems to be distorted. This method seems to work with 2D graphs but I cant get it to work for 3D graphs. I cant seem to figure out what the problem is so any help would be much appreciated. This is what I am trying to generate:-
but this is what I end up with:-
The first part of the sketch;
- import processing.opengl.*;
- PVector[] vecs = new PVector[160];
- int dim = 250;
- float x;
- float y;
- float z;
- float maxX, maxY, maxZ;
- float minX, minY, minZ;
- float rotY; // Amount of rotation around y-axis.
- float rotX; // Amount of rotation around the x-axis.
- PFont font;
- void setup()
- {
- size(500,500,P3D);
- smooth();
- setupSketch1();
- setupSketch2();
- }
- void draw()
- {
- scale(.5,.5);
- drawSketch1();
- translate(width,0);
- drawSketch2();
- }
The second bit of the sketch;
- void setupSketch1()
- {
- font = createFont( "arial", 14 );
- textFont(font);
- Random gauss = new Random(0);
- for (int i=0; i<vecs.length; i++)
- {
- x = (float)gauss.nextGaussian()*118.9533 + 261.3167;
- y = (float)gauss.nextGaussian()*48.88477 + 133.6271;
- z = (float)gauss.nextGaussian()*3318.683 + 906.6409;
- vecs[i] = new PVector(x, y, z);
- println(vecs[i]);
- maxX = max(maxX,vecs[i].x);
- maxY = max(maxY,vecs[i].y);
- maxZ = max(maxZ,vecs[i].z);
- minX = min(minX,vecs[i].x);
- minY = min(minY,vecs[i].y);
- minZ = min(minZ,vecs[i].z);
- }
- }
- void drawSketch1()
- {
- background(255);
- translate(width/2,height/2);
- scale(1,-1,1); // so Y is up, which makes more sense in plotting
- rotateY(rotY);
- rotateX(rotX);
- noFill();
- strokeWeight(1);
- stroke(0,10);
- box(dim);
- translate(-dim/2,-dim/2,-dim/2);
- strokeWeight(2);
- stroke(0);
- line(0,0,0,dim,0,0);
- line(0,0,0,0,dim,0);
- line(0,0,0,0,0,dim);
- // Draw axis labels.
- textSize(25);
- String axisLabel;
- fill(50);
- pushMatrix();
- scale(1,-1,1);
- axisLabel = "x-axis";
- text(axisLabel,dim-textWidth(axisLabel),0,0);
- axisLabel = "y-axis";
- rotateZ(HALF_PI);
- text(axisLabel,-dim,0,0);
- axisLabel = "z-axis";
- rotateZ(-HALF_PI);
- rotateY(HALF_PI);
- text(axisLabel,-dim,0,0);
- popMatrix();
- // Draw cubes.
- for (int i=0; i<vecs.length; i++)
- {
- PVector v = vecs[i];
- // cubes
- noStroke();
- fill( 255, 100, 100 );
- pushMatrix();
- // translate(v.x,v.y,v.z);
- translate( map(v.x,minX,maxX,0,dim),
- map(v.y,minY,maxY,0,dim),
- map(v.z,minZ,maxZ,0,dim));
- box(5);
- popMatrix();
- }
- }
1