Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

100
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda