• Advertisement
Sign in to follow this  

[java] Java3D Coloring problem

This topic is 3959 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, I finally managed to get some shapes on the screen. I have since created a small demo that displays a spinning checkerboard. Everything compiles without a hitch, and runs as expected with one exception: I end up with a bunch of vertical lines running through the board. However, when I add the stock ColorCube beside it on the scene graph (same rotation, even), the cube displays perfectly. As they say, an image is worth a thousand words: clicky (8k) If it helps, here's the code that builds the checkerboard:
  protected BranchGroup createSceneGraph()
    // Generate a grid of w*h tiles, each one unit square.
    bg = new BranchGroup();

    // Determines if the current tile is red; if not, then it's green.
    boolean isRed = true;

    // FIXME: The colors don't match the names...(on purpose).
    final Color3f red = new Color3f(0.0f, 0.0f, 1.0f);
    final Color3f green = new Color3f(0.0f, 1.0f, 1.0f);
    // dim is a Dimension member variable
    for(int x = 0; x < dim.width; x++)
      float xPos = -1.0f * (x / 2.0f);
      for(int y = 0; y < dim.height; y++)
        float yPos = -1.0f * (y / 2.0f);
        float[] coords = new float[]{ xPos,        yPos,        0.0f,
                                      xPos + 1.0f, yPos,        0.0f,
                                      xPos + 1.0f, yPos + 1.0f, 0.0f,
                                      xPos,        yPos + 1.0f, 0.0f };
        QuadArray qa = new QuadArray(4, QuadArray.COORDINATES
                                      | QuadArray.BY_REFERENCE
                                      | QuadArray.COLOR_3);

        // Set the quad's color
        Color3f color = (isRed ? red : green);
        qa.setColorRefFloat(new float[]{color.x, color.y, color.z,
                                        color.x, color.y, color.z,
                                        color.x, color.y, color.z,
                                        color.x, color.y, color.z});

        // The next quad should be the opposite color
        isRed = !isRed;

        // Add the quad to the tree
        bg.addChild(new Shape3D(qa));
      xPos += 1.0;
    return bg;

(For the record, I *do* know how to make RGB colors; the colors were changed to make a better screenshot, but I didn't change the names to match.) I can provide more code if needed. Like my last question, I'm sure this is something rather simple, but I can't find it; I really don't know where to start (or what to call the problem for a Google search). EDIT: Bad HTML. [Edited by - dragonknightx on May 18, 2007 1:47:01 AM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement