Can anybody help me with parameters for ortho view?

Hello,

can anybody help me with the parameters so that I can see something like the below:
image

import processing.serial.*;

Serial myPort;  // The serial port

int cols = 2;
int rows = 2;
int[][] intensityGrid = new int[rows][cols];  // Intensity values for the grid

float cameraZ = 600;  // Camera Z position for depth

void setup() {
  size(600, 600, P3D);  // Set the window size and enable 3D mode
  myPort = new Serial(this, "COM7", 9600);  // Replace "COM7" with your Arduino's port
  myPort.bufferUntil('\n');
  background(255);
}

void draw() {
  background(255);

  // Set the camera position
  lights();  // Add lights for better 3D rendering
  translate(width / 2, height / 2);  // Move the origin to the center

  // Isometric view transformation
  rotateX(-PI/6);  // Rotate down 30 degrees (in radians)
  rotateY(PI/4);   // Rotate around Y-axis (45 degrees)

  // Set orthographic projection
  ortho(-width / 2, width / 2, -height / 2, height / 2, -1000, 1000); // Define the orthographic view

  float boxWidth = width / cols / 2; // Reduced width for spacing
  float boxDepth = height / rows / 2; // Reduced depth for spacing
  float separation = 20;  // Separation distance between bars

  // Loop through each cell and draw a 3D bar for each touch intensity
  for (int i = 0; i < rows; i++) {
    for (int j = 0; j < cols; j++) {
      // Calculate the position for each bar with added separation
      float x = map(j, 0, cols, -width / 4, width / 4) + (j * separation);
      float y = map(i, 0, rows, -height / 4, height / 4) + (i * separation);

      // Map the intensity to the height of the bar (min height = 10, max = 200)
      float barHeight = map(intensityGrid[i][j], 0, 1023, 10, 200);

      // Move and draw the box (bar)
      pushMatrix();
      translate(x, y, barHeight / 2);  // Move the bar into position

      fill(0, 255, 0);  // Set the fill color for the bars
      stroke(0);        // Set the stroke color (black)
      strokeWeight(2);  // Set the stroke weight (thickness)

      box(boxWidth, boxDepth, barHeight);  // Create the 3D bar
      popMatrix();
    }
  }
}

void serialEvent(Serial myPort) {
  // Read data from the serial port
  String inString = myPort.readStringUntil('\n');
  if (inString != null) {
    inString = trim(inString);

    // Debugging: Print incoming string
    println("Incoming: " + inString);

    if (inString.equals("no_touch")) {
      // Clear the entire grid if no touch is detected
      for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
          intensityGrid[i][j] = 0;  // Reset intensity
        }
      }
    } else {
      String[] data = split(inString, ',');
      if (data.length == 3) {
        int row = int(data[0]);
        int col = int(data[1]);
        int intensity = int(data[2]);

        // Debugging: Print parsed data
        println("Row: " + row + ", Col: " + col + ", Intensity: " + intensity);

        // Mark the intensity in the grid
        intensityGrid[row][col] = intensity;
      }
    }
  }
}

This is what I see when I run your code:

Is there some Arduino code that we need to have in order to help you? It would help others if you formatted your code. Copy/Paste your code in between two sets of three graeve characters by using Preformated text from the menubar of this editor. Icon looks like this </>.

1 Like

Thanks. I actually tried to use that button for my code but it does not work unfortunately or I am missing something. When I click on that nothing happensæ however other buttons like QUOTING works fine.
Yes, there is an Arduino code but it does not matter at this point. I need this four rectangle to be shown in the isometric view as I showed in my past post.

Could be a problem with boxDepth. When I do this:
box(50, 50, 50);

I get this:

Box is defined as width, height, depth, ie, box(w, h, d). You have width, depth, height.

I found it. I have to add a rotation over Z axis. Thanks by the way

  rotateX(PI/4);  //
  rotateY(0);   // 
  rotateZ(PI/4);

Concerning formatting, if the editor’s menubar is non-functional on your system you can type in two sets of three graeve characters and copy/paste your code in between. The graeve character is usually on the key to the left of ‘1’. It would look like this when done correctly (without the slashes):

\```
type or paste code here
\```
2 Likes

Your post has been edited to format the code for better readability. Please review our FAQ for guidance on posting code. Thank you!

ezgif.com-gif-maker (1)