04-02-2023, 04:04 PM
No one seems to be answering this question, I read through the article and wrote this function that outputs quaternions by entering a point3 value, I'm pasting it here in case anyone else has the same trouble.
public Quat EulerToQuaternion(Point3 euler)
{
float yaw = euler.y * Mathf.Deg2Rad;
float pitch = euler.x * Mathf.Deg2Rad;
float roll = euler.z * Mathf.Deg2Rad;
float cy = Mathf.Cos(yaw * 0.5f);
float sy = Mathf.Sin(yaw * 0.5f);
float cp = Mathf.Cos(pitch * 0.5f);
float sp = Mathf.Sin(pitch * 0.5f);
float cr = Mathf.Cos(roll * 0.5f);
float sr = Mathf.Sin(roll * 0.5f);
Quat q = new Quat();
q.w = cy * cp * cr + sy * sp * sr;
q.x = cy * sp * cr + sy * cp * sr;
q.y = sy * cp * cr - cy * sp * sr;
q.z = cy * cp * sr - sy * sp * cr;
return q;
}
This is an example of a call function :
public void simulationStep()
{
for (int i = 0; i < eventParticleCount; i++)
{
int sInx = tf.GetSimIndex(i);
float eventAge = tf.GetEventAge(sInx);
tf.SetSeed(sInx,(int)GetFloat("seed"));
Point3 randRot = new Point3(0,0,tf.GetRandInt(sInx,0,4)*90);
tf.SetRot(sInx,EulerToQuaternion(randRot));
}
}
public Quat EulerToQuaternion(Point3 euler)
{
float yaw = euler.y * Mathf.Deg2Rad;
float pitch = euler.x * Mathf.Deg2Rad;
float roll = euler.z * Mathf.Deg2Rad;
float cy = Mathf.Cos(yaw * 0.5f);
float sy = Mathf.Sin(yaw * 0.5f);
float cp = Mathf.Cos(pitch * 0.5f);
float sp = Mathf.Sin(pitch * 0.5f);
float cr = Mathf.Cos(roll * 0.5f);
float sr = Mathf.Sin(roll * 0.5f);
Quat q = new Quat();
q.w = cy * cp * cr + sy * sp * sr;
q.x = cy * sp * cr + sy * cp * sr;
q.y = sy * cp * cr - cy * sp * sr;
q.z = cy * cp * sr - sy * sp * cr;
return q;
}
This is an example of a call function :
public void simulationStep()
{
for (int i = 0; i < eventParticleCount; i++)
{
int sInx = tf.GetSimIndex(i);
float eventAge = tf.GetEventAge(sInx);
tf.SetSeed(sInx,(int)GetFloat("seed"));
Point3 randRot = new Point3(0,0,tf.GetRandInt(sInx,0,4)*90);
tf.SetRot(sInx,EulerToQuaternion(randRot));
}
}