Forums → Programming Forum → Vector - Linear Algebra
3 | 3339 |
I've been making games for a while now, and one of the things I use often are vectors. Not the Flash 10 Vectors (types arrays) but linear algebraic Vectors. I was curious if anyone else used them as well, or if there was something similar that you use?
- 3 Replies
Using them in what way? Physics calculations or graphic rendering? Just about everyone uses them in a game with any sort of physics involvement, whether they know it or not.
Hmm, a relatively large part of what I do at work involves Euclidean vectors, however I am also familiar with Coordinate vectors. Not sure how much help I would be to someone wanting to design a game, but I am familiar with the solving of the equations, if that's any help.
Vectors and other trig-related stuff is just way too useful not to use.
Dank mentioned the obvious physics-related usage, but I wanted to clarify that it's useful even in "quick and dirty" physics. For example, if I'm doing a Pong-style ball bouncing, vectors are the way to go for storing the ball's movement. In that case, you'd want to store the vector as a vx and vy component (rather than as angle and magnitude) since you use the vx and vy values on every tick to update the ball's position.
Anyway, I keep meaning to make a proper vector class, but I just haven't gotten around to it. The problem is that the math is simply enough that I find myself just quickly creating vx and vy member variables on the object that I'm working with, and it's only later that I realize I've rewritten several vector manipulation functions (rotate it while keeping the magnitude, make an absolute change in the magnitude while keeping the angle, and make a relative change in the magnitude while keeping the angle, and so forth).
Also, even with non-physics and non-vector stuff, I still find trig functions insanely useful. It's been about 15 years since I went over this stuff in school, and I still find myself mapping things out in terms of right triangles with hypotenuses that're radii of a unit circle. Between atan2, cos, and sin, you can construct some very nice graphics.
For example, my most recent project involves making an LCD-type display. The individual segments are shaped like rectangles with triangles on the ends. I wound up creating a nifty generalized drawing routine that creates the shape given two endpoints (the tips of the triangles on each end) and the segment width. First, I compute the angle of the line with atan2. Then I find the other points in the triangle (which are also the corners of the rectangle) by treating them as if they were points on a unit circle. For the triangle on the other end, I just add 180 degrees (well, technically Pi since it's in radians) to the angle and repeat the process. Makes things work out great.
You must be logged in to post a reply!