Forum

mouse controls

20 October 2015 21:00 #4511
i was wonder if it was possible to control the camera using buttons on the canvas, i want to create a set of controls. left right up down in out, that when a user clicks simulate moving a hover camera. for example left would do the same as left button, up same as up bottom, and in same as mousewheel in. i tried using the move_local but it doesn't work the same, any ideas?
21 October 2015 08:10 #4512
Here is a demo that uses buttons in a UI type overlay. The source files for this are in your SDK (blend4web\deploy\tutorials\examples\cartoon_interior).
With a little programming, I'm sure it can be done.
~Will
Blend4Web Videos
https://www.youtube.com/channel/UCp6x8JP7oCiiTjbJorPPMsQ/videos
21 October 2015 16:07 #4520
Hi, sdc44! You can use hover_cam_set_translation function or set_hover_pivot to translate the camera in the world space. Both methods do the same work but affect different points (translation or pivot).

For zooming you should use rotate_camera or rotate_hover_camera.

This should also be useful to perform rotations correctly: Camera Controls API
Blend4Web Team
26 October 2015 16:06 #4579
Thanks i ended up using the controls you talked about. Is there anyway to make the movement not so choppy, i provided the interface to move in increments like i wanted, but i was hoping to make the camera move smoothly to the new point,
26 October 2015 16:43 #4580
also is there a way that i can tell which way the camera is facing and than move the camera left/right/forward/back relative to that, i understand how to move the camera using
m_cam.translate_hover_cam_v(camera, pos);
But if the camera rotates how do i know which direction to move the camera left?
27 October 2015 11:27 #4613
Ответ на сообщение пользователя sdc44
Thanks i ended up using the controls you talked about. Is there anyway to make the movement not so choppy, i provided the interface to move in increments like i wanted, but i was hoping to make the camera move smoothly to the new point,
We have smoothing in the "Viewer" app for mouse actions. It's done via the "app.js" addon but we don't currently provide any API methods. Therefore some coding is needed.

You should take a look at this callback - this is how it's done for mouse translations/rotations. The code is a bit unwieldy but the main idea is simple:
1) In this function we have "dest_x_mouse" value which means the total amount of "movement".
2) We get the amount of time elapsed since the previous frame:
var value = m_ctl.get_sensor_value(obj, id, 0);

And use it to calculate the amount of "movement" for the current frame:
var x_mouse = m_util.smooth(dest_x_mouse, 0, value, smooth_coeff_rot_trans_mouse());
dest_x_mouse -= x_mouse;
...

3) Then we move camera somehow according to the "x_mouse" value, for example:
trans_hover_cam_horiz_local(obj, m_util.AXIS_X,
                            (x_mouse + x_touch)
                            * HOVER_MOUSE_TOUCH_TRANS_FACTOR);



also is there a way that i can tell which way the camera is facing and than move the camera left/right/forward/back relative to that
There is the get_camera_angles function which returns azimuth and elevation angles for the given camera. They can be used to determine the orientation in the world space.

Also you can extract the camera rotation quaternion and convert one of the camera local axes to a world space to calculate the direction of desirable moving:
var quat = transform.get_rotation(cam, _vec4_tmp);
var z_world_cam = util.quat_to_dir(quat, m_util.AXIS_Z, _vec3_tmp);



m_cam.translate_hover_cam_v(camera, pos);
Beware! You are using the deprecated method. It also spams in the console about this.
Blend4Web Team
30 October 2015 17:02 #4685
Also you can extract the camera rotation quaternion and convert one of the camera local axes to a world space to calculate the direction of desirable moving:

var quat = transform.get_rotation(cam, _vec4_tmp);
var z_world_cam = util.quat_to_dir(quat, m_util.AXIS_Z, _vec3_tmp);


What do you mean by this, doing this i get a vector, and im assuming its the directional vector the camera is pointing, but from this how do i know when i click a direction, which direction to translate on?
30 October 2015 17:39 #4687

What do you mean by this, doing this i get a vector, and im assuming its the directional vector the camera is pointing, but from this how do i know when i click a direction, which direction to translate on?
An appropriate vector is needed here. For example, if we need to know which way is left from the camera's current point of view we can take the local negative X axis and convert it:
var quat = transform.get_rotation(cam, _vec4_tmp);
var left_dir = util.quat_to_dir(quat, m_util.AXIS_MX, _vec3_tmp);

Blend4Web Team
 
Please register or log in to leave a reply.