// MonoBehaviour.Updateで回す際に呼び出す処理 public void ManualExecute(int index, Transform transform) { DokabenStruct accessor = this.Accessor[index]; transform.rotation = Rotate(ref accessor, transform.rotation); this.Accessor[index] = accessor; }
// 回転の算出 Quaternion Rotate(ref DokabenStruct accessor, Quaternion rot) { if (accessor.DeltaTimeCounter >= Constants.Interval) { accessor.CurrentRot += accessor.CurrentAngle; rot = Quaternion.AngleAxis(accessor.CurrentRot, -Vector3.right); accessor.FrameCounter = accessor.FrameCounter + 1; if (accessor.FrameCounter >= Constants.Framerate) { accessor.CurrentAngle = -accessor.CurrentAngle; accessor.FrameCounter = 0; } accessor.DeltaTimeCounter = 0f; } else { accessor.DeltaTimeCounter += this.DeltaTime; } return(rot); }
// 回転の算出 static DokabenStruct Rotate(float deltaTime, DokabenStruct data) { Matrix4x4 m = Matrix4x4.identity; float x = 0f, y = 0f, z = 0f; m.SetTRS(new Vector3(x, y, z), Quaternion.identity, Vector3.one); if (data.DeltaTimeCounter >= Constants.Interval) { // 原点を-0.5ずらして下端に設定 float halfY = y - 0.5f; float rot = data.CurrentAngle * Mathf.Deg2Rad; float sin = Mathf.Sin(rot); float cos = Mathf.Cos(rot); // 任意の原点周りにX軸回転を行う m.m11 = cos; m.m12 = -sin; m.m21 = sin; m.m22 = cos; m.m13 = halfY - halfY * cos + z * sin; m.m23 = z - halfY * sin - z * cos; data.FrameCounter = data.FrameCounter + 1; if (data.FrameCounter >= Constants.Framerate) { data.CurrentAngle = -data.CurrentAngle; data.FrameCounter = 0; } data.DeltaTimeCounter = 0f; } else { data.DeltaTimeCounter += deltaTime; } data.Matrix = m; return(data); }
// Jobで実行されるコード実行 public void Execute(int index) { DokabenStruct accessor = this.Accessor[index]; this.Accessor[index] = JobParallelForTest.Rotate(this.DeltaTime, accessor); }