# Quasar Engine - Basic 3D Engine

7/2017 – 8/2018## Introduction

Quasar Engine is a simple/intuitive 3D engine designed: to learn about 3D rendering, and to use for small projects.

## Background

Over the summer of 2017, I decided to try to learn about how 3D graphics worked. At the time, I was unfamiliar with linear algebra, matrices, etc. so I tried to think of an intuitive approach to the problem.

### Attempt One

At first, I thought about attempting to use my knowledge of perspectives (such as 2-point perspectives), and apply that to my engine. To do this, I planned on rendering each object by drawing a line from each point on screen (ignoring the Z component) to the vanishing point on the horizon. The point’s z-coordinate would then determine how far along this line the point would actually be rendered. While this approach somewhat worked, it caused many artifacts, distortions and facets did not always line up.

### Attempt Two

I eventually tried a second approach to the problem, which ended up working. In this second approach, I started by imagining a large tiled room where you are looking straight ahead. In this room, the edges of the tiles become an easy way to visualize how a constant distance appears different depending on its relation to the viewer (you could see this as having a three-dimensional grid for the space you are in). By looking at one point strait ahead of you, you can notice that as objects get farther away from you, they get skewed towards this point.

To convert this observation to a 2D computer screen, all we have to do is set the origin from where everything is drawn to be the center of the viewport/screen (this becomes the vanishing point on the horizon). The z-index of each point then determines the factor which you scale the X and Y coordinate towards the origin/vanishing point (the z-index also becomes a factor in which order each facet is drawn—an approach called the painter’s algorithm). This scaling factor was calculated by the formula: f(c, z) = c / (c + z) where z is the z-coordinate of the point, and c was the clipping pane. In my trials, I found c=1000 to work well.

To let the user move around, I added the camera’s position to the point of each shape. To allow the user to rotate the camera, I found formulas that described rotation around a 3D axis, and applied these formulas before calculating where to draw each facet.

## Other Features

In addition to 3D rendering, I also added basic physics/collisions between the user and the ground, as well as a basic terrain generation algorithm as shown in the main picture above.

## Timeline

The QuasarEngine was my first introduction to 3D rendering. Since then, I continued to do more with 3D rendering. For example, I expanded on what I had learned to use a z-buffer for my Archon project, and I later followed tutorials on building a 3D engine with ray tracing.

QuasarEngine

Basic, intuitive 3D rendering

Expanded on QuasarEngine, used a z-buffer

3D rendering with ray tracing & ray marching

## Specifications

Language(s): | Java | ||||
---|---|---|---|---|---|

Relevant Topics: | Basic Collision Management/Physics Painter's Algorithm Basic terrain generation |