CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Drawing a cube

  1. #1
    Join Date
    Dec 2008
    Posts
    2

    Exclamation Drawing a cube

    Okay so I'm reading a book about the win32 api and were on the chapter where we learn to add menus and shapes and the whole chapter ends with making a simple PaintProgram that can draw shapes, it has brushs, pens, and colors for those pens/brushes, and diffrent styles for those pens. Then theres exercises you do to extend upon that program. This is the exercise I'm stuck on:

    "As you can see, a cube is made up of twelve lines. Write a function that
    draws a cube to the client area of a window. Then add a new “cube” primitive to Program 15.5 that the
    user can select from the menu and draw."

    So my question to you is where do I even begin to learn how to write a function that can draw a cube. I tried seeing if it was a trick exercise and there is already a cube function in the library. But I don't see any cube functions on msdn.

    Can anyone help?

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Drawing a cube

    If you know how to draw lines then you can also draw a cube.
    A cube is basically 2 squares drawn using some offset and then connect the corners of the square with some other lines. Of course, things get more complicated if you want to rotate the cube in 3D space.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Dec 2008
    Posts
    2

    Re: Drawing a cube

    I know how to make lines easily. But for some reason it's mind boggling to me to take the lines and know to take them in 2d(i guess its 2d) space and tell the lines where to "spawn" to sorta make it appear to be a cube. The only way the book taught me is how to make simple lines that are generated with the mouse left click and as you hold it down it "captures" the beginning of the mouse click to the end. (When lifting up the left mouse button). Oh well

  4. #4
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Drawing a cube

    You can use Polygon function. Your first step is to draw what you think a cube would look like on paper. Then assign coordinates to the corners and then use Polygon function to connect them.

    First step, draw one face of the cube. Did you figure that out ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured