DEV Community

conjurer
conjurer

Posted on • Edited on

4

Rotating cube | C++

A quick and cool code!
SDL2 is a library designed to provide low level access to audio, graphics hardware etc.
Supports C++, lessgoo!

Setup - screen.h

Initialised the event handler, window and render pointers, and basic data members.

Requirements

Show pixels on screen
Clear the screen
Check if quit activity detected by user

Solution

A vector that stores all points to be rendered on screen. Looped to render them. Cleared the vector to clear the screen.
Quit if user wants to exit.

functions

The Cube

Some structs and functions for 3d geometry

cube parts

On the screen | int main()

Initialised the cube with vertices and edges, and a centroid for easy translations
main func

Brought each point to the origin, rotated it along the axes, translated it back.
while loop

Show time!

Rendered

Thanks to The Builder for sharing the amazing tutorial!

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more