Jump to content

Maths trigonometry problems scripting RezObject()


VirtualKitten
 Share

You are about to reply to a thread that has been inactive for 1064 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Not just yours mine too Jenna  was lost with it too my little brain fried too . You must be very smart prof . you said to use quaternians rather than trig now we are both lost.

I realised the code above only works when model is set pointing exactly North any other doesn't work .

Now I have distance out from particle will this still be the same when dragon is rotated . I am guessing not as the amount on each axis will change proportionally with the rotation . For example 5 degrees will need more in y than in x . 15 degrees will need everything in x but minus . 45 degrees everything  in x positive everything south all in y minus. This said how do you calculate the amounts in x and y at a finite amount say 26 degrees or the current rotation of the dragon from llGetRot();

Link to comment
Share on other sites

I presume when I rotate my pet my distance out  calculated as above will become the hypotenuse and the opposite or adjacent will be the x and y ?

So if h = hypotonuse= my distance out a = adjacent  would be cos (theta) *h and opposite=o = sqrroot(Sqr(h) - sqr(cos (theta) *h))? maybe ?

x would be o or a and y would be o or a  depending on quadrant you was in?

Edited by VirtualKitten
Link to comment
Share on other sites

Start with a simple test harness, rezz a prim. Put a script inside that chats out the current Z angle (llGetRot()) in Radians, plus the sin and cosine of that angle, then rotates another PI/12 (15 degrees). Watch what happens to Sin and Cos as it turns through a full revolution, the values are similar but the signs change. Multiply the radius by those values of Sin and Cos and a set of X,Y points will ensue that plot a circle when added to the X,Y of the prim's position. You don't need to know the actual base forward vector, the Z component of llGetRot will always give you the object's rotation from that base forward vector.

Alternatively, as it's going to take some work, why not bite the bullet and learn to use Quarternions? The same effort you're expending trying to do this in basic trig would actually get you a passing familiarity with SL's way of doing things.

 

Edited by Profaitchikenz Haiku
Link to comment
Share on other sites

5 hours ago, Wulfie Reanimator said:

Can somebody explain what the actual goal/feature is, or is this purely a trigonometry puzzle?

pretty much the conversation has devolved into the second, which is fine as conversations go this way sometimes

Jenna provided the solution to the original OP question way back earlier

  • Thanks 1
Link to comment
Share on other sites

3 hours ago, Mollymews said:

Jenna provided the solution to the original OP question way back earlier

The OP stated they needed a solution to work in the X Y and Z planes. "I need this to work 360  in Y and 360 Z  and X 360"

This is a problem of three degrees of rotation, one of which is global and the other two are local.

What I believe they were asking was how to convert the local rotation and position of the head into global values?

Here's a picture to illustrate.

ThreeDegrees.png.0fd919601b8d5a320b08a87ea2268b5d.png

 

The yellow circle represents the global rotation that the dragon linkset can have as a whole.

The green arc represents the local rotation that the neck/body can have as the dragon rears or crouches.

The red arc represents the local rotation of the side-to-side movement of the dragon's head.

The red and green arcs move together as a result of the movement around the yellow circle, the red arc moves as a result of the green arc value.

Somewhere along the bottom of the red arc is where the OP wants to rezz the fireball, but the red arc position is determined first by the green arc and yellow arc positions.

The natural (SL) way to resolve this is with rotations using * or / to apply them.

Trig will work just as well, some of the earlier solutions foundered because of the mixing of degrees together with Radians, but that was a minor issue.
 

 

Edited by Profaitchikenz Haiku
Link to comment
Share on other sites

1 minute ago, Profaitchikenz Haiku said:

ThreeDegrees.png.0fd919601b8d5a320b08a87ea2268b5d.png

 

 

a way to build this is there is a root prim and a linked emitter prim

the emitter prim is script coordinated with the custom animation set of the dragon. Offset from the root prim so that the emitter prim remains in the mouth of the dragon

when the animation to move the dragon's head plays then the linked prim is scripted to follow the arc of the dragon's head. We know what the arc is for each animation, as we created the animations

then we can emit particles (dragon breath) so that its source is the dragon's mouth

knowing the rotation and position of the emitter in the dragon's mouth (relative to the root prim) and knowing a grid target position forward of the emitter then the emitter can rez an object at the grid position. (and this is what Jenna's script does, it rezzes a prim at a target position forward of the emitter prim)

Link to comment
Share on other sites

19 minutes ago, Profaitchikenz Haiku said:

I agree, that's a way around the calculations, and I believe VK is able to make such animations from posts elsewhere?

yes, VK is learning how to make just about everything that can be made

part of the learning process is coming to understand how SL functions. And in this process we learn to set aside how we think/preconceive it should work. Which can take us some time to let go of, how we think it should rather than how it actually does. And when we do get our head round this and let go of our preconceptions then it goes a lot easier for us

Edited by Mollymews
Link to comment
Share on other sites

yes I am still stuck with this giggles . I asked about the trig and some one said use the stuff in LSL very complex math I though as we established the distance out . I could get coordinates from  this length as the hypotenuse side and cos-sine to calculate others i was hoping for some examples in code and these could be negative or negative and positive on deferent axis depending of the angle of the emitter again you said use quaternions can you show how to do this then please as scratching my head like others  and clearly you know best prof being a kind professor. DX Thank you

Edited by VirtualKitten
TO add thanks
Link to comment
Share on other sites

I think any future instructions are going to have to be in-world, at least two regulars on this sub-forum are indicating their exasperation with our monopolising the discussions with what are to them irrelevancies and I don't want my trouser-cuffs to get any more ragged than they already are.

  • Like 1
Link to comment
Share on other sites

Well I met up with the lovely professor and he showed me my rig was not root linked that is a bit of a mess silly blender made the wing the root lol. idk. that's another story .anyway he said stick with Pythagoras and trig:) Thanks Professor I hope i can get this sorted

 

Link to comment
Share on other sites

Ok have been thinking about this trig is not going to work here let me try and explain x y and z are controlled by head bone from armature  therefore the only change i think i need to worry about is x . This said 

if we have already worked out the length of the particle by trig and call it j  and use the emitter at the center j will be the same all through Pi degrees on x on nearing x=-j see i noted radians. Further more if we assume angle is the angle of x in radians :

rot = llGetRt()

angle_rot =Eullert2Euler(rot);

angle -= angle_roy.x;

if (angle ==llPi ){ x _axis =  -j;y_axis = 0 } else if((angle ==0){ x _axis =  j;x_axis=0} else if(angle == PI_BY_4)  {y_axis = j; xaxis = 0;} else if angle == PI_BY_3) {y_axis = -j; x_axis = 0;} else if (angle>PI_BY_2) angle = llPi-angle;

//We then have a triangle with two sides the length of J this is a problem as angle if more than 90 we cant use trig so best not use it at all. 
//with two sides J and to calculate other side base , we cannot use Pythagoras either .My memory now gets hazy  it would be better to ignore Trig and Pythagoras for this as we would solve the y without breaking it down further.

 

Please excuse my rubbish drawing:
2d2aae276f98c83c2ea7505f6f051c19.png
 

 

How do we do this with out Pythagoras or Trig? thank you for looking? nope didn't work at all

 

 

Edited by VirtualKitten
got lost had to correct
Link to comment
Share on other sites

On 5/4/2021 at 3:47 PM, Profaitchikenz Haiku said:

I think any future instructions are going to have to be in-world, at least two regulars on this sub-forum are indicating their exasperation with our monopolising the discussions with what are to them irrelevancies and I don't want my trouser-cuffs to get any more ragged than they already are.

You're fine!

  • Like 2
Link to comment
Share on other sites

Generally, may I recommend the following articles too?     The first one, by Chalice Yao, may offer a solution to the OP's question, since, as Chalice explains, 

Quote

Here is a little snippet for the rotationally-challenged, or those who have some complex solution but want something much simpler.
How to rotate an object so it points its X axis (which is the 'forward' axis on prims) towards another object?

so it may help with the OP's question.    The second two, by Grandma Bates, are excellent introductions to SL rotations and quaternions, which I found really aren't difficult once someone who knows what she's talking about and who knows how to explain things simply (like Grandma) took me through them*

Chalice Yao: Kept simple: Rotate object towards another object

Grandma Bates: Basic Introduction to Rotations and More Advanced Tutorial for Rotations with Translations

*ETA:  And Void Singer, of course (anyone searching for help on rotations in the forum archives will see how tirelessly patient she was with me and a lot of other people!).

Edited by Innula Zenovka
  • Like 4
Link to comment
Share on other sites

Those three are excellent guides and really should be stickied in this thread, BUT

In this instance and in a few others, there were a couple of stumbling-blocks

People with a build in progress are reluctant to put it to one side and go back to school, or to build small simple test rigs to investigate how to do something, they're stuck to their build

Builds that have not been put together with a view to subsequent puppeteering/actioning cause problems that cannot be resolved by studying rotations.

That said, it was another fine mess I   another great adventure to liven up the week.

I have great hopes Molly and Quistessa's work in another thread are going to be of assistance in future adventures.

 

ETA

The answer to the OP's problem by the way, I never got around to explaining to them because the discovery of the other issues took over.

There was an emitter prim in the mouth of the dragon which spat flames as a particle stream. It always spat them in the correct direction no matter which way the dragon was pointing, and I was going to explain to the OP that within that child prim, a call to llGetPos() would know where in the region the mouth was, a call to llGetRot() would get the emitter prim rotation in region directions, and as the emitter Z-axis was the direction in which the particles were streaming, the expression llGetPos() + <0.0, 0.0, 2.0>*llGetRot() would therefore give the region position for rezzing the object, regardless of the root rotation. It really was that simple, one line of script. I built a test harness to demonstrate this but it never had the chance to be shown.

I had a cunning plan, to let the OP to work the position out by Trig as they had insisted they wanted to do, and then demonstrate that the one line did the same, but faster and with less pain. Like all cunning plans, it came to rest on the reefs of reality.

Edited by Profaitchikenz Haiku
  • Like 2
Link to comment
Share on other sites

On 5/9/2021 at 9:20 AM, Profaitchikenz Haiku said:

 Quistessa's work

i think it would be quite good if somebody with wiki edit capabilities could add Quistessa's uEuler2Rot and uRot2Euler to  the respective llEuler2Rot and llRot2Euler pages, as LSL coded examples of how what these functions do. Similar to the LSL coded examples of other rotational functions on the wiki

edit add. looks like somebody already did for llEuler2Rot. If they could do the same for llRot2Euler that would be good

Edited by Mollymews
Link to comment
Share on other sites

Prof you are great don't get  worried we all are capable of making mistakes and learning the real ones here's admit it, so you must be a hero or a humble man. ,. I did see your note card but it rezed it in the air  not on ground xD. I haven't had a chance to fix it yet.  I think I am going to have to use the llCastRay which i hate ! to to get it ground or surface nearest up .

list ray = llCastRay(llGetPos()+(rezOffset*llGetRot()),llGetPos()+((rezOffset+<.25,.25,.25>)*llGetRot()),[RC_MX_HITS,5]);

Will this work to return a list of the ground surfaces keys in list  top first in list ray?

 

Edited by VirtualKitten
Link to comment
Share on other sites

I used list ray=llCastRay(pos+<-(width/2),0.0,0.0>,pos+<width,0.-50.0,0.0>,[RC_MAX_HTS,5|RC_DETECT_PHANTOM,TRUE]);

but get nothing in list but it does come in sometimes any ideas please were pos is emitPos ?

Edited by VirtualKitten
Link to comment
Share on other sites

perhaps try

vector pos = llGetPos(); // for testing.
rotation rot = llGetRot(); // in practice will want to use http://wiki.secondlife.com/wiki/LlGetLinkPrimitiveParams
float distance = 10; //ray length.
vector displacement = llRot2Fwd(rot) * distance; // llRot2Fwd gives you the red vector you would see while editing the object with with the move checkbox and local coordinates turned on. see related functions llRot2Up,llRot2Left
list ray = llCastRay(pos,pos+displacement,[RC_REJECT_TYPES,(RC_REJECT_AGENTS|RC_REJECT_PHYSICAL),RC_MAX_HITS,5]);

 

1 hour ago, VirtualKitten said:

ray=llCastRay(pos+<-(width/2),0.0,0.0>,pos+<width,0.-50.0,0.0>,[RC_MAX_HTS,5|RC_DETECT_PHANTOM,TRUE]);

Also looks like you have a bit of a typo in the list you're passing to CastRay. The pipe (in this case) should be a comma : [RC_MAX_HTS,5,RC_DETECT_PHANTOM,TRUE]

P.S. if you're using this to detect the position on the ground 'height' units below the emitter (I think that was the question in the original post?) you could instead:

vector pos = llGetPos(); // for testing.
rotation rot = llGetRot(); // in practice will want to use http://wiki.secondlife.com/wiki/LlGetLinkPrimitiveParams
float height = 5.0; // height above ground, or equivalently, how tall your thing is.
vector displacement = llRot2Fwd(rot);
displacement *= ((-height)/displacement.z) ; // scale by a factor such that the z coordinate is negative height.

vector pos2 = pos+displacement; // the point on the 'ground' that would be hit by a ray cast from pos along its local x axis.

float p = 0.5; // percentage (ranging from 0 (at pos1) to 1 (at pos2)) of the way along the line from pos to pos2.
vector pos3 = pos*(1-p) + pos2*(p); // a weighted sum of the 2 points.

 

Edited by Quistessa
added p.s.
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1064 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...