A smooth swing?
|
Barrington John
Yorkshire guy
Join date: 17 Nov 2007
Posts: 119
|
07-30-2008 14:30
I'm trying to build a swing - using the popular and obvious method of changing the Z rotation in a loop - the core of which currently looks something like this: // float swingRad contains the desired angle of movement in radians // vector normal contains the Euler rotation of the swing when at rest integer steps=128; // the number of steps involved in the swing movement for(i=0 ; i< steps ; i++) { SetLocalRot(llEuler2Rot( <normal.x, normal.y, normal.z + swingRad*llSin((float)(i+1)/steps*TWO_PI)>)); } OK, it all works and everything, but the movement of the swing is jerky no matter how much I push the various variables - by increasing the number of steps and decreasing the angle of rotation, the swinging movement becomes slower and slower until it's way too slow and still has very noticeable jerks at each rotation change. I've tried doing all the calculations up-front and storing the results in a list in a hope to make it quicker (and hence be able to include more steps for smoother action), but that's no better, and memory doesn't allow more than a couple of hundred steps in the list. This is the case whether I keep a list of vectors or lists of Z and S coordinates. Yet somehow it's possible to get a perfectly smooth swing. There's a lovely but expensive script available here (demo swing by the vendor) - http://slurl.com/secondlife/Cantankarous/160/204/21 - but that's no-mod and doesn't seem to allow for any configuration to change the speed and angle of rotation. I've come to the conclusion that in order to get a perfectly smooth swinging action, a completely different approach to the problem is needed, but after weeks of pondering I'm still at a loss as to what that might be. Does anyone have any ideas on this?
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
07-30-2008 15:51
I've never seen a 'perfectly smooth swing', but many of the rotation models that use 4-6 steps are fairly smooth... especially if you use smaller increments on the edge movements (gives it more realistic gravity)
your other option would be target omega, but it has it's own host of problems with accumulating errors and differing views for multiple people in the area...
I knew someone was trying to make a vehicle version, but never heard anything about results...
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
07-30-2008 22:59
I did exactly what Void said in the previous post, you can check it out at my store (search clockwerks), I have it setup in my store. http://www.secondscripter.com
_____________________
My tutes http://www.youtube.com/johanlaurasia
|
Barrington John
Yorkshire guy
Join date: 17 Nov 2007
Posts: 119
|
07-31-2008 11:48
Thanks, Void and Johan - I'm still puzzled, though. Johan's swing is a good one (but nothing like as good as his wonderful clocks!) as these things go, but there are still discernible jerks during the progress of each swing. The one I linked to doesn't seem to have that effect, just a rather abrupt beginning and end to each swinging motion. In between, it's a completely smooth movement, even sitting on the swing with full-screen mouselook, and this is what I've been trying to achieve.
I started to come to the conclusion now that this probably dependent upon factors such as the viewer and the graphics card, and that maybe the jerking I'm seeing even in a nicely-tuned swinging motion is simply not being seen by anyone else. However, if I try comparisons with as many different factors as I can get - different machines, different OSes, different graphics cards and even a shorter alt to get a different seating position - I'm still seeing a big difference.
This is particularly important in this case because the drop height (fulcrum to seat) of the swing I need to make is 15m, and any jerkiness in the movement will be hugely exaggerated. I've tried standard scripts in the prototype of that swing, and riding on it is a pretty nauseating experience!
I'll ask my lady friend to come with me on a comparison tour when she logs in tonight - after all, the swing I'm trying to make is for her, to her specifications - and see if she sees what I'm seeing.
|
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
|
07-31-2008 12:03
Since the swing is unlikely to be above 800kg in weight then you could use physical movements to make it swing. You would set llSetStatus(STATUS_PHYSICAL, TRUE) to make it physical, then use functions such as llRotLookAt() to perform the smooth rotation, with llRotTarget() so you can know when to change direction.
You have to beware though that this can result in collisions but you can minimise this. Also make sure to set it back to non-physical once it stops moving =)
_____________________
Computer (Mac Pro): 2 x Quad Core 3.2ghz Xeon 10gb DDR2 800mhz FB-DIMMS 4 x 750gb, 32mb cache hard-drives (RAID-0/striped) NVidia GeForce 8800GT (512mb)
|
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
|
07-31-2008 12:41
I had a look at the swing you mentioned, and iI think it is using llTargetOmega, which is how I do my swings. Here is the code I use, it was originaly meant to wag a tail but works very nicely for a swing, just substitute your own start/stop bits in place of the linked messages. It did take a lot of searching to find this script but it does the job very well. // SMooth Tail proof-of-concept // Code by Nepenthes Ixchel // Released under the GPL, so do what you like provided it remains copy/mod/trans with this notice in. // // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details.
//user variables, set manually float MaxRot=60; //in degrees float swingtime=2.0; //seconds for a swing from centre to MaxRot integer swing = FALSE; //Swing state vector RotAxis; float RotRate;
//runtime variable rotation gBaseRot=ZERO_ROTATION;
do_swing() {
//Swing up llTargetOmega(RotAxis,RotRate,1); llSleep(-0.2+swingtime); llSetLocalRot(gBaseRot*llAxisAngle2Rot(RotAxis,MaxRot*DEG_TO_RAD));
//swing to other side llTargetOmega(RotAxis,-1*RotRate,1); llSleep(-0.2+(swingtime*2)); llSetLocalRot(gBaseRot*llAxisAngle2Rot(RotAxis,-1*MaxRot*DEG_TO_RAD));
//And back to centre llTargetOmega(RotAxis,RotRate,1); llSleep(-0.2+swingtime); llSetLocalRot(gBaseRot); }
default { state_entry() {
}
link_message(integer sender_num, integer num, string str, key id) { if(str == "swing") { state wag; } }
}
state wag {
state_entry() {
llSitTarget(<0.0, 0.0, 0.2>, ZERO_ROTATION); gBaseRot=llGetLocalRot(); RotAxis=llRot2Fwd(llGetLocalRot()); RotRate=(MaxRot*DEG_TO_RAD)/swingtime; swing = TRUE; llSetTimerEvent((swingtime * 4) - 0.6); do_swing(); }
timer() {
if(swing == TRUE) { do_swing(); } else { //stop rotation llSetTimerEvent(0.0); llTargetOmega(RotAxis,0,0); llSetRot(gBaseRot); state default; } } link_message(integer sender_num, integer num, string str, key id) { if(str == "stop") { swing = FALSE; } }
}
|
Barrington John
Yorkshire guy
Join date: 17 Nov 2007
Posts: 119
|
07-31-2008 12:44
Thank you very much, Beverly - that's exactly the effect I was looking for. It's perfect for the job.
Problem solved!
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
07-31-2008 13:51
Thanks for the compliments Barrington  Clocks do seem to be my forte. The swing project was actually for a friend of my who had been rooked by a supposed friend, so I wound up creating that swing, which seems to be one of my better selling items. I agree that there are way too many factors involved that seems to make stuff like that look different from machine to machine. http://www.secondscripter.com
_____________________
My tutes http://www.youtube.com/johanlaurasia
|
Barrington John
Yorkshire guy
Join date: 17 Nov 2007
Posts: 119
|
07-31-2008 14:09
No problem, Johan - credit where it's due.
Just to clarify for reference, the use of llTargetOmega(), as in the code Beverly posted (which I what used with very minor modifications) gives precisely the smooth effect I'd been wanting to achieve; on a 15m-high swing, it's wonderful to see.
|
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
|
07-31-2008 15:30
Credit where it is due the credit for this goes to Nepenthes Ixchel. I just posted there script :: And if you hadn't been from Yorkshire I wouldnt have posted it 
|
Dekka Raymaker
thinking very hard
Join date: 4 Feb 2007
Posts: 3,898
|
07-31-2008 16:47
Ohh I\m a Yorkshire guy too, originally from Hull 
|
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
|
07-31-2008 17:27
We are all from Yorkshire 
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
08-01-2008 07:38
and I'm Brian and my wife is Brian too 
_____________________
My tutes http://www.youtube.com/johanlaurasia
|
Celty Westwick
Registered User
Join date: 24 Jun 2006
Posts: 145
|
11-24-2008 12:32
hmm, must be think headed today (not that unusual). Am trying to do a mod of this code with simple touch rather than linked messages .. any suggestions?
|
Barrington John
Yorkshire guy
Join date: 17 Nov 2007
Posts: 119
|
11-24-2008 13:04
Wow - I must have missed the end of this thread until Celty posted and I got an alert. Yes, I'm from Yorkshire (Hull too, in fact) and still live there - good to know there are locals or kinda-locals here among thing cosmopolitan mix of SL.  Celty - what problems are you having getting a touch to work? At its simplest, you should be able to take the script as it is and add a script to detect touch and send the linked message, or simply replace the link_message() events with touch_start(), doing the same thing.
|
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
|
11-24-2008 14:58
Ok this is the original script, that did work on touch. I modifiedied for my needs  // SMooth Tail proof-of-concept // Code by Nepenthes Ixchel // Released under the GPL, so do what you like provided it remains copy/mod/trans with this notice in. // // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details.
//user variables, set manually float MaxRot=60; //in degrees float swingtime=2.0; //seconds for a swing from centre to MaxRot integer swing = FALSE; //Swing state vector RotAxis; float RotRate;
//runtime variable rotation gBaseRot=ZERO_ROTATION;
do_swing() {
//Swing up llTargetOmega(RotAxis,RotRate,1); llSleep(-0.2+swingtime); llSetLocalRot(gBaseRot*llAxisAngle2Rot(RotAxis,MaxRot*DEG_TO_RAD));
//swing to other side llTargetOmega(RotAxis,-1*RotRate,1); llSleep(-0.2+(swingtime*2)); llSetLocalRot(gBaseRot*llAxisAngle2Rot(RotAxis,-1*MaxRot*DEG_TO_RAD));
//And back to centre llTargetOmega(RotAxis,RotRate,1); llSleep(-0.2+swingtime); llSetLocalRot(gBaseRot); }
default { state_entry() { }
touch_start(integer count) {
state wag; } }
state wag {
state_entry() {
gBaseRot=llGetLocalRot(); RotAxis=llRot2Fwd(llGetLocalRot()); // maybe. RotRate=(MaxRot*DEG_TO_RAD)/swingtime; swing = TRUE; llSetTimerEvent((swingtime * 4) - 0.6); do_swing(); }
timer() {
if(swing == TRUE) { do_swing(); } else { //stop rotation llSetTimerEvent(0.0); llTargetOmega(RotAxis,0,0); llSetRot(gBaseRot); state default; } } touch_start(integer count) { swing = FALSE; }
}
If your from Hull, you may get more help  Bev
|
Naiman Broome
Registered User
Join date: 4 Aug 2007
Posts: 246
|
11-25-2008 02:13
Hello ... its possible to use and modify this script to make a good realistic floating script for a rowboat? like to wind x and y rotation to give the illusion of waves pushing and pulling the boat stability?
|
Dekka Raymaker
thinking very hard
Join date: 4 Feb 2007
Posts: 3,898
|
11-25-2008 02:18
Naiman there is a freebie linden sailing boat out there that uses Linden wind to move, maybe that would help you do something like this. I think it's called a Tako sailing boat. If you IM me in world I'll remember to send you a copy, I think it's possible to transfer it.
|
Naiman Broome
Registered User
Join date: 4 Aug 2007
Posts: 246
|
11-25-2008 02:36
No I am trying to make a rowboat , nothing pulled by wind , I already using a freebie script to move and I edited it to be less fast but I need something to make it float realistically I tought this sript cold help if I could ease the movements when it goes on aside to sde and add asecond axis swing but I did two scripts and seems to work but its a bt steppy...
|
Celty Westwick
Registered User
Join date: 24 Jun 2006
Posts: 145
|
11-25-2008 06:12
Thanks so much, for the help, perfect 
|