How would I shift the 3D render perspective?
in
Contributed Library Questions
•
7 months ago
I have written my code to split the screen into 4 quadrants to display data from a motion capture. I have a 3D model in the lower right quadrant. When it renders, it applies perspective based on the center of the screen, meaning the model is stretched down and to the right. Is there a way to change where the "center" to render from is?
Here is my code to see that is going on.
Here is my code to see that is going on.
- import saito.objloader.*;
- int num = 100;
- int style = 1;
- PFont f;
- int qWidth, qHeight;
- OBJModel model;
- float[] acelX = new float[num];
- float[] acelY = new float[num];
- float[] acelZ = new float[num];
- float[] rotX = new float[num];
- float[] rotY = new float[num];
- float[] rotZ = new float[num];
- boolean sketchFullScreen() {
- return true;
- }
- void setup() {
- f = createFont("Arial", 36, true);
- textFont(f, 24);
- model = new OBJModel(this, "objattmpt basin.obj", "relative", TRIANGLES);
- model.translateToCenter();
- size(displayWidth, displayHeight, P3D);
- qWidth = width/2;
- qHeight = height/2;
- model.scale((qHeight/3)*10);
- model.enableTexture();
- model.enableMaterial();
- smooth();
- }
- void draw() {
- // copy everything one value down
- for (int i=0; i<acelX.length-1; i++) {
- acelX[i] = acelX[i+1];
- }
- for (int i=0; i<acelY.length-1; i++) {
- acelY[i] = acelY[i+1];
- }
- for (int i=0; i<acelZ.length-1; i++) {
- acelZ[i] = acelZ[i+1];
- }
- for (int i=0; i<rotX.length-1; i++) {
- rotX[i] = rotX[i+1];
- }
- for (int i=0; i<rotY.length-1; i++) {
- rotY[i] = rotY[i+1];
- }
- for (int i=0; i<acelZ.length-1; i++) {
- rotZ[i] = rotZ[i+1];
- }
- // new incoming value
- float newValue = noise(frameCount*0.01)*qHeight;
- // set last value to the new value
- acelX[acelX.length-1] = newValue;
- acelY[acelY.length-1] = qHeight-newValue;
- acelZ[acelZ.length-1] = newValue/2 + qHeight/2;
- rotX[acelX.length-1] = newValue/3 + qHeight/3;
- rotY[acelY.length-1] = qHeight-newValue;
- rotZ[acelZ.length-1] = (qHeight-newValue)/2 + qHeight/4;
- // display all values however you want
- background(175, 175, 255);
- drawGrid();
- fill(0);
- text("Acceleration", 10, 34);
- drawGraph(acelX, 255, 0, 0, style);
- drawGraph(acelY, 0, 255, 0, style);
- drawGraph(acelZ, 0, 0, 255, style);
- pushMatrix();
- translate(qWidth, 0);
- drawGrid();
- fill(0);
- text("Rotation", 10, 34);
- drawGraph(rotX, 255, 0, 0, style);
- drawGraph(rotY, 0, 255, 0, style);
- drawGraph(rotZ, 0, 0, 255, style);
- popMatrix();
- pushMatrix();
- translate(0, qHeight);
- drawGrid();
- fill(0);
- text("Compass", 10, 34);
- //drawGraph(acelX, 255, 0, 0, style);
- //drawGraph(acelY, 0, 255, 0, style);
- //drawGraph(acelZ, 0, 0, 255, style);
- popMatrix();
- pushMatrix();
- lights();
- translate((qWidth/2)+qWidth, (qHeight/2)+qHeight);
- rotateX(radians(rotX[acelX.length-1]));
- rotateY(radians(rotY[acelY.length-1]));
- rotateZ(radians(rotZ[acelZ.length-1]));
- noStroke();
- model.draw();
- popMatrix();
- stroke(0);
- strokeWeight(3);
- line(0, height/2, width, height/2);
- line(width/2, 0, width/2, height);
- }
- void keyPressed()
- {
- switch (key) {
- case 'q':
- exit();
- break;
- default:
- break;
- }
- }
- void drawGrid()
- {
- noStroke();
- fill(255);
- rect(0, 0, qWidth, qHeight);
- stroke(0);
- strokeWeight(1);
- line(qWidth, qHeight/2, 0, qHeight/2);
- line(qWidth, (255*qHeight)/1024+qHeight/2, 0, (255*qHeight)/1024+qHeight/2);
- line(qWidth, -(255*qHeight)/1024+qHeight/2, 0, -(255*qHeight)/1024+qHeight/2);
- }
- void drawGraph(float data[], int R, int G, int B, int style)
- {
- switch(style) {
- case 0:
- for (int i=0; i<data.length; i++) {
- noStroke();
- fill(R, G, B, 255);
- ellipse(qWidth*i/data.length+qWidth/num/2, qHeight-data[i], qWidth/num, qWidth/num);
- }
- break;
- case 1:
- for (int i=0; i<data.length-1; i++) {
- strokeWeight(5);
- stroke(R, G, B);
- line(qWidth*i/(data.length-1), qHeight-data[i], qWidth*(i+1)/(data.length-1), qHeight-data[i+1]);
- }
- break;
- }
- }
And in zip form to include the model
display.zip
As this is just testing the display side, it is making fake data.
display.zip
As this is just testing the display side, it is making fake data.
1