i got the arframe pose from arkit on ios,I want to update camera’s view Matrix and project Matrix manualy,but they are read only fileds,i can’t write them.
i saw calculateProjection api function,but i don’t konw how to use it.
any suggestions are welcome.
Hi @kendal1014 and welcome!
Here is a script on how to add your custom projection method to a camera:
var CameraProjection = pc.createScript('cameraProjection');
// initialize code called once per entity
CameraProjection.prototype.initialize = function() {
var entity = this.entity;
var camera = this.entity.camera;
this.entity.camera.calculateProjection = function(mat, typeView) {
if (camera.projection === pc.PROJECTION_PERSPECTIVE) {
mat.setPerspective(camera.fov, camera.aspect, camera.nearClip, camera.farClip, camera.horizontalFov);
} else {
var y = camera.orthoHeight;
var x = y * camera.aspectRatio;
var r = mat.data;
var left = -x;
var right = x;
var bottom = -y;
var top = y;
var near = camera.nearClip;
var far = camera.farClip;
r[0] = 1.73 / (right - left);
r[1] = 0;
r[2] = 0;
r[3] = 0;
r[4] = 0;
r[5] = 2 / (top - bottom);
r[6] = 0;
r[7] = 0;
r[8] = 0;
r[9] = 0;
r[10] = -2 / (far - near);
r[11] = 0;
r[12] = -(right + left) / (right - left);
r[13] = -(top + bottom) / (top - bottom);
r[14] = -(far + near) / (far - near);
r[15] = 1;
}
};
};
This script adds a custom projection matrix for orthographic projection.
i will try your code as soon as possible.
thanks a lot @Leonidas
1 Like
// 逐帧分析
const onFrame = timestamp => {
const frame = session.getVKFrame(canvasWidth, canvasHeight);
const camera = frame.camera;
//
const viewMatrix = camera.viewMatrix;
const projectionMatrix= camera.projectionMatrix;
}