Skip to main content
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
35 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
  • 15.1k
32 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
  • 13.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
  • 141k
20 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
  • 123k
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,671
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.9k
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
  • 141k
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
  • 141k
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
  • 141k
5 votes
Accepted

Getting the bounding box of a sphere

Calculating the bounding box of a sphere is pretty trivial given the simplicity of sphere geometry. Let's assume we have the radius of the sphere defined as a scalar (float or integer) value \$r\$, ...
doppelgreener's user avatar
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,117
4 votes
Accepted

OpenGL calculate UV sphere vertices

Let's start by generating all unique vertices. You can then decide whether to index those vertices, or copy them into strips/fans, depending on your needs. Here's some example code showing how to ...
DMGregory's user avatar
  • 141k
4 votes

Why are spherical worlds so rare?

For anyone considering this... A tile-based spherical world is possible, but you need to carefully consider the topology of your world sphere. And you need to decide what to do about the poles of the ...
Mentalist's user avatar
  • 213
4 votes

Most efficient way to get the closest point to a 3d rectangle

This is actually a pretty simple problem if you first rotate the rectangle so it lies flat and at right angles on one plane, and also apply the same rotation to the player location. Now, everything ...
Tim Holt's user avatar
  • 10.3k
4 votes

space map generation

You can scatter points using... uniform random coordinates (prone to uneven clusters and gaps) or a shaken or jittered grid, where you start with a regular lattice of points, then add a small ...
DMGregory's user avatar
  • 141k
4 votes
Accepted

Deriving shadow position from a 2D heightmap

You can associate a "shadow height" with each cell on your map. This is the elevation something would need to have above 0 / "sea level" in order to rise out of the shadow and into ...
DMGregory's user avatar
  • 141k
4 votes
Accepted

Finding the position of a point based on a relative point inside a quad

Assuming that your quad is convex, you can solve for an interior point using a few linear interpolations (lerps) between the corner points of the quad. To illustrate, consider finding a point (R for ...
Pikalek's user avatar
  • 13.4k
4 votes
Accepted

Efficiently find all points within a circle

About this algorithm: You don't have to check whether every object is inside the circle. If a node square is completely inside or outside the circle, you can use all objects in it directly without ...
Mangata's user avatar
  • 2,796
4 votes
Accepted

Add and Removing Elements on the Circumference of a Circle

Firstly, atan2(p2.y - p1.y, p2.x - p1.x) isn't what you want, as that just gives the direction between the two points, not the distance, so comparing atan2(p2.y,p2.x) and atan2(p1.y,p1.x) is closer to ...
Roy Ward's user avatar
  • 783
4 votes
Accepted

Given two points (A and B), how can I obtain a point a set distance along the line between them?

If you want to use standard Euclidean distance, this is pretty easy: ...
DMGregory's user avatar
  • 141k
3 votes

How to achieve this sprite/mesh tile splitting like in Peggle?

This can be done in general using a shape where you can get the normals at any point. It's particularly easy if the shape is a circle or an ellipse, because we can just use the parametric equation for ...
Jay's user avatar
  • 822
3 votes

Easy way to project point onto triangle (or plane)

There is an excellent answer to this question on the Math community of Stack Exchange: Determine if projection of 3D point onto plane is within a triangle. Which is, in turn, just a summary of this ...
Craig Reynolds's user avatar
3 votes
Accepted

How to draw a 3D capsule?

First we can construct a local basis for the space of the capsule. ...
DMGregory's user avatar
  • 141k
3 votes
Accepted

How to know if two surface are in the same direction?

Imagine applying a force along those normals to the faces. If the normals both face in the same direction (e.g. outward), then it would have a book closing effect, the faces would get closer. If they ...
Bálint's user avatar
  • 15.1k
3 votes

Finding rotation quaternion from orthonormal basis?

@Andrew Tomazos is correct, but conversion of the three vectors to a matrix first requires the storage of 16x additional floats, and is a bit slow. A better solution is found by writing out the basis ...
ramakarl's user avatar
3 votes
Accepted

Finding the position of a point inside a triangle, based on the position of a point in another triangle (barycentric coordinates in Godot)

As DMGregory suggested, Barycentric Coordinates were indeed the solution. Since there are no built-in functions for converting Cartesian to Barycentric in Godot, I converted the c++ answer here What&#...
Kasper Arnklit Frandsen's user avatar
3 votes
Accepted

Find closest open space in grid of rectangles?

I did some tests and found that this method does work. First you need to find the nearest grid coordinates to the position of the dragged block (blue box). Then do a grid-based BFS on the target ...
Mangata's user avatar
  • 2,796
3 votes
Accepted

Vertex Shader Sphere Projection and CPU Distance Calculation

I ended up finding an answer. To obtain the center of a projected plane that is projected on the GPU, you need to take the position of the unprojected plane and project it. ...
Miguel Myers's user avatar

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