Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
camera has a sort of fisheye

I am toying around with p5js, and while generating some cubes, it appeared to me that the "camera" the "render" deforms around the edges, kind of like a fisheye to me.

side to side cubes

Here is the bit of code :

function setup() {
    createCanvas(800, 850, WEBGL);
    angleMode(DEGREES);
  }
  
  function draw() {
    //background color
    background("#ece5d8");

    //don't draw faces, only vertices
    noFill();
    //color of the strokes
    stroke(0);

    //save the following state
    push();
    //we save that we don't draw, that we face the edge, and that we're at the left

      //start drawing at the left
      translate(-200, 0, 0);

      //draw our cubes
      for (let i = 0; i < 10; i++) {
        push();
          translate(i * 150, 0, 0);
          box(150);
        pop();
      }
    pop();
  }

I only translate and never rotate or anything, why aren't the cube perfectly aligned with their edges, and why is it curving ?

Thanks

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In WEBGL mode the default camera projection is perspective(). The edges don't curve like they would with fish-eye lens, they are straight, but the edge dimensions change based on depth.

If you want to render the cubes and have the edges simply use a parallel projection using ortho():

function setup() {
    createCanvas(800, 850, WEBGL);
    ortho(-width / 2, width / 2, height / 2, -height / 2, -3000, 3000);
    angleMode(DEGREES);
  }
  
  function draw() {
    //background color
    background("#ece5d8");
    orbitControl();
    //don't draw faces, only vertices
    noFill();
    //color of the strokes
    stroke(0);

    //save the following state
    push();
    //we save that we don't draw, that we face the edge, and that we're at the left

      //start drawing at the left
      translate(-200, 0, 0);

      //draw our cubes
      for (let i = 0; i < 10; i++) {
        push();
          translate(i * 150, 0, 0);
          box(150);
        pop();
      }
    pop();
  }
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.1/p5.min.js"></script>

Note Based on the dimensions and positioning of the boxes I've increased near/far clipping distances (last arguments of ortho()). I've also added orthoControl(): this is totally optional, but helpful to illustrate the ortho view (since by default a front view will look the same as using 2D rect() calls )

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!