protected override void BuildObstacles() { SetObstacleCount(1); Nebukam.ORCA.Obstacle o = SetObstacleLength(0, samples); Vector2 offset = colliderComponent.offset; float3 pos = transform.position, pt = float3(0f, colliderComponent.radius, pos.z), zero = float3(0f); quaternion rot = transform.rotation; float inc = Maths.TAU / samples; float3 Project(int sample) { float3 proj = Maths.RotateAroundPivot(pt, zero, float3(0f, 0f, inc * sample)); proj.x += offset.x; proj.y += offset.y; proj.z = pos.z; proj = Maths.RotateAroundPivot(proj, zero, rot); proj.x += pos.x; proj.y += pos.y; proj.z = pos.z; return(proj); } for (int i = 0; i < samples; i++) { o[i].pos = Project(i); } }
protected virtual void DrawObstacle(Color col) { for (int o = 0, oCount = m_obstacles.Count; o < oCount; o++) { Nebukam.ORCA.Obstacle subObstacle = m_obstacles[o]; int count = subObstacle.Count; for (int i = 1; i < count; i++) { DrawSegment(subObstacle[i - 1].pos, subObstacle[i].pos, col); } if (!subObstacle.edge) { DrawSegment(subObstacle[count - 1].pos, subObstacle[0].pos, col); } } }
protected Nebukam.ORCA.Obstacle SetObstacleLength(int index, int length) { Nebukam.ORCA.Obstacle o = m_obstacles[index]; int oLength = o.Count; if (oLength == length) { return(o); } while (oLength != length) { if (oLength < length) { o.Add(float3(0f)); } else { o.Pop(true); } oLength = o.Count; } return(o); }
protected override void BuildObstacles() { SetObstacleCount(doubleSided ? 2 : 1); Vector2[] points = colliderComponent.points; Vector2 offset = colliderComponent.offset; float3 pos = transform.position; quaternion rot = transform.rotation; int count = points.Length; Nebukam.ORCA.Obstacle o = SetObstacleLength(0, count); o.edge = true; float3 Project(Vector2 pt) { float3 proj = Maths.RotateAroundPivot(float3(pt.x + offset.x, pt.y + offset.y, pos.z), float3(0f), rot); proj.x += pos.x; proj.y += pos.y; proj.z = pos.z; return(proj); } for (int i = 0; i < count; i++) { o[i].pos = Project(points[i]); } if (doubleSided) { float3 overlap = float3(float.Epsilon, float.Epsilon, float.Epsilon); o = SetObstacleLength(1, count); o.edge = true; for (int i = 0; i < count; i++) { o[i].pos = Project(points[count - (i + 1)]) + overlap; } } }