ECS Math.axisAngle()

Having a problem with the new ECS system. trying to use math.axisAngle but i get the error ‘math’ does not contain a definition for axisAngle. any ideas?

using Unity.Entities;
using Unity.Transforms;
using Unity.Mathematics;
using System;
using Unity.Jobs;
using UnityEngine;

public class Rotation_System : JobComponentSystem {
    private struct RotationJob : IJobProcessComponentData<Rotation_Speed, Rotation> {
        public float DeltaTime;

        public void Execute(ref Rotation_Speed speed, ref Rotation rot) {
//the line below here is the line in question.. the math.axisAngle..
            rot.Value = math.mul(math.normalize(rot.Value), math.axisAngle(math.up, speed.RotationValue * DeltaTime));
        }
    }
}

Looks like it’s only part of the quaternion structure (see the file in github here):

        //...
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static quaternion axisAngle(float3 axis, float angle)
        {
            float sina, cosa;
            math.sincos(0.5f * angle, out sina, out cosa);
            return quaternion(float4(math.normalize(axis) * sina, cosa));
        }
        //...

The problem is, i believe the quaternion structure won’t work with the new ECS job system? in all of the examples for ECS it shows them using this exact line, with the same using statements. not sure if im missing something somewhere… but im at a standstill atm.

Under the hood, it looks like it’s just a blittable struct containing a float4 with associated helper methods. It should work with ECS/Jobs just fine.

EDIT: The version on github is clearly newer than what the sample docs/projects are using. It’s likely they moved that function into quaternion since it was a more recent addition than when most of the samples were made. If you’re updating the math package with a manual manifest reference or copying it in from github, it’s likely you have a version that already have those changes.

The samples definitely need some cleanup. The problem is all the libraries are in various states of flux, plus it’s summer and I’m sure a lot of Unity devs are getting their family vacation times in before the push for 2018.3.

1 Like

Recursive is correct, the quaternion structure will do it. please note its quaternion and NOT Quaternion, lower case q.

quaternion.axisAngle(math.up(),speed.RotationValue * DeltaTime));

this seems to do the trick just right.

thank you!

I just found and fixed a few outdated references to “math.axisAngle” in the Entities package documentation, this will be part of the next release. Thanks a lot for drawing our attention to the issue!