CODE
| Root
| __
| / \
| | |
| \__/ ^
| //
| //
| //
| //
| //
| V Rot. center
The line down the left is to ensure the spaces show up correctly.
Let's say we have an object with 2 prims. A root prim that's a sphere, and a child prim that's a long bar or cylinder (for ease of illustration with bad ASCII art). Let's say the cylinder's length is along its local Z axis. The cylinder's position and rotation aren't aligned with the root prim.
I want to rotate the cylinder around one of its ends. What would the code for this look like? The rotation is easy, it will be:
CODE
llSetLocalRot(desiredRot * localRot);
Assuming my desired rotation is relative to the cylinder's local axis. But the problem is the translation that needs to happen with this rotation to get the prim to rotate around its end.
I've managed to get partway through this, I think. To find the rotation center, this is what I did:
CODE
vector p = llGetLocalPos(); // This is the vector from center of root prim to center of cylinder
vector direction = llRot2Up(llGetLocalRot()); // Unit vector pointing in the direction of the cylinder
vector size = llGetScale();
float length = size.z; // Length of prim
vector cylinder = direction * length; // Vector "pointing in the direction of the cylinder", magnitude is the length of the cylinder
vector rotOrigin = p - (cylinder / 2.0); // Subtract half the length of the cylinder
Hopefully, so far so good? But here's the problem. I tried:
CODE
vector newPos = rotOrigin + (p - rotOrigin) * desiredRot * localRot;
But that didn't seem to work, probably because the rotation is calculated relative to the cylinder, but this ends up rotating the same angle around the root prim? Or something like that. This is where my brain explodes, so I won't try to explain it any further. If anyone knows how to do this, I will be most grateful

And I can't build this so that the cylinder is cut in a way that the prim center is at the visible end of the prim. This will be on a flexi prim so the length of the prim has to be its Z axis, and the only cut that I know of that will allow me to cut in half on the Z axis is the sphere -> dimple -> back to cylinder torture sequence, which is undone when you turn flexi on. But if there is some other building trick I can use to achieve this, that would help a lot too.
Thanks,
Ziggy