本文整理汇总了C#中Matrix3.ToQuaternion方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix3.ToQuaternion方法的具体用法?C# Matrix3.ToQuaternion怎么用?C# Matrix3.ToQuaternion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix3
的用法示例。
在下文中一共展示了Matrix3.ToQuaternion方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrepareSimulationParameters
/// <summary>
/// This function will get used by importers for example if there were only strand vertex positions available.
/// It will calculate everything inside of the HairStrand and HairStrandVertex based off the vertex positions.
///
/// This function assumes that hair strands always have atleast 2 vertices!
/// and atleast 2 strands.
///
/// NOTE: This is currently non-functional, it seems like somewhere some rounding issues happen that will make the output of this unusable.
/// The logic was taken from AMD's AssetConverter. I already spent some days of debugging on this but there is something really weird going on here.
/// My best guess is that C++ floats are more precise than C# floats for this calculations.
/// </summary>
public void PrepareSimulationParameters(ref int hairIndexCounter)
{
// TODO: Validity checks
int counterOffset = hairIndexCounter;
for (int i = 0; i < this.strandCount; i++)
{
// Get current strand
HairStrand strand = this.strands[i];
// Set the root follow hair offset
if (strand.isGuidanceStrand)
strand.followRootOffset = new Vector4(0, 0, 0, hairIndexCounter);
else
{
if (strand.guidanceStrand == null)
throw new FormatException("Tried to process a follow strand without guidance strand reference!");
Vector3 offset = strand.vertices[0].position - strand.guidanceStrand.vertices[0].position;
strand.followRootOffset = new Vector4(offset, counterOffset + this.strands.FindIndex(0, this.strands.Count, s => s == strand.guidanceStrand));
}
// First vertex
HairStrandVertex firstVertex = this.strands[i].vertices[0];
HairStrandVertex secondVertex = this.strands[i].vertices[1];
{
Vector3 vec = (secondVertex.position - firstVertex.position);
Vector3 vecX = Vector3.Normalize(vec);
Vector3 vecZ = Vector3.Cross(vecX, new Vector3(1, 0, 0));
if (vecZ.LengthSquared < 0.0001f)
{
vecZ = Vector3.Cross(vecX, new Vector3(0, 1, 0));
}
vecZ.Normalize();
Vector3 vecY = Vector3.Normalize(Vector3.Cross(vecZ, vecX));
// Construct rotation matrix
Matrix3 rotL2W = new Matrix3();
rotL2W.R0C0 = vecX.x;
rotL2W.R1C0 = vecX.y;
rotL2W.R2C0 = vecX.z;
rotL2W.R0C1 = vecY.x;
rotL2W.R1C1 = vecY.y;
rotL2W.R2C1 = vecY.z;
rotL2W.R0C2 = vecZ.x;
rotL2W.R1C2 = vecZ.y;
rotL2W.R2C2 = vecZ.z;
firstVertex.localTranslation = firstVertex.position;
firstVertex.localRotation = rotL2W.ToQuaternion();
firstVertex.globalTransform = firstVertex.localTransform;
}
// The rest n-1 vertices
for (int j = 1; j < strand.vertices.Count; j++)
{
Vector3 currentPosition = strand.vertices[j].position;
Vector3 previousPosition = strand.vertices[j-1].position;
HairStrandVertex previousVertex = strand.vertices[j - 1];
HairStrandVertex currentVertex = strand.vertices[j];
Vector3 vec = Vector3.TressFXTransform((currentPosition - previousPosition), Quaternion.Invert(previousVertex.globalRotation));
Vector3 vecX = Vector3.Normalize(vec);
Vector3 X = new Vector3(1.0f, 0, 0);
Vector3 rotAxis = Vector3.Cross(X, vecX);
float angle = Mathf.Acos(Vector3.Dot(X, vecX));
if (Mathf.Abs(angle) < 0.001f || rotAxis.LengthSquared < 0.001f)
{
currentVertex.localRotation = Quaternion.Identity;
}
else
{
rotAxis.Normalize();
Quaternion rot = Quaternion.FromAxisAngle(rotAxis, angle);
currentVertex.localRotation = rot;
}
currentVertex.localTransform.translation = vec;
currentVertex.globalTransform = previousVertex.globalTransform.Multiply(currentVertex.localTransform);
// Set the reference vector
//.........这里部分代码省略.........
示例2: PrepareSimulationParameters
//.........这里部分代码省略.........
{
int jk = 0;
}
Vector3 vec = (secondVertex.position - firstVertex.position);
Vector3 vecX = Vector3.Normalize(vec);
Vector3 vecZ = Vector3.Cross(vecX, new Vector3(1, 0, 0));
if (vecZ.LengthSquared < 0.0001f)
{
vecZ = Vector3.Cross(vecX, new Vector3(0, 1, 0));
}
vecZ.Normalize();
Vector3 vecY = Vector3.Normalize(Vector3.Cross(vecZ, vecX));
// Construct rotation matrix
Matrix3 rotL2W = new Matrix3();
rotL2W.R0C0 = vecX.x;
rotL2W.R1C0 = vecX.y;
rotL2W.R2C0 = vecX.z;
rotL2W.R0C1 = vecY.x;
rotL2W.R1C1 = vecY.y;
rotL2W.R2C1 = vecY.z;
rotL2W.R0C2 = vecZ.x;
rotL2W.R1C2 = vecZ.y;
rotL2W.R2C2 = vecZ.z;
firstVertex.localTranslation = firstVertex.position;
firstVertex.localRotation = rotL2W.ToQuaternion();
firstVertex.globalTransform = firstVertex.localTransform;
}
else
{
// -6.54806995f 71.0205994f 44.4449997f
// if (vertex.position.x == -4.19069004f && vertex.position.y == 73.1125031f && vertex.position.z == 42.9104004f)
if (i == 10 && j == 9) // vertex.position.x == -33.5211029f && vertex.position.y == -21.6556110f && vertex.position.z == -11.5229073f)
{
int elite = 123;
}
Vector3 v = Vector3.Cross(new Vector3(1, 0, 0), new Vector3(1, 0, 0.010100123f));
float d = Vector3.Dot(new Vector3(1, 0, 0), new Vector3(1, 0, 0.010100123f));
float angleTest = Mathf.Acos(d);
Vector3 vec = Vector3.TressFXTransform((currentPosition - previousPosition), Quaternion.Invert(previousVertex.globalRotation));
Vector3 vecX = Vector3.Normalize(vec);
Vector3 X = new Vector3(1.0f, 0, 0);
Vector3 rotAxis = Vector3.Cross(X, vecX);
float angle = Mathf.Acos(Vector3.Dot(X, vecX));
if (Mathf.Abs(angle) < 0.0011f || rotAxis.LengthSquared < 0.0011f)
{
vertex.localRotation = Quaternion.Identity;
}
else
{
rotAxis.Normalize();