Skip to Content

Vertex

This is a WIP project - Expect breaking changes to occur.

Overview

Represents a single vertex in 3D space.

Each vertex carries four attributes that are uploaded to the GPU as separate VBOs, bound to the following shader attribute locations:

  • location 0 - position (x, y, z)
  • location 1 - color (r, g, b)
  • location 2 - normal (x, y, z)
  • location 3 - uv (u, v)

Two constructors are provided, as shown below.

Vertex(...)

public Vertex(Vector3f position, Vector3f color, Vector3f normal, Vector2f uv) {}

Constructs a vertex with:

  • position - 3D position in world space
  • color - RGB color, used if no texture is sampled in the shader
  • normal - Normal vector for lighting calculations
  • uv - Texture coordinates for sampling from a texture atlas

Vertex(...)

public Vertex(Vector3f position, Vector3f color, Vector3f normal) {}

Constructs a vertex without explicit UV data.

UV defaults to (0,0) - suitable for hand-authored primitives that rely on vertex color not texture sampling.

Getters and Setters

getPosition()

public Vector3f getPosition() { return position; }

Returns the world-space position of this vertex.

getColor()

public Vector3f getColor() { return color; }

Returns the RGB color of this vertex.

getNormal()

public Vector3f getNormal() { return normal; }

Returns the surface normal of this vertex.

getUV()

public Vector2f getUV() { return uv; }

Returns the UV texture coordinate of this vertex.

(0,0) = bottom-left, (1,1) = top-right.

Last updated on