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.

• Richardus Raymaker

Well, my second idfea could not work anyway i think. Doing 0.0f * rot.X is asking for problems. vector with sort of Quaternion. So, still stuck with this one.

Edited by Richardus Raymaker
• Galen

Use Vector.Rotate()

• Richardus Raymaker

I tried vector rotate. But doing something wrong and it's not the time of day to see the light. Lack of example makes it harder to. But if that command solves the problem..

The simple test by just writing output to log is failing.

• Gindipple

Yea use Rotate() what you tried to do above is not the answer for sure.

I would suggest a bare bones script with just an object a position and trying to rotate it.

Use an object that you can fully know all directions like one of the many axis on the store. I use this one I made in blender.

https://gyazo.com/0baf298bc7308ec1fa5dc14007269a16

• Richardus Raymaker

Well i have a prim. let's say 10 meter long. that prim can be placed in different angles. I know the center.because that's the pivot point and position i can copy from properties.

But i need to know where the begin and end positions are. That is what the LSL script is doing for me. from there i could calculate the steps for moving my object with SetPosition.The solution must be ready in Vector.html. but that type of math is not the easy part for me. Maby Lerp is doing what i need. but no example. so i need to find info on it.

ADD: Lerp not the solution. not sure if any of it will do what i need. Looking further.

Edited by Richardus Raymaker
• Gindipple

You need to operate under the assumption that there is no examples or that they are wrong.

Sure examples can help sometimes, but there is no substitute for doing the long haul research. And this means baby steps. Lerp() might do what you want, but you need to know what it does. It's a Linear interpolation. And then you have to know if it's implemented correctly. And the only way to do this is by comparing a known operation to the one in here. For that you'd need to set up a table of numbers to operate on and perhaps compare the outputs to something like excel.

Make yourself a simple vector in blender, I did, place it in the scene and see if you can get it pointing in a predictable direction with a script. Then you will have yourself a baseline set of tools.

Expect to have to upload new scripts dozens of times, make tiny single variable changes so you can track changes. Read the output logs, the console isn't going to help all that much when you need to look at 50 output data points and maybe copy them into excel for comparing.

Make yourself tools like single keypress operations. I have one set of tools I use just to step through all 64 90 degree orientations. And I've used it numerous times when I have gotten in a pinch.

• Richardus Raymaker

Thanks gindipple. You not want to know how many tiny steps i have uploaded already. I still like C# more then LSL. because you can follow what happens. With LSL is a bit guessing.

I checked script log again. mabye things are fixed in this version. but i see log.write data in the log file. So that helps a bit too. Key input with sansar, interesting idea. but then i first need to look at how to code that.

I think i found the code on unity that is mabye doing what i need. i made it work in sansar.

`float a = degrees * Mathf.PI / 180f;return new Vector((float)Math.Sin(a) * dist, 0, (float)Math.Cos(a) * dist);`

Edited by Richardus Raymaker
• Gindipple

There's an example script on that, it's pretty easy really

• Galen

LERP works well in Sansar. I use it in my scripts. I also created a custom SLERP implementation for LERP-like behavior in rotations.

Like Gindipple says, you just have to work at these things. All of us have to upload our scripts hundreds of times as we explore adding even modest behaviors to things in Sansar. It's not easy, which is why there are not many active scripters here yet.

Edited by Galen
• Richardus Raymaker

If i could work out how the keep a linearvelocity object resistant against bumping i would still use that for moving. because it's more easy then moving with position. position have the good thing that you have more control on things.

Shame we not have upload counter. lol. i think it's going to pass the 5000 before end of this year.

I keep trying different idea;s and new idea's i get in my mind. The rust is getting a bit scraped off my mind and C# is fun. Feels a bit like the old days. Most errors i can find easy now in the code back. the log.write is improvement. Only need to learn to stop soemtimes with it on a day and take a break.

So, it keeps me busy for a while. meanwhile sansar only get better. The terrain makes me to get it working only more.

Again thanks to Galen & Gindipple

Edited by Richardus Raymaker
• Richardus Raymaker

Am really getting stuck on this LSL i cannot convert.
If i would have that working i can move on and do something in sansar. Right now am running round. try things. most things you find on internet are for unity. That does not help. Other C# solution did end in sansar cannot find system.numerics i did add the line in the code.

I gave up on linear movement. a simple 5 degree ramp seems to hard for sansar. or the object is starting to rotate.

So i made a good normal pos movement script. But without the code below i think i can never move it in all directions in steps.

I think C# in sansar is to complex, and that need to change or it's not attractive for people. And the positive and negaitive system make things only more difficult. the could have at least stay in the positive range.

Still try to convert this code. i now post all 3 lines so you see what it's doing i hope. You guys advise to try things that are above my head to.

This LSL code i used in SL/Opensim.

`trackstartposition = trackcurrentposition+offset-<trackpartsize/trackdivide ,0.0 , 0.0>*trackrotation;trackcenterposition = trackcurrentposition+offset-<0.0 ,0.0 , 0.0>*trackrotation;trackendposition = trackcurrentposition+offset+<trackpartsize/trackdivide ,0.0 , 0.0>*trackrotation; `

No massive building in sansar before i have a simple train.

Edited by Richardus Raymaker
• Gindipple

in a word, Rotate()

Is C# a complex language? yes, and that's also a very big benefit

It is also far superior to LSL.

I think you are struggling with math more than C#. That's not uncommon.

I encourage you to keep at it, just break it down more and go slow with small incremental steps.

• Galen

Yep. I said it before, Richardus. You can't do Vector * Quaternion and have it do a rotation for you. Use Vector.Rotate(ref Quaternion).

• Richardus Raymaker

I tried rotate. but never got it working. Same with Lerp. because i did add ref. But that's not enough.

What would fix all problems (and mabye rotate is doing that) is if you can rotate the object so the X is rotating with it. Like you do with angularvelocity. But then i like that with Setpos and rot.

Now i know what i did wrong with rotate before. I need to try it again. Still a mystery what rotate really is doing. no documentation found about the real function.

Also admit, the LSL code can never work in sansar. because there are negaive and positive directions. But i do not like LSL

And yes, math is the big struggle. The basics of C# are like otehr languages.

"Back to the drawingboard"

Edited by Richardus Raymaker
• Richardus Raymaker

Same error as with Lerp.

Let's see if google works better at this clock.

Edited by Richardus Raymaker
• Gindipple

You cannot just type Vector.Rotate(something)

You have to have an object.

So like Vector A = new Vector(0.0f);

A.Rotate(something)

That is what that error message is telling you.

• Richardus Raymaker

Ohh.. It's a bit what the used in Delphi to. but a bit different. Did take me a while to get it. Need to relearn that. I think i did try that with Lerp. Let me try it again with rotate. Otherwise i read the link

• Richardus Raymaker

@gindipple @Galen. So if i understand rotate good then when i do this.

Vector facing = new Vector(0, 0, 90);
Quaternion rot = Quaternion.FromEulerAngles(facing);
Vector rotResult = new Vector(0, 0, 0);
rotResult.Rotate(ref rot);
Log.Write("B1: " + rotResult.ToString());

Then i would expect output show (0,0,90) but i always get (0,0,0)

Also, if i do not put log.write between  while (true)  { } It seems to not always write to the log.

• Gindipple

90 is a degree, convert it to Radians

see my recent bug report on Log.Write()

rotating a vector of size 0 isn't gong to get you much

• Richardus Raymaker

Ok. i made possible a small error with conversion. It's all looking so fast the same. For safety i changed the rotation so it's not 0. But. i do not see any change.

A1: (0.7069991,0.01234072,0,0.7071068)
B1: <1,1,1>

Vector facing = new Vector(1, 1, 90);
facing.W = 0;
Quaternion rot = Quaternion.FromEulerAngles(facing);
Log.Write("A1: " + rot.ToString());

Vector rotResult = new Vector(1, 1, 1);
rotResult.Rotate(ref rot);
Log.Write("B1: " + rotResult.ToString());

• Gindipple

You need to capture the output of Rotate()

try Vector MyNewRotatedVector = rotResult.Rotate(ref rot);

• Richardus Raymaker

That's a trap. It feels like it makes code only more complex then needed. Well i have at least some output. But it does not feel correct. Getting this as result.

<-0.9823952,0.9820935,1.034598>

Expected a higher number on Z.
Or i expect the wrong the from Rotate()

• Galen

If you are trying to rotate something around the look at Vector, that's cool. But if you are trying to rotate something so that it points in the same direction as look at, you need to do additional work. It is complicated work. I ended up avoiding it.

• Galen

Also:

rotResult = someVector.Rotate(ref rot);

• Richardus Raymaker

I tried Rotate i get some results. But complete lost with what the use of rotate really is. Same with fromlook. And so there a few more commands.

It would be nice if you can do SetPosition on the X direction. and stil rotate the object and rotate also the X with it so you can keep moving forward.

But i think that's not possible to. Or i do not see why

• Galen

Consider a simple example:

`Vector OriginalVector = new Vector(10, 0, 0);//WRONG: Quaternion Rot = Quaternion.FromEulerAngles(new Vector(0, 0, 90));Quaternion Rot = Quaternion.FromEulerAngles(new Vector(    0  * Mathf.RadiansPerDegree,    0  * Mathf.RadiansPerDegree,    90 * Mathf.RadiansPerDegree));Vector NewVector = OriginalVector.Rotate(ref Rot);`

This should give you <0, 10, 0>, though I didn't not run it to test.

In this case, you are expressing the rotation in Euler angles. The Z axis represents rotation around the Z axis ("yaw") using the right-hand rule. Think of a top spinning counter-clockwise.

The X value should represent rotation about the X axis ("pitch" if the object is facing forward along the Y axis) and the Y value should represent rotation about the Y axis ("roll").

It looks to me like you are trying to do something very particular: get some thing to point in the same direction that the person is facing. This is a vector, not an orientation. So you cannot just use it as though it were a rotation value.

I have a useful formula for you. You can get a vector pointed parallel with another vector using a simple algorithm:

`Vector SomeVector = new Vector(123, 321, 132);Vector TargetDirection = new Vector(1, 1, 0);SomeVector = TargetDirection.Normalized() * SomeVector.Length();`

That is, you take your target direction (must be non-zero length) and normalize it (make it length = 1) and then multiply by the magnitude of your original vector (SomeVector.Length()).

Now, this doesn't really solve your problem. You are (probably) trying to find the quaternion that represents a rotation of an object so that it points in a direction you specify. That's where the real work comes in.

However, one clue to keep in mind is that one "facing" vector does not a rotation make. You need to turn along some axis. You could choose the vertical (Z) axis to rotate around. Then you just need to find the rotation around Z that turns your object in the "facing" direction. That gets you part of the way there.

Edited by Galen
• Gindipple

Watch and learn

This uses projected vectors, not entirely the same thing as a rotation, but could be adopted to work like one. And a bit more simplistic than messing with Quanternians.

• Richardus Raymaker

I just tried it galen. The result is D1: <-4.480687,8.939935,0> with this code. Tim e to watch gindipple video and make a pivot type thing in blender.

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

### FromEulerAngles Method

Generates the corresponding quaternion.

## Syntax

public static Quaternion FromEulerAngles (Vector a)

#### Parameters

a
A vector of angles in radians.

#### Returns

The corresponding quaternion.

## Remarks

Rotates first around X (local/global coincide), then around new local Y, and finally around new local Z.

## Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0
• Richardus Raymaker

Confused, but i think you where pointing at the NewVector. So i converted that , i cannot do it in a single row. but did X,Y,Z separate. But the output is something i need to look a while at. Mabye confused because the negative numbers. when you input positive.

rX: -76.7244601303973

rY: 27.77946041416

rZ: 179.999995125836

So, the code i have now. I wish the object properties could view it in degree, radians and angles. Then you can simplfy the code lots.

`Vector OriginalVector = new Vector(10, 0, 0);Quaternion Rot = Quaternion.FromEulerAngles(new Vector(0, 0, 90));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());`

And i made a new object. This arrows point in the positive way in sansar. So i plan to use this for some basic rotate testing. As long physics not bite it, same shape as object.