Difference between revisions of "User talk:Brattle Resident"

From Second Life Wiki
Jump to navigation Jump to search
m (change tags)
 
Line 3: Line 3:
Your method works but it's a bit overkill and doesn't perform very well (in my experience, llRot2Axis and llRot2Angle are slowish). Here's an alternative:
Your method works but it's a bit overkill and doesn't perform very well (in my experience, llRot2Axis and llRot2Angle are slowish). Here's an alternative:


<lsl>
<source lang="lsl2">
float getCurrentAngle()
float getCurrentAngle()
{
{
Line 9: Line 9:
     return llAtan2(fwd.x, fwd.y);
     return llAtan2(fwd.x, fwd.y);
}
}
</lsl>
</source>


I get a speedup of about 2.4x (i.e. more than double) with respect to your method. Note that the <1,0,0> trick is important for performance. Replacing <1,0,0>*rot with llRot2Fwd(rot) the speedup is just about 1.3x. As for memory, it also takes less. --[[User:Sei Lisa|Sei Lisa]] 15:17, 14 July 2014 (PDT)
I get a speedup of about 2.4x (i.e. more than double) with respect to your method. Note that the <1,0,0> trick is important for performance. Replacing <1,0,0>*rot with llRot2Fwd(rot) the speedup is just about 1.3x. As for memory, it also takes less. --[[User:Sei Lisa|Sei Lisa]] 15:17, 14 July 2014 (PDT)


Ooh, thanks - if that works that's great! I knew there had to be an easier way than what I did, but nobody knew what it was. I'll try yours out. [[User:Brattle Resident|Brattle Resident]] 17:52, 14 July 2014 (PDT)
Ooh, thanks - if that works that's great! I knew there had to be an easier way than what I did, but nobody knew what it was. I'll try yours out. [[User:Brattle Resident|Brattle Resident]] 17:52, 14 July 2014 (PDT)

Latest revision as of 07:36, 27 January 2015

getCurrentAngle performance and code memory

Your method works but it's a bit overkill and doesn't perform very well (in my experience, llRot2Axis and llRot2Angle are slowish). Here's an alternative:

float getCurrentAngle()
{
    vector fwd = <1,0,0> * llGetRootRotation();
    return llAtan2(fwd.x, fwd.y);
}

I get a speedup of about 2.4x (i.e. more than double) with respect to your method. Note that the <1,0,0> trick is important for performance. Replacing <1,0,0>*rot with llRot2Fwd(rot) the speedup is just about 1.3x. As for memory, it also takes less. --Sei Lisa 15:17, 14 July 2014 (PDT)

Ooh, thanks - if that works that's great! I knew there had to be an easier way than what I did, but nobody knew what it was. I'll try yours out. Brattle Resident 17:52, 14 July 2014 (PDT)