Forum

Camera zoom limits

07 December 2017 18:34
I've a scene where the camera goes to several spots and where the focus goes to another Target.
The camera is in Target mode. I want to set several camera limits (horizontal panning limits/zoom limits/e.g.).
However I can't seem to get it to work. I tried it with nodes which will activate upon buttonclick. But no luck.

Is it possible to set different (zoom) limits e.g. in Javascript when a camera has reached his destination and looks at the target? The following code is the button action for the moment:

   var test_1 = create_button("Start");
    test_1.onclick = "Start";
    controls_container.appendChild(test_1);
	test_1.className = "btn 1";
	test_1.addEventListener("click", function(e) {
	
		var cam_obj = m_scenes.get_active_camera();

        var final_cam_pos_obj = m_scenes.get_object_by_name("cam_2");
        var final_target_obj = m_scenes.get_object_by_name("tar_2");

        rotate_final_cam_pos_object_to_final_target(final_cam_pos_obj, final_target_obj);

        m_cam.static_setup(cam_obj);

        var set_target_mode = function() {
            var target = m_trans.get_translation(final_target_obj, _vec3_tmp2);
            m_cam.target_setup(cam_obj, {pivot : target});
        }

        m_cam_anim.move_camera_to_point(cam_obj, final_cam_pos_obj, 5.0, 50, set_target_mode);
		m_logic_n.run_entrypoint("Scene", "scene1");
    }, false);


Much appreciated!
13 December 2017 15:07
Is it possible to set different (zoom) limits e.g. in Javascript when a camera has reached his destination and looks at the target? The following code is the button action for the moment:
Helllo,

sorry for the delayed answer.
Zoom limits for target camera are called distance limits in b4w and there are dedicated api method and logic node properties to configure them
Blend4Web Team - developer
Twitter
LinkedIn
24 July 2018 12:16
Zoom limits for target camera are called distance limits in b4w and there are dedicated api method and logic node properties to configure them

Okay, I did play a lot with it and I come up with the following problem(s)/findings:

When going from scene to scene (with the following line) it works great when you don't (or just a little) move the camera:
m_cam_anim.move_camera_to_point(cam_obj, final_cam_pos_obj, 25.0, 50, set_target_mode);

However, when you move the camera a lot (like 180 degrees) it takes forever to move to the next scene.
So it would be great if you can set a fixed time to move towards the next target instead of only the speed.

But for now, camera limitations could be a solution. However, again a problem.
My .js don't know if the camera movement is finished, so it sets the camera BEFORE the camera movement is finished. When the script/node is runned before the movement is finished, the node doesn't work at all and nothing happens.
So I tested a button that fires the camera limits node manually. Works like a charm:


Is it possible to catch a callback (from the model) that when the camera movement is finished, the script will continue and not before?
24 July 2018 18:49
However, when you move the camera a lot (like 180 degrees) it takes forever to move to the next scene.
So it would be great if you can set a fixed time to move towards the next target instead of only the speed.
I don't understand. If you can set any speed, you should be able to set a speed that matches your time requirement.


My .js don't know if the camera movement is finished, so it sets the camera BEFORE the camera movement is finished.
No, your .js knows exactly when the camera movement has finished because at that point it fires the callback (in your case: "set_target_mode").

I think you may have some confusion in your code about timing and what happens when:
        rotate_final_cam_pos_object_to_final_target(final_cam_pos_obj, final_target_obj);

        m_cam.static_setup(cam_obj);

        var set_target_mode = function() {
            var target = m_trans.get_translation(final_target_obj, _vec3_tmp2);
            m_cam.target_setup(cam_obj, {pivot : target});
        }

        m_cam_anim.move_camera_to_point(cam_obj, final_cam_pos_obj, 5.0, 50, set_target_mode);
        m_logic_n.run_entrypoint("Scene", "scene1");

With this code, you start 4 things right away:

- rotate_final_cam_pos_object_to_final_target (call to a custom function you did not quote)
- static_setup
- move_camera_to_point
- run_entrypoint

All of this happens immediately. Then, when move_camera_to_point() has finished, it calls the callback "set_target_mode", which contains a call to m_cam.target_setup.

If you want things to happen after move_camera_to_point() has finished, you need to put those things into the callback ("set_target_mode"), not outside of it.

Also, you don't need to call a Logic Node with run_entrypoint at all. Not only does this make the whole thing a lot harder to read for you, but you already have a target_setup call in your callback that can set the camera limits, you only need to tell it to do so:

Look at the API:

target_setup(camobj, params) LINK

Where params contain the params you want: LINK

So, let's say you want to set the horiz.rot and vert.rot params from your Logic Node, you just put that in your function call:
m_cam.target_setup(cam_obj, 
{
pivot : target, 
horiz_rot_lim: {left: m_util.deg_to_rad(-10), right: m_util.deg_to_rad(10), camera_space:true}, 
vert_rot_lim: {down: m_util.deg_to_rad(15), up: m_util.deg_to_rad(-20), camera_space:true}
}
);

I cannot test this, but since the params apparently demand radians (not degrees), I had to add deg_to_rad(), so you need to include the M_UTIL module at the top of your script.
 
Please register or log in to leave a reply.