Tag Info

Hot answers tagged

35

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 ...


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 ...


27

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 ...


21

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 ...


15

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) * ...


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 ...


12

Okay, a couple of questions here, so I'll do my best to explain them all. Coordinate System The coordinate system of anything affects more than just the orthographic projection. It affects translation and rotation as well. For example, set up your camera projection as you have described. Now create an object and set it to move either toward you or away ...


11

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 ...


10

As you already noticed, there's no way around UV coordinates for games. Thankfully, blender comes with some very good UV unwrapping tools. The simplest way to get UV coordinates from a 3D model in blender is to use Smart UV Project. You can do that by pressing U while in edit-mode and then select "Smart UV Project" from the menu. This creates UV "patches" ...


9

It's just tradition. Neither system is objectively better than the other, so you just have to get used to using both and switching between them from time to time! Right-handed coordinates are traditional for modelling where one imagines the XY-plane to be horizontal, and the Z-axis to be vertical. Left-handed coordinates are traditional for cameras where ...


9

What you need is to know the geometric distance between the user's touch (T) and your "difference point" (D). distance = squareroot((T.x - D.x)² + (T.y - D.y)²) Then as another answer said, just check if the distance is less than the circle's radius, 5 pixels in your example.


8

Actually it seems that your calculation is correct - you are just mistaken about pixel 96. Column 3 contains pixels 64-95 inclusive, not 64-96. Dividing by the tile size is in fact the correct method.


8

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; ...


8

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, ...


8

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 ...


8

r: radial distance θ: inclination φ: azimuth via Wikipedia public Vector3 getCartesianFor(float radius, float inclination, float azimuth) { return new Vector3(radius*Sin(inclination)*Cos(azimuth), radius*Sin(inclination)*Sin(azimuth), radius*Cos(inclination)); }


7

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 ...


7

You can use either the x or the y value of the intersection to compute the z-value (using x): t = (x - X1) / (X2 - X1) z = Z1 + (Z2 - Z1) * t Where x is the x-intersection. X1, X2 and Z1, Z2 are your known x and z-values, respectively, of the segment's endpoints.


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

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 ...


6

Having tried every conceivable way of doing it, I have found if it's purely a 2D game, just use the screen drawing system, it will make your life much easier. Sin, Cos, and atan2 need to be used slightly differently, but this inconvenience is easily made up for by the simplicity of knowing which way up, down, clockwise and anti-clockwise are. I would also ...


6

I think that for creating the matrix you should get the front vector first, you do: Vector3 vFront = Camera.vTarget - Camera.vPosition, vUp = Camera.vUp, vRight(0,0,0); vFront.Normalize(); vRight.Cross( vUp, vFront ); // Up x Front = Right vRight.Normalize(); vUp.Cross( vFront, vRight ); // Front x Right = Up vUp.Normalize(); then you build the matrix ...


6

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 ...


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 / ...


5

Unless you're going to have so much going on that the speed of trig functions is going to be a concern, I think focusing on a Polar system will be sufficient. Storing the angle and distance-from-center for your sprite (Theta and R, respectively) will make the logic for moving based on Left, Right, Up, and Down understandable: Moving Left and Right would ...


5

Your question sounds a bit confused; there's no such thing as "the matrix of a point"; matrices just convert from one coordinate system to another. Did you mean that you have the two matrices that go from A to world coordinates, and B to world coordinates? And you want to find the matrix that converts from B to A? In that case, you'd just want B_to_world ...


5

Downvote me if I am wrong, but I don't see why people are recommending swapping y and z. That would make your coordinate system from being right handed to left handed. Try this yourself, swap the y and z, and reorient the axis so that x points right and y points up. You will see that z points the opposite direction from its original (away from the screen). ...


5

I find your question very confusing but I believe that this will do what you want. Assuming you want the center of the object to be draw to the center of the screen irregardless of resolution. var screenCenter = new Vector2( GraphicsDevice.Viewport.Bounds.Width / 2, graphicsDevice.Viewport.Bounds.Height / 2); var textureCenter = new Vector2( ...



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