3d first person/ free space cam with mouse interaction


Can someone please give me a hi t how to archieve a fps 3d cam with openframework? Since 2 days i try to make it work but im still unable to do it… I was already reading a lot of articles regarding dot product and so on but i just cant get my head arround…

Thank you best regards

just use ofCamera and move it when there’s a key press by using camera.move(x,y,z)

Thank you for your answer but unfortunatelly it doesnt fix my issue :(. The problem is still the same. e.g. If I start rotating the camera around the x axis and after I want to move along the z axis later on the camera will follow the global z axis but I want that it follows according to the local object coordinate system. To simplify things its like I want to look up in an angle of 45° and than I want to move along an 45° vector. In 2d I would do something like this:

position.x += cos(45);
position.y += sin(45);

This is just an example of course. In 2d i can handle this requirement without an problem but in 3d I still stuck…

Any suggestion?
Thank you!

you can also use dolly() if you are applying rotations and it’ll move along the local z axis

1 Like

Hey Arturo,

Thanks for your help !!!
Happy Easter

Hi. Is there a way to move along the x axis depending on the actual rotation angle?

This is what I got. When I drag the mouse the position changes keep taking initial rotation angle as reference. In the video I’m just pressing W and S keys to move forward and backward:

I figured it out:

void ofApp::update(){

	// Calculate player position and rotation
	position.z += -(wsad[0] + wsad[1]) * cos(rotation.x*RADS);
	position.x += (wsad[0] + wsad[1]) * sin(rotation.x*RADS); 

	float alpha = (180 - rotation.x)*RADS;
	position.z += -(wsad[2] + wsad[3]) * sin(alpha);
	position.x += (wsad[2] + wsad[3]) * cos(alpha);

	cam.setPosition(position.x, position.y, position.z);
	cam.setOrientation(ofVec3f(rotation.y, -rotation.x, 0));


void ofApp::keyPressed(int key) {
	switch (key)
	case 'w':
		wsad[0] = 10;
	case 's':
		wsad[1] = -10;
	case 'a':
		wsad[2] = 10;
	case 'd':
		wsad[3] = -10;
1 Like