Skip to content

Due to #6216, some of the reference examples related to cameras are broken. #6611

@inaridarkfox4231

Description

@inaridarkfox4231

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build Process
  • Unit Testing
  • Internalization
  • Friendly Errors
  • Other (specify if possible)

p5.js version

1.9.0

Web browser and version

Chrome

Operating System

Windows11

Steps to reproduce this

Steps:

  1. use orbitControl() on reference page of ortho().
  2. Then the object flies off somewhere.

https://p5js.org/reference/#/p5/ortho

Snippet:

//drag the mouse to look around!
//there's no vanishing point
function setup() {
  createCanvas(100, 100, WEBGL);
  ortho(-width / 2, width / 2, height / 2, -height / 2, 0, 500);
  describe(
    'two 3D boxes move back and forth along same plane, rotating as mouse is dragged.'
  );
}
function draw() {
  background(200);
  orbitControl();
  normalMaterial();

  translate(0,0,500);
  rotateX(0.2);
  rotateY(-0.2);
  push();
  translate(-15, 0, sin(frameCount / 30) * 65);
  box(30);
  pop();
  push();
  translate(15, 0, sin(frameCount / 30 + PI) * 65);
  box(30);
  pop();
}
2023-12-07.10-14-19.mp4

The cause is due to translate(). This causes the cube to be drawn far up in the sky, so when you rotate the camera around the viewpoint using orbitControl(), the object disappears from view.

In the current specifications, simply calling ortho() does not change the viewpoint position as it is initially set. In this case, it will remain at 800.

ortho800

Value of eye without ortho():

pers800

So, for example, by setting the far value to 1000, you can prevent the object from disappearing.

2023-12-07.10-17-16.mp4

However, I can understand why they would want to do translate(0, 0, 500). I'm just guessing since I'm not involved.
Since it is a parallel projection, I think this indicates that the appearance does not change even if the drawing position moves up or down. Probably.
However, it is also true that because of this, orbitControl() actually behaves like a bug.
Therefore, I think some kind of modification is necessary, such as cutting orbitControl(). But I don't know what kind of fix it will be.

As suggested here, I am not suggesting that you should stop using translate() and set far to 1000. The problem is the unnatural behavior of orbitControl().
However, since there is no problem with orbitControl(), I think that some other modification is necessary.

In addition, it seems that a similar problem occurs with perspective().
https://p5js.org/reference/#/p5/perspective

I don't understand why the eyeZ default is uniformly 800. Previously, the value should have been based on the canvas size.
Looks like it was changed in #6216. I don't understand why this was allowed. It feels unnatural to always have 800. I don't understand.

After that, it seems that a change was made to #6549 to add this translate(0,0,500). However, because of this, orbitControl() has become a bug. Was this the right solution to do? I don't know.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions