In the past soemone did have me this line. because i could not figure out how. Now i decided to test that line in sansar. But you cannot do vector*quart.

This the line i used in SL. This the center line i used.

newpos = curpos-<0.0 ,0.0 , 0.0>*rot;

Now i would think, easy to convert. so i made this code.

`Quaternion rotation = RigidBody.GetOrientation().Normalized();Vector currentposition = RigidBody.GetPosition(); Vector centerposition = currentposition-new Vector(0.0f ,0.0f , 0.0f)*rotation;textChat(centerposition.ToString());But i get a Error;Just got a smart idea.Vector centerposition = currentposition - new Vector(0.0f * rot.X, 0.0f * *rot.Y, 0.0f * rot.Z);`

But no, then where stuck with pointer errors. Reminds me at the pascal time and pointers.

Lost, i know this same one i could not figure out on other platform to. What it's doing at the end. is give you the start position of object and the end position on all axis. and the one above i used for the center. that way.

• Galen

Whoops. That's what I get for not testing my code. I forgot to convert to radians. Should have been:

`Quaternion Rot = Quaternion.FromEulerAngles(new Vector(0, 0, 90 * Mathf.RadiansPerDegree))`
• Richardus Raymaker

Oooh, thanks. I changed the code. But the output is something unexpected.

rX: 179.999940484326
rY: -32.957846596255
rZ: 179.999995125836

`Vector OriginalVector = new Vector(10, 0, 0);Quaternion Rot = Quaternion.FromEulerAngles(new Vector(0, 0, 90 * Mathf.RadiansPerDegree));Vector NewVector = OriginalVector.Rotate(ref Rot);Quaternion convRot = Quaternion.FromEulerAngles(NewVector);double rX = convRot.GetEulerAngles().X * Mathf.DegreesPerRadian;double rY = convRot.GetEulerAngles().Y * Mathf.DegreesPerRadian;double rZ = convRot.GetEulerAngles().Z * Mathf.DegreesPerRadian;Log.Write("rX: " + rX.ToString() + " rY: " + rY.ToString() + " rZ: " + rZ.ToString());`
• Galen

Why don't you just output NewVector, which should be <0, 10, 0>, proof that you rotated it.

Your other code does not make sense to me. You are treating your vector as Euler angles, which doesn't make sense. And then you are converting it back to a vector of angles.

Something you need to keep in mind is that trios of Euler angles are not unique representations of rotations. You won't always get out what you put in, as your odd example shows.

It really looks like you are trying stuff at random. You should do a little more research.

• Richardus Raymaker

How todo research when the documentation from sansar is a bit limitted. other exampels are for unity and complete different. Biggest problem with sansar is the lack of a good Degree support. I now need to try everytime to convert radians or angles to degree. The radians and angles are already confusing enough.

I do not learn in normal way, so most documentation that's seems fine for others are most of the time not really helpfull And if something not works, because error. I try to see if it's correct in degree. And that conversion still confuse me in sansar. How longer i do not make progress how bigger the mess. To much difefrent options and nothing worked.

In the begin i used newvector as output. But that where wrong. After that and your change i where still in the wrong idea that newvector where giving wrong output.

I now did output newvector again.And the troubel is a bit better. It's not the output you expect. And what you expect. and that is why is started to mess around with the code again before.

D1: <-9.536743E-07,10,0>

`Vector OriginalVector = new Vector(10, 0, 0);Quaternion Rot = Quaternion.FromEulerAngles(new Vector(0, 0, 90 * Mathf.RadiansPerDegree));Vector NewVector = OriginalVector.Rotate(ref Rot);Log.Write("D1: " + NewVector.ToString());`

• Gindipple

Looks like the right output to me.

Radians are more natural for trig than degrees.

The circumference of a circle is 2 * pi * r.  Not 360 * r

Get used to working in radians, at the end convert to degrees if you must. And if you need, convert the inputs from degrees to radians, but internally use radians.

Don't get wrapped up in how other programs do things. It will change from place to place. But one thing that won't change is the underlying math.

Here's another video that might help you. The guy shows the most natural way to derive the rotation matrix in 2D. https://www.youtube.com/watch?v=h11ljFJeaLo

• Richardus Raymaker

I need to try to put this on hold and first jump into radians. As soon the have radian view in properties. things will be more easy to understand i think.

Can i say that radians in SL are the same as radians in Sansar ?! Then i can play a bit first with radians in SL to understand it more. That platform is a bit more stable. :O

Edited by Richardus Raymaker
• Galen

The problem here isn't one of stability. You are trying to do something difficult. Understandably, you are trying things somewhat at random. You're going to have the same problems in LSL, though you may find it more comfortable for now to program with. But it has the same basic model for vectors and quaternions.

Here is a suggestion. Take it step by step. Learn more about vectors and rotations. Take them on their own terms. Try out some simple things. When you come to something hard like what you are trying to do, set it aside for now.

As you progress, do some searches because almost everything you want to do has been documented somewhere. Try Googling "how do I get rotation from vector". Many of the solutions will not be ideal for your case, but you may learn some key concepts that lead you to the next questions.

Don't feel bad. Most LSL programmers don't know how to deal properly with rotations. That's a lot of programmers.

• Gindipple

Radians are a universal thing, not a LL thing LOL

This is no different than converting meters to feet.

If I ask you the cosine of 90 and the cosine of pi/2 you would know how to give me the answer for each and you would know that the answer would be 0 in both case.

Try this on a calculator, realize that you have to switch to radians for one to give the correct answer.

• Richardus Raymaker

I did loked at some document. and especially with particels in SL pi where used. and pi =  3.14 (and a lot more)

So, i just need to play a bit with radians in SL. that works faster then in sansar. because 90 degree would by pi/2 (this out of my mind)

Just need to play with numbers in SL and print results back. i think radians are not to bad after some sleep. Still wish i could skip the conversion step from object properties degree to radians. or Quaternion . other thing i need to look at.

But am still not sure if sansar have the option to rotate the X,Y,Z direction of object. So it can always move forward on teh X direction. That's my main problem. rotating is not so hard. done it and it worked. but i need to change the X,Y,Z direction togheter with the object rotation.

• Galen

So generally, programmers (and mathematicians) favor radians because they are easier and faster to compute with. If you were able to express angles/rotations/orientations in degrees, the API would still have to convert them to radians and then back. It sucks that you have to keep this in mind, but you get used to it.

Edited by Galen
• Richardus Raymaker

I go look at the radian stuff tomorrow. I think the are not a real problem to learn. I need to learn to see what is radian and what is angle i think. because the sansar documentation most talkes about qaut or vector. and you need to guess what vector output you get.

First some testing in SL. then i make a keyboard controlled script to rotate in sansar with output.

• Galen
• Richardus Raymaker

Aha good page, why did google not gave me that as result :O

57.2958 hmm i have seen that number before. Mabye i just make the radian thing straight in sansar. That's more fun !

Thanks.

• Gindipple

I found this gem in a wiki and thought it was worth a look, 1977 using quanternions with the space shuttle :)

https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19770024290.pdf

By Hamilton himself. (creator of them)

Of note is that there are 12 different ways to rotate and arrive at the same answer there in the appendix.

Edited by Gindipple
• Richardus Raymaker

Foudn a nice website, it can help more people to visualize Quaternion / Radians / Degree, And the first 2 are important.

Edited by Richardus Raymaker
• Galen

Okay, good news. I've had to crack this problem, too, just today. The method you want to use is Quaternion.FromLook(). Here's a boiled-down script:

`Quaternion Ori = Quaternion.FromLook(Dir, Vector.Up);Body.SetOrientation(Ori);`

I'm going to assume you are in the same boat I am, where I want to rotate a body around the Z axis (Vector.Up) and to follow a direction pointed to by the Dir vector. Try this experiment out, even it if is not exactly what you need, because it is instructive.

Let's say it rotates right, but your object is pointing 90° one way or the other. You can adjust that by using a tactic like this:

`Quaternion Ori = Quaternion.FromLook(Dir, Vector.Up);Ori *= Quaternion.FromEulerAngles(new Vector(0, 0, Mathf.PiOverTwo));Body.SetOrientation(Ori);`

Pi over 2 is equivalent to 90°, so you don't need to do a radian conversion.

• Richardus Raymaker

Sound sgood, except what if you go hill up or down ? :O

Now playing first with radians in test script. it looks more fun and make code more easy. But a simple rotation does not work. but sansar is a bit in weird mood tonight anyway.

• Richardus Raymaker

Still doing something wrong now between quart and radian conversion.  Doing this to read it.

Quaternion rot = RigidBody.GetOrientation();
Log.Write("rR:  " + rot.ToString());

I get a quart as output, so i need to convert it. and the commands for that still confuse me. because the talk about vector as output. but it can be quat or radian as output.

I think there's a conversion step from quat to rad missing now. Am looking at that. For sure it's now writing in quat to log rR:  (1,0,0,0) easy to see if i step up one radian it's changing more colums rR:  (0.9993908,0.03489951,0,0)

Edited by Richardus Raymaker
• Galen

You probably won't find reading a quaternion value's components very helpful. Easier to convert them back to Euler angles and read those, IMO.

However, be aware that Quaternion.ToString() has been reported (by Gindipple?) to output "W, X, Y, Z" instead of "X, Y, Z, W", I believe.

• Richardus Raymaker

Yes the WXYZ i have already noticed. because the 1 at the begin. thanks galen. But i want to read output in radians. and i think sansar not have a command for that. And to understand radians i like to see it as numbers.

I think to late on the day to get the number right :O

• Galen

Regarding the uphill/downhill thing. Once you master turning look-at vectors into quaternions using .FromLook() on the flat plain, you can pay more attention to the "Up" vector you pass into it. What you really need is for that to be a "normal" vector to the surface you're traversing. This is the same concept as normal vectors for surface rendering. In this case, think of it as purely perpendicular to the surface a person is walking on or car driving on.

Edited by Galen
• Galen

If you want a quaternion output in radians, do it this way:

`//WRONG: Rot.ToEulerAngles().ToString()Rot.GetEulerAngles().ToString()`

If you want it in degrees, try this:

`(Rot.GetEulerAngles() * Mathf.DegreesPerRadian).ToString()`

By the way, you are going to get the radian equivalent of -180' to +180'. It won't represented it as the 0' - 360' you want.

Edited by Galen
• Richardus Raymaker

This not the first time i trip over this. and mabye when i fix it i break something. SO i used your code.

Quaternion rot = RigidBody.GetOrientation();
String text = rot.ToEulerAngles().ToString();
Log.Write("rR:  " + text);

And then sansar is going to point a finger at me.

Double checked the pages from sansar. there's no ToEulerAngles and that is why i possible go always wrong.

• Galen

Try not to be so literal when you see my code samples. Very often I write the without testing. I have a bad memory for function names. It's "GetEulerAngles".

https://help.sansar.com/hc/en-us/articles/115002629266-Quaternion#M:Sansar.Quaternion.GetEulerAngles()

• Richardus Raymaker

Don;t worry Galen.
But i get still a bit confused with the conversion commands. I want to write tomorrow some notes for myself. So i stop mixing up the converter commands.

Big thanks, that are radian numbers i have seen on the other website.

Edited by Richardus Raymaker
• Galen

It seems I was slightly wrong about how Quaternion.FromLook() works. It is appropriate for hills, too.

When you use Quaternion.FromLook(LookingAt, Vector.Up), the rotation you get out of it will tilt your object "uphill" or "downhill" to my surprise. I thought it would be parallel with the flat X,Y plane, but it's not.

Picture it as being like a bicycle on a hill. If you're going in a straight line on that hill, you want to keep the bike upright so it doesn't tip left or right, while the wheels still must meet the ground on its slope. That's what the Vector.Up vector will do for you. It will keep your object upright like the bike while keeping it oriented with the hill's slope.

Edited by Galen
• Gindipple

Actually Galen, only in 1st person right now as there's a bug from newest release on this I reported.

• Richardus Raymaker

I wish i could lock my avatar in first person mode as default. It's always default in third person mode. and that's no fun anymore.

I go look in the Mylook after the radian investigation. First need to modify my object :O

• Galen

Gindipple: Right. Although I wasn't speaking of the avatar stuff. Just the vector math. I think Richardus is working on an object following a path separately from any avatars.

• Galen

Question, though. Is it really a bug for the Facing vector to be level with the ground in first person? That sounds desirable. And I'm pretty sure that's how it works in SL.