Howdy, Stranger!

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


3D Cube in C++

obiobi Member Posts: 5

I'm wondering what kind of structure to use when building a 3d-cube in C++.

I'm thinking of having a class Cube and with sub-routines like Cube.rotateX and Cube.moveZ. How do I convert 3d-coordinates to 2d? like (x,y,z) -> (x,y) ?



  • SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
    Uhm, I think the raw formula for getting the screen coordinates is something like this:


    I am not sure though, since all of my stuff is hardware accelerated now. I suggest checking out OpenGL for a quick intro. You'll find that OpenGL is easier to code than even software, and all you have to do is feed it the coordinates of your object(s) and it will automatically draw the stuff for you! Check out the site below if you have some time. I spent about four hours there after spending a month getting nowhere with D3D, and in that four hours I managed to create my own 3D engine with texturing!


  • programmeurkeprogrammeurke Member Posts: 19
    the formula is indead
    X_Screen = X_3d / Z_Screen * SOMETHING
    Y_Screen = Y_3d / Z_Screen * SOMETHING

    where something is usually 256 (you can choose your own number too)

    For the Cube: don't forget a cube are 8 poits and 12 lines !
    with the points only you can't make the cube, because the planes will be drawn through the cube itsself (unless you're very lucky).
    I hope you've learned something...


  • mohammed abbasmohammed abbas Member Posts: 12
    [b][red]This message was edited by the mohammed abbas at 2002-3-2 14:6:49[/red][/b][hr]
    to Creat 3d wireframe cube you must create three struct
    the first one is to hold the vertecs of cube
    simple example
    [code]struct vertecs
    int local_x,local_y,local_z; // to hold local coordinates
    int wolrd_x,wolrd_y,wolrd_z;// to hold transformed coordinates
    int screen_x,screen_y;// to hold the screen value
    } // by using screen_x=wolrd_x/wold_z+destance
    // screen_y=wolrd_y/wolrd_z+destance

    and another struct called lines
    struct line

    vertecs start;
    vertecs end;
    final struct called shape to hold all information about wireframe
    3dshape for example CUBE shape is contents array of 8 vertecs and
    array of 12 lines
    struct shape
    int number_of_vertecs;
    int number_of_lines;
    line *l;
    int color;
    this is for wireframe 3d shape.

Sign In or Register to comment.