Please help with camera control
|
|
HtF Visconti
Registered User
Join date: 21 Jul 2006
Posts: 123
|
08-12-2006 09:37
Hi,
after a few hours of trying I am thoroughly frustrated. Especially since I never managed to be able to understand WHAT doesn't work. The errors just were not conclusive to fix it.
Here is what I was trying to do:
An avatar *lies* on a board - the board is rotated by 90°, so he is standing after the rotation is ended. Just like this would be in real life I want the avi to be looking straight up when lieing. Since the camera shouldn't move again - after it has been set once - he should then the be looking straight ahead when he is standing.
The camera would have to be at about head heigt and approx. 10 to 20 cm in front of it - looking at a apoint, say 1 or two meters directly in front of it.
No matter how I tried - I got the weirdest results. And inverting a value didn't at times even change the direction the camera was looking at. So ... I was unable to learn from my mistakesc- all errors seem to be pretty random.
I would apprechiate any help you could give me in getting this one right. What should I set Cameraoffset and Eyeoffset to, to achive the desired effect of just looking up straight.
The poseball - just in case this is important - is a bit rotated so when lieing the y-Axis is along the body, the z-Axis is from floor to ceiling and the x-Axis is left and right. I do not know (nor could I find this information in the wiki) how the axis are determined for the camera. Are they intrinsic (i.e. in front of the avatar is alway x, left and right is always y and up and down is always z) or are they relative to the avatar's position (which would mean a poseball could change the meaning of the axis). I tried to get a couple of tests done to learn this by trial and error but, alas, the results of the tests were nonconclusive.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
08-12-2006 23:43
Errr....your language is REALLY confusing me. Can you draw a picture or throw some prim arrows up and take a snapshot or something?
|
|
HtF Visconti
Registered User
Join date: 21 Jul 2006
Posts: 123
|
08-13-2006 01:58
There you go .... one thinks one has explained it so well and apparently one hasn't. It is better, I think, to simply show it. I will try to catch you online - you will understand in seconds. If this isn't possible .... here is another attempt at describing things:
Go to your bedroom and lie down. What do you see? The ceiling, I hope. Or a mirror - depending on preferences. This is what I want to do. The plain look at the ceiling/mirror. But with the default camera ... when you sit, it is positioned *behind* you so you see your own head (or the underside of your bed in this example). This will not do. The camera would have to move so, that is is *in front* of your head so that you can see the wall with no head or underside of the bed.
Since rotation will not alter the relative camera position you would then look straight at a wall if someone rotated your bed by 90°. This SL does automatically - I just have to get the first part right - looking at the ceiling with no underside of bed or head visible.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
08-13-2006 03:09
Ah. Well, first off the Wiki documentation is AGAIN lacking significantly, but the example (and what I can recall from my experimenation with vehicles) is that the positions passed to 'llSetCameraEyeOffset()' and 'llSetCameraAtOffset()' are prim-relative (they could be object-relative, but I hope not  ). So IF YOUR PRIM'S Z-AXIZ is still pointing upward, you should be able to use some positive z-value for the eye offset (go to the Edit window and choose a Local coordinate frame; you'll have to click on the prim again for the axes to reset). An appropriate offset is going to depend on the size and shape of the prim. If it is a box with height 1, use an offset around one (0.5 m above the box). If it is a box with height 2, use an offset of about 1.5 (still 0.5 m above the box). You are probably just going to have to play with this. Whatever your eye offset is, add <0, 0, 1.0> to it (AGAIN assuming your box's z-axis is pointing upward) to get the, "at offset."
|
|
HtF Visconti
Registered User
Join date: 21 Jul 2006
Posts: 123
|
08-13-2006 08:34
Ah well - glad I caught you online. And it took a while to get it right, didn't it? Thanks again bunches for your help. Without it I probably wouldn't have gotten it done and now it is perfect. And now I know why Ikept getting nonconclusive results ... if the camera changes only the *second* time you sit on something ....  I will have to fiddle with the code a bit to see if I cannot get *immediate* results.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
08-15-2006 21:38
From: HtF Visconti Ah well - glad I caught you online. And it took a while to get it right, didn't it? Yeah. Advice to others: never point the camera EXACTLY straight up or down with these funcitons. The functiona only specify a direction to point the camera and cannot specify a full orientation, so SL tries to orient the camera's local, "up," direction to be in the plane between the look direction and the global z-axis (<0, 0, 1.0>  . Thus if there is no plane between them (they point in the same or opposite directions) the code will go crazy and assign some random, "upward," direction (or maybe default rather than random). This is probably to be expected if you really think about the matter, but it can be strange to have your camera suddenly flip by 90 degrees. Anyway, the solution is to add a very small angle in the direction you want to be, "down." e.g if your feet are pointed in the negative y direction, offset the AtOffset by -0.001 in the y direction from the EyeOffset even if you'd really LIKE it to be EyeOffset+<0, 0, 1.0> or whatever. From: someone Thanks again bunches for your help. Without it I probably wouldn't have gotten it done and now it is perfect. And now I know why Ikept getting nonconclusive results ... if the camera changes only the *second* time you sit on something ....  I will have to fiddle with the code a bit to see if I cannot get *immediate* results. I believe you were setting the camera offsets as a result of the 'changed' event triggered by the avatar sitting. At that point the avatar is already sitting any any changes to the offsets using these functions will not dynamically move the camera. Since the offsets are persistent, the solution is to just change the offsets inside the 'state_entry' event handler or whatever.
|
|
InuYasha Meiji
Half Demon
Join date: 14 Mar 2005
Posts: 127
|
um trying to learn a few things here..
08-28-2006 17:31
I'm sorry if I sound nosy over here. But, I also have been trying to find a solution to this problem. It has been driving me nuts for months. I was hoping someone would share the answer with all of us new at trying to script camera control.
If you find it within your heart I would love to see the code behind it. I would love chairs that didn't show the back of my own head when I sat down. Either looking in the direction my AV is looking, or even directly at my avatar at the table eating his lunch. No matter, just not the back of my head.
Thanks, InuYasha Meiji
|
|
HtF Visconti
Registered User
Join date: 21 Jul 2006
Posts: 123
|
08-29-2006 01:20
Lol - no code, really - just two lines  I will edit this post when I am home again and post the "code" for my device - it should give you the same look you'd have when sitting. In genereal - the WIKI information seems to be a bit misleading - at least I interpreted it wrong. The following functions can be used - when sitting: llSetCameraAtOffset This defines where your camera is looking at. The default must be something like <10,0,approx. coordinate of head) If you want to see your avi from the front this should be done with a negative x index - I will have to play with it when I'm back home but <-10,0,1.5> should work. llSetCameraEyeOffset Now - this defines where the eyes are - imagine your "eyes" to be floating - they will look at the spot defined by the previous parameter and now you position them. If you want to see yourself sitting you have to move the eyes in front of you - possible at about head height. So - maybe <5,0,1.5). This will - if you are not thinking SL camera and SL eyes - bring a normal camera on a tripod to a place 5m in front of you with the lens 1.5m above the ground and centered around the avatar's y axis. The camera would then be swivelled to look at a place 10m behind the avatar, centered around the avatar's y axis and 1.5m above the ground - in other words - same height as the lens but 15m away from it.  I have to test this but I'm pretty certain that I am getting this right ... The important thing about this is that both parameters must be set on state entry! Otherwise they will only work the *second* time you sit on your object. And also - while trying - make sure you have an autoreset on the script when the inventory changes - I sometimes forget and wonder why things are not working: changed( integer change ) { // // Reset script if anything in the inventory changes // if( change == CHANGED_INVENTORY ) { llResetScript(); } }
|
|
InuYasha Meiji
Half Demon
Join date: 14 Mar 2005
Posts: 127
|
Thanks, I appreciate it, really.
08-29-2006 15:11
The Title says it all. I was really thinking there was much more to it.
-InuYasha Meiji
|
|
HtF Visconti
Registered User
Join date: 21 Jul 2006
Posts: 123
|
08-31-2006 12:18
OK - as promised (though with a bit of a delay): Looking forward, almost like in RL: llSetCameraAtOffset(<5, 0, 2>  ; llSetCameraEyeOffset(<0.5, 0, 2>  ; See yourself sitting from front: llSetCameraAtOffset(<-5, 0, 2>  ; llSetCameraEyeOffset(<5, 0, 2>  ; Bird's eye: llSetCameraAtOffset(<0.01, 0.01, -10>  ; llSetCameraEyeOffset(<0, 0, 10>  ; The small changes to x and y are somewhat neccessary so the cam doesn't mess up. Actually this is a very nice view - when used outside  Here's the script for the last one: // // Demo script for camera control //
key avatar = NULL_KEY;
default { state_entry() { // // cam code must be in state_entry to work immediately // llSitTarget(<0,0,0.5>, ZERO_ROTATION); llSetCameraAtOffset(<0.01, 0.01, -10>); llSetCameraEyeOffset(<0, 0, 10>); } changed(integer change) { avatar = llAvatarOnSitTarget(); if(change & CHANGED_LINK) { if(avatar == NULL_KEY) { // // stuff to put here when someone got up // } else { if(avatar == llAvatarOnSitTarget()) { // // stuff to put here when someone plants his behind // } } // // Reset script if anything in the inventory changes // if( change == CHANGED_INVENTORY ) { llResetScript(); } } } }
|
|
InuYasha Meiji
Half Demon
Join date: 14 Mar 2005
Posts: 127
|
I chose a diffent path
09-03-2006 13:26
I thank you again for your help. I tried it, after feeling stupid that I wasn't already enlightened by just the two lines you gave me before. After using those commands I found no comends to lock the camera inplace, hat were as easy as that. I was hoping to lock the camera and it rotations, or at least constraine the angles to maybe 45 degrees. Since there where no commands for that, I decided to go with the llRequestPermissions(sit, PERMISSION_CONTROL_CAMERA); With these settings: Mirror() { // llOwnerSay("focus_on_me" ; // say function name for debugging llClearCameraParams(); // reset camera to default vector here = llGetPos(); llSetCameraParams([ CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive CAMERA_BEHINDNESS_ANGLE, 10.0, // (0 to 180) degrees CAMERA_BEHINDNESS_LAG, 3.0, // (0 to 3) seconds CAMERA_DISTANCE, 0.5, // ( 0.5 to 10) meters CAMERA_FOCUS, here, // region relative position CAMERA_FOCUS_LAG, 0.1 , // (0 to 3) seconds CAMERA_FOCUS_LOCKED, TRUE, // (TRUE or FALSE) CAMERA_FOCUS_THRESHOLD, 0.0, // (0 to 4) meters // CAMERA_PITCH, 0.0, // (-45 to 80) degrees CAMERA_POSITION, here + <2.1,0.0,0.0>, // region relative position CAMERA_POSITION_LAG, 1.0, // (0 to 3) seconds CAMERA_POSITION_LOCKED, TRUE, // (TRUE or FALSE) CAMERA_POSITION_THRESHOLD, 0.10, // (0 to 4) meters CAMERA_FOCUS_OFFSET, ZERO_VECTOR // <-10,-10,-10> to <10,10,10> meters ]); }Now I thought with a lock on FOCUS and POSITION that I would be all set, or the best would be if I ould lock the angle in which it was allowed to move. I would like to be able to move the direction the camera looks only a few degrees left-right and up-down. But instead people are allowed to move it all around, and the whole camera in all directions no matter what. If there is no way to do that, is there a way to detect when someone uses the camera controls to move the camera that it returns the camera view to the avatar? Since I can't seem to get the locks to actually hold when the avatar uses the camera control buttons, I might as well give it back to the avatar view. Thanks again for all the help. -InuYasha Meiji 
|
|
InuYasha Meiji
Half Demon
Join date: 14 Mar 2005
Posts: 127
|
I think I stumbled across another bug in SL!
09-03-2006 14:58
My code does work part way in my script. It does lock the focus and the position of the camera if you use the arrows on the keyboard or the A, S, W, and Z keys, What it seems to miss is when the little Camera controls under the VIEW menu are engaged. Thos will let you move al over the place. And for some reason ruin my return to the avatar view.
Am I right, or is there a way to kill the function of those VIEW/Camera Controls? Or detect when they might be used.
-InuYasha Meiji
|
|
HtF Visconti
Registered User
Join date: 21 Jul 2006
Posts: 123
|
09-05-2006 07:23
Hi, I'm not sure (just a green scripter myself) but I have not yet found a way to lock the camera HUD controls. Actually ... the question is what you want to do. If you want to help your visitors/victims/whatever to get a proper view on default you can set the cam parameters. Instead of the usually less then useful default cam you can have them see the way you intend to let them see. This can, however, be broken by the user if he or she uses the HUD - and to a certain degree I believe it is their right.  A single tap on one of the arrow buttons will restore the default view you set. So - there is - to the best of my (limited) knowledge - no 100% sure way to totally control avatars - at least not those, *not* owned and commanded by yourself. There are good reasons for this - I can imagine how many people would feel annoyed if they were 100% under foreign control and couldn't do a thing themselves. You can provide a default view and you can hope they enjoy it so much they do not change the cam but you cannot deny them the right/ability to do so. To the best of my knowledge there is also no way to detect camming/HUD cam control using. What I have not yet tried is to force people into mouselook and use a timer to do it over and over again. I never tried because I personally wouldn't like being subjected to this but maybe you can try this? With mouselook on there are very few options available.
|