From UFOpaedia
Jump to navigation Jump to search

I'm surprised X-COM has sines and cosines. The only place I can think that these might be used, is with the construction/presentation of the world globe and related things, perhaps night/day lighting changes and maybe aircraft travel arcs. Thoughts on why they might have trig values? --MikeTheRed 19:29, 21 September 2006 (PDT)

My interest was the Battlescape. (I'm thinking of figuring out the LOS algorithm. There's some definite weirdness since you can reaction-fire on aliens you can't see during your turn.) The numerical approximations could be responsible for the possibility of missing at 100% accuracy reported by NKF. It also could be involved in computing the trajectories of missed shots.

--Zaimoni 12:01 Sept 21 2006 CDT

For the movement of projectiles at particular angles. I'm guessing the game uses fixed velocities, so that's not a problem, but it needs to know were the bullet is going to appear in the next frame update. To find how much to add to the X, Y and height coordinates, trig functions are used.

Storing all sine and cosine values in lookup tables helps speed up the maths as the computer need not re-calculate everything over and over again. Ye olde Computers of yore did not have math coprocessors, so repeat calculations, particularly slow math routines like trig functions, tended to really bog down the computer. It was much faster to just populate a lookup table and just grab the pre-calculated values.

X-Com, rather than generating the lookup tables at the start of the game, has all the values pre-calculated and stored in a file.

I have the feeling that it's one of the game's trig functions that's causing the problem with CE's blaster bomb bug, but I don't think it's the fault of the Sine and Cos tables.


It was my impression that all fired weapons travel in a straight line (with the exception of celatid spit). I don't see why you'd need trig for a simple "rise 0.1 and go left 0.2, per tile" (or whatever) velocity. Bullets drop?

However, clearly thrown items and celatid spit (should) use an arc. I had been thinking that too didn't have to have trig (although it can be used), because one could just start with initial heading and subtract the effect of gravity each tile. Which seemed simpler to me... and X-COM likes to stay simple. Just a guess on my part, though.

Zai, we've seen a lot of small inaccuracies due to integer rounding. I wouldn't be surprised if they are what lead to small surprises on the battlefield. Possibly even the co/sine values themselves get rounded too, "in action". It would be real interesting if you found any mistakes in the co/sine tables.

Does anyone see a need for co/sines, for drawing the globe on the geoscape? I have no idea how they might have programmed it. --MikeTheRed 17:24, 22 September 2006 (PDT)

I'm not good at this, as I was sadly not that attentive during trig - but as I have attempted (Attempted being the key word) to write a computer game, I have run into movement of objects along a 2d plane, and it does require use of trig functions.

Shooting is indeed in a straight line, but everything on the battlescape and geoscape works in a 2d cartesian plane.

Let's say, in Chess, the Knight moves in an L shaped pattern. That's easy to do. It's just one move to the side and then walks straight on until it reaches its destination. In a 2d grid, that's easy to implement. But we can't have bullets or ships jerking about like that can we? We want them to go straight to their destination.

To move in a straight line, we need to know the origin coordinates and the destination coordinates to help determine the angle we are going to be moving. We also need to know how fast we're moving (a fixed speed in the Battlescape, variable in the Geoscape) to determine how far to move each update.

You can use then Sine and Cosine to determine how much the X and Y coordinates need to be updated every update. Something like X displacement = Speed * Cos(Angle) and Y displacement = Speed * Sin(angle)

Basically, the trig functions are there to let the game determine how much the bullet or aircraft needs to update each update.

I never liked trig because I never thought it would be useful in the real world. But now I deserve a kick for thinking like that. Unbeknowest to myself or a number of people, math happens all around us whether we like it or not.

A much better explanation can be found at:


Thanks for the link, NKF. Let me ponder it a bit. And of course, whatever I think is independent of what the Gollop brothers did :) --MikeTheRed 19:31, 22 September 2006 (PDT)

It's quite common for games to use trig for movement, actually.

As much as I want to get away with not using Trig for 2d/3d movement, there's just no escaping it.


In theory, the line could be traced parametrically...but you still need trig to compute the line when a shot misses.

Accurate shots theoretically could be implemented to not need trig, but this is implausible.

-- Zaimoni 11:48PM Sept 22 2006 CDT