A mathematical concept that can be used to express position, direction or velocity and which can simplify or outright trivialise spatial problems.

learn more… | top users | synonyms

24
votes
2answers
2k views

Calculating the rotational force of a 2D sprite

I am wondering if someone has an elegant way of calculating the following scenario. I have an object of (n) number of squares, random shapes, but we will pretend they are all rectangles. We are ...
19
votes
3answers
939 views

What's so different/complicated/useful about vectors?

Forgive me if this isn't considered a real question, but it is something I am genuinely confused about. I constantly hear other game developers talk about how using vectors are very useful, but also ...
17
votes
6answers
5k views

Vectors in game development

I'm new to programming and game programming. I've reading something about vectors and math, but I have a question - where do I use vectors in game programming? Maybe anyone can give a simple example ...
17
votes
4answers
13k views

How can I calculate the angle and proper turn direction between two 2D vectors?

I am working on some movement AI where there are no obstacles and movement is restricted to the XY plane. I am calculating two vectors, v, the facing direction of ship 1, and w, the vector pointing ...
15
votes
7answers
688 views

Do I need a Point and a Vector object? Or just using a Vector object to represent a Point is ok?

Structuring the components of an engine that I am developing along with a friend (learning purposes), I came to this doubt. Initially we had a Point constructor, like the following: var Point = ...
15
votes
1answer
3k views

Determine arc-length of a Catmull-Rom spline

I have a path that is defined by a concatenation of Catmull-Rom splines. I use the static method Vector2.CatmullRom in XNA that allows for interpolation between points with a value going from 0 to 1. ...
14
votes
5answers
723 views

Can I simplify the inequality “distance(p1, p2) < distance(p1, p3)?”

I am working on some vector logic, so am asking: can I save processor time by simplifying this inequality: distance(vector1, vector2) < distance(vector1, vector3) I see that vector1 is repeated ...
14
votes
5answers
5k views

Do I need the 'w' component in my Vector class?

Assume you're writing matrix code that handles rotation, translation etc for 3d space. Now the transformation matrices have to be 4x4 to fit the translation component in. However, you don't actually ...
11
votes
2answers
463 views

How do I find a point on a line?

I have two points (A, B) and the length of d. How can I find point C?
11
votes
1answer
2k views

How do I tell if my enemy can see my player?

Given a player and an enemy with position, and given the direction vector of each, how can I tell if one can "see" the other? In other words, how do I test if one position with direction is in front ...
10
votes
3answers
6k views

What are normal, tangent and binormal vectors and how are they used?

I would like to find out the following information: What are they? Example usage in game development (the area they are used in) About the following vector types: Normal Tangent Binormal A ...
10
votes
4answers
1k views

How does normal mapping really work?

I'm trying to grasp the concept of normal mapping, but I'm confused by a few things. In short, I'm not sure whether a normal map is viewpoint dependent or not (i.e. whether you'll get a different ...
10
votes
2answers
634 views

Shooting the bullet out of the gun instead of the camera, yet keeping it accurate with respect to the reticle

I'm working on a first person game, and I've ran into a problem. In my game, there's the player's gun being rendered, as well as a reticle in the center of the screen - like this: First, Let's ...
9
votes
4answers
384 views

What exactly causes a surface to overlap another?

I cannot really figure out what causes one surface to overlap another. In a 3D engine I'm creating, my technique is failing in edge cases. My method is sorting the surfaces to be painted from the ...
9
votes
2answers
7k views

How do I linearly interpolate between two vectors?

I have a velocity vector where my client is at and where its going, and I have the same vector that comes from the server telling where the client should be. Sometimes its a bit different, so I want ...
9
votes
2answers
389 views

Dynamic thruster balancing of space ship

The space ships in my game a meant to be player-built with an arbitrary amount of thrusters attached anywhere with any rotation. I currently have some dirty code to rotate the ship to a given angle ...
8
votes
7answers
2k views

What's the best way of transforming a 2D vector into the closest 8-way compass direction?

If you have a 2D vector expressed as x and y, what's a good way of transforming that into the closest compass direction? e.g. x:+1, y:+1 => NE x:0, y:+3 => N x:+10, y:-2 => E // ...
8
votes
3answers
685 views

Vector3 vs. Vector2 - performance, usage?

I'm currently playing around with XNA, and creating a simple 2D platformer. I was thinking of adding multiple layers to make it a little bit of challenge. In stead of having a Vector2 for my ...
8
votes
2answers
15k views

Moving a sprite in XNA/C#, using vectors

I'm currently looking into XNA game development with the C# language. I have two classes: the main game handler and a "sprite" class. Following is some basic pseudo-code which I hope adequately ...
8
votes
2answers
2k views

How to calculate the vector of an interception?

Given are a twodimensional space, and 1 friendly spaceship standing still, one foe is moving NOT directly to the friendly ship with known actual position, speed and direction. The friendly ship wants ...
8
votes
2answers
2k views

How do I determine if one polygon completely contains another?

I have 2 polygons. I know the vertex coordinates of both polygons. What's the best way to check if one is completely inside the other? For example, the algorithm should only recognize the black ...
8
votes
3answers
642 views

Collision detection problems using AABB's

I implemented a simple collision detection routine using AABB's between my main game sprite and various platforms (Please see code below). It works great, but I'm now introducing gravity to make my ...
8
votes
4answers
855 views

Moving objects colliding when using unalligned collision avoidance (steering)

I'm having trouble with unaligned collision avoidance for what I think is a rare case. I have set two objects to move towards each other but with a slight offset, so one of the objects is moving ...
8
votes
1answer
552 views

Downprojecting an imaginary 4D mesh to the screen

As a mental exercise, I'm trying to imagine projecting an arbitrary 4D mesh onto the screen (2D). I'm guessing a single 4D triangle would still consist of only 3 points, however each of those 3 ...
7
votes
2answers
5k views

How do I find the angle between two vectors?

I have 3 points on my screen: a = a point which is (c.x, 0) makes a line pointing straight up b = a user input touch, can be anywhere on the screen c = a moving object a _______.________ | ...
7
votes
2answers
646 views

Rotate a vector

I want my first-person camera to smoothly change its viewing direction from direction d1 to direction d2. The latter direction is indicated by a target position t2. So far I have implemented a ...
7
votes
2answers
263 views

How do I find the closest points(thereby forming a polygon) enclosing a particular point?(see image)

I am working with a game engine, and my task is to add code for simulating fracture of rigid meshes. Right now I'm only working on breaking a cube. I am using Voronoi's algorithm to make a ...
7
votes
1answer
3k views

How do I calculate collision response between a sphere and a plane?

I'm trying to create a simple 3D game and need to constrain the player within the limits of the game world. When the player hits the sides of the world I want the player's ship to bounce off slightly. ...
7
votes
3answers
2k views

Rotating a vector by another vector in shader

I have a terrain surface with a normal for each point on the terrain. I have a second detail normal map to be applied to the terrain. These normals are in 3-space. The Y value of both normals is ...
6
votes
1answer
2k views

Rotate object to face player

This is probably a simple vector question, but I'm not sure how to do it. I have an object at vector position (ox,oy). Potentially every update, the user walks around the screen, and will be at ...
6
votes
2answers
1k views

For a 2D XNA game, should I use the built in Vector2 or Vector3 or port my own class from ActionScript?

I use a lot of 2D vectors in my Flash games - basically all velocities, positions etc I store in this way. My Vector2D class has lots of built in functions for rotation, dotproduct, projectOnto etc. ...
6
votes
2answers
449 views

Vector problem: which one is the left / centre / right one?

In aviation, runways are named according to their magnetic orientation seen from the pilot's perspective. For example: a strip of asphalt oriented along the east-west axis will be named 9 for the ...
6
votes
2answers
513 views

Collision Detection/Response in Vector-based levels

I have a 2D side scroller whose levels are stored as vectors (that is, a bunch of lines) which looks like this: How would I detect that I'm colliding with one of these lines, and react accordingly ...
6
votes
3answers
4k views

Implementing Separating Axis Theorem (SAT) and Minimum Translation Vector (MTV)

I was following codezealot's tutorial on SAT and MTV and trying to implement it myself but I've come a cropper when it comes to getting the correct MTV. Here is my example: (Cue pretty pictures...) ...
6
votes
2answers
2k views

Vector games (Wireframe, Elite-like) theory and implementations?

I'm interesting in knowing more about how vector games like Elite and Star Wars Atari were built from grounds up. The question is not how to implement vector graphics with modern 3D APIs like OpenGL ...
5
votes
1answer
3k views

How do I rotate a sprite so that it is 'pointing' in the direction it is moving?

I have a sprite, e.g a missile, heading in a certain direction (using a velocity vector). How do I figure out its how much to rotate it so that it gets drawn 'pointing' in the direction it is ...
5
votes
3answers
1k views

Why aren't linked lists more common data structures for enemies?

I was recently listen to a talk that Jonathan Blow gave, you can find it here. In the talk, he was talking about what data structures he (and he seemed to imply many others) use, and why. Which is ...
5
votes
2answers
107 views

How can I draw a line of certain length and direction?

I want to create a line of certain length and direction. What I mean by this is drawing a line from Point A to Point B. Normally in Unity C# to draw a line from Point A to Point B is simply: ...
5
votes
1answer
154 views

Vector Math question

Suppose I have two game object located at two Vector3s v1 and v2, respectively. If I wanted to locate a position between v1 ad v2, but 3 units away from v2, how would I manage that in terms of ...
5
votes
1answer
496 views

How can I calculate a vertex normal for a hard edge?

Here is a picture of a lovely polygon: Circled is a vertex, and numbered are its adjacent faces. I have calculated the normals of those faces as such (not yet normalized, 0-indexed): Vertex 1 ...
5
votes
1answer
209 views

Moving in a diamond - enemy gets stuck

I have an enemy that I would like to move as follows: Start at (0, 200, 0) Move to (200, 0, 0) Move to (0, -200, 0) Move to (-200, 0, 0) Move to start point, repeat as long as it remains active. ...
5
votes
3answers
1k views

Split a 2D scene in layers or have a z coordinate

I am in the process of writing a 2D game engine, and a dilemma emerged. Let me explain the situation... I have a Scene class, to which various objects can be added (Drawable, ParticleEmitter, ...
5
votes
2answers
762 views

Calculate vector in local space

I have a vector (8,5). It's origin is at (10,9) I can calculate a perpendicular like so: MyPerpendicularVector.x = -MyVector.y MyPerpendicularVector.y = MyVector.x Given that I now know these two ...
5
votes
1answer
562 views

What's the 'proper' way to get unit vectors?

My apologies if I've misunderstood the term 'unit vector' or misapplied it in concept, but I think that is the term for an object's heading when expressed as [x, y] when x and y are a value between -1 ...
5
votes
3answers
801 views

Why is this code producing jittery movement?

I have a new project, all settings default with a simple cube on a plane. Cube is not kinematic but is a rigid body under the effects of gravity. I'm trying to normalize the direction before I ...
5
votes
3answers
750 views

Should we go for our Vector2Int/Vector3Int implementation or just use built-in float based vectors?

So in one of our projects we're using Vector2/Vector3's a lot but we do only use integer/byte values mostly. So up to the point we've implemented our Vector2Int, Vector3Int, Vector2Byte and so ...
5
votes
1answer
247 views

Trouble with speed and vectors

I'm working on adding bullets to my game. Right now I can shoot bullets in the direction that I would like from a ship by getting the ship's angle: int speed = 5; int dx = ...
5
votes
1answer
461 views

Rotating plane to be parallel to given normal via change of basis

I have two planes and their respective normals. I would like to rotate the second plane, planeB, so that it is parallel to the first, planeA. To do this, I am using a change of basis to rotate each ...
4
votes
2answers
1k views

Why isn't this physics code scaling velocities separately?

I'm working my way through this book and I'm trying to work this code out: var squaredVelocity = this.velocity.x*this.velocity.x + this.velocity.z*this.velocity.z; if ...
4
votes
2answers
409 views

What are the properties of “position, velocity, acceleration, rotation” collectively named?

They say naming things is one of the hardest problems in computer programming. They were right. Given the pseudocode below, what is a more appropriate name for this collection of properties? ...