Renanse / Ardor3D

Ardor3D is a free Java based, professionally oriented, open source 3D graphics engine.
Other
229 stars 77 forks source link

XZGrid is not position at 0, 0, 0 #110

Closed jfelrod1960 closed 5 months ago

jfelrod1960 commented 1 year ago

Hey Josh I upgraded to A3D 1.6.1 and now my XZGrid is either not positioned at 0, 0, 0 or the spatial objects are not positioned correctly. I did not change this code when it was created using 1.5.3.

image

Renanse commented 1 year ago

Would you mind posting code where you create and attach the grid to your scene?

On Sun, Jun 18, 2023, 8:26 PM Jeffrey Elrod @.***> wrote:

Hey Josh I upgraded to A3D 1.6.1 and now my XZGrid is either not positioned at 0, 0, 0 or the spatial objects are not positioned correctly. I did not change this code when it was created using 1.5.3.

[image: image] https://user-images.githubusercontent.com/5440235/246703946-60d29509-2073-45a7-b34c-422012fd60d3.png

— Reply to this email directly, view it on GitHub https://github.com/Renanse/Ardor3D/issues/110, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOXBW4BDKTWYLHYV7YNHHLXL6TCZANCNFSM6AAAAAAZLHZUJI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

jfelrod1960 commented 1 year ago

Josh I will get that to you in a few days. I want to make sure I didn't introduce a bug.

Renanse commented 8 months ago

@jfelrod1960 Could you post that code if you still have it?

jfelrod1960 commented 5 months ago

Sorry for the late reply ...

package com.complexsive.testing.util;

import com.ardor3d.bounding.BoundingBox; import com.ardor3d.math.ColorRGBA; import com.ardor3d.math.Quaternion; import com.ardor3d.math.Vector3; import com.ardor3d.math.type.ReadOnlyColorRGBA; import com.ardor3d.renderer.Renderer; import com.ardor3d.scenegraph.Line; import com.ardor3d.scenegraph.Node; import com.ardor3d.scenegraph.shape.Quad;

import java.util.ArrayList;

public class XZGrid { private float minX; private float maxX; private float minZ; private float maxZ;

private Vector3[] interiorLinesVector;
private Vector3[] xzLineVector;
private Vector3 xAxis = new Vector3(1.0, 0.0, 0.0);
private ColorRGBA[] colorlist;
private Node xzGridNode;

private Line xzLine;
private Quad xzQuad;

private int imageWidth;
private int imageHeight;

// Constructor to display an XZGrid defaulting to color white.  The grid is
// displayed.
public XZGrid(int dimensions, int unitsize) {
    this(dimensions, unitsize, ColorRGBA.WHITE);
}

// Constructor to display an XZGrid.  The grid is color is passed and
// displayed.
public XZGrid(int dimensions, int unitsize, ReadOnlyColorRGBA color) {
    calculateXZMaxMin(dimensions, unitsize);
    calculateInteriorLinesVectors(unitsize);
    xzLineVector = new Vector3[interiorLinesVector.length + 12];
    colorlist = new ColorRGBA[interiorLinesVector.length + 12];
    for (int i=0; i < interiorLinesVector.length + 12; i++) colorlist[i] = new ColorRGBA(color);
    createInteriorLines();
    xzLine = new Line("XZGrid", xzLineVector, null, colorlist, null);
    xzLine.setModelBound(new BoundingBox());
    xzLine.setAntialiased(true);
    xzLine.setLineWidth(0.01f);
    xzLine.updateModelBound();
    xzLine.setSolidColor(color);

    xzGridNode = new Node("XZGridNode");
    xzGridNode.attachChild(xzLine);
    xzGridNode.setTranslation(0, 0, 0);
    xzGridNode.setRotation(Quaternion.IDENTITY);
}

// Constructor to display an XZGrid.  A string representing the file name is
// passed and no grid is displayed.
public XZGrid(int dimensions, int unitsize, String[] textures, Renderer renderer) {
}

public XZGrid() {
    this(100,5);
}

public XZGrid(ColorRGBA color) {
    this(100, 5, color);
}

private void calculateXZMaxMin(int dimensions, int unitsize) {
    minX = - ((dimensions * unitsize)/2.0f);
    maxX = minX * -1.0f;
    minZ = minX;
    maxZ = maxX;
}

private void calculateInteriorLinesVectors(int unitsize) {
    ArrayList<Vector3> vlist = new ArrayList<Vector3>();
    float start = minX;
    while (start <= maxX) {
        vlist.add(new Vector3(start, 0.0f, minZ));
        vlist.add(new Vector3(start, 0.0f, maxZ));
        start += unitsize;
    }

    start = minZ;
    while (start <= maxZ) {
        vlist.add(new Vector3(minX, 0.0f, start));
        vlist.add(new Vector3(maxX, 0.0f, start));
        start += unitsize;
    }

    interiorLinesVector = new Vector3[vlist.size()];
    vlist.toArray(interiorLinesVector);
}
private void createInteriorLines() {
    int v = 12;
    int i = 0;
    while (i < interiorLinesVector.length) {
        xzLineVector[v] = interiorLinesVector[i];
        v++;
        i++;
        xzLineVector[v] = interiorLinesVector[i];
        v++;
        i++;
    }
}

public Node getXZGridNode() {
    return xzGridNode;
}

public float getMaxX() {
    return maxX;
}

public float getMaxZ() {
    return maxZ;
}

}

Renanse commented 5 months ago

Hey Jeff, I want to look into this, but I'm not sure what I'm looking for from the previous screenshot. I pulled your code into BoxExample, added it into the scene with 2 lines of code, and got a result that looked as I expected (box is rotating, of course, but is centered on the plane of the grid.)

final var grid = new XZGrid(); _root.attachChild(grid.getXZGridNode());

image
jfelrod1960 commented 5 months ago

Okay I will close. If it worked for you then it is my code. Thanks! :)