Difference between revisions of "LlGetEnergy"

From Second Life Wiki
Jump to navigation Jump to search
m
 
(4 intermediate revisions by 2 users not shown)
Line 8: Line 8:
|caveats
|caveats
|constants
|constants
|examples=<lsl>
|examples=<source lang="lsl2">
// This script tests the energy use of most of the physics functions
// This script tests the energy use of most of the physics functions
// 18 March 2008 by Karzita Zabaleta
// Last version: 07 October 2009 by Gianni Lupindo
 
vector homePos;
vector homePos;
integer timerCount = 0;
integer timerCount = 0;
integer testCount = 0;  
integer testCount = 0;
 
string space = "  ";
// move more than 10m
// move more than 10m
moveTo(vector origin, vector destination) {
moveTo(vector origin, vector destination) {
Line 28: Line 29:
     llSetPrimitiveParams(params);
     llSetPrimitiveParams(params);
}
}
 
returnHome()
returnHome()
{
{
    llSetTimerEvent(0);
     llSetStatus(STATUS_PHYSICS, FALSE);
     llSetStatus(STATUS_PHYSICS, FALSE);
     llSleep(0.2);
     llSleep(0.2);
     moveTo(llGetPos(),homePos);
     moveTo(llGetPos(),homePos);
    llSetTimerEvent(0);
     llSetRot(ZERO_ROTATION);
     llSetRot(ZERO_ROTATION);
}
}
 
default
default
{
{
Line 48: Line 49:
     }
     }
     touch_start(integer n) {
     touch_start(integer n) {
        space = "  ";
         do {
         do {
           llSleep(0.5);
           llSleep(0.5);
Line 54: Line 56:
         llSetStatus(STATUS_PHYSICS,TRUE);
         llSetStatus(STATUS_PHYSICS,TRUE);
         llSetTimerEvent(1.0);
         llSetTimerEvent(1.0);
       
         vector impulse = <0,0,5>*llGetMass();
         vector impulse = <0,0,5>*llGetMass();
         if (testCount == 0) {
         if (testCount == 0) {
             llOwnerSay("ApplyImpulse");
             llOwnerSay("ApplyImpulse (test 0)");
             llApplyImpulse( impulse, TRUE );  
             llApplyImpulse( impulse, TRUE );  
         } else if (testCount == 1) {
         } else if (testCount == 1) {
             llOwnerSay("ApplyRotImpulse");
             llOwnerSay("ApplyRotImpulse (test 1)");
             llApplyRotationalImpulse( impulse, TRUE);
             llApplyRotationalImpulse( impulse, TRUE);
         } else if (testCount == 2) {
         } else if (testCount == 2) {
             llOwnerSay("PushObject");
             llOwnerSay("PushObject (test 2)");
             llPushObject(llGetKey(), impulse, ZERO_VECTOR, TRUE);  
             llPushObject(llGetKey(), impulse, ZERO_VECTOR, TRUE);  
         } else if (testCount == 3) {
         } else if (testCount == 3) {
             llSetForceAndTorque( ZERO_VECTOR, ZERO_VECTOR, TRUE );  
             llSetForceAndTorque( ZERO_VECTOR, ZERO_VECTOR, TRUE );  
             llOwnerSay("Force");
             llOwnerSay("Force (test 3)");
             llSetForce( impulse, TRUE );  
             llSetForce( impulse, TRUE );  
         } else if (testCount == 4) {
         } else if (testCount == 4) {
             llSetForceAndTorque( ZERO_VECTOR, ZERO_VECTOR, TRUE );  
             llSetForceAndTorque( ZERO_VECTOR, ZERO_VECTOR, TRUE );  
             llOwnerSay("Torque");
             llOwnerSay("Torque (test 4)");
             llSetTorque( impulse, TRUE );  
             llSetTorque( impulse, TRUE );  
         } else if (testCount == 5) {
         } else if (testCount == 5) {
             llSetForceAndTorque( ZERO_VECTOR, ZERO_VECTOR, TRUE );  
             llSetForceAndTorque( ZERO_VECTOR, ZERO_VECTOR, TRUE );  
             llOwnerSay("Force and Torque");
             llOwnerSay("Force and Torque (test 5)");
             llSetForceAndTorque( impulse, impulse, TRUE );  
             llSetForceAndTorque( impulse, impulse, TRUE );  
         } else if (testCount == 6) {
         } else if (testCount == 6) {
             llSetForceAndTorque( ZERO_VECTOR, ZERO_VECTOR, TRUE );  
             llSetForceAndTorque( ZERO_VECTOR, ZERO_VECTOR, TRUE );  
             llOwnerSay("MoveToTarget");
             llOwnerSay("MoveToTarget (test 6)");
             llMoveToTarget( impulse, 0.4 );  
             llMoveToTarget( impulse, 0.4 );  
         } else if (testCount == 7) {
         } else if (testCount == 7) {
             llStopMoveToTarget ( );  
             llStopMoveToTarget ( );  
             llOwnerSay("RotLookAt");
             llOwnerSay("RotLookAt (test 7)");
             llRotLookAt( llEuler2Rot(impulse*DEG_TO_RAD), 0.4, 0.4 );  
             llRotLookAt( llEuler2Rot(impulse*DEG_TO_RAD), 0.4, 0.4 );  
         } else if (testCount == 8) {
         } else if (testCount == 8) {
             llStopLookAt ( );  
             llStopLookAt ( );  
             llOwnerSay("LookAt");
             llOwnerSay("LookAt (test 8)");
             llLookAt( impulse, 0.4, 0.4 );  
             llLookAt( impulse, 0.4, 0.4 );  
         } else if (testCount == 9) {
         } else if (testCount == 9) {
             llStopLookAt ( );  
             llStopLookAt ( );  
             llOwnerSay("Hover Height");
             llOwnerSay("Hover Height (test 9)");
             llSetHoverHeight( 5.0, TRUE, 0.5);
             llSetHoverHeight( 5.0, TRUE, 0.5);
         } else if (testCount == 10) {
         } else if (testCount == 10) {
             llSetHoverHeight( 0, TRUE, 0.5);
             llSetHoverHeight( 0, TRUE, 0.5);
             llOwnerSay("Ground Repel");
             llOwnerSay("Ground Repel (test 10)");
             llGroundRepel( 5, TRUE, 0.5);
             llGroundRepel( 5, TRUE, 0.5);
         } else if (testCount == 11) {
         } else if (testCount == 11) {
             llGroundRepel( 0, TRUE, 0.5);
             llGroundRepel( 0, TRUE, 0.5);
             llOwnerSay("Buoyancy");
             llOwnerSay("Buoyancy (test 11)");
             llSetBuoyancy( 0.997 );
             llSetBuoyancy( 0.997 );
         } else {
         } else {
             llSetBuoyancy( 0.0 );
             llSetBuoyancy( 0.0 );
             llOwnerSay("Done");
             llOwnerSay("Done");
            testCount=(-1);
         }
         }
        llOwnerSay((string)timerCount+". energy    :"+(string)llGetEnergy());
         timerCount = 0;
         timerCount = 0;
         testCount++;
         if (testCount != 12) {
            llOwnerSay((string)timerCount+". Energy:    "+space+(string)llGetEnergy());
            testCount++;
        }
        else {
            testCount = 0;
            returnHome();
        }
     }
     }
     timer() {
     timer() {
        llOwnerSay((string)timerCount+". energy    :"+(string)llGetEnergy());
         timerCount++;
         timerCount++;
         if (timerCount>10) { // just in case floating
         if (timerCount >= 10) space = "";
        llOwnerSay((string)timerCount+". Energy:    "+space+(string)llGetEnergy());
        if (timerCount>=10) {
             returnHome();
             returnHome();
         }
         }
     }
     }
     collision(integer n) {
     collision(integer n) {
         llOwnerSay((string)timerCount+". energy   :"+(string)llGetEnergy());
         llOwnerSay("*. Energy:   "+space+(string)llGetEnergy()+" (collision)");
        returnHome();
     }
     }
}
}
 
</source>
</lsl>
|helpers
|helpers
|also_functions
|also_functions
Line 132: Line 138:
|permission
|permission
|negative_index
|negative_index
|haiku={{Haiku|Vigor of the script.|Impulses, force, torque and push.|Tenebrous design.}}
|cat1=Script
|cat1=Script
|cat2=Physics
|cat2=Physics

Latest revision as of 01:51, 22 January 2015

Summary

Function: float llGetEnergy( );

Returns a float that is how much energy is in the object as a percentage of maximum

Examples

// This script tests the energy use of most of the physics functions
// Last version: 07 October 2009 by Gianni Lupindo
 
vector homePos;
integer timerCount = 0;
integer testCount = 0;
string space = "  "; 
 
// move more than 10m
moveTo(vector origin, vector destination) {
    float dist = llVecDist(origin, destination);
    integer passes = llCeil( llLog(dist/10.0) / llLog(2.0) );
    integer i;
    list params = [PRIM_POSITION, destination];
    for (i=0; i<passes; i++) {
        params = (params=[]) + params + params;
    }
    // actually move the prim, now
    llSetPrimitiveParams(params);
}
 
returnHome()
{
    llSetTimerEvent(0);
    llSetStatus(STATUS_PHYSICS, FALSE);
    llSleep(0.2);
    moveTo(llGetPos(),homePos);
    llSetRot(ZERO_ROTATION);
}
 
default
{
    state_entry() {
        homePos = llGetPos();
        llOwnerSay("Mass is "+(string)llGetMass());
    }
    on_rez(integer _n) {
        llResetScript();
    }
    touch_start(integer n) {
        space = "  ";
        do {
          llSleep(0.5);
        } while (llGetEnergy() < 0.998);
        llSetPos( llGetPos()+<0,0,5>);
        llSetStatus(STATUS_PHYSICS,TRUE);
        llSetTimerEvent(1.0);
 
        vector impulse = <0,0,5>*llGetMass();
        if (testCount == 0) {
            llOwnerSay("ApplyImpulse (test 0)");
            llApplyImpulse( impulse, TRUE ); 
        } else if (testCount == 1) {
            llOwnerSay("ApplyRotImpulse (test 1)");
            llApplyRotationalImpulse( impulse, TRUE);
        } else if (testCount == 2) {
            llOwnerSay("PushObject (test 2)");
            llPushObject(llGetKey(), impulse, ZERO_VECTOR, TRUE); 
        } else if (testCount == 3) {
            llSetForceAndTorque( ZERO_VECTOR, ZERO_VECTOR, TRUE ); 
            llOwnerSay("Force (test 3)");
            llSetForce( impulse, TRUE ); 
        } else if (testCount == 4) {
            llSetForceAndTorque( ZERO_VECTOR, ZERO_VECTOR, TRUE ); 
            llOwnerSay("Torque (test 4)");
            llSetTorque( impulse, TRUE ); 
        } else if (testCount == 5) {
            llSetForceAndTorque( ZERO_VECTOR, ZERO_VECTOR, TRUE ); 
            llOwnerSay("Force and Torque (test 5)");
            llSetForceAndTorque( impulse, impulse, TRUE ); 
        } else if (testCount == 6) {
            llSetForceAndTorque( ZERO_VECTOR, ZERO_VECTOR, TRUE ); 
            llOwnerSay("MoveToTarget (test 6)");
            llMoveToTarget( impulse, 0.4 ); 
        } else if (testCount == 7) {
            llStopMoveToTarget ( ); 
            llOwnerSay("RotLookAt (test 7)");
            llRotLookAt( llEuler2Rot(impulse*DEG_TO_RAD), 0.4, 0.4 ); 
        } else if (testCount == 8) {
            llStopLookAt ( ); 
            llOwnerSay("LookAt (test 8)");
            llLookAt( impulse, 0.4, 0.4 ); 
        } else if (testCount == 9) {
            llStopLookAt ( ); 
            llOwnerSay("Hover Height (test 9)");
            llSetHoverHeight( 5.0, TRUE, 0.5);
        } else if (testCount == 10) {
            llSetHoverHeight( 0, TRUE, 0.5);
            llOwnerSay("Ground Repel (test 10)");
            llGroundRepel( 5, TRUE, 0.5);
        } else if (testCount == 11) {
            llGroundRepel( 0, TRUE, 0.5);
            llOwnerSay("Buoyancy (test 11)");
            llSetBuoyancy( 0.997 );
        } else {
            llSetBuoyancy( 0.0 );
            llOwnerSay("Done");
        }
        timerCount = 0;
        if (testCount != 12) {
            llOwnerSay((string)timerCount+". Energy:    "+space+(string)llGetEnergy());
            testCount++;
        }
        else {
            testCount = 0; 
            returnHome();
        }
    }
    timer() {
        timerCount++;
        if (timerCount >= 10) space = "";
        llOwnerSay((string)timerCount+". Energy:    "+space+(string)llGetEnergy());
        if (timerCount>=10) {
            returnHome();
        }
    }
    collision(integer n) {
        llOwnerSay("*. Energy:    "+space+(string)llGetEnergy()+" (collision)");
    }
}

Deep Notes

Search JIRA for related Issues

Signature

function float llGetEnergy();

Haiku

Vigor of the script.
Impulses, force, torque and push.
Tenebrous design.