Tag Info

Hot answers tagged

41

Radians are used in math because They measure arc-length on the circle, i.e. an arc of angle theta on a circle of radius r is just r * theta (as opposed to pi/180 * r * theta). When trig functions are defined in terms of radians, they obey simpler relationships between each other, such as cosine being the derivative of sine, or sin(x) ~= x for small x. If ...


14

I believe your intuition was correct, just not your formula. atan(4 / 3) = 53.1301024 degrees This ratio can be useful because it forms a Pythagorean triangle, meaning that the length of the diagonal is an exact integer value.


10

Although they compare properly, the difference between them is 315 degrees instead of the correct 45 degrees. What makes you think 315 is incorrect? In one direction, it is 315 degrees, in the other direction, it's 45. You want to choose whichever is the smallest of the 2 possible angles and this seems to intrinsically require a conditional. You can't ...


6

The industry standard for first-person view simulation in most shooters is to have character models and animations distinct from those used for third-person view. There are several reasons for this: The player has a much smaller field of view upon the world than a real person in the character's situation would, and he lacks other forms of input such as ...


6

That vector can be obtained simply by summing up the normals of the boxes faces and normalize. The normal vector even point outside the box so the sum vector points toward the direction where the boxes exit from the intersection. along with the vector you need the intersection segment too (if you still don't have it)


6

You do not need to know the angle, because the difference in X and Y already gives you the desired orientation of the enemy. The only thing that remains to be done is normalise that direction vector (if possible -- otherwise it means the player and the enemy are exactly at the same position), and multiply it by the enemy’s speed: dx = player_x - enemy_x; dy ...


6

Two parts: 1. coordinate systems for angles can be...finicky. 2. You don't really need degrees for anything, with the possible exception of outputting their value to the user interface. Coordinate system angles So you want an angle from "North", and judging from your example math, that means the -Y direction (in sprite coordinates with the origin in the ...


4

GLM's rotation function uses Euler's rotation theorem, which implies that any rotation or sequence of rotations of a rigid body in a three-dimensional space is equivalent to a pure rotation about a single fixed axis. However consecutive calls to GLMs rotate function just multiply the rotation so rotating a rigid body by Yaw, Pitch, Roll is as simple as ...


3

Nathan's answer is very concrete. I'd like to supply a more general view: The most complex mathematical concept that is natively implemented in most processing units are floating point numbers as models for the field of real numbers ℝ. Visual geometriy is based on the three dimensional real vector space ℝ³. Coordinates are real numbers. Geometric quantities ...


3

double angle = Math.atan2(y,x); // Note: keeping angle in radians for cos & sin. dx = enemy.speed * Math.cos( angle ); dy = enemy.speed * Math.sin( angle ); This will work fine with negative angles. See also: What are atan and atan2 used for in games?


3

Normally I store all objects as 4x4 Matrices (you could do 3x3 but easier for me just to have 1 class) instead of translating back and forth between a 4x4 and 3 sets of vector3s (Translation, Rotation, Scale). Euler angles are notoriously difficult to deal with in certain scenarios so I would recommend using Quaternions if you really want to store the ...


3

When working with floating point values it's usually not a good idea to use the comparison operator, as even slight inaccuracies will result in inequality. That's why a comparison of floats usually incorporates some sort of "epsilon".. a margin of error. Example: if(Math.abs(floatA - floatB) <= epsilon){ // equal } Epsilon is the desired ...


3

Let b be the angle between vectors p1p2 and p1p3. Its value can be computed as: b = pi - atan2(p1p3.y, p1p3.x) The angle between p1p4 and p1p3 is b-a. Since p1p3p4 is a right-angled triangle, we know that cos(b-a) is the distance p1p4 divided by the distance p1p3. The answer is then: a = pi - atan2(p1p3.y, p1p3.x) - acos(r / length(p1p3)) Replacing ...


3

First figure out the direction based on where the particle is in reference to where it came from (the explosion). Then you take the arc-tangent of that to get the angle. Vector2 direction = particlePosition - explosionPosition; float angle = Math.Atan2(direction.Y, direction.X);


2

Assuming true evaluates to -1 and false evaluates to 0, and '~', '&' and '|' are bitwise not, and and or operators respectively, and we're working with two's-complement arithmetic: temp1 := angle1 > angle2 /* most processors can do this without a jump; for example, under the x86 family, it's the result of CMP; SETLE; SUB .., 1 instructions */ ...


2

While your question made no reference of them, I'm going to be working on the assumption that your angle calculation question stems from wanting to know the minimum angle between two vectors. That calculation is easy. Assuming A and B are your vectors: angle_between = acos( Dot( A.normalized, B.normalized ) ) If you didn't have vectors and wanted to use ...


2

EDIT: The answer is now correct, you had to add 360 in case of diff negative You just have to look at the difference between the two angles. It it is between 0 and 180, you turn left (anticlockwise), otherwise right. int FindTurnSide(int current, int target) { int diff = target - current; if(diff < 0) diff += 360; if(diff ...


2

The camera angle used by most "isometric" games is actually 30 degrees (a true isometric view where the x, y, and z axis have the same length is 35.264 degrees). The reason for this angle is so that the width of the tile ends up being twice its height. This way you can get an even 2:1 ratio when drawing the diagonals so the tiles line up neatly without any ...


2

Basically you will want to do something like this: deltaX = event.x - playerX deltaY = event.y - playerY normDeltaX = deltaX / math.sqrt(math.pow(deltaX,2) + math.pow(deltaY,2)) normDeltaY = deltaY / math.sqrt(math.pow(deltaX,2) + math.pow(deltaY,2)) ... bullet:setLinearVelocity( normDeltaX * speed, normDeltaY * speed )


2

The Red is: atan2(vectorA.y - vectorB.y, vectorA.x - vectorB.x) The Green is: atan2(vectorB.y - vectorA.y, vectorB.x - vectorA.x) The Blue which I think is what you are looking for: atan2(vectorA.y, vectorA.x) - atan2(vectorB.y, vectorB.x) You can use abs() if you want the absolute value like I think you do. Sometimes you will get a value that is ...


2

It looks like your code to mirror the bullet's angle just flips the sign of the angle. This works great for reflecting an angle about the x-axis. 45 degrees becomes -45 degrees, etc. Now imagine reflecting off a wall that itself has an angle of 90 degrees. In this case, 85 degrees is reflected to 95 degrees; 45 degrees becomes 135 degrees, etc. Basically ...


1

For FPS cameras, there is no technical reason why the pitch needs to be smaller than +/- 90 degrees; the reasons for limiting it are purely gameplay-related, and it's obvious if you've encountered it. When you are looking straight up or down, attempting to look left or right will not move your reticle with respect to the game world, instead you simply ...


1

I don't think there's a standard value. Some games let you go all the way to 90 degrees; some cut you off at somewhere around 85 degrees, I'd guess. I don't think the precise value is a big deal. Regarding the point about Euler angles, gimbal lock, etc. - there's actually no particular reason to limit the pitch to strictly less than 90 degrees, aside from ...


1

While I use radians too, for all the reasons specified, there's at least one good reason why degrees are preferred: Precision and accumulation of errors. Rotating through a full circle 1 degree at a time is exact. Rotating through a full circle 2PI/360 radians at a time is not. Performing a 90 degree rotation 4 times on a pixel grid gets you back to ...


1

As it says: // Angle adjustment to make 0 up to match how our sprite was drawn. var angleAdjustment = -90; Likely that means the sprite was created with the plane facing right. This adjusts it to face "up". The angle doesn't have any thing to do with the coordinates system. Remember that you can always use the coordinate system you're familiar with and ...


1

It is common to render the players own character vastly different from other characters in order to avoid these issues. With a real rifle you have got two mechanics that don't translate well to computer games: When not aiming you'll typically raise your head higher to get a better view, some games implement multiple different tiers of aiming to simulate ...


1

The function takes angles and calculates vectors that point in directions relative to angles. For angles, and the operations sin cos and tangent, you'll want to look up trigonometry. Multiplying an angle in degrees by M_PI*2 / 360 converts degrees to radians. (M_PI = 3.14). forward is a vector that points in the direction that the angles form to create ...


1

It just computes a (slightly wacky, because of Quake's "entity pitches are negative" thing) 3x3 rotation matrix, with each column (or row, depending on your preference) being one of the forward/right/up vectors. This can then be used to position various objects/effects/etc relative to the view; Quake uses it for pushing muzzleflashes slightly forwards and ...


1

The angles used to build a rotation for each of the three axes are known as Tait-Bryan angles (often confused with Euler angles). Wikipedia has all the formulas you need to convert Euler or Tait-Bryan angles into a rotation matrix. Here is some code to build a rotation matrix from three Tait-Bryan angles and the order of the rotations: /* i, j and k are ...



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