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 Classic Chat / catmull rom splines

Author
Message
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Nov 2021 17:58 Edited at: 21st Nov 2021 21:13
When I finally found my old spline source code, it was written in DBP which had hermite and catmull splines built in with the vector commands so I couldn't translate that to agk. So here's a super simple implementation. It's something I needed for my tower defense game, so I'll be building on this example and will update that bit here.





Cleaner code:



messy code:
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

Attachments

Login to view attachments
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Nov 2021 19:11
Nice one. Thanks
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Nov 2021 19:42 Edited at: 21st Nov 2021 19:51
Updated snippet. Shows how to traverse the path at a constant speed by calculating the overall length of the spline and angling a sprite to stay facing the path.
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

Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 21st Nov 2021 20:18
Wahoo, excellent !! thank you a lot, it's really good, not only to use it as path, but for drawing app !
Thanks again.
AGK2 tier1 - http://www.dracaena-studio.com
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Nov 2021 21:09 Edited at: 21st Nov 2021 21:16
Cleaned up the code, turned things into functions. That's probably my final update on this.

Performance can be improved by include an additional array into the Point2D UDT to maintain the lengths of the segments. If your path isn't changing dynamically very often then I'd suggest that route. Although, I do think the square roots could be removed now that I look at it.
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-20 09:43:01
Your offset time is: 2024-04-20 09:43:01