# How to setup camera from a view matrix

**URL:** <https://forum.babylonjs.com/t/how-to-setup-camera-from-a-view-matrix/24801>\
**Category:** Questions\
**Created:** [October 25, 2021, 11:24am UTC](https://forum.babylonjs.com/t/how-to-setup-camera-from-a-view-matrix/24801 "2021-10-25T11:24:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnrn](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dnrn/32/4723_2.png) [@dnrn](https://forum.babylonjs.com/u/dnrn)\
**Post date:** [October 25, 2021, 11:24am UTC](https://forum.babylonjs.com/t/how-to-setup-camera-from-a-view-matrix/24801/1 "2021-10-25T11:24:14Z")

</div>

I am working on a project where we are using OpenCV to compute a pose. From the pose we get in OpenCV have I created the view matrix. I would now like to use add some 3D model(s) in BabylonJS but are a bit lost on how I can setup a camera from a view matrix.

I would also like to dynamic update the camera when a new pose arrive.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [October 25, 2021, 12:43pm UTC](https://forum.babylonjs.com/t/how-to-setup-camera-from-a-view-matrix/24801/2 "2021-10-25T12:43:49Z")

</div>

your view matrix contains position and rotation which you can use directly on your camera.  
What you can do (instead of forcing the camera’s view matrix) is construct a babylon matrix from the view matrix and decompose ([Matrix | Babylon.js Documentation](https://doc.babylonjs.com/typedoc/classes/babylon.matrix#decompose)) it to the camera’s position and rotation(Quaternion). this will update the camera’s transformation according to the matrix provided

---

<div class="post-metadata">

**Author:** ![dnrn](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dnrn/32/4723_2.png) [@dnrn](https://forum.babylonjs.com/u/dnrn)\
**Post date:** [October 26, 2021, 6:44am UTC](https://forum.babylonjs.com/t/how-to-setup-camera-from-a-view-matrix/24801/3 "2021-10-26T06:44:30Z")

</div>

Thanks for the quick answer!  
It was what I was looking for.

I forgot to do a cast from the base Camera to FreeCamera, so poor Typescript wasn’t to much help.
