Jump to content


Geoscape Test

  • Please log in to reply
6 replies to this topic

#1 iperez



  • Forum Members
  • PipPip
  • 3 posts

Posted 27 June 2008 - 03:56 PM

Hi all,

I have been working on a complete remake of X-COM for a little while, and I realized that instead of branching off into my own project, I should try to provide whatever help I can to this existing project.

I have mostly been working on the Geoscape, where I have actually come quite far I think. I have the Geoscape rendered (in wireframe so far) exactly how it is in the game. I already know how to add the texture, I just haven't got to it yet because I'm stuck on one part: Translating screen (i.e. mouse) coordinates to the geoscape coordinates. I could really use some help with this if anyone is really good at math.

Here is a link to my test program:


Arrow Keys = rotate globe
Home = zoom in
End = zoom out


#2 kafros


    Creative Text Department

  • Xenocide Creative-Text Departmen
  • 1,800 posts

Posted 28 June 2008 - 12:44 PM

Very nice try iperez :)

Concerning your question, you may want to have a look at the source of another open source project, for example Xenocide or Alien Invasion.

Edited by Kratos, 28 June 2008 - 10:01 PM.

#3 Kratos


    UFO2000 Staff

  • Moderators
  • PipPipPipPipPip
  • 4,113 posts

Posted 28 June 2008 - 01:05 PM

What we (ufo2000) have so far:

- A globe with texture
- Left and right rotation using arrow keys (could be better).
- Time (not noticeable) using the function keys.

If you want to help with the Geoscape, read here and here.

Btw, I cannot run your program, I don't have Windows.

UFO2000 and Xenocide are two different entities. In UFO2000 we use C++ for programming, and Lua for scripting, while staying closest, graphically, to the original X-com. Xenocide uses C# (and something else?) while using mostly newer graphics such as 3D, straying from X-com somewhat.

#4 Guest_Azrael Strife_*

Guest_Azrael Strife_*
  • Guests

Posted 29 June 2008 - 05:00 PM

Alright... here we go... take two... hopefully this time my post will pass the test...

iperez, I don't seem to be allowed to comment on the previous two posts, but expanding on kafros post, you could very well take a look at the Project Xenocide codebases to look at how our programmers dealt with the issue you are having, you even have two flavors to pick from: C++ and C# :) hopefully you'll get a good idea of how to do it there.

Good luck!

#5 feliciafan89



  • Forum Members
  • PipPipPip
  • 52 posts

Posted 26 August 2008 - 09:51 AM

I've been getting back into XCOM slowly... but I'd love to see what comes out after that prototype globe from ufo2000! Any word on adding labels to the regions and countries?

(Sorry, been gone a while!)
Posted Image

#6 dteviot


    Programming Department

  • [Xenocide Senior Members]
  • 1,479 posts

Posted 26 August 2008 - 01:47 PM

Sorry for delay in replying, but I usually don't monitor the UFO2000 threads.
The function used in Xenocide to convert the mouse position to location on earth is WindowToGeoPosition() found in
/// <summary>
		/// Convert a position in the viewport to a geoposition on the globe
		/// </summary>
		/// <param name="coords">The position in the viewport (in relative co-ords)</param>
		/// <returns>The geoposition or null if point isn't on globe</returns>
		/// <remarks>Uses equation from http://wikipedia.org/Ray-sphere_intersection.htm</remarks>
		public GeoPosition WindowToGeoPosition(PointF coords)
			double lx = Math.Tan(ViewAngle / 2.0) * (coords.X - 0.5) * 2.0 * AspectRatio;
			double ly = Math.Tan(ViewAngle / 2.0) * (coords.Y - 0.5) * -2.0;
			double sz = CameraPosition.Z;

			double term = (sz * sz) - ((lx * lx) + (ly * ly) + 1) * ((sz * sz) - 1);

			// if term is negative, then postion isn't on the globe
			// we're also going to ignore the result when we're close to edge of globe
			// because it's difficult to hit a point accurately around there
			if (term < 0.1f)
				return null;

			// we're only interested in the near solution
			double d = (sz - Math.Sqrt(term)) / ((lx * lx) + (ly * ly) + 1);

			// convert back to get cartesian co-ordinates
			double x = lx * d;
			double y = ly * d;
			double z = sz - d;

			// convert to polar
			GeoPosition origin = new GeoPosition(0.0f, 0.0f);
			GeoPosition offset = new GeoPosition((float)Math.Atan(x / z), (float)Math.Asin(y));

			// add in camera's displacement
			float distance = origin.Distance(offset);
			float azimuth  = origin.GetAzimuth(offset);
			GeoPosition camera = new GeoPosition(CameraPosition.X, CameraPosition.Y);
			return camera.GetEndpoint(azimuth, distance);

Basic process is sending a ray through the screen based on the pixel selected, and computing the line/sphere intersection.
Note, the math is simplified by modeling the earth as a sphere with a radius of 1, centered at 0, 0, 0, and the center of the camera is looking at 0, 0, 0.
Saving the world from the scum of the universe is hard work. Especially when you have to create the scum to begin with.

#7 Raptor29



  • Forum Members
  • PipPipPip
  • 18 posts

Posted 06 September 2008 - 03:20 PM


It's been a long time since I have posted :yarr: sorry about that

Anyways it's good to hear that people are willing to help out with geoscape I for one feel it could use some work, but I am glad it is there.

Anyways any help is appresiated
- Faith is the only thing that can cross the "gaps" or inconsistancies that exsist in logic-