Jump to content

CaptainCode

Resident
  • Posts

    3
  • Joined

  • Last visited

Everything posted by CaptainCode

  1. OMGosh Thank you!!! I'm definitely down for some reading and experimenting - that's kind of my process for learning new APIs anyway, plus SL scripting is a blast most of the time - but it helps when I know what the heck the documentation is talking about. When you explained what a radian is, then it started making sense (thanks also for the info on "local" rotation btw). So for the script above I came up with a couple functions (in case someone with the same question comes by this post): /*Rotates an object by degrees (no messing with radians and quatermions and whatever alien encryption algorithms are involved in making SL work under the hood. :DParameters: x (float): Rotation in degrees along x-axis y (float): Rotation in degrees along y-axis z (float): Rotation in degrees along z-axisNotes: - To rotate in the opposite direction, use negative numbers. - It also worked with a linked object*/Rotate(float x, float y, float z){ rotation rot = llGetRot(); // Get the object's current rotation in its encrypted form vector euler = llRot2Euler(rot); // Convert the rotation to "radians" euler *= RAD_TO_DEG; // Convert this to degrees euler += <x, y, z>; // Add the user-specified degrees to the variable euler *= DEG_TO_RAD; // Convert degrees back to "radians" rot = llEuler2Rot(euler); // Convert the euler back to a rotation "quarternion" (IMO same as encryptiing it LOL) llSetRot(rot); // Apply the updated rotation to the prim }/*This sets the rotation (not relative to its current position)Parameters are the same as above.*/SetRotation(float x, float y, float z){ llSetRot(llEuler2Rot(<x, y, z> * DEG_TO_RAD));} Anyway, thanks again for helping me get going in the right direction.
  2. Hi, I'm sure this question has been asked before, but I haven't found a straightforward explanation yet lol. The problem: In short, there is no clear-cut, plain English explanation of how the rotation API works. It appears tohave been developed by an angry mathematician, seeking vengeance on all programmers who don't know their roots. LOL - really? Quatermion sounds like a planet from a science fiction sim, Euler sounds like that kid that had a day off (wait that was Bueler), and Radian sounds like something nuclear. The LSL Wiki and Wikipedia explanations may as well be written in Japanese. I've learned entire languages faster than I've been able to grasp this stuff. I can code, but I'm no rocket scientist (yet). :D What I'm looking for An explanation of the basic concepts behind the mysteries of the SL rotation API. My goal is to reach a point where I at least have a clue. Rotation doesn't seem to be the only API that uses some of this random lingo (particle systems and object movement being others) but I can kinda get by for now. But if I can somehow decrypt the documentation, to where it makes sense to the average programmer, then I'll really be able to take my skills to the next level. Then it gets interesting. :) An example On every developer forum I've ever visited, example code is usually encouraged, so here's one of my most recent projects. It's simple enough conceptually, a chair that can rotate on 90-degree angles on command. I copied four rotations and wrote a function to switch between them. Then I wrote a listener (probably going to be a HUD down the road) and idk what the heck is wrong with it, but anyway here's the code: rotation r1 = <0.00000, 0.00000, 0.00000, 1.00000>; rotation r2 = <0.00000, 0.00000, 0.70711, 0.70711>; rotation r3 = <-0.00000, 0.00000, -1.00000, 0.00000>; rotation r4 = <-0.00000, 0.00000, -0.70711, 0.70711>; RotateLeft() { if (llGetLocalRot() == r1) { llSetLocalRot(r2); return; } else if (llGetLocalRot() == r2) { llSetLocalRot(r3); return; } else if (llGetLocalRot() == r3) { llSetLocalRot(r4); return; } else if (llGetLocalRot() == r4) { llSetLocalRot(r1); return; } else { // llOwnerSay((string)llGetLocalRot()); } } default { /* This sets the "sit target" The sit target is the coordinates ("vector" data type) and rotation (another SL specific data type). A friend mentioned you can also do animations with this, but I'm not going there yet. */ state_entry() { llSitTarget(<0.0, 0.0, 0.5>, ZERO_ROTATION); llSetLocalRot(r1); } changed(integer change) { if (change & CHANGED_LINK) // A random bit of bitwise math I don't get yet { key av = llAvatarOnSitTarget(); // Here's where it gets interesting; it detects whether the avatar is on the object's sit target if (av) // on sit { llListen(7, "", NULL_KEY, ""); } else // on stand { llResetScript(); } } } listen(integer channel, string avName, key avKey, string message) { if (channel == 7 && message == "l") RotateLeft(); } }So when I call the rotate function, it works the first time (rotates 90 degrees to the left), but the second time it does nothing. Now if I understood rotation beyond copy & paste, I could debug this no problem. But as it is, I'm left scratching my head and trying very hard not to pull my hair out. :)) So many questions... like: What is this mysterious Fourth Dimension used in rotations? I think it has something to do with Planet Quatermion. Z. :)How the heck did it get 0.70711? I literally laughed out loud at that... what the function? :DFrom what I managed to understand from the LSL wiki, Radian is some kind of alternative to degrees, and one the developers of SL preferred for some reason... how do those work?Thanks in advance. Seriously, I know this is a huge post and probably sounds more like a rant than anything (and I apologize for that), so I truly appreciate your taking the time to read through this. This is one of those few situations where it seems like the more I read, the less I understand. I never took quantum physics and barely passed algebra, so while I understand and respect that programming was oriignally based on math, I'm totally and completely lost. So any (comprehensible) information on the subject would be awesome! I've been over the LSL wiki and Wikipedia and plenty of random Googling, but I don't know where else to start on this. Thanks in advance for your time. :)
×
×
  • Create New...