Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 5864

2D refers to two dimensional space where coordinates are represented with X and Y values.

1 vote

OpenGL 2D Rasterization Sub-Pixel Translations

To avoid the camera jerkiness, you should keep the floating-point coordinates camera, but clamp the OpenGL projection to the nearest pixel.
sam hocevar's user avatar
  • 23.9k
6 votes
Accepted

How to draw equal length line stripes on a parabola?

The derivative of the ball position is: dx/dt = vx dy/dt = vy + gravity * t So the derivative of the parabola arc length s is, using Pythagora’s theorem: ds/dt = sqrt(vx² + (vy + gravity * t)²) …
sam hocevar's user avatar
  • 23.9k
0 votes

Algorithm that always returns the same pseudorandom output if given the same input of seed, ...

Why not a PRNG, actually? It looks like a simple and good tool to me. Some pseudocode using srand/rand that you should be able to adapt to any other PRNG: int shuffle(int seed, int x, int y) { i …
sam hocevar's user avatar
  • 23.9k
7 votes

Optimal sprite size for rotations

I think what you are trying to do is the 2D image space equivalent to double rounding. …
sam hocevar's user avatar
  • 23.9k
6 votes
Accepted

Physics/Logic behind self-bounce

If I was the ball, I think I would try to 1. maximise the surface of contact with the ground and 2. maximise the vertical compression so that the release will generate forces that are normal to the gr …
sam hocevar's user avatar
  • 23.9k
25 votes

a simple 2D rectangle collision algorithm that also determines which sides that the rectangl...

Adapted from my answer to "Which Side Was Hit?": I suggest computing the Minkowski sum of B and A, which is a new rectangle, and checking where the centre of rectangle A lies relatively to that new r …
sam hocevar's user avatar
  • 23.9k
2 votes

Calculating the 2D edge normals of a triangle

Here is a method that works: get a vector normal to the triangle, for instance p1p2 ^ p1p3 for each edge, take the result of its cross product with that vector normalize If your triangles are in a 2D
sam hocevar's user avatar
  • 23.9k
2 votes

Why is my collision resolution failing on the corners?

Maybe this: elif sides & LEFT: Should actually be this: if sides & LEFT: Otherwise the left/right branches are never visited when there is a top/bottom collision. The first part o …
sam hocevar's user avatar
  • 23.9k
3 votes
Accepted

Collision method for multiple circles

In this line: double targetY = circle1.getLayoutX() + Math.sin(angle) * minDistance; Certainly you meant getLayoutY. As a side note, it is useless to compute angle = atan2(y,x) if the only thing y …
sam hocevar's user avatar
  • 23.9k
2 votes

Help finding time of collision

You are not using the right variable to perform the collision time calculation. distanceXin is the distance between the two objects’ centres, whereas what you actually want is the distance between the …
sam hocevar's user avatar
  • 23.9k
20 votes
Accepted

Sorting array of points in clockwise order

Your question is not precise enough. An array of points is only « clockwise » or « anti-clockwise » relative to a reference point. Otherwise, any array of three points can always be either CW or CCW. …
sam hocevar's user avatar
  • 23.9k
15 votes
Accepted

Fastest way to render lines with AA, varying thickness in DirectX

If you are going to render Y = f(X) graphs only, then I suggest trying the following method. The curve data is passed as texture data, making it persistent, and allowing for partial updates through g …
sam hocevar's user avatar
  • 23.9k
8 votes
Accepted

Rotating a group of sprites - How to calculate origin

If you have three sprites (or if they have very specific relative positions, which almost never happens) there is a special point called the circumcentre which is at an equal distance of each sprite. …
sam hocevar's user avatar
  • 23.9k
2 votes

Isometric smooth fog

Here is a simple proposal: you could try modulate the fog intensity for each cell. Here is an example of applying a simple convolution filter: float fog = 0.0; for (int dj = -3; dj <= 3; dj++) for (i …
sam hocevar's user avatar
  • 23.9k
1 vote
Accepted

Iterating 1D array and getting 2D tile position

One possible way is to split the integer into two values between 0 and 29 (this is done using integer division and modulus) then offset them by -15: for (int n = 0; n < 30 * 30; ++n) { if (Array[ …
sam hocevar's user avatar
  • 23.9k

15 30 50 per page