first commit
This commit is contained in:
34
Assets/dobot/Sc/MotionPlanner.cs
Normal file
34
Assets/dobot/Sc/MotionPlanner.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MotionPlanner
|
||||
{
|
||||
public Frame[] GeneratePath(Frame start, Frame end, int steps)
|
||||
{
|
||||
var list = new List<Frame>();
|
||||
if (steps <= 0)
|
||||
{
|
||||
list.Add(new Frame(end.Position, end.Rotation));
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
for (int i = 0; i <= steps; i++)
|
||||
{
|
||||
float t = i / (float)steps;
|
||||
Vector3 pos = Vector3.Lerp(start.Position, end.Position, t);
|
||||
Quaternion rot = Quaternion.Slerp(start.Rotation, end.Rotation, t);
|
||||
list.Add(new Frame(pos, rot));
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
|
||||
// Utility: create N repeated frames (hold)
|
||||
public Frame[] RepeatFrame(Frame f, int count)
|
||||
{
|
||||
if (count <= 0) return new Frame[0];
|
||||
Frame[] arr = new Frame[count];
|
||||
for (int i = 0; i < count; i++) arr[i] = new Frame(f.Position, f.Rotation);
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user