Jump to content
XCOMUFO & Xenocide

Geoscape Test


iperez

Recommended Posts

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:

 

http://www.ianandmonica.com/geoscapetest.zip

 

Arrow Keys = rotate globe

Home = zoom in

End = zoom out

 

Thanks,

Ian

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Guest Azrael Strife

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!

Link to comment
Share on other sites

  • 1 month later...

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

http://svn.projectxenocide.com/xenocide/xn...eoscapeScene.cs

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

http://en.wikipedia.org/wiki/Line%E2%80%93...re_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.

Link to comment
Share on other sites

  • 2 weeks later...

Sweet!

 

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

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...