I found the problem!
if run the code with debugger step by step I get normalized values (the IPoint3.Length set to 1!)
But if run the code normal and log the vars to listener all works!!
public class SDKTools
{
private static readonly IGlobal Global = Autodesk.Max.GlobalInterface.Instance;
private static void LogToListener(string message, bool newLine = true)
{
if (Global != null)
{
IListener listener = Global.TheListener;
IWindowStream editStream = listener.EditStream; // Declare and assign editStream here
editStream.Wprintf(message + (newLine ? Environment.NewLine : string.Empty), null);
}
}
private string Point3ToStr(IPoint3 point)
{
return $"[{point.X}, {point.Y}, {point.Z}]";
}
public float[] GetPoint3()
{
IPoint3 mypoint = Global.Point3.Create(8f, 6f, 4f);
float myX = mypoint.X;
float myY = mypoint.Y;
float myZ = mypoint.Z;
float pLen = mypoint.Length;
LogToListener($"mypoint: [{myX}, {myY}, {myZ}] Lenght: {pLen}");
IMatrix3 myMatrix = Global.Matrix3.Create();
myMatrix.SetRow(3, mypoint);
IPoint3 row3 = myMatrix.GetRow(3);
LogToListener($" myMatrix Row3: {Point3ToStr(row3)}");
float[] aPoint = new float[3];
aPoint[0] = myX;
aPoint[1] = myY;
aPoint[2] = myZ;
LogToListener($" aPoint: {aPoint} ");
IPoint3 mypoint2 = Global.Point3.Create();
//get values again
mypoint2.X = 10.0f;
mypoint2.Y = 5.0f;
mypoint2.Z = 2.0f;
LogToListener($" mypoint2: {Point3ToStr(mypoint2)}");
IPoint3 sum = mypoint2.Add(mypoint); //mypoint2+mypoint = 18.0f, 11.0f, 6.0f
LogToListener($" Sum = mypoint2 + mypoint: {Point3ToStr(sum)} ");
IPoint3 point3 = myMatrix.PointTransform(sum); // Point3 = [26, 17, 10]
float[] SumPoints = new float[3];
SumPoints[0] = point3.X;
SumPoints[1] = point3.Y;
SumPoints[2] = point3.Z;
LogToListener($" point3 = myMatrix * sum: {Point3ToStr(point3)} ");
return SumPoints;
}
}
Output
mypoint: [8, 6, 4] Lenght: 10.77033
myMatrix Row3: [8, 6, 4]
aPoint: System.Single[]
mypoint2: [10, 5, 2]
Sum = mypoint2 + mypoint: [18, 11, 6]
point3 = myMatrix * sum: [26, 17, 10]