Results 1 to 3 of 3

Thread: Using Excel to draw 3D graphics

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2016
    Posts
    100

    Using Excel to draw 3D graphics

    okay, this is pretty cool stuff. I'm actually a part video game developer and I do a lot of 3D modeling. When I saw this though, I had to investigate it:

    https://www.gamasutra.com/view/featu...ionary_3d_.php

    There is a download link for the workbook in the article. It is the OGAL_Demo.

    It's actually pretty simple in it's design. Basically Excel can draw graphics on screen (which I already knew about), but I never thought of integrating a basic in a basic 3D graphics engine. It actually produces a 3D cube that rotates on screen. It follows a basic 3D pipe line, where it builds shapes using triangles as building blocks. Two triangles make one polygon (4 sided shapes), and polygons are the building blocks of most 3D graphics.

    So I have been playing around with the values on the sheet, and the VBA code to draw the graphics using the Shapes.AddPolyline() method to help me better understand how it's all working. I had to do some research to understand basic 3D programming principles. However I'm still having trouble understanding all of it. From what I have read, the math behind it is used in OpenGL programming.

    I get how the code works, and how it basically takes points in space and draws shapes in a loop. There are several different types of matrixes as well that are dependant on one another to produce the final coordinates used to draw shapes on screen. There is the Relative Coordinates, Rotation and shift matrix, absolute coordinates, projected coordinates and finally screen coordinates, which is the final result used for drawing shapes.

    From what I can gather, the VBA code adjusts the rotation angle in the Rotation and Shift matrix, and which ultimatley changes the coordinates in the other matrixes, so while the cube rotates, it knows where to draw all the points. It seems to use trigonometry to get the Sin() and Cos() of the input rotation angle, which probably is how it calculates the on-screen triangles.

    Anyway, my understanding of it is limited, because I understand how it is calculating the position of points to make triangles (I think I do). What I don't understand is, how does it know to make a cube? I can't figure that out. I would like to modify the existing values to create other shapes, like a Pyramid, or maybe a sphere? What do you guys think?

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Using Excel to draw 3D graphics

    Wouldnt you just use some api to draw... opengl or something?

    So you do the 3d modeling but havent looked at how to draw 3d on the screen ?

    general gist as I see it is:


    x,y stay pretty much the same, calculated from the pov position with a calculation applied using z to show depth.



    I wouldnt have thought excel and shape would be a good way to go unless its just to see if you can and make a nice spinning cube on the screen too...

    good luck!!

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Using Excel to draw 3D graphics

    Quote Originally Posted by JohnnyWaffles View Post
    .... What I don't understand is, how does it know to make a cube? I can't figure that out. I would like to modify the existing values to create other shapes, like a Pyramid, or maybe a sphere? What do you guys think?
    I can't look at that site from work, but as a logical exercise:
    A square has four corners, so you have four points to define a square.
    A cube has six faces (squares), so you would have 24 points total (6 * 4) for the cube.
    Since the corner of three faces share a common point to make a cube, you actually only need eight points (24 / 3) to define a cube.
    Likewise, as you noted it should take two triangles to make a square, so the cube should be defined by 12 triangles ( 6 squares * 2 triangles).
    Those 12 triangles should be defined using the eight points that make up the corners of the cube.

    Now there may be an order to the points for each triangle, i.e. either in a counter-clockwise, or clockwise order (I would have to look it up) which the software can use to determine if the face of the triangle is facing toward you or away from you.
    You should look at the data used to define the original triangles to see if you can see the relationships mentioned above.

    Defining other shapes would be done following the same method. create the shape using a number of points in 3D-space, then triangulate the points so that all the points are included in a set of triangles. Then define the triangles using the coordinates in the order as seen from the front of that triangle (that may be the harder part to understand).

    Some code keeps the points separate from the structures made up of those points, so that when you rotate the cube you aren't rotating the 36 coordinates of the 12 triangles, but the 8 common points used to define those 12 triangles thus reducing the number of math operations considerably.

    Again, I haven't looked at that code and wouldn't be able to until after work.

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