Notifications
Clear all

[Closed] BlendMatrix

 MZ1
fn dotQuat q q_prev =
( 
   (q.w * q_prev.w + q.x * q_prev.x + q.y * q_prev.y + q.z * q_prev.z) < 0 
)

fn blendMatrix m1: m2: weight:0.5 =
(
	r1 = m1.rotationpart
	r2 = m2.rotationpart
    if (dotQuat r1 r2) do r1 *=-1
	
    r = slerp (normalize r1) (normalize r2) weight
	t = m1.translationpart + (m2.translationpart - m1.translationpart) * weight
	s = m1.scalepart
	translate (rotate (scale (matrix3 1) s true) r) t  -- ignores scale
)

I found this function from @denisT which is great. Anyone can help me to convert this code to the C# code? I just stocked in some parts. for example:

if (dotQuat r1 r2) do r1 *=-1

We can’t multiply Quat value like that.

21 Replies
1 Reply
(@serejah)
Joined: 11 months ago

Posts: 0
really?

or maybe you’re talking about something else?

 MZ1

Yes! that’s it. And I tried another function from SDK, seems to work:

public static class TestClass
{
    static IGlobal globalInterface = GlobalInterface.Instance;
    static IInterface coreInterface = globalInterface.COREInterface;

    public static IMatrix3 BlendMatrix(IMatrix3 tm1, IMatrix3 tm2,float ratio)
    {
        IMatrix3 tm3 = globalInterface.Matrix3.Create(true);

        if (ratio == 1.0f) {return tm2; }
        else if (ratio == 0.0f) return tm1;

        IAffineParts parts1 = globalInterface.AffineParts.Create();
        globalInterface.DecompAffine(tm1, parts1);

        IAffineParts parts2 = globalInterface.AffineParts.Create();
        globalInterface.DecompAffine(tm2, parts2);

        if (parts1.T != parts2.T) { parts1.T = parts1.T.Add(parts2.T.Subtract(parts1.T).MultiplyBy(ratio)); }

        parts1.Q.MakeClosest(parts2.Q);
        parts1.Q = globalInterface.Slerp(parts1.Q, parts2.Q, ratio);

        if (parts1.K != parts2.K) { parts1.K = parts1.K.Add(parts2.K.Subtract(parts1.K).MultiplyBy(ratio)); }

        tm3.IdentityMatrix();
        tm3.SetRotate(parts1.Q);
        tm3.PreScale(parts1.K);
        tm3.Translate(parts1.T);
        return tm3;
    }
}

I hope Denis approve this as well

1 Reply
(@klvnk)
Joined: 11 months ago

Posts: 0

or perhaps Character Animation Technologies

Did you test it for memory leaks? Last time I used matrix3 and point3 classes intensively it was leaking as hell

 MZ1

No, I didn’t tested performance yet. do you have any advice for this? I’m trying to create a pose importer-exporter.

Reference types like IPoint3 & IMatrix3 allocate themselves on the heap so I had to use custom value type structs example to eliminate mem leaks.
Calling .Dispose for each class instance or wrapping everything in using’s makes code much slower.

 MZ1

The link is broken.

 MZ1

of course , This is common in Computer Graphic!

fixed the link

come on you didn’t even change the variable names !

 MZ1

Why I should change the variables? Sorry, I don’t get your point.
I just want to make sure the code that I found in the SDK is the best code to convert and use in the C# library. I mean maybe there is a built-in library or any other resources for this.
My first challenge is to find the correct mathematical function and second challenge is to make the correct C# one.

Page 1 / 2