How to get the forward direction from the Matrix4 of the camera

Hello good day, everybody. I need help of three.js mater.

I would like to move camera forward, backward, left and right focusing the target.
But I don’t use the three.js library, I’m using handmade Camera function.
And it’s only have own Matrix4 value.

So please teach me how can I get the forward direction and how can I move camera.

Hello, Mr.copy

I’m still a beginner, but I recently did something similar, so I hope this helps you in your work.

``````const e = Any// Your Matrix4
const position = new Vector3().setFromMatrixPosition(e);
const frontValue = position.z;

// MoveCamera
camera.position.z += 0.1;
// or
camera.position.z -= 0.1;
``````

This is only move the camera up, down, left, right.

Actually I want to make the camera rotate the point.

It looks like i gave the wrong answer.

i don’t know if this is what you want but
I wrote code that also changes LookAt .

``````const st = .5;
var cameraPosition = camera.position.clone();
if (move.forward) {
camera.position.copy(cameraPosition);
}
if (move.backward) {
camera.position.copy(cameraPosition);
}
if (move.right) {
var cameraRight = new Vector3();
camera.position.copy(cameraPosition);
camera.lookAt(cameraTarget); // LookAt Update
}
if (move.left) {
var cameraLeft = new Vector3();
cameraPosition.sub(cameraLeft.multiplyScalar(st));
camera.position.copy(cameraPosition);
}
``````

PS: If you want to look at a specific target when moving right or left, I think the “camera.lookAt” part in the last line can be realized with ``camera.lookAt(target.position.clone())‘’.

As I said, I don’t use three.js module, so I can’t use getWorldDirection(), and other functions.
I would like to get everything from worldmatrix (Matrix4) of the camera.

Mr.copy

understood.

I’m sorry I can’t be of any help.

to my knowledge,
It may be a little difficult to answer.

var fwdValue = 0
var tempVector = new THREE.Vector3()
var upVector = new THREE.Vector3(0, 1, 0)
this.tempVector.
set(0, 0, -fwdValue).
applyAxisAngle(this.upVector, angle);