Skip to main content
88 votes
Accepted

I'm rotating an object on two axes, so why does it keep twisting around the third axis?

No this isn't an engine bug or an artifact of a particular rotation representation (those can happen too, but this effect applies to every system that represents rotations, quaternions included). You'...
DMGregory's user avatar
  • 135k
44 votes
Accepted

What is a "normal" in game development

Direct Answer I see that other answer going into technical details, but I don't know if that hits the spot for answering "What are even normals" - so here's a plain English answer for ...
Raphael Schmitz's user avatar
36 votes

If a 3D vector represents a point, how can it have a length?

Does that mean that the magnitude is simply it is distance from the origin point (0, 0, 0)? That's exactly that. Among other things, a vector can represent a point (a position), a direction and/or a ...
Vaillancourt's user avatar
  • 16.3k
34 votes
Accepted

How to compute the area of an irregular shape?

You can use Gauss' shoelace formula: You need to take the x coordinate of every point, multiply them by the next point's y coordinate, then subtract the current point's y coordinate multiplied by the ...
Bálint's user avatar
  • 14.9k
33 votes

What is a "normal" in game development

In the context of geometry, a normal is a vector that is oriented perpendicular to a given object. It is commonly used for lighting calculations, but it can also be used to for calculating visibility, ...
Pikalek's user avatar
  • 12.4k
29 votes
Accepted

How do game engines avoid recalculating normals upon mesh rotation?

They don't. When you rotate a mesh, the normals in memory are not changed in any way. All that changes is the object's transformation matrix is updated. The raw mesh vertex and normal data remains ...
DMGregory's user avatar
  • 135k
28 votes
Accepted

How can I get the normal vector for a plane from a set of vertices?

You could easily find the normal by calculating two vectors, V1 = P2-P1, and V2 = P3-P1, and then find the cross product N = V1 x V2. Then you normalize N. Depending on the ordering of the vertices (...
Hermetix's user avatar
  • 507
20 votes
Accepted

If a 3D vector represents a point, how can it have a length?

Does that mean that the magnitude is simply it is distance from the origin point (0, 0, 0)? The tl;dr answer may be: Yes, you can imagine it like that. But I'm not sure whether this might not lead ...
Marco13's user avatar
  • 673
19 votes
Accepted

Algorithm for "healing" multiple rectangles into a smaller number of rectangles?

First, we can convert your source rectangles to cells in your underlying grid, to make the input more uniform. (Effectively rasterizing the problem) This will let us find optimizations that might not ...
DMGregory's user avatar
  • 135k
18 votes

How does a 4x4 matrix represent an object in space and matrix lore?

How is Matrix Multiplication a Transformation? A matrix is just a big grid of numbers with rules that define how we can multiply it with other grids or lists of numbers. In games, we usually want to ...
DMGregory's user avatar
  • 135k
16 votes

Procedurally generating a building of specific area

A simple way to build a procedural generator is: Randomly build things Run a function that checks whether the output is good If the output is not good, go to step 1 Even if it takes thousands of ...
congusbongus's user avatar
  • 14.8k
16 votes

How do game engines avoid recalculating normals upon mesh rotation?

DMGregory's answer explains how this is actually handled, but I'd like to point out a couple of misconceptions: Assume that a face of a mesh is defined by vertices ...
Kevin Reid's user avatar
  • 5,508
12 votes

Why are spherical worlds so rare?

Because spherical maps, compared to rectangular ones, create a lot of additional complexities regarding the technical implementation and the UI design while usually offering very little gameplay ...
Philipp's user avatar
  • 120k
10 votes
Accepted

Efficient minimum distance between two axis aligned squares?

By far the slowest part of this algorithm would be the square root. Try to avoid it if you can, and deal with the squared distance directly. For example, if you're comparing distances, the results ...
congusbongus's user avatar
  • 14.8k
9 votes
Accepted

How to calculate the surface area of a mesh

Looking at the formula you're using, it looks like it's designed to calculate the area of a planar polygon, where the vertices are all in clockwise / counterclockwise order about the perimeter. That'...
DMGregory's user avatar
  • 135k
8 votes

If a 3D vector represents a point, how can it have a length?

Does that mean that the magnitude is simply it is distance from the origin point (0, 0, 0)? You can see it that way, but only seeing it that way may lead to a wrong understanding. First of all, a ...
Polygnome's user avatar
  • 803
8 votes
Accepted

Find ID from Spiral x, y positions. Hard programming formula

Let's add some colour coding to see if we can reveal some structure in the problem: Here I've colour-coded the spiral into concentric rings of alternating colours. You'll notice the tile just before ...
DMGregory's user avatar
  • 135k
7 votes

How can I project a 3D point onto a 3D line?

Here's a fast and easy way to do it in python: ...
caleb c.'s user avatar
  • 171
7 votes

Procedurally generating a building of specific area

Given a restriction of "all areas are at are at least 3-4 blocks wide" the first idea that leaps to my mind is something like the following: pick one of 3x3, 3x4, 4x3 or 4x4 place a block of that ...
Ryan1729's user avatar
  • 714
7 votes
Accepted

Procedurally generating a building of specific area

You could use pre-generated polyominoes as meta shapes to build an assortment of buildings. Let's say your minimum acceptable distance is 3 blocks. Then the smallest acceptable building unit we'll ...
Pikalek's user avatar
  • 12.4k
5 votes
Accepted

Most efficient way to calculate angle between two line-segments that do not necessarily touch each other

Let s1 and s2 the segments, so you can calculate the angle of each using ...
Bruno Vieira Costa's user avatar
5 votes
Accepted

How to draw an arc between two angles?

You can define an arc with a radius and start and end angle. Then you simply need to create a series of points to define the arc. ...
House's user avatar
  • 73.3k
5 votes
Accepted

Determine the z coordinate of a deformed plane based on uv (xy) coordinates

Your image can be interpreted a couple different ways so I will make a few assumptions up front: The "geometry" you are emulating is meant to look as if it has already been "projected" (if it was ...
Cobertos's user avatar
  • 1,644
5 votes
Accepted

How does one calculate the surface normal, in 2D collisions?

I think the following may help. You have the sphere center, box center and hopefully the details of the rectangle. Since the rectangle may be rotated we need the rectangle extents, and the ...
Biggy Smith's user avatar
5 votes

If a 3D vector represents a point, how can it have a length?

A vector can represent a line between two points in 3d space (direction and distance) or a location in 3d space (length is the distance from origin). If you have point A, and point B, then B-A = AB = ...
Ian Young's user avatar
  • 2,649
5 votes
Accepted

How can I convert my list of vertices and indices to a list of triangles?

Typically, your list of indices looks like this: ...
DMGregory's user avatar
  • 135k
5 votes
Accepted

How to determine polygon based on point lists?

A possible solution is to cull points that you are certain that are not part of the polygon. Start with a definition of the polylines: ...
Felsir's user avatar
  • 4,067
4 votes
Accepted

Point plotting with a line graph

You can solve this with some basic trigonometry. I wrote the code in Unity, but the general idea should be the same. Consider the following image: We already have P1 and P2. Here is some code to ...
jgallant's user avatar
  • 8,424
4 votes
Accepted

Moving a sprite along a circle given by an implicit equation

We can solve this by completing the square: $$\begin{align} x^2 + y^2 + ax + by + 1 &= 0\\ \left(x^2 + ax \right) + \left(y^2 + by \right) + 1 &= 0\\ \left(x^2 + ax + \frac {a^2} 4\right) + \...
DMGregory's user avatar
  • 135k

Only top scored, non community-wiki answers of a minimum length are eligible