Skip to content

2. Geometry Type Basics

Dietrich Geisler edited this page Apr 17, 2020 · 3 revisions

The theory behind geometry types is explored properly in the Gator paper (not linked here for anonymity reasons, but you can ask me for it). Practically, however, geometry types consist of three components: coordinate scheme, reference frame, and geometric object in the syntax form scheme<frame>.object. Note that since object is a type, it can be parameterized itself, as in the case of transformations.

We will leave the analysis of how to create schemes and objects to a later article (TODO: link that page here), and instead focus on how to declare frames and use geometry types. Declaring frames is used frequently in shader code to introduce a new reference frame in which to do calculations. Every reference frame has a name and a dimension, which both must be declared statically:

frame model has dimension 3;
frame world has dimension 3;
frame plane has dimension 2;

Variables can be declared with a geometry type so long as the incoming data matches the given frame dimension and associated scheme. We provide in glsl_defs the definitions for cartesian and homogeneous coordinates (cart2, cart3, and hom), which we will use in the following examples:

using "glsl_defs.lgl"; // or another standard library

cart3<model>.point x = [1., 2., 3.];
cart3<world>.vector y = [2., 3., 4.];
// Declaring a transformation from model to world
cart3<model>.transformation<world> uModel;
// Example of a bad declaration; frame dimension doesn't fit scheme
cart3<plane>.point bad;

The usual way to transform between schemes and reference frames is using in expressions (see this page on casts for more information). It is possible to transform manually, however, using matrix-vector multiplication and functions like homify and hom_reduce, as shown in the Gator paper.

Geometry types generally require that all operations happen in the same coordinate scheme and reference frame. Additionally, the geometric object associated with the geometry types must match the arguments to the function; for instance, it is not permitted to add two points. To support this, it is possible to parameterize functions over frames (function parameterizations will be explained in greater detail in a future page):

with frame(3) T:
hom<T>.point homify(cart3<T>.point v) {
  return vec4(v, 1.) as! hom<T>.point;
}

Clone this wiki locally