Tag Info

Hot answers tagged

32

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


28

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


19

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

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


13

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


11

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


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

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

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

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


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

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


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

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


5

The simple answer is: Whatever you want them to be. There isn't a "right answer" here. In effect, you've asked a question like "I have a tetrahedron, what is the right color?" Nobody can give you a meaningful answer. You'll need to rephrase the question in a way that can be answered, such as "What are the texture coordinates of the 'bottom' face if I ...


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

Basically, you need to repeat performing multiple different tasks at independent intervals. In pseudocode that will typically look something like this: updateTime=1000/120 nextUpdate=time() repeat{ while(nextUpdate<time()){ updatePlayerPositionPhysicsAndStuff() nextUpdate+=updateTime } render() } So ...


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


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

I solved my own problem--and rather than just blow it off as a simple explanation, I want to describe the steps I took to debug the issue. I left out that I was using a single FBO for special-effects. First, it turns out everything above is in fact correct and a step I left out was the problem. I verified my orthogonal matrices through-and-through. ...


5

It doesn't particularly matter. As long as you're consistent throughout your game. I believe the more common approach is to have the world bounds centered around (0,0), meaning you'd have your bounds go from -halfSize, halfSize. Since most data structures that represent position (Vector2 or Vector3) default to zeros, you know that the default placement for ...


5

Window coordinates - the coordinates in which the viewport is specified using glViewport - are not the same as the view space coordinates that you pass to glOrtho. Window coordinates are always measured in pixels from the lower-left corner of the window, while view space coordinates are entirely up to you and can be defined however you like. You can think ...


4

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


4

If you dont mind using your rect as two triangles, here is the code from my (working) raytracer: //RAY-TRAINGLE test Vec3f e1 = p2 - p1; Vec3f e2 = p3 - p1; Vec3f s1 = cross(aRay.dir, e2); float divisor = dot(s1, e1); if (divisor == 0.) return false; //not hit float invDivisor = 1.f / divisor; // Compute first barycentric coordinate Vec3f d = aRay.org - ...


4

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



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