How to draw [these kind of] splines?

Started by
2 comments, last by Juliean 9 years, 11 months ago

Hello,

I'm implementing visual scripting similar to what Unreal realizes in their blueprints to my engine. Now I'm wondering, how do you render those kind of connection-splines in DX/OpenGL?

2435-rocket_spawner_blueprint.png

As you can see in this screenshot, they behave quite... special... and appear totally smooth here. I suppose that did use something other than pure DX/OGL, but does somebody know a formular for generating enough controller-points between two points p1 and p2 so I can render such a smooth line in that fashion using line rendering?

Advertisement

To my eye it looks like most of the curves could be done using Bezier curves. E.g., for horizontal: (screen coord) control points p1 = p0 + (scale,0), p2 = p3 + (-scale,0), where p0 and p3 are the screen coord start/end points. It's been a few years since I've done it, but, if you're working in Windows, you can grab the window HDC and use GDI with PolyBezier. "scale" would be proportional to delta-x.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

I suspect you'll be able to draw such a spline as a Hermite curve using only an outgoing and an incoming set of positions and (flat/horizontal) tangents.

You can use the Hermite routines that come with the D3DX-library.

http://msdn.microsoft.com/en-us/library/windows/desktop/bb204998(v=vs.85).aspx

Or you can use the cubic equations mentioned there directly.

Thanks,

I managed to get a generic b-spline algorithmn that I further found to running using the control points you mentioned, though I had to use delta-x/2 to get the desired result. I'm simply drawing the lines in DX/GL for now, since my whole gui is rendered with those, it fit better than using GDI. Now all I've got to do is adding support for drawing thicker lines, but I already got an basic idea how to do this, so not a problem.

This topic is closed to new replies.

Advertisement