Results 1 to 3 of 3

Thread: Please help with drawing a dome...

  1. #1
    Member Contributor
    Join Date
    Mar 2000
    Posts
    94

    Please help with drawing a dome...

    First off, I want to thank all the people on this board that have helped me in OpenGL. I've never been to a board that had such speedy responses (every time) and with such knowledgeable people....Now to my question

    I have a 3d plane that stretches by 10000 pixels in all directions...I've built some scenery on the plane (like a building or two). I want to make a sky...A simple sky...

    I want to encase my little 3D world in a dome(half a sphere)...Not texture mapped (I havn't learned how to do that yet) I want to create it with pixels with a little space in between (cross hatch) to give the illusion of a star filled sky... Can any one tell an approach to do this (or a tutorial online)...Is it just a simple "for" loop? Thanx again...

  2. #2
    Junior Member Newbie
    Join Date
    Mar 2000
    Location
    ...
    Posts
    28

    Re: Please help with drawing a dome...

    hi there,i've got some code for you...
    it's the "hard way" for rendering a hemisphere.sorry,but it's only for borland c...
    if you want to do this in openGL,you should check out things like NURBS and meshes..

    //
    //this code can be compiled only in borland c++
    //
    #include <graphics.h>
    #include <stdlib.h>
    #include <iostream.h>
    #include <conio.h>
    #include <math.h>
    #include <dos.h>

    #define Pi 3.1415926536

    enum Action{move,draw};

    struct Point3D
    {
    int x;
    int y;
    int z;
    Action action;
    };

    //this function init's graphics mode in borland c++
    void init_gr(void)
    {
    //detect the hardware
    int gdriver = DETECT, gmode, errorcode;


    initgraph(&gdriver, &gmode, "");

    errorcode = graphresult();

    if (errorcode != grOk) //an error occured
    {
    cout << "error: " << endl << grapherrormsg(errorcode) << endl;
    cout << "press a key:";
    getch();
    exit(1);
    }
    }

    //ends the gr.mode in borland c++
    void end_gr(void)
    {
    closegraph();
    }

    //moves the origin:
    void MoveTo(int x, int y)
    {
    moveto(x,y);
    }


    void LineTo(int x, int y)
    {
    lineto(x,y);
    }

    void draw3Dobject(Point3D *object, int N, float rho, float theta,
    float phi, float dist_to_screen, int xshift, int yshift)
    {
    int x,y;
    float xe,ye,ze,costh,sinph,cosph,sinth,v11,v12,v13,v21,v 22,v32,v33,v23,v43;

    /* get the coefficients */
    costh=cos(theta);
    sinth=sin(theta);
    cosph=cos(phi);
    sinph=sin(phi);
    v11=-sinth; v12=-cosph*costh; v13=-sinph*costh;
    v21=costh; v22=-cosph*sinth; v23=-sinph*sinth;
    v32=sinph;
    v33=-cosph;
    v43=rho;
    for (int i=0;i<N;i++)
    {
    //get the camera position
    xe=v11*(object+i)->x+v21*(object+i)->y;
    ye=v12*(object+i)->x+v22*(object+i)->y+v32*(object+i)->z;
    ze=v13*(object+i)->x+v23*(object+i)->y+v33*(object+i)->z+v43;
    // screen coordinates
    x=dist_to_screen*xe/ze+xshift;
    y=dist_to_screen*ye/ze+yshift;
    //drawing
    if((object+i)->action==move)
    MoveTo(x,y);
    else
    LineTo(x,y);
    }
    }

    int main(void)
    {
    const int n=10; //number of segments in the hemisphere
    Point3D hemisphere[8*n*n+n]; //all points of the hemisphere
    float rho=1800,theta=Pi,phi=3*Pi/4,dist_to_screen=600; //camera position
    int xshift=300, yshift=250;
    float delta=Pi/(2*n), R=300; /* parameters of the hemisphere */
    float alpha,cosa,sina,beta,cosb,sinb; //support variables

    // Init
    init_gr();

    // generate the hemisphere */
    for (int i=0;i<4*n;i++)
    {
    alpha=i*delta;
    cosa=cos(alpha);
    sina=sin(alpha);
    for (int j=0;j<n;j++)
    {
    beta=j*delta;
    sinb=sin(beta);
    cosb=cos(beta);
    hemisphere[i*n+j].x=R*cosa*sinb;
    hemisphere[i*n+j].y=R*sina*sinb;
    hemisphere[i*n+j].z=-R*cosb;
    hemisphere[i*n+j].action=(j==0?move:draw);
    }
    }
    int c=4*n*n;
    for (i=0;i<n;i++)
    {
    beta=i*delta;
    sinb=sin(beta);
    cosb=cos(beta);
    for (int j=0;j<4*n+1;j++)
    {
    alpha=j*delta;
    cosa=cos(alpha);
    sina=sin(alpha);
    hemisphere[c+i*(4*n+1)+j].x=R*cosa*sinb;
    hemisphere[c+i*(4*n+1)+j].y=R*sina*sinb;
    hemisphere[c+i*(4*n+1)+j].z=-R*cosb;
    hemisphere[c+i*(4*n+1)+j].action=(j==0?move:draw);
    }
    }

    //drawing
    draw3Dobject(hemisphere,8*n*n+n,rho,theta,phi,dist _to_screen,xshift,yshift);

    //shutdown
    getch();
    end_gr();

    return 0;
    }

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2010
    Location
    Hyderabad,India
    Posts
    1

    Re: Please help with drawing a dome...

    try this out.
    Surely gives out the result but is slow in rendering.

    void hemiSphere(float radx,float rady,float radz)
    {
    float i,j,k;
    float x,y,z,t1x,t1y,t1z,t2x,t2y,t2z;
    glBegin(GL_QUADS);
    {
    for(i=0;i<91;i+=side)
    {
    for(j=0;j<359;j+=side)
    {
    t1x=(sin(j*RAD)*cos(i*RAD) + sin((j+side)*RAD)*cos((i+side)*RAD))/2;
    t1y=(sin(i*RAD) + sin((i+side)*RAD))/2;
    t1z=(cos(j*RAD)*cos(i*RAD) + cos((j+side)*RAD)*cos((i+side)*RAD))/2;

    t2x=(sin((j+side)*RAD)*cos(i*RAD) + sin(j*RAD)*cos((i+side)*RAD))/2;
    t2y=(sin(i*RAD) + sin((i+side)*RAD))/2;
    t2z=(cos((j+side)*RAD)*cos(i*RAD) + cos(j*RAD)*cos((i+side)*RAD))/2;

    glNormal3f((t1x+t2x)/2,(t1y+t2y)/2,(t1z+t2z)/2);
    glVertex3f(radx*sin(j*RAD)*cos(i*RAD),rady*sin(i*R AD),radz*cos(j*RAD)*cos(i*RAD));
    glVertex3f(radx*sin((j+side)*RAD)*cos(i*RAD),rady* sin(i*RAD),radz*cos((j+side)*RAD)*cos(i *RAD));
    glVertex3f(radx*sin((j+side)*RAD)*cos((i+side)*RAD ),rady*sin((i+side)*RAD),radz*cos((j+si de)*RAD)*cos((i+side)*RAD));
    glVertex3f(radx*sin(j*RAD)*cos((i+side)*RAD),rady* sin((i+side)*RAD),radz*cos(j*RAD)*cos(( i+side)*RAD));
    }
    }
    }
    glEnd();
    }



    if in the first loop i = -90 is used result is a sphere.
    Beginners are the best.

Similar Threads

  1. Drawing points before drawing a curve line
    By PepeBeef in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-26-2017, 09:34 PM
  2. Collada Dome Ubuntu Problem
    By stefan78 in forum COLLADA
    Replies: 0
    Last Post: 05-03-2014, 07:16 AM
  3. Simply drawing lines; Adjusting drawing to window
    By Zaemz in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-12-2012, 03:56 AM
  4. Clear screen in gradient mode instead of sky-dome?
    By anuchka in forum OpenGL: Basic Coding
    Replies: 12
    Last Post: 10-16-2008, 08:07 AM
  5. Need help...reflection of environment in transparent dome.....
    By new2ogl in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-30-2001, 11: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