Perspective 2 points

Hello,
I found this to build a camera view with 2 perspective points, but I don’t know what is p and q in the matrix and what they correspond to in Babylon.

In advance, thank you for your help !

Hello and welcome to the Babylon community! :smiley:

I think this video does a wonderful job of explaining perspective projection: Lecture 07: Perspective Projection and Texture Mapping (CMU 15-462/662) - YouTube

Usually, you don’t have to manually calculate this matrix in Babylon, as the Camera class does that for you: Babylon.js/camera.ts at master · BabylonJS/Babylon.js (github.com) . If you want to implement your own projection matrix, then you’ll have to subclass Camera to override the getProjectionMatrix method.

Hello, thanks for this, but when I try to use the perspective transformation, a part of my screen disappears or is not clickable.

Can you provide us with a playground.babylonjs.com reproduction of your code so we can take a better look?

Yes, of course, https://playground.babylonjs.com/#BET8RW#1
I let you try to change the var theta (the angle between Z1 and Z2)

And I’m using this too : The Mathematics of Two- and Three-Point Perspective

This code would work better to set your own projection: https://playground.babylonjs.com/#BET8RW#3 and it looks like your plane currently intersects with the box.

It’s not going to work, because if I freeze the matrix, it won’t be able to be modified afterwards, which I’m doing.

You can always unfreeze, update and freeze again

Calling back freezeProjectionMatrix should be enough to replace it normally

I will try, thanks for answer.

It’s working :+1:, but my initial questions isn’t resolve

I let @carolhmj check this part :wink:

What exactly is your initial question? What is a perspective matrix? Have you watched the video on perspective projection I linked?

Hello @emaf just checking in, was your question answered?

Hello,
To resume try to reproduce this from sketchup in babylon

You could also set your projection matrix at a custom shader, so it ignores the matrix that comes from the camera: Basic ShaderMaterial | Babylon.js Playground (babylonjs.com)

Actually, i set the projectionMatrix of the Camera like this

//Where q is the angle between Z1 and Z2

new BABYLON.Matrix.FromArray([
					1, 0, 0, sin(q)/this.distance,
					0, 1, 0, 0,
					0, 0, 1, cos(q)/this.distance,
					0, 0, 0, this.scale
				])

I found this to set Camera projection matrix of multi transformation in function of number of Vanishing points
https://people.eecs.berkeley.edu/~barsky/perspective.html#rotate%20axis%202%20points