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 ...
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 ...
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, ...
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 ...
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 ...
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 ...
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 ...
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'...
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 ...
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:
...
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\$, ...
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:
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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:
...
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 ...
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 ...
3
votes
Accepted
How to draw a 3D capsule?
First we can construct a local basis for the space of the capsule.
...
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 ...
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 ...
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&#...
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 ...
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.
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
geometry × 537mathematics × 133
3d × 68
unity × 66
c# × 53
collision-detection × 53
algorithm × 52
2d × 50
opengl × 36
vector × 31
physics × 28
rotation × 24
computational-geometry × 24
c++ × 23
3d-meshes × 23
shaders × 18
java × 16
matrix × 15
transformation × 15
coordinates × 15
linear-algebra × 15
trigonometry × 14
intersection × 14
xna × 13
mesh × 13