DisplayCore has a built-in rudimentary 3D engine. It renders a 3D scene using coloured triangles described as triplets of points in a 3D environment.


A 3D environment is described by a Scene object. The Scene object takes an array of triangles to describe the scene. The scene can be modified by adjusting ambient light levels and moving a master light around. The scene is viewed (and rendered) via a camera which can be both moved and angled.

Before 3D rendering can be performed the Field of View of the TFT device must be set. This is performed on the TFT device not the Scene:


The best value for a Field of View is half the width of the TFT screen.

Triangles themselves are made up of three points (point3d) and a colour. They are combined into an array which is passed, along with the number of triangles, to the constructor of the Scene object:

triangle things[3] = {
    // Point 1 x,y,z    Point 2 x,y,z    Point 3 x,y,z   Colour
    { {100, 100, 100}, {150, 100, 100}, {120, 140, 110}, Color::Red },
    { {200, 200, 200}, {250, 200, 200}, {220, 240, 210}, Color::Green },
    { {300, 300, 300}, {350, 300, 300}, {320, 340, 310}, Color::Blue }

Scene scene(things, 3);

Scene Methods

void scene.setAmbientLight(float brightness);
Sets the ambient light level between 0 (none) and 1 (full brightness). Full brightness nullifies the mobile light source.
void scene.setCameraPosition(point3d position);
void scene.setCameraPosition(int x, int y, int z);

Sets the location of the camera in 3D space, either using a point3d object or three discrete values.

void scene.setCameraAngle(point3d angle);
void setCameraAngle(int pitch, int yaw, int roll);

Sets the facing angle of the camera. When using a point3d the value mapping is as follows:

int scene.render(DisplayCore *device);
int render(DisplayCore &device);

Renders the scene to the provided TFT device. Returns the number of triangles rendered.

point3d scene.translatePoint(point3d point);

Translates a point within 3D space relative to the camera. Used when translating the scene for rendering, or for placing primitives at the right location when augmenting the rendered scene after rendering has been performed.

TFT Methods

point2d tft.map2Dto3D(point3d point);

Maps a 3D point in 3D space to a 2D point on the screen itself.

void tft.setFOV(int fov);

Set the Field of View of the TFT device. Half the TFT width gives a good result.

Point3d Methods

Constructor point3d(double x, double y, double z);

point3d point1 - point2;

Subtract one point from another

point3d point1 + point2;

Add one point to another

point3d point1 * point2;

Calculate the cross-product of the two points

point3d point1 * scale;

Scale a vector by a given factor

double point1.dot(point2);

Calculate the dot product of two vectors

double point.length();

Return the length of the point (vector) from the origin

point3d point.norm();

Return a normalized version of the point (that is a point scaled to a length of 1)