Tag Info

Hot answers tagged

31

You're trying to calculate the Torque. Torque depends on the applied force F, the point of application, and the center of mass of the object. 1) Center of Mass. Define the center of mass of the object. 2) Point of Application: Define the point at which the force acts on. 3) Moment Arm: The distance between the two points defined above. Point ...


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


26

What are vectors? Vectors are sets of coordinates of varying dimension. Each coordinate in a vector represents some absolute position in that direction of the space the vector is in. A 1-D vector would be {1} . This could be, for example, a position at X = 1. Or a time t = 1. A 2-D vector would be {-4,3}. This could be, for example, a position at -4 on ...


26

Compute a vector V from A to B, and normalize it. V = (B - A) / |B - A| Since the vector is normalized, it will have a length of one, and it will indicate the direction of B relative to A. If you then scale the vector by d you will have the displacement from A to C V' = d * V which you can simply add to A to yield C: C = V' + A


24

Yes, you can simplify this. First, stop calling them vectors. They are points. Let’s call them A, B and C. So, you want this: dist(A, B) < dist(A, C) Replace distances with distances squared, then with dot products (from the definition of the Euclidean length. Replace AC with AB + BC (now these are real vectors). Expand, simplify, factor: dist(A, B)² ...


19

It's much faster to use a 2d cross-product. No costly trig function involved. b2Vec2 target( ... ); b2Vec2 heading( ... ); float cross = b2Cross( target, heading ); if( cross == -0.0f ) // turn around if( cross == 0.0f ) // already traveling the right direction if( cross < 0.0f) // turn left if( cross > 0.0f) // turn right If you ...


19

It sounds like you want to keep the speed of the object at some constant value over the entire curve - knowing the arc-length won't help you do this. It will help you calculate at what time the object would reach its end-point if it were going at that speed, so it will be better than what you have now (the object will have the same average speed between all ...


17

Yes. Assuming your distance function uses a square root, you can simplify this by removing the square root. When trying to find the larger (or smaller) of a distance, x^2 > y^2 still holds true for x > y. However, further attempts to simplify the equation mathematically are likely pointless. The distance between vector1 and vector2 is not the same ...


16

EDIT Disclaimer: For convenience in this answer vectors with w==0 are called vectors and with w==1 are called points. Although as FxIII pointed out, that is not a mathematically correct terminology. However, since the point of the answer is not the terminology, but the need to distinguish both types of vectors, I'll stick to it. For practical reason this ...


16

I fear the subject is quite tricky, few multi platform solutions seem to have launched, and even fewer seem to have survived on their own. I was looking into the subject a few months ago. I had a constraint as I needed the engine to run on iOS and Android. Didn't find anything that suited me really at the time. But a few pointers from what I remember: each ...


16

The reason for this is Pythagorean Theorem, and it's probably the bit of math I use most often in games. Even when working with a full-featured engine, there are times when knowing this math has helped me get the gameplay and look I wanted. Don't worry though, it's very simple once you've used it a few times. :) What this bit of code does is ensure that ...


15

The angle you need to rotate by is the the angle your velocity vector makes with the positive x-axis. This angle can be calculated using the inverse tan of the slope of the vector. In XNA, we use the Math.Atan2 function. Give the function the y coordinate and the x coordinate of the velocity vector (in that order). Atan2 will return an angle between +PI/2 ...


15

The simplest way is probably to get the angle of the vector using atan2(), as Tetrad suggests in the comments, and then scale and round it, e.g. (pseudocode): // enumerated counterclockwise, starting from east = 0: enum compassDir { E = 0, NE = 1, N = 2, NW = 3, W = 4, SW = 5, S = 6, SE = 7 }; // for string conversion, if you can't just do ...


15

Shoot a ray from the camera through the center/reticle into the world. Find out where in the world it hits. Fire the bullet from the gun's muzzle at that point instead of straight out of the gun. Bonus points for animating the hands and gun to point in that direction while aiming around so the bullet still looks like it's firing straight out of the muzzle ...


14

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


14

A texture mapping is the mapping between points on the 3D surface and their corresponding points on a texture image. If you have a 1:1 texture mapping, then every point on the 3D surface maps to a specific and unique point in the texture image (though the reverse would not need to be true. Some locations in the texture would not necessarily map to locations ...


13

A 2D example are screen coordinates, it identifies a pixel on the screen and has an x- and an y-component [x, y] i.e. Left upper screen position [0, 0] Another example: Imagine a text scrolling from right screen border to the left screen border. Now you need to define the velocity of the scrolling text in pixel per second, i.e. [-20, 0] which means the text ...


13

Blue vector can be calculated easily: red - black (the sign between vectors is minus). But if you want just to interpolate between black and red vector, you don't have to calculate it. Linear interpolation is just linear combination. So you can just take: alpha * black + (1 - alpha) * red, where alpha has to be from interval <0,1>. If alpha will be 1, ...


13

You are looking for the wondrous atan2. // v1 moving object float boxX = this.mScene.getLastChild().getX(); float boxY = this.mScene.getLastChild().getY(); // v2 user touch float touchX = pSceneTouchEvent.getX(); float touchY = pSceneTouchEvent.getY(); double theta = 180.0 / Math.PI * Math.atan2(boxX - touchX, touchY - boxY); Normally it is used ...


13

Is there any notable performance between Vector2s and Vector3s, for example when adding or multiplying them, or when calling Normalize, Transform, or Distance? Yes, you have one more coordinate so you will use more CPU cycles. But it is very unlikely that it will ever give you any trouble. XNA 4 is using SIMD extensions for vector math (EDIT: on ...


13

Generally speaking, a Normal vector represents the direction pointing directly "out" from a surface, meaning it is orthogonal (at 90 degree angles to) any vector which is coplanar with (in the case of a flat surface) or tangent to (in the case of a non-flat surface) the surface at a given point. A Tangent vector is typically regarded as one vector that ...


13

dot(A,B) = |A| * |B| * cos(angle) which can be rearranged to angle = arccos(dot(A,B) / (|A|* |B|)). With this formula, you can find the smallest angle between the two vectors, which will be between 0 and 180 degrees. If you need it between 0 and 360 degrees this question may help you. By the way, the angle between two parallel vectors pointing in the ...


11

If I understand your problem properly, you should just have a direction Vector2 representing the direction you want to move in inside your sprite class. Like this: public Vector2 Direction { get; set; } This is the normalized vector(which means it has a length of 1) showing where you want to go. Then, add a Speed float property, which says how fast the ...


11

You seem to be trying to implement the Painters Algorithm. I'm guessing you're trying to write a rasteriser from scratch as a learning exercise, as most modern 3D hardware uses what Bart has mentioned (the Z/Depth buffer). For the painters algorithm to work in all cases, you'd need to be prepared to subdivide the surfaces as they're rendered to solve ...


11

From MathWorld: Given the plane Then the normal vector is The normal unit vector n is given by: Therefore, for the plane 5x+2y+3z-1=0, The normal vector N is N = [5,2,3] The magnitude |N| is |N| = sqrt(5^2 + 2^2 + 3^2) |N| = 6.1644 The normal unit vector n is therefore approximately: n = N / |N| n = [0.8111, 0.3244, ...


10

This is a simple operation of vector difference. In XNA you don't even need to create a specific method for it - vectors already support subtraction. If you want the velocity of Body B from the perspective of Body A, you subtract Body A's velocity from Body B. So in C# with XNA, using your example: Vector2 MovingBody = new Vector2(1, 0); Vector2 Impact = ...


10

Think about the problem differently. You want to object always to "face" the player, which means you want its "forward" vector rotated around to be parallel to the vector from itself to the player. Assuming its "forward" vector is normally at obj.Rotation = 0, the proper rotation is basically the arctangent of Vector2.Subtract(playerPos, objectPos). Most ...


10

You'll need to duplicate the normal for the corner N times (where N is the number of "sides" it is shared amongst). If you try to use one value for all "sides," you'll end up averaging it, and your lighting will not appear to have that hard edge that you're looking for.


10

The position and rotation (and scale) are generally referred to as the transform. Velocity, acceleration, force, impulse, etc are usually just lumped together as "physics state" or "body" (which might also have handles to the shape of the physical object or any bounding shapes, or those might be part of a separate "collider"). I don't believe there is a ...


10

Like Sean said, position and rotation are usually referred to as the object's transform. Velocity and angular velocity can be called the "kinematic state" or "kinematic properties" of your object. Force, torque, and impulse can be called the "dynamic state" or "dynamic properties" of your object. ("Dynamics" and "kinematics" come from two sub-fields of ...



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