Results 1 to 4 of 4

Thread: How to draw a 3D globe?

  1. #1
    Member Newbie
    Join Date
    Jul 2009
    Posts
    33

    How to draw a 3D globe?

    Im trying do draw a 3D globe, but dont succeed.
    A circle is beeing drawn, but then I would like to draw circels each with 1 grade angle increase since the last drawn circle. What do I have to modify in my code?

    Code :
        final float DEG2RAD = (float)3.14159/180;
        float grade = 0.0f;
     
        void drawCircle(float radius)
        {
           gl.glBegin(GL.GL_LINE_LOOP);
     
           for (int i=0; i < 360; i++)
           {
               for(int y=0; y<360; y++)
               {
                   float degInRad = y*DEG2RAD;
                   gl.glVertex2f(((float)Math.cos(degInRad)*radius)+grade, (float)Math.sin(degInRad)*radius);
                   grade++;
               }
           }
     
           gl.glEnd();
        }

  2. #2
    Senior Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Los Angeles
    Posts
    374

    Re: How to draw a 3D globe?

    I suggest you try something simpler than a 3D globe first. Then move on to the globe. I say this because in the code above you say you are trying to do a 3D globe, but there are no Z coordinates computed or specified. You need x, y, and z coordinates to draw things in 3D. My suggestion is to first try to do a 3D cube with all x, y, and z coordinates set to +1 or -1. If you can do that it means you have a basic understanding of 3D coordinate systems, and OpenGL viewing transformations, i.e. orthographic, perspective, etc. Once you get a wireframe unit cube done, then try to do a wireframe, unit sphere, inside it.
    Am I doing your homework for you?

  3. #3
    Senior Member Regular Contributor
    Join Date
    Jun 2009
    Location
    FL , USA
    Posts
    192

    Re: How to draw a 3D globe?

    1. Either use in built functions such as gluSphere()


    2. or using your approach , need to draw circles with 3D coord with same diameter axis.

    To easy things, draw two circles in 3D perpendicular to each other with same axis. Then change angle for the third circle so that it shares same axis but at an inclination != 90.

    Try:
    Code :
    gl.glVertex2f(((float)Math.cos(degInRad+grade)*radius), (float)Math.sin(degInRad)*radius , z);
    Where z also needs to be changed.

    3. Another way is to draw a torus using in built function where inner radius and outer radius are near.

    4. Define a 3D rotation matrix (do not use glRotatef() say M and corresponding function such that it takes an angle range and renders points or circle at rotated positions.

  4. #4
    Member Newbie
    Join Date
    Jul 2009
    Posts
    33

    Re: How to draw a 3D globe?

    Thanks for your answers! I will make a try within the next 24 hours and return here if I can't get it working.

    awhig: I will check out gluSphere().

Similar Threads

  1. globe-texture without a seam?
    By CarstenT in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-02-2014, 05:25 AM
  2. Rotate a globe to a Lat Lon position
    By TOO_THIRSTY in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 04-23-2013, 12:54 PM
  3. Exaggerated Elevations on Globe
    By bmcclint_gl in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 04-11-2013, 06:57 PM
  4. Drawing Arcs between two points on a globe
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 08-10-2006, 04:42 PM
  5. 3D Globe
    By Kem Peng in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-15-2001, 04:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean