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 ...
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 ...
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:
...
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 ...
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.
...
4
votes
Accepted
LibGDX How can I draw a line at a specific angle
you should use ShapeRenderer for this.
In your draw loop
...
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 ...
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
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 ...
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 ...
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 ...
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, ...
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 ...
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 ...
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 ...
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:
...
2
votes
Accepted
Coordinates of the corners of a rectangle bridging two circles
This is pretty straightforward:
...
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 ...
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.
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 ...
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 ...
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{...
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 ...
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 ...
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 ...
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?
...
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 ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
trigonometry × 149mathematics × 56
unity × 21
vector × 17
2d × 15
geometry × 14
angles × 14
rotation × 13
c# × 12
java × 11
javascript × 11
c++ × 9
libgdx × 9
physics × 9
3d × 8
camera × 8
movement × 8
opengl × 6
coordinates × 6
algorithm × 5
linear-algebra × 5
collision-detection × 4
shaders × 4
raycasting × 4
collision-resolution × 4