Skip to main content
9 votes
Accepted

Why doesn't games use CORDIC for sin and cos?

Because on the x87 (the x86's FPU) the fsin, fcos and fsincos instructions are much faster than software CORDIC. On other architectures such as PowerPC and ARM you usually can rely on an optimized ...
Stephane Hockenhull's user avatar
7 votes
Accepted

Any fast alternative to sine in GLSL?

ATI made an announcement that the sine / cosine instructions in their newest GPUs now requires only a single clock cycle... in 2004! Modern GPUs in fact have special function units specifically for ...
Philipp's user avatar
  • 122k
6 votes

Why are rotations in 2D game engines often counter-clockwise = positive systems?

Why have we arrived at the convention that rotations should be counter-clockwise then, even in engines where positive y is down? Have we? Let us try CSS: ...
Theraot's user avatar
  • 27.5k
5 votes
Accepted

Is there a generic formula to determine the angle of deflection off of a rectangle?

The edges of your rectangle are just straight lines, so the angle of reflection is equal to the angle of incidence: Now, if this surface has its own angle, we can factor that in. Call the angle of ...
phlp's user avatar
  • 126
4 votes

How can I correct an unwanted fisheye effect when drawing a scene with raycasting?

It looks like you're firing out your rays at evenly spaced angular intervals. ...
DMGregory's user avatar
  • 136k
4 votes
Accepted

LibGDX How can I draw a line at a specific angle

you should use ShapeRenderer for this. In your draw loop ...
Sebastien Servouze's user avatar
4 votes
Accepted

Math behind drawing one game object relative to another?

The way this is usually handled in games is something called a transformation hierarchy. Here objects are arranged in a parent-child relationship, where each object's position, rotation, etc is ...
DMGregory's user avatar
  • 136k
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
  • 136k
4 votes

How can I rotate a 16-bit signed integer vector?

Use 32-bit integers for the intermediate calculations. They'll usually be divided down into the 16-bit range at the end. If they're not - for example, rotating \$(30000,30000)\$ by an eighth-turn ...
Toph's user avatar
  • 346
4 votes

How can I rotate a 16-bit signed integer vector?

There are two issues to address here, each of which has a couple of solutions. Size of vectors Your first problem is how you do any processing at all without overflows. A vector (32767, 0) is clearly ...
Graham's user avatar
  • 262
3 votes
Accepted

Unity Mathf.Atan2 algorithm complexity

It doesn't make a lot of sense to talk about algorithmic complexity (in the big-O sense) for the way we use atan2 in game development. Our inputs are always one fixed size (32 bit floats for the Mathf ...
DMGregory's user avatar
  • 136k
3 votes

Why doesn't games use CORDIC for sin and cos?

First of all, the FPS wouldn't be better. Most modern games are bottlenecked by the GPU mostly and are pretty OK with the CPU (often times only reaching a CPU usage of around 50% or less). Second, ...
Bálint's user avatar
  • 15k
3 votes
Accepted

When are oblique triangles used in game development?

Trigonometry is rarely applied directly in video game development. Allow me to explain what I mean by that: We will approach problems from a vector algebra standpoint first. And if you are struggling ...
Theraot's user avatar
  • 27.5k
3 votes
Accepted

Position Object always at the same distance of 2 other moving Objects?

My final approach has been using basic trigonometry: I have a and b I was just needing to calculate ...
fguillen's user avatar
  • 243
3 votes

Need help on finding the algorithm for getting the FlipX, Y and TextureRotation of my DirectionalAnimation class

See Asking and, because I know you've been linked it previously, The Good Asker. No-one is going to fix all of your code for free regardless of where you ask. It would be beneficial for us all to ...
spacer GIF's user avatar
3 votes
Accepted

How to overshoot with direction_to

In you code, you care computing the direction form the current position to the target every (physics) frame: ...
Theraot's user avatar
  • 27.5k
2 votes
Accepted

Coordinates of the corners of a rectangle bridging two circles

This is pretty straightforward: ...
DMGregory's user avatar
  • 136k
2 votes

Find vector tangent to circle through a point

It's pretty easy with some trigonometry. Here's a hand drawn image of your problem: OTP angle is a right angle. Calculating l is done with the pythagorean ...
Bálint's user avatar
  • 15k
2 votes

LibGDX How can I draw a line at a specific angle

Accepted answer is good, but I couldn't use ShapeRenderer as it need to be used on closed batch. In that case you can use ShapeDrawer which is ShapeRenderer that can be used on open batch.
Elas's user avatar
  • 121
2 votes

How to make a sprite blink with Libgdx?

The blinking requires an alpha value that swings 0 and 1. The Sinus function swings between 1 and -1. So to solve the problem, the function has to be multiplied by 0.5 and be added to 0.5, so that the ...
purpule's user avatar
  • 113
2 votes

Getting an object to move in another objects direction

You're overcomplicating it. Let's say the object you want to move is at (x1; y1) and the player is at (x2; y2) The vector ...
Bálint's user avatar
  • 15k
2 votes

Move object at angle like a sine wave

Let's take a unit vector \$\vec u\$ in the direction we want to travel, and a vector perpendicular to it, \$\vec v\$: $$\vec u = \begin{bmatrix}cos \Theta\\sin \Theta\end{bmatrix}, \vec v = \begin{...
DMGregory's user avatar
  • 136k
2 votes
Accepted

Aim/Scope Oscillation Algorithm

Using polar coordinates would do the trick. Here’s a graph of the function r=sin(2.3θ), with θ going from 0 to 2π: Given ...
Noah Witherspoon's user avatar
2 votes

Are there recursive variants for trigonometric functions to potentially improve performance?

Even if you could make something that's better on paper, than the already available sine and cosine functions, you'd have to essentially go down to the metal to make it useful. Some systems use the ...
Bálint's user avatar
  • 15k
2 votes
Accepted

How to panning camera on XZ axis with different angles

You can construct the camera's forward direction vector as: forward = normalize(lookAt - position) Then you can construct a vector pointing to the camera's right ...
DMGregory's user avatar
  • 136k
2 votes
Accepted

Convert GPS coordinates into Unity world space?

Presumably you considered just converting your angle and distance from polar coordinates into a Cartesian vector in the usual way? ...
DMGregory's user avatar
  • 136k
2 votes

How to find if a Ray intersects a Triangle Clockwise or Counter Clockwise

Assume the triangle's vertices are wound in the order A, B, C Form a normal to the triangle N = (B - A) x (C - A) Now you can detect whether your triangle is clockwise or counter-clockwise by the sign ...
DMGregory's user avatar
  • 136k
2 votes
Accepted

Could you explain how this GameObject rotating around another GameObject works?

The purpose of the sine and cosine function is to turn an angle into X and Y coordinates. Here is an animation from Wikipedia (source) which visualizes what these functions do as the input angle is ...
Philipp's user avatar
  • 122k
2 votes
Accepted

reposition object in circle

For circle p2 and p3 to be close enough to eachother to touch, we know that the distance between them must be ...
bornander's user avatar
  • 4,616
2 votes

rotating a sprite with mouse cursor

It turns out the issue came from what I thought was my player position used in the calculation. I had forgotten I had a camera that followed the player as it moved, so player position was relative to ...
user21746705's user avatar

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