fix operator*

This commit is contained in:
ousttrue
2021-05-10 20:59:52 +09:00
parent 46add88112
commit b3dd5dc1f3
3 changed files with 57 additions and 60 deletions

View File

@@ -1,6 +1,5 @@
using System;
using System.Text;
using UniGLTF.Extensions.VRMC_node_constraint;
using UnityEditor;
using UnityEngine;
@@ -36,12 +35,9 @@ namespace UniVRM10
void DrawDstCurrent()
{
var s = m_target.transform.lossyScale.x;
// current
Handles.matrix = m_target.transform.localToWorldMatrix;
Handles.matrix = m_target.GetDstCurrent().TRS(0.05f * s);
Handles.color = Color.yellow;
var size = 0.05f / s;
Handles.DrawWireCube(Vector3.zero, new Vector3(size, size, size));
Handles.DrawWireCube(Vector3.zero, Vector3.one);
}
void DrawDstCoords()

View File

@@ -18,7 +18,7 @@ namespace UniVRM10
var toRelative = from.worldToLocalMatrix;
return new TR(toRelative.rotation * t.rotation, toRelative.MultiplyPoint(t.position));
}
public TR(Quaternion r, Vector3 t)
{
Rotation = r;
@@ -31,6 +31,6 @@ namespace UniVRM10
public Matrix4x4 TRS(float s) => Matrix4x4.TRS(Translation, Rotation, new Vector3(s, s, s));
public static TR operator *(TR a, TR b) => new TR(a.Rotation * b.Rotation, b.Rotation * a.Translation + b.Translation);
public static TR operator *(TR a, TR b) => new TR(a.Rotation * b.Rotation, a.Rotation * b.Translation + a.Translation);
}
}

View File

@@ -94,59 +94,15 @@ namespace UniVRM10
public TR GetSourceCurrent()
{
switch (SourceCoordinate)
var coords = GetSourceCoords();
if (m_src != null)
{
case ObjectSpace.model:
{
var r = Quaternion.identity;
if (Source != null)
{
if (ModelRoot != null)
{
r = ModelRoot.rotation;
if (m_src != null)
{
r *= m_src.RotationDelta(ObjectSpace.model);
}
}
}
var t = Vector3.zero;
if (Source != null)
{
t = Source.position;
}
return new TR(r, t);
}
case ObjectSpace.local:
{
if (Source != null)
{
if (m_src != null)
{
// runtime
var parent = Quaternion.identity;
if (Source.parent != null)
{
parent = Source.parent.rotation;
}
var delta = m_src.RotationDelta(ObjectSpace.local);
return new TR(parent * m_src.LocalInitial.Rotation * delta, Source.position);
}
else
{
return TR.FromWorld(Source);
}
}
return TR.Identity;
}
return coords * new TR(m_src.RotationDelta(SourceCoordinate));
}
else
{
return coords;
}
throw new NotImplementedException();
}
public Quaternion Delta
@@ -180,7 +136,7 @@ namespace UniVRM10
{
parent = TR.FromWorld(transform.parent);
}
return m_dst.LocalInitial * parent;
return parent * m_dst.LocalInitial;
}
else
{
@@ -192,6 +148,51 @@ namespace UniVRM10
throw new NotImplementedException();
}
public TR GetDstCurrent()
{
var coords = GetDstCoords();
if (m_src != null)
{
return coords * new TR(m_src.RotationDelta(SourceCoordinate));
}
else
{
return coords;
}
// switch (DestinationCoordinate)
// {
// case ObjectSpace.model:
// {
// var r = Quaternion.identity;
// if (ModelRoot != null)
// {
// r = ModelRoot.rotation;
// }
// return new TR(r, transform.position);
// }
// case ObjectSpace.local:
// {
// if (m_src != null)
// {
// // runtime
// var parent = TR.Identity;
// if (transform.parent != null)
// {
// parent = TR.FromWorld(transform.parent);
// }
// return parent * m_dst.LocalInitial;
// }
// else
// {
// return TR.FromWorld(transform);
// }
// }
// }
// throw new NotImplementedException();
}
/// <summary>
/// Editorで設定値の変更を反映するために、クリアする
/// </summary>