POV-Ray : Newsgroups : povray.off-topic : Trying to code an "offset rotation" for SL. : Re: Trying to code an "offset rotation" for SL. Server Time
10 Oct 2024 06:25:54 EDT (-0400)
  Re: Trying to code an "offset rotation" for SL.  
From: Patrick Elliott
Date: 16 Jul 2008 01:58:16
Message: <MPG.22e73bdde113168b98a183@news.povray.org>
Ok, there is a bug in your "fixed" math (mind you, I was also forgetting 
to convert to radians when doing the sin/cos, so that was what made it 
go completely insane the first attempt... This however, rotating on the 
Y axis, goes nuts:

vector Rot = <0,0,0>;

default
{
    state_entry()
    {
        llSetTimerEvent(0);
        llSetLocalRot(<0,0,0,0>);
        llSetPos(<1,1,1>);
    }
    
    on_rez(integer dummy)
    {
        llSetTimerEvent(0);
    }

    touch_start(integer total_number)
    {
        llSetTimerEvent(0.2);
    }
    
    timer()
    {
        vector pos = llGetLocalPos();
        vector bpos = llGetRootPosition();
        llOwnerSay((string)pos);
        //llOwnerSay((string)bpos);
        
        vector npos;
        float x = pos.x;
        float y = pos.y;
        float z = pos.z;
        Rot = Rot + <0,1,0>;
        if (Rot.x > 359)
        {
            Rot.x = 0;
        }
        if (Rot.y > 359)
        {
            Rot.y = 0;
        }
        if (Rot.z > 359)
        {
            Rot.z = 0;
        }
        
        float x2 = x;
        float y2;
        float z2;
        y2 = llCos(Rot.x* DEG_TO_RAD)*y - llSin(Rot.x* DEG_TO_RAD)*z;
        z2 = llSin(Rot.x* DEG_TO_RAD)*y + llCos(Rot.x* DEG_TO_RAD)*z;
        
        y = y2;
        z = llCos(Rot.y* DEG_TO_RAD)*z2 - llSin(Rot.y* DEG_TO_RAD)*x2;
        x = llSin(Rot.y* DEG_TO_RAD)*z2 + llCos(Rot.y* DEG_TO_RAD)*x2;
        
        x2 = llCos(Rot.z* DEG_TO_RAD)*x - llSin(Rot.z* DEG_TO_RAD)*y;
        y2 = llSin(Rot.z* DEG_TO_RAD)*x + llCos(Rot.z* DEG_TO_RAD)*y;
        npos = <x2,y2,z2>;
        
        llSetPos(npos);
        //llSetLocalRot(llEuler2Rot(Rot * DEG_TO_RAD));
        //llSetRot(llEuler2Rot(Rot * DEG_TO_RAD));
    }
}

Note, this is using "Rot = Rot + <0,1,0>;", or changing the rotation by
 
one degree in the Y axis each time. The result is:

[22:41]  Object: <1.00000, 1.00000, 1.00000>
[22:41]  Object: <0.99969, 1.01760, 1.00000>
[22:41]  Object: <1.01607, 1.03549, 1.00000>
[22:41]  Object: <1.04878, 1.05396, 1.00000>
[22:41]  Object: <1.09741, 1.07327, 1.00000>
[22:41]  Object: <1.16148, 1.09371, 1.00000>
[22:41]  Object: <1.24037, 1.11553, 1.00000>
[22:41]  Object: <1.33332, 1.13897, 1.00000>
[22:41]  Object: <1.43941, 1.16427, 1.00000>
[22:41]  Object: <1.55757, 1.19163, 1.00000>
[22:41]  Object: <1.68650, 1.22125, 1.00000>
[22:41]  Object: <1.82472, 1.25329, 1.00000>
[22:41]  Object: <1.97058, 1.28788, 1.00000>
[22:41]  Object: <2.12223, 1.32512, 1.00000>
[22:41]  Object: <2.27763, 1.36508, 1.00000>
[22:41]  Object: <2.43464, 1.40778, 1.00000>
[22:41]  Object: <2.59100, 1.45322, 1.00000>
[22:41]  Object: <2.74437, 1.50135, 1.00000>
[22:41]  Object: <2.89242, 1.55206, 1.00000>
[22:41]  Object: <3.03286, 1.60524, 1.00000>
[22:41]  Object: <3.16347, 1.66070, 1.00000>
[22:41]  Object: <3.16347, 1.66070, 1.00000>
[22:41]  Object: <3.16347, 1.66070, 1.00000>
[22:41]  Object: <3.16347, 1.66070, 1.00000>
[22:41]  Object: <3.16347, 1.66070, 1.00000>
[22:41]  Object: <3.16347, 1.66070, 1.00000>
[22:41]  Object: <3.16347, 1.66070, 1.00000>
[22:41]  Object: <3.16347, 1.66070, 1.00000>
[22:41]  Object: <3.16347, 1.66070, 1.00000>
[22:41]  Object: <3.16347, 1.66070, 1.00000>
[22:41]  Object: <3.16347, 1.66070, 1.00000>
[22:41]  Object: <3.16347, 1.66070, 1.00000>
[22:41]  Object: <3.16347, 1.66070, 1.00000>
[22:41]  Object: <3.16347, 1.66070, 1.00000>
[22:41]  Object: <3.15236, 1.71598, 1.00000>
[22:41]  Object: <3.12541, 1.77079, 1.00000>
[22:41]  Object: <3.08492, 1.82491, 1.00000>
[22:41]  Object: <3.03322, 1.87813, 1.00000>
[22:41]  Object: <2.97264, 1.93031, 1.00000>
[22:41]  Object: <2.90536, 1.98131, 1.00000>
[22:41]  Object: <2.83341, 2.03107, 1.00000>
[22:41]  Object: <2.75858, 2.07953, 1.00000>
[22:41]  Object: <2.68245, 2.12667, 1.00000>
[22:41]  Object: <2.60630, 2.17249, 1.00000>
[22:41]  Object: <2.53117, 2.21700, 1.00000>
[22:41]  Object: <2.45784, 2.26024, 1.00000>
[22:42]  Object: <2.38688, 2.30225, 1.00000>
[22:42]  Object: <2.31867, 2.34307, 1.00000>
[22:42]  Object: <2.25339, 2.38276, 1.00000>
[22:42]  Object: <2.19114, 2.42137, 1.00000>
[22:42]  Object: <2.13189, 2.45895, 1.00000>
[22:42]  Object: <2.07555, 2.49556, 1.00000>
[22:42]  Object: <2.02198, 2.53123, 1.00000>
[22:42]  Object: <1.97101, 2.56602, 1.00000>
[22:42]  Object: <1.92247, 2.59997, 1.00000>
[22:42]  Object: <1.87616, 2.63311, 1.00000>
[22:42]  Object: <1.83194, 2.66549, 1.00000>
[22:42]  Object: <1.78962, 2.69714, 1.00000>
[22:42]  Object: <1.74905, 2.72808, 1.00000>
[22:42]  Object: <1.71012, 2.75834, 1.00000>
[22:42]  Object: <1.67268, 2.78796, 1.00000>
[22:42]  Object: <1.63664, 2.81695, 1.00000>
[22:42]  Object: <1.60189, 2.84534, 1.00000>
[22:42]  Object: <1.56834, 2.87315, 1.00000>
[22:42]  Object: <1.53593, 2.90040, 1.00000>
[22:42]  Object: <1.50456, 2.92710, 1.00000>
[22:42]  Object: <1.47419, 2.95328, 1.00000>

In other words, it heads straight out to a corner, *then* starts 
rotating.

Rotation in the X and Z vectors works correctly (well, mostly, there 
seems to be some precision loss, maybe), though I still need to figure 
out how to make the prim face the "direction" that it is supposed to 
have moved to. Local rotation didn't seem to want to do that correctly.

Rotation in X:

[22:52]  Object: <1.00000, 1.00000, 1.00000>
[22:52]  Object: <1.00000, 0.98240, 1.01730>
[22:52]  Object: <1.00000, 0.94629, 1.05097>
[22:52]  Object: <1.00000, 0.88999, 1.09905>
[22:52]  Object: <1.00000, 0.81116, 1.15846>
[22:52]  Object: <1.00000, 0.70711, 1.22474>
[22:52]  Object: <1.00000, 0.57521, 1.29195>
[22:52]  Object: <1.00000, 0.41348, 1.35242>
[22:52]  Object: <1.00000, 0.22123, 1.39680>
[22:52]  Object: <1.00000, 0.00000, 1.41421>
[22:52]  Object: <1.00000, -0.24558, 1.39273>
[22:52]  Object: <1.00000, -0.50681, 1.32028>
[22:52]  Object: <1.00000, -0.77024, 1.18606>
[22:52]  Object: <1.00000, -1.01730, 0.98240>
[22:52]  Object: <1.00000, -1.22474, 0.70711>
[22:52]  Object: <1.00000, -1.36603, 0.36603>
[22:52]  Object: <1.00000, -1.41400, -0.02468>
[22:52]  Object: <1.00000, -1.34500, -0.43702>
[22:52]  Object: <1.00000, -1.14412, -0.83125>
[22:52]  Object: <1.00000, -0.81116, -1.15846>
[22:52]  Object: <1.00000, -0.36603, -1.36603>
[22:52]  Object: <1.00000, 0.14783, -1.40647>
[22:52]  Object: <1.00000, 0.66393, -1.24868>
[22:52]  Object: <1.00000, 1.09905, -0.88999>
[22:52]  Object: <1.00000, 1.36603, -0.36603>
[22:52]  Object: <1.00000, 1.39273, 0.24558>
[22:52]  Object: <1.00000, 1.14412, 0.83125>
[22:52]  Object: <1.00000, 0.64204, 1.26007>
[22:52]  Object: <1.00000, -0.02468, 1.41400>
[22:52]  Object: <1.00000, -0.70711, 1.22474>
[22:52]  Object: <1.00000, -1.22474, 0.70711>
[22:52]  Object: <1.00000, -1.41400, -0.02468>
[22:52]  Object: <1.00000, -1.18606, -0.77024>
[22:52]  Object: <1.00000, -0.57521, -1.29195>
[22:52]  Object: <1.00000, 0.24558, -1.39273>
[22:52]  Object: <1.00000, 1.00000, -1.00000>

This doesn't seem to be "exactly" right either, it seems to rotate more 
than the one degree I was attempting, so I need to work out why, but its 
way closer to what it should be doing than what "Rot = Rot + <0,1,0>;" 
ends up generating...

Was right about how the rotations worked though. This method is needed 
to rotate off of center, instead of just rotating around the prims own 
center...

This is "very" close to what I was trying to do, but, obviously, there 
is a bug some place in it. :(

-- 
void main () {

    if version = "Vista" {
      call slow_by_half();
      call DRM_everything();
    }
    call functional_code();
  }
  else
    call crash_windows();
}

<A HREF='http://www.daz3d.com/index.php?refid=16130551'>Get 3D Models,
 
3D Content, and 3D Software at DAZ3D!</A>


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.