Howdy, Stranger!

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

Categories

3D Cube in C++

obiobi Member Posts: 5
Hey!

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) ?

Thanks!

Comments

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

    x=x/z
    y=y/z

    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!

    http://nehe.gamedev.net/

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

  • 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...

    [green][b][size=5]P[/size][size=4]ro[/size][size=3]g[/size][size=2]r[/size][size=1]amm[/size][size=2]e[/size][size=3]u[/size][size=4]rk[/size][size=5]e[/size][/b][/green]

  • 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

    [/code]
    and another struct called lines
    [code]
    struct line
    {

    vertecs start;
    vertecs end;
    }
    [/code]
    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
    [code]
    struct shape
    {
    int number_of_vertecs;
    int number_of_lines;
    line *l;
    int color;
    }
    [/code]
    this is for wireframe 3d shape.







Sign In or Register to comment.