| 1989 | } |
| 1990 | |
| 1991 | void Render2D::DrawSpline(const Float2& p1, const Float2& p2, const Float2& p3, const Float2& p4, const Color& color, float thickness) |
| 1992 | { |
| 1993 | RENDER2D_CHECK_RENDERING_STATE; |
| 1994 | |
| 1995 | // Find amount of segments to use |
| 1996 | const Float2 d1 = p2 - p1; |
| 1997 | const Float2 d2 = p3 - p2; |
| 1998 | const Float2 d3 = p4 - p3; |
| 1999 | const float len = d1.Length() + d2.Length() + d3.Length(); |
| 2000 | const int32 segmentCount = Math::Clamp(Math::CeilToInt(len * 0.05f), 1, 100); |
| 2001 | const float segmentCountInv = 1.0f / (float)segmentCount; |
| 2002 | |
| 2003 | // Draw segmented curve |
| 2004 | Lines2.Clear(); |
| 2005 | Lines2.Add(p1); |
| 2006 | for (int32 i = 1; i < segmentCount; i++) |
| 2007 | { |
| 2008 | const float t = (float)i * segmentCountInv; |
| 2009 | Float2 p; |
| 2010 | p.X = Math::Lerp(p1.X, p4.X, t); |
| 2011 | AnimationUtils::Bezier(p1.Y, p2.Y, p3.Y, p4.Y, t, p.Y); |
| 2012 | Lines2.Add(p); |
| 2013 | } |
| 2014 | Lines2.Add(p4); |
| 2015 | DrawLines(Lines2.Get(), Lines2.Count(), color, color, thickness); |
| 2016 | } |
| 2017 | |
| 2018 | void Render2D::DrawMaterial(MaterialBase* material, const Rectangle& rect, const Color& color) |
| 2019 | { |