Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need a program to create a 3D square ?

roselinroselin Posts: 7Member
Hai all,

I am initiating a simple project in 3D graphics.I want to do the following things:

1)creating a simple square in 3D
2)Move the sqaure to the given final position through some intermediate position already given.

Please give your suggestions to do these things.

Comments

  • JaguarZJaguarZ Posts: 4Member
    I would sugguest using OpenGL.

    Making a square is simple enough.
    You specify the points (either hardcoded or in variable form) for the
    corners of the first plain, then simply shift it back for the back panel. Rotate 90 degrees on the Y axis and shift 1/2 way left/right for the 2 side panels. Rotate 90 degrees on the X axis and shift 1/2 way up/down for the top and bottom panels.

    I haven't actually coded moving an object place to place in OpenGL yet, so I'm not sure how it works, but it shouldn't be hard. Rotating all the planes on the cube (if you wanted to do so) is just one command, not one for each plane. I'm thinking movement should be similar.

    www.gametutorials.com has some very nice tutorials on OpenGL.

    Hope this helps,
    JaguarZ
  • XLoomXLoom Posts: 129Member
    I would sugguest using OpenGL as well.
    Command for moving objects is
    glTranslate(x,y,z);
    Nothing more to do after calling that than drawing whatever you want to draw.

    XLoom
  • roselinroselin Posts: 7Member
    hai,
    thanks for u'r reply.i have created the 3D object using opengl commands.now i want to recognize it as a sphere or cube or...
    How can i do it?Is there any command to scan the lines or pixels and to measure the angle between the lines?
    roselin
  • gautamgautam Posts: 642Member
    No, there is no way (from OpenGL point of view), there may be other ways to recognize as cube or sphere. All OpenGL does is render triangles on screen. The system doesn't have any notion of sphere cube or anything. And No there is no function to calculate the angle between two line in OpenGL - its purely a graphical API, you need to use trignometry to do that. Its not that difficult.

    : hai,
    : thanks for u'r reply.i have created the 3D object using opengl commands.now i want to recognize it as a sphere or cube or...
    : How can i do it?Is there any command to scan the lines or pixels and to measure the angle between the lines?
    : roselin
    :

  • XLoomXLoom Posts: 129Member
    Hi,

    I don't quite understand the question. Do you mean that you want to draw the cube or sphere first and pretend you don't know what you have drawn and then try to make computer to recognize whether it is a cube or sphere? If so then first you need to get the image to memory with

    void glReadPixels(GLint x,
    GLint y,
    GLsizei width,
    GLsizei height,
    GLenum format,
    GLenum type,
    GLvoid *pixels);

    (Description of this function can be found from
    http://www.mevis.de/~uwe/opengl/glReadPixels.html)

    And after doing this, you find the edges of the object and check whether they are on one line (for cube edge) or do any two farthest edgepoints have the same average (for sphere) or whatever you need to find out.
    Is this what you meant?
    Anyway I hope it helps ;), even if it has no connection to the question :)

    XLoom
  • roselinroselin Posts: 7Member
    hai,

    Thank u very much for u'r reply.It's really what i am seeking.Now i got it.if i have any doubt i will contact u.Agin ,lot of thanks...

    roselin

    : Hi,
    :
    : I don't quite understand the question. Do you mean that you want to draw the cube or sphere first and pretend you don't know what you have drawn and then try to make computer to recognize whether it is a cube or sphere? If so then first you need to get the image to memory with
    :
    : void glReadPixels(GLint x,
    : GLint y,
    : GLsizei width,
    : GLsizei height,
    : GLenum format,
    : GLenum type,
    : GLvoid *pixels);
    :
    : (Description of this function can be found from
    : http://www.mevis.de/~uwe/opengl/glReadPixels.html)
    :
    : And after doing this, you find the edges of the object and check whether they are on one line (for cube edge) or do any two farthest edgepoints have the same average (for sphere) or whatever you need to find out.
    : Is this what you meant?
    : Anyway I hope it helps ;), even if it has no connection to the question :)
    :
    : XLoom
    :

  • liviu2003liviu2003 Posts: 8Member
    : Hai all,
    :
    : I am initiating a simple project in 3D graphics.I want to do the following things:
    :
    : 1)creating a simple square in 3D
    : 2)Move the sqaure to the given final position through some intermediate position already given.
    :
    : Please give your suggestions to do these things.
    :
    :

    Hello, there

    You say you want to make a simple square in 3D(a cube or square?)
    and that's simple. You either use the command "auxWireCube()" for a wireframe cube or "auxSolidCube" for a solid cube or either you create your own cube with the "glVertex3f(x,y,z)" function(The prefferable option).
    For a square you colud also use the "gl Vertex(x,y,z)" function as follows:

    glBegin(GL_SQUARE); //you could also use GL_POLYGON
    {
    glVertex3f(0.0,0.0,0.0);
    glVertex3f(0.0,1.0,0.0);
    glVertex3f(1.0,1.0,0.0);
    glVertex3f(1.0,0.0,0.0);
    }
    glEnd();

  • mitulgolakiyamitulgolakiya Posts: 2Member
    : Hai all,
    :
    : I am initiating a simple project in 3D graphics.I want to do
    : the following things:
    :
    : 1)creating a simple square in 3D
    : 2)Move the sqaure to the given final position through
    : some intermediate position already given.
    :
    : Please give your suggestions to do these things.
    :
    :
    I am giving code for 3D square in turbo c

    /* Program for 3D square

    By:
    Mitul Golakiya

    E-Mail ID : mitulgolakiya@yahoo.com
    mitul.gorkiya@avinashi.com

    */
    #include
    #include
    #include
    #include
    #include
    #include

    void main()
    {
    int x = 250, y = 200;
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "E:\TC\BGI");
    moveto(x, y+100);
    lineto(x, y);
    lineto(x+25, y-25);
    lineto(x+125, y-25);
    line(x, y, x+100, y);
    line(x, y+100, x+100, y+100);

    moveto(x+100, y);
    lineto(x+100, y+100);
    lineto(x+125, y+75);
    lineto(x+125, y-25);
    lineto(x+100, y);

    setlinestyle(2, 1, 1);
    line(x+25, 175, x+25, y+75);
    line(x+25, 275, x, y+100);
    line(x+25, 275, x+125, y+75);

    getch();
    getch();
    closegraph();
    }


Sign In or Register to comment.