Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Mapping Points, Zones, etc on a Sphere

  1. #1
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Mapping Points, Zones, etc on a Sphere

    Hey I was hoping that I could get some quick pointers on how I would be able to do some simple functions for my next game project. [size=9px](Will start after GQ is completed!)[/size]

    I'm planning to have the Earth rendered as a single 3D sphere and will need to plot locations on and around the surface. I'll also need to plot and track movement as well as determine specific zones (countries, regions, fallout areas) and day/night.

    I can think of how to do it in 2D no problem, but somehow I can't wrap the idea around my head using vectors or 3D maths. :?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  2. #2

    Mapping Points, Zones, etc on a Sphere

    How do you want the mapping? Polar, longtitude/latitude, something else?
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  3. #3
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Mapping Points, Zones, etc on a Sphere

    I think Long and Lat would be easiest for me. (My brain still works in 2D )

    Also note that I'm a newcomer to 3D. This will be my first 3D project. (and I'll be using OpenGL if thats relevant)
    Jason McMillen
    Pascal Game Development
    Co-Founder





  4. #4

    Mapping Points, Zones, etc on a Sphere

    [pascal]function LatlongToVec3(latitude, longtitude, sphereRadius: single): TVector3;
    begin
    result.x := cos(longtitude)*sin(latitude)*sphereRadius;
    result.y := sin(longtitude)*sphereRadius;
    result.z := cos(longtitude)*cos(latitude)*sphereRadius;
    end;[/pascal]
    I think that'll do
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  5. #5
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Mapping Points, Zones, etc on a Sphere

    Nice! Thanks.

    Now I'm guessing that I'll just have to plot all my movement in 2D then translate it for display into vectors?

    ie. a Plane or craft that is going from say:

    Latitude = 43.5167, Longitude = -78.4863

    to

    Latitude = 53.4880, Longitude = -1.6699

    Not bothering with altitude...
    Jason McMillen
    Pascal Game Development
    Co-Founder





  6. #6

    Mapping Points, Zones, etc on a Sphere

    Well that's a bit of a problem as you can't linearly interpolate the latlong coordinates to get a straight path. AFAIK you have to use some kind of scheme like spherical interpolation using quaternions.

    (PS. And remember that my latlongtovec3 function needs coordinates in radians )
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  7. #7
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Mapping Points, Zones, etc on a Sphere

    Wow... ok this might not be as super easy as I thought it would be.

    Do you think you could give me a simple example of how I'd use this? (maybe a poor-man's diagram just so I get the idea in my head a bit clearer.)
    Jason McMillen
    Pascal Game Development
    Co-Founder





  8. #8

    Mapping Points, Zones, etc on a Sphere

    quaternions are not an easy subject. Writing the code for a quaternion spherical linear interpolation here would take too much space. You could have my library if you want it.

    I just discovered that there's a way to do it with vectors
    [pascal]
    function slerp2(src, dest: tvec3; t: single): tvec3;
    var d,s1,s2,s3,ld,l: single;
    begin
    d := arccos(src.x*dest.x+src.y*dest.y+src.z*dest.z);

    s1 := sin((1-t)*d);
    s2 := sin(t*d);
    s3 := sin(d);

    result.x := (s1/s3)*src.x+(s2/s3)*dest.x;
    result.y := (s1/s3)*src.y+(s2/s3)*dest.y;
    result.z := (s1/s3)*src.z+(s2/s3)*dest.z;
    {l := sqrt(result.x*result.x+result.y*result.y+result.z* result.z);
    result.x := result.x/l;
    result.y := result.y/l;
    result.z := result.z/l; }//uncomment this to normalize the resulting vector
    end;[/pascal]
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  9. #9

    Re: Mapping Points, Zones, etc on a Sphere

    Ok i might throw some ideas:
    - First thought came that sphere can consist of spherified cube; say a cube with NxN grid on each of 6 sides and vertices moved so they are from equal length out of center. This divides sphere more evenly into "tiles". Each side is 90 degrees away from each other.
    - Day night calculation. 2 parameters needed: Earth rotation angle, Earth angle towards sun.
    - Positioning, i'd place every object using 3D coordinates instead of 2D even when it's surface of sphere. That way it is easier to calculate distances and pathing. Note that paths still aren't linear; earth isn't flat Path creates an arc instead of line.. not bothered to draw it, formula might be easy to make.
    - Zones/continents could propably be made of arrays of 3D points forming the outlines. Bit tricky checking if object is in area. Only other choice i can think of would be marking each "tile" with zone info, however this is very rough solution. Even as rough solution it could still be used as pre-calculation, narrowing down the choices quickly.

    PS. Please somebody make a Starcraft like 3D game that features several planet like battlefields

  10. #10
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Mapping Points, Zones, etc on a Sphere

    Thanks a lot for the great information guys. I'm sort of wrapping all the issues that I'm going to be facing in my mind a little clearer now.

    However, I must admit that some of the maths that you are trying to explain is going over my head a bit. To be completely honest, I'm a bit of a dumby when it comes to anything much further than basic trig and algebra right now. Though I do want to learn, I'm just unsure where to focus my efforts.

    I have an alternative idea to creating a 3D model of the map. I could instead use a 2D version (same texture) and calculate the distance using a parabolic calculation of sorts. Doesn't have to be 100% accurate. It would be plausible solution should I just not be able to get things grooving the other way.

    Actually this isn't too far off my original idea of just doing it in 2D (distances, movement, zones, etc) and simply plotting visually in 3D

    My end goal is to do this at a level that I can learn rather quickly, yet retain some similarity to the real thing.

    As I've said, I'm NEW to 3D. So I would like to dip my toe in to get a feel for it, not jump right into the Atlantic just yet.
    Jason McMillen
    Pascal Game Development
    Co-Founder





Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •