PlayBASIC Math Libraries – Early Preview




New core math features originally planned for PlayBASIC 2 have been pulled forward and are now nearing completion.




This gallery entry showcases recent work on a set of new PlayBASIC libraries focused on **math, geometry, and data handling**. These additions include a **Vector3 library**, a **Matrix library**, and an **Intersection library** designed to handle common geometric tests such as ray–sphere and ray–plane intersections.

These features were originally scheduled for PlayBASIC 2, but development realities made it clear they needed to be finished sooner. Rather than delay everything, the decision was made to bring them forward and integrate them properly into the current runtime.

A large part of this work involved solving long-standing issues with **floating-point accuracy**, particularly when comparing values during intersection tests. Floating point math is notoriously imprecise, and careless comparisons can easily lead to incorrect or unstable results.




Pointer-Based Structures

One of the key enabling changes behind these libraries is updated support for **typed pointers**. PlayBASIC can now safely:

• Declare pointers to specific types
• Allocate and assign structure data
• Copy entire structures from right to left
• Clear structure fields by zero-assignment
• Use raw memory pointers (including arrays) as data sources

This functionality was either broken or unavailable during much of the long transition from version 1.64 to 1.65, and several hard-to-track crashes have now been fully resolved.




Why This Matters

These changes allow PlayBASIC code to be:

• Cleaner
• Safer
• More expressive
• Closer to modern programming styles

They also explain why recent updates were made to the `linkdll` system — these libraries depend on passing and manipulating structured data through pointers, something older versions simply couldn’t do reliably.




Looking Ahead

In PlayBASIC 2, vectors will become far more natural to use — almost as utilitarian as integers and floats. This opens the door for cleaner syntax, multiple-value assignments, and fewer lines of boilerplate code overall.

The goal remains the same:
Keep PlayBASIC simple, powerful, and fun — while letting retro languages do increasingly crazy things.




More updates soon.