论坛

由用户创建的信息 chdcchris
29 October 2015 18:57
I'm working on another project atm, but will continue later with this project.

So once I work on it again I will try your suggestions and let you know.

Thanks for everything!
26 October 2015 16:57
Dear Evgeny,

Thanks for the help. I have inserted your block of code and I didn't know what to put instead of cam_quat, so I looked in the cam_anim js file and it used m_transform.get_rotation(camobj). So now my code looks like this:


function target_camera_action(){

var camobj = m_scenes.get_active_camera();
var old_pivot = _cam_anim.current_target;;

if(m_cam.is_eye_camera(camobj)){
console.log("was eye cam");
var cam_eye = m_cam.get_eye(camobj, _vec3_tmp);
var view_vector = m_util.quat_to_dir(m_transform.get_rotation(camobj), m_util.AXIS_MY,_vec3_tmp);
old_pivot = m_vec3.scaleAndAdd(cam_eye, view_vector, 900, view_vector);
} else {
console.log("was target cam");
old_pivot = _cam_anim.current_target;
}

m_app.set_camera_move_style(m_cam.MS_TARGET_CONTROLS);

m_cam.set_pivot(camobj, old_pivot);
}


I started with 100 as you recommended, but that didn't seem enough. I tried 100.000 and that was close to the real thing, but still not as smooth. Once you take over the camera, the pivot will be as far as 100.000 away. This is kindof a problem for me.

So I tried 900. It is still way better as before your code, but still not perfect. The target is still sort of too far away, but it is reasonable.

I understand that it is the recalculated pivot distance that causes this to happen. Would there be any solution to the pivot being too far away once you take over the camera?

Thanks again
24 October 2015 01:07
_cam_anim.current_target contains the last known pivot. Once it switches to EYE it will still contain the old pivot thats why it works.

But if EYE camera is used to look, _cam_anim.current_target is an old position/rotation, so it jumps to the old one. I need the new one from the EYE.

I know that only the target camera has got pivot property, but I'm trying to find a way to keep the TARGET camera in the exact same position/rotation as the previous EYE camera

If you look at my demo and use EYE to look around, and then go to Next, you see it jumps to the old pivot.

23 October 2015 17:01
Dear Roman,

Thank you for the explanation and example.
I tried your example, but to me it seems like the target can move past the translation limit and then jumps back. This is better then before but not exacly what I need.

What I needed was a realtime version of that, so that you can never ever look under a certain plane.

I have combined your example together with what I already had. This works for me:


start_limit_check() ;

function start_limit_check() {
var cam_obj = m_scenes.get_active_camera();
var e_sensor = m_controls.create_elapsed_sensor();

var logic_func = function(s) {
return true;
};

var update = function(cam_obj, id, pulse) {
if(m_cam.is_hover_camera(cam_obj) == false && m_cam.is_eye_camera(cam_obj) == false){
var cam_target = m_cam.get_pivot(cam_obj);
var new_vec3 = m_vec3.fromValues(cam_target[0], 10, cam_target[2]);

if (cam_target[1] <= 10) {
m_cam.set_pivot(cam_obj,new_vec3);
console.log(new_vec3);
}
}
};

m_controls.create_sensor_manifold(cam_obj, "random", m_controls.CT_CONTINUOUS, [e_sensor], logic_func, update);
}


It seems that all I needed was a good update function (I'm used to the Unity's update method).

I am not completely sure if this is the best way to do it and if it has a performance impact. I'm on a very fast pc, so I can't test the performance impact.

23 October 2015 11:50
Hey,

I have been searching for this quite a while, but I can't seem to find a way to do this.

Is there a way to limit the Z translation position of the TARGET camera type in panning mode?

I have tried to use the limit_object_position function from the furniture demo to limit the camera OBJECT3D, but that didn't work.

Thanks.
20 October 2015 16:00
Here is my new example (Red/Green button is disabled):

link

As you can see, the animation is smooth only if you don't look around with the EYE camera.
But if you look around and then navigate to the next location, it will use the old pivot and jump to it.

What I have tried until now is this:

Works for TARGET to TARGET because I can use get_pivot:

m_app.set_camera_move_style(m_cam.MS_TARGET_CONTROLS);
////////some statements inbetween////////////
var old_pivot = m_cam.get_pivot(camobj, _cam_anim.current_target);
m_app.set_camera_move_style(m_cam.MS_TARGET_CONTROLS);
m_cam.set_pivot(camobj, old_pivot);


The next code doesn't work:

m_app.set_camera_move_style(m_cam.MS_EYE_CONTROLS);
////////some statements inbetween////////////
var old_pivot = m_cam.get_pivot(camobj, _cam_anim.current_target); //No error but code execution will stop
m_app.set_camera_move_style(m_cam.MS_TARGET_CONTROLS);
m_cam.set_pivot(camobj, old_pivot);


This does work but instantly rotates the camera to the old pivot.

m_app.set_camera_move_style(m_cam.MS_EYE_CONTROLS);
////////some statements inbetween////////////
var old_pivot = _cam_anim.current_target;
m_app.set_camera_move_style(m_cam.MS_TARGET_CONTROLS);
m_cam.set_pivot(camobj, old_pivot);


The user can look around, so if I use the old pivot point before switching to EYE it will look at the old again and not use the new one based on the target the eye looks at.




20 October 2015 11:51
Thank you very much for your time!

This seemed to have worked for switching TARGET to TARGET. I use the get_pivot() method to get the pivot of the old TARGET and save it to set_pivot after changing camera styles.

I'm almost there, but how would I get the pivot point of the current EYE camera, because the get_pivot method seems to crash the code when the current camera style is EYE. Probably because it doesn't have a pivot right?

I tried _cam_anim.current_target, but that seems to instantly rotate to the current target, as expected ofcourse.

How would you calculate or get the current pivot of the EYE camera if the user rotated the camera?

thanks!

19 October 2015 12:30
I have prepared an example scene and I have left only the important elements in to show my problem.

link

On top of the screen you see a simple menu. If you click on the right orange button it will go to the next camera location, same with the left button for previous.

In the bottom left corner you see a green button, which u can toggle if you click on it. If the button is green it will be smooth, but if the button is red you will see that the camera quickly looks at the target, but slowly moves to the eye location.

When the red color is on it will execute this code:

function move_style(){
console.log("change to target");
m_app.set_camera_move_style(m_cam.MS_TARGET_CONTROLS);

(function delay () {
setTimeout(function () {
//console.log(_delta_target);

if(_delta_target < 0.02){
m_app.set_camera_move_style(m_cam.MS_EYE_CONTROLS);
console.log("change to eye");
} else {
delay();
}

}, 100)
})();
}


As you can see, it changes the camera move style to TARGET everytime a user clicks on next. Once it arrives it will change to EYE.

When the green color is active, it only uses the camera animation function, but doesn't change the camera's styles (it doesn't execute this function). This is when it's smooth.
16 October 2015 16:01
I understand sorry. I will make an example scene.

Thanks :)
16 October 2015 15:28
Thanks for the quick response!

Sorry if I didn't explain it well (English is not my native language)

The camera does stay on the right rotation/orientation when it arrives and changing the camera type works well with EYE camera type (HOVER is not really important for us right now).
That is only when it's standing still.

My problem however is changing the camera type from lets say EYE to TARGET. The very next animation will not be smooth sadly. The animation after that will be, as it was already a TARGET camera.

In my script. Everytime the user clicks on next, "m_app.set_camera_move_style(m_cam.MS_TARGET_CONTROLS);" will be executed before camera animation. So the animation is smooth if the camera is already MS_TARGET_CONTROLS but not when it was m_cam.MS_EYE_CONTROLS.

edit: I made a mistake in the above explanation. It seems that not only when changing from EYE to TARGET but also from TARGET to TARGET makes this occur. It does indeed reset something, but what I
don't understand is why does the switch affect the camera animation.

It looks like once there is a delay between TARGET to TARGET and the animation, it will go smoothly.


STATIC typed camera would be an option for some animations in the scene, but not for all, since we want the user to be able to take over the camera.