Author: Daniel Green
Description: Random useful source code
Keywords: free source code, R-Tree, skiplist, quaternion, intersection test, C++, class library

Free Source Code

Here are a few useful bits of free source code. You're completely free to use them for any purpose whatsoever. All I ask is that if you find one to be particularly valuable, then consider sending a brief thank you note to the email address in the code comments. Enjoy.

- Java Code
- C & C++

Java Code

The links following each Java implementation show HTML versions of the code with syntax highlighting which were generated using the Java to HTML utility below. The simpliest way to download one as a .java file is to view the page and copy & paste the text from your browser into a .java file.

JarLoader

Java class able to load all the jar files in a given directory containing classes of a given type. It can also be set to continuously track that directory for new jar files that are added later.

View the code

Component Dependency Handler

A small Java GUI utility class. Ever pull your hair out tracking down why some GUI component is not enabled or disabled when it should be? Or visible or invisible, etc? Sometimes the rules for knowing under exactly which combinations of application state should affect a given component can get quite complicated, and creating listeners with complex if/else blocks often result which need constant fixing. Well, there's a better way to manage all those state changing rules. Rather than trying to figure out all the possible components that might be affected by a given component state change and trying to set their states directly, you can create dependency graphs that describe which components are dependent on which others and then enforce those dependencies through the use of the ComponentDependencyHandler class. An object of this class represents all the dependencies of one component's particular state upon one or more other components. See the description and example code in the source file for details.

> View the code

Infinite Binary Tree

Here is a good Java example of one important way to create JTrees. This a tiny Java test program has some surprizingly interesting behavior. It creates a JTree with an infinite number of internal nodes and no leaf nodes! Each internal node is labeled with a unique positive integer such that every positive number can be found if you know where to look. The basic concept demonstrated is use of the TreeModel class to display hierarchically structured information that may be huge or expensive to access--for example, data in a database.

> View the code

java2html

You can find lots of converters by the same name with a quick Google search on the term "java2html" but most are way more complex than needed. I weeded through dozens and found this lettle gem which was small but effective. I did expand on it a bit and think it's quite useful. Click the following link to see the result of running java2hml.java on itself.

> View the code

Stack Method Extractor

This simple yet clever utility contains a static method which returns the full name of the method a given number of stack frames above the calling method Click following link to see the code. It's magic.

> View the code

C & C++ Code

R-Trees

Straight "C" implementation of Tony Gutman's R-Tree method, R-Trees provide Log(n) speed rectangular indexing into multi-dimensional data. Based on his original implementation, I've brought it up to date with ANCI specifications and added a nice improvment based on sphere volumes.

Download R-Tree code

Skiplists

Skiplists are fast associative collections invented by William Pugh. Key/Value pairs are added to skiplist containers and can then values looked up extremely quickly by key. The implementation is based on a fairly generic one originally in "C" by Bruno Grossniklaus which I converted into a C++ class library.

Download SkipList code

Quaternions

Implementation of a simple C++ quaternion class called "Squat". Popularized by a seminal paper by Ken Shoemake, a quaternion represents a rotation about an axis. Squats can be concatenated together via the `*` and `*=` operators and converted back and forth between transformation matrices. Implementation also includes a wonderful 3D vector macro library by Don Hatch.

Download Squat code

Polygon-Cube Intersection Testing

"C" implementation of an extremely fast and robust polygon-cube intersection test by Don Hatch and myself as published in Graphics Gems V. Very useful for collision detection and view frustum visibility checking.

View the readme file
Download PCube code

Back to the Superliminal home page.