JMonkeyEngine to create a cube

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blackraven1425
    New Member
    • Mar 2008
    • 27

    JMonkeyEngine to create a cube

    I'm using JMonkeyEngine, and trying to make objects in a cube. Meaning, a three-dimensional cube out of objects (Spheres, to be specific). However, the logic is escaping me. This is what I have so far:

    for(int i = 1; i<9; i++){
    for(int j=1; j<9; j++){
    for(int k=1; k<9;k++){
    add object
    }
    }
    }

    I'm really sitting here scratching my head, cause this gives a triangle viewed from different angles to be a different triangle. It gives a sliver of a cube. I'm looking for an algorithm for a whole cube, in pseudo code or java so I can trace it out and understand how to do this.
  • blackraven1425
    New Member
    • Mar 2008
    • 27

    #2
    oh shoot, i forgot to add that the add object is at i,j,k

    Duh duh = duhs.get((i*j*k )-1);
    duh.setLocalTra nslation(new Vector3f(i, j, k));

    Comment

    • blackraven1425
      New Member
      • Mar 2008
      • 27

      #3
      the actual source code i have working that gives the triangle
      that canged at different angles

      Node n = new Node();
      for(int i = 1; i<9; i++){
      for(int j=1; j<9; j++){
      for(int k=1; k<9;k++){
      AtomSphere atom = atoms.get((i*j* k)-1);
      atom.setLocalTr anslation(new Vector3f(i, j, k));
      atom.setSolidCo lor(ColorRGBA.g ray);
      n.attachChild(a tom);
      }

      }
      }

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by blackraven1425
        AtomSphere atom = atoms.get((i*j* k)-1);
        This can't be correct; e.g. it fetches the same atom for values i,j,k == 2,3,4 and
        i,j,k == 4,6,1

        kind regards,

        Jos

        Comment

        • blackraven1425
          New Member
          • Mar 2008
          • 27

          #5
          So, I'm still lost on how to traverse the cube correctly. i*j-k doesnt work right, it only works for the last square in the cube. The rest that shows up is one edge of the cube.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by blackraven1425
            So, I'm still lost on how to traverse the cube correctly. i*j-k doesnt work right, it only works for the last square in the cube. The rest that shows up is one edge of the cube.
            Just guessing from the little code snippet you showed us:

            [code=java]
            for(int i = 0; i<9; i++){
            for(int j= 0; j<9; j++){
            for(int k= 0; k<9;k++){
            AtomSphere atom = atoms.get(81*i+ 9*j+k);
            ...
            [/code]

            This is assuming that 'atoms' is a simple list that stores all the atoms. The
            three indexes i,j,k are transformed to a single linear index value.

            kind regards,

            Jos

            Comment

            • BigDaddyLH
              Recognized Expert Top Contributor
              • Dec 2007
              • 1216

              #7
              Originally posted by JosAH
              Just guessing from the little code snippet you showed us:

              [code=java]
              for(int i = 0; i<9; i++){
              for(int j= 0; j<9; j++){
              for(int k= 0; k<9;k++){
              AtomSphere atom = atoms.get(81*i+ 9*j+k);
              ...
              [/code]
              Or maybe (to keep arithmetic out of it...
              [code=java]
              int atomIndex = ???;
              for(int i = 0; i<9; i++){
              for(int j= 0; j<9; j++){
              for(int k= 0; k<9;k++){
              AtomSphere atom = atoms.get(atomI ndex++);
              ...
              [/code]
              No one in this forum has stepped forward and admitted to knowing JCodeMonkey, so you need to explain things better or see if that product has its own forum.

              Comment

              Working...