# Tag Info

46

I think the direction of the coordinate axes are holdovers from different domains where the crucial plane was different, and X/Y were aligned with that crucial plane. In some applications the ground plane was the most important, thus X/Y were the ground and Z ended up perpendicular to that. For games however the crucial plane is usually the screen (...

43

This is caused in the history. Early computers had Cathode Ray Tubes (CRTs) which "draw" the image with a cathode ray from the upper left corner to the lower right. To ease the interface between the graphics card memory and the CRT the memory was read from the beginning and the image was drawn from the top left (with the lowest memory address) to the lower ...

29

Don't let a math major hear you calling Vectors points or coordinates! A 2D vector has an x and y component, not coordinate. Vectors do not define a position, they define a direction and a magnitude. I can't tell you why people are intimidated by them, likely the same reason people are intimidated by math in general, because everyone says it's hard before ...

23

First, here is the code. An explanation will follow: /* * tw, th contain the tile width and height. * * hitTest contains a single channel taken from a tile-shaped hit-test * image. Data was extracted with getImageData() */ worldToTilePos = function(x, y) { var eventilex = Math.floor(x%tw); var eventiley = Math.floor(y%th); if (hitTest[...

21

LERP - Linear Interpolation I gave this answer for a similar problem some days ago, but here we go: Linear Interpolation is a function that gives you a number between two numbers, based on the progress. You could actually, get a point between two points. The Great Formula - How to calculate it The general LERP Formula is given by pu = p0 + (p1 - p0) * u. ...

20

Okay, so Assuming that you know what the World Transformation matrix for that object A is, You just need to construct the inverse of that matrix and you will have what you need. Suppose the rotation, scaling and translation matrices of object A used to get it to Global Space are R, S and T respectively. You will multiply these together like S * R * T = W ...

15

It seems to me that having the center of your space be (0, 0, 0) is better. Assuming you are using a signed format to represent positions in space, a center of (0, 0, 0) allows you to use both the negative and positive parts of your format, which can do wonders for precision for floats and range for signed integers. This may not matter for small scales, but ...

11

In the image the red vector is the one we are trying to convert to cartesian, given angles phi & theta (in the description I will refer to the length of the vector as r, for radius of the sphere). So, the y-coordinate is the easy one, we know what the angle is between the red vector and the y-axis (phi), we just project the vector onto the y-axis; y=|...

9

Most APIs represent the Sprite's origin in local space, not in world space. This is supported by libgdx's documentation which states: A Sprite also has an origin around which rotations and scaling are performed (that is, the origin is not modified by rotation and scaling). The origin is given relative to the bottom left corner of the Sprite, its position. ...

9

Before I answer the question you already asked, some notes: You can use A* with the original grid system you are using. The key things you need are neighbors and distance (for the heuristic). For neighbors with your grid system, you need to do something different for even and odd columns (as you mention); here's how: neighbors = [ [ [+1, +1], [+1, 0]...

9

I think the intimidation factor may arise when you start dealing with more complicated operations such as normalization, dot and cross products, and using multiple coordinate systems with matrices to transform between them. These are not necessarily easy to understand at first, even if you have a strong geometry and algebra background. Also, at least in ...

9

I've done this with trigonometry rather than matrixes in the past (I am a matrix noob). Ashes999's answer is halfway there, get the relative vector, then rotate that by the inverse of EntityA's angle. relativeX = B.x - A.x relativeY = B.y - A.y rotatedX = Cos(-Angle) * relativeX - Sin(-Angle) * relativeY rotatedY = Cos(-Angle) * relativeY + Sin(-...

9

8

In Pseudocode: speed_per_tick = 0.05 delta_x = x_goal - x_current delta_y = y_goal - y_current goal_dist = sqrt( (delta_x * delta_x) + (delta_y * delta_y) ) if (dist > speed_per_tick) { ratio = speed_per_tick / goal_dist x_move = ratio * delta_x y_move = ratio * delta_y new_x_pos = x_move + x_current new_y_pos = y_move + y_current ...

8

If what you want is to bypass the floating inaccuracy caused by single point precision problem, for the sake of creating bigger environments for your game, then it depends on what you are willing to accept as a solution. Let's start by making this clear: it is impossible to alter the coordinate system at the inner core of Unity. So, you can't use double-...

8

The point P to be transformed is, in homogeneous coordinates: $$\begin{pmatrix} 50 \\ 40 \\ 1 \end{pmatrix}$$ The homogeneous transformation matrix M is (using $cos(\frac{\pi}{4}$) = sin($\frac{\pi}{4}) = 0.7071)$:  \begin{pmatrix} 0.7071 &0.7071 &-42.426 \\ -0.7071 &0.7071 &14.142 \\ 0 &0 & 1 \\ \end{...

7

Sounds like you might want to start using a delta time and a time-based movement speed. It could be a little difficult considering that it looks like you could be using a tile-based engine, but if you use a delta-time, your movement equation will look something like this: x += unitsPerSecond * deltaTime; Where x is a floating point variable (float or ...

7

You can normalize the first value, this will give you a value in the [0,1] range. You can think of that as X percentage, the percentage the value maps to between the minimum and maximum values. Then you can find where that percentage belongs in your destination coordinate system by seeing what value is X percentage through the destination system. I'll use ...

7

This depends on the combination of frameworks you are using. Sometimes a 2D game framework makes it very difficult to work with coordinates that are not bound to pixels because they were designed specifically for designers to think about their game world in pixel units. However, it's not a requirement. A game I'm currently working on relies on Box2D units ...

7

Vectors really aren't that bad. There is just a bit of math that people are unfamiliar with. First and foremost, a Vector does not represent a position in space. This is conceptually very important. A vector represents a direction, like 'North', and a magnitude. On a map with normal Math X-Y coordinates, 'North' would be the vector (0,1) (up on the Y ...

7

My guess is you're trying to implement a camera, and should not be using SDL Viewports. The viewports are for UI elements like menus, minimaps, etc. It's a way of dividing up the screen into multiple areas. To implement a camera, you will want to think about coordinate systems. The world coordinates are the positions in the world, without thinking about the ...

6

I'm not sure about OpenGL but DirectX allows you to over write the default left-handedness therefore it wouldn't matter. As you've said, it's "nothing but" a convention, and at least DirectX allows you to work with both. Conventions do not matter by themselves, the only problem is that you need to be consistent with your choice. Mixing two such systems leads ...

6

Unless your paths are parameterized based on lengths, then you'll have a bit of difficulty doing this. I'm going to give you a solution outline for paths containing only line segments, because distances are easy to calculate on line segments as they are with parameterizations. The setup I'm assuming there is that you have n + 1 points P_1, P_2, ..., P_{n}, ...

6

Your description is a bit vague, but it sounds like what you're trying to do is map coordinates from one space (the window coordinates) to another (your tile coordinate space). Doing so is a simple transformation using the window size: x_trans = x - (windowWidth / 2); y_trans = y - (windowHeight / 2); x_norm = x / (windowWidth / 2); y_norm = y / (...

6

Try using this Camera:unproject method: unproject(Vector3 screenCoords, float viewportX, float viewportY, float viewportWidth, float viewportHeight) from the documentation: Function to translate a point given in screen coordinates to world space. It's the same as GLU gluUnProject, but does not rely on OpenGL. The x- and y-coordinate of vec are assumed ...

6

Let me try to give you something somewhere between The Light Spark's answer and Elliot's answer, because from what I read, you're really looking for an algorithm to follow and not just math tossed at you. Problem Statement: Given that you have a location A (50, 50) and a heading (since you didn't provide one, I'll assert it as y = 2 * x + 25), find where B (...

6

That's a question that frequently pops up. I will take the liberty to forward you to another fairly detailed answer I already gave to the same issue, instead of just repeating it here: Is a custom coordinate system possible in Unity From there, what I would suggest the most is that you read the amazing paper at: http://citeseerx.ist.psu.edu/viewdoc/download?...

6

Triangulate the area. Pick a random triangle. Generate a random point inside that triangle (link).

5

Hmm, I'm not so sure about rotating the vertices. Perhaps this is not the answer you're looking for, but I can suggest an alternate method. I've done something similar with maps in my game. I wrote a shader to wrap terrain into a sphere, but it can easily be done outside the graphics card too. It's as simple as mapping the Cartesian coordinates to spherical ...

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