Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / Spline Maths Help

Author
Message
BitManip
10
Years of Service
User Offline
Joined: 20th Dec 2013
Location: Essex
Posted: 14th Nov 2021 14:44
Hi All

I am trying to copy the code from the youtube video of this :

[video=youtube]https://www.youtube.com/watch?v=9_aJGUTePYo&t=861s [/video]

But my paths are all over the place and my poor maths will not help me at all!

My code is as follows:



and to draw the spline (quick a dirty)



Any help is welcomed greatly

I control all the juicy in here!

Attachments

Login to view attachments
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 14th Nov 2021 15:13
I did a simplified version of this a few weeks ago but never did get round to adding more path points

https://forum.thegamecreators.com/thread/227843#msg2666293

javidx9 is one mean coder, I'v learnt a lot of C++ from him, I actually need this for a project I am working on so I may do this tutorial tonight, all I can suggest for now is rewatch and redo the tut until you get it right


Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
BitManip
10
Years of Service
User Offline
Joined: 20th Dec 2013
Location: Essex
Posted: 14th Nov 2021 15:22
PartTimeCoder

I may be wrong, but your is for Bezier Curves with control points whereas the code I am *failing* to get to work is for splines where the curve passes though the control points?

I can get the bezier code to work but wanted more control and accuracy of the path.

Or am I missing something.
I control all the juicy in here!
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 14th Nov 2021 15:32
Well its a little bit of both, what you want is called a B-Spline I think, all semantics to me mate my math isn't that great either I just watch a lot of people smarter than myself hoping to soak some of it up.

Without watching the entire video I cant see where you went wrong and if I watch the vid I am doing the code and don't have time right now, Id be happy to go through it with you once I know what I am talking about! lol

Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 14th Nov 2021 15:41
One thing I do know tho, when I set my mind to something I get it done, I will get this sussed tonight, 100%
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
hendron
8
Years of Service
User Offline
Joined: 20th Dec 2015
Location:
Posted: 14th Nov 2021 15:47
The way I make splines that flow through each point is by using linked cubic (4 point) bezier curves. The 1st and 4th points of each curve act as the path (control) points and the 2nd and 3rd points act as tangent controls around the control points. As long as the tangent points form a straight line through the control points, you'll get a smooth path through them.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 14th Nov 2021 16:02
Yeah, so taking my previous example (link)

Cubic(a as tVec2, b as tVec2, c as tVec2, d as tVec2, t as float)

c and d become a and b of the next path segment, and b aligns with a, c aligns with b for each seg?

I am not sure how it lines up, I know that function can produce a spline I just never got round to it
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
hendron
8
Years of Service
User Offline
Joined: 20th Dec 2015
Location:
Posted: 14th Nov 2021 16:20 Edited at: 14th Nov 2021 16:34
as an example, say you have 2 cubic bezier curves (1a, 1b, 1c, 1d) and (2a, 2b, 2c, 2d).

1a = 1st path point
1b = tangent handle
1c = tangent handle
1d = 2nd path point
2a = 2nd path point, must be the same position as 1d
2b = tangent handle
2c = tangent handle
2d = last path point

The raw path from 1c, through 1d/2a, to 2b, should form a straight line. Basically as long as you ensure the vector from 1c to 1d is the same as 2a to 2b, the curve will flow smoothly through the point 1d/2a.

here's an image I found on stack overflow that illustrates the idea. Z being the path points and the squares being tangent controls. Each Z to Z segment is a cubic bezier.

hendron
8
Years of Service
User Offline
Joined: 20th Dec 2015
Location:
Posted: 14th Nov 2021 17:35 Edited at: 14th Nov 2021 17:42
Here's a bit of a rough example I put together. Hope it helps!

PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 14th Nov 2021 17:42 Edited at: 14th Nov 2021 17:44
Ok, I think I get it,

@BitManip, my function *can* do what you want but you are right in saying its not suited, javids math automates everything hendron just outlined and hence why its 100 times more complicated.

I think this is the calculation that positions those *virtual* handles and q1 and q4 are the actual path nodes, so you get the same result as the image above but without the control nodes .. ?
q2 = 3.0*ttt# - 5.0*tt# + 2.0
q3 = -3.0*ttt# + 4.0*tt# + t#

I think I understand but I am not 100%, recheck those 2 calculations as they are the control points

not sure if this is effecting it but multiplication verses subtracting and addition, I think multiplication takes precedence so you might need to encapsulate the equations in the order they need evaluating, there are 4 equations in one and not a bracket in sight, I am pretty sure that could effect it, again, not 100%

Edit: ah cool I'll take a look when I get home.

@BitManip, does hendron's code work for you?, is that what you was after?
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
BitManip
10
Years of Service
User Offline
Joined: 20th Dec 2013
Location: Essex
Posted: 14th Nov 2021 18:19 Edited at: 14th Nov 2021 18:20
ANSWERED!

My error (surprise).

I had

q1 = -ttt# * 2.0*tt# - t#

and it should have been

q1 = -ttt# + 2.0*tt# - t#

(Addition instead of multiplication).

Now works a dream with as many control points as I care to wave at it!

Thanks for your help anyhow. and OneLoneCoder...Awesome!
I control all the juicy in here!
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 14th Nov 2021 23:13
Ah! I was 1 line out! lol

Awesome glad you got it working, do you mind if I steal your code? lol
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Nov 2021 06:20
Maybe my recent example will help you?

https://forum.thegamecreators.com/thread/228068
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-04-24 12:31:02
Your offset time is: 2024-04-24 12:31:02