How to create labyrinth

i thought that it gonna work like PQTorus and sphere in TestCollisionTree…

ok, i have my matrix, now i'm trying to build lab with it

hope this isn't too late:


import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.SharedNode;
import com.jme.scene.Spatial;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Quad;



public class MazeTest extends SimpleGame {

    private final int width = 11,  length = 16,  tileSize = 10;
    private boolean[][] mazeData = new boolean[ length ][ width ];
    //
    private final float halfHeight = tileSize / 2f;
    private final float halfWidth = width * tileSize / 2f;
    private final float halfLength = length * tileSize / 2f;
    //
    //
    // This is test data to 'mimic' the logic of text reading
    private final String testString =
            "0,12n0,13n0,14n0,15n" +
            "1,14n" +
            "2,0n2,1n2,2n2,3n2,4n2,5n2,6n2,7n2,8n2,9n2,10n2,11n2,12n2,13n2,14n" +
            "3,6n3,7n" +
            "4,0n4,1n4,2n4,3n4,4n4,5n4,6n4,7n4,8n4,9n4,10n4,11n4,12n4,13n4,14n" +
            "5,14n" +
            "6,0n6,1n6,12n6,13n6,14n" +
            "7,0n7,1n7,2n7,3n7,4n7,5n7,6n7,7n7,8n7,9n7,10n7,11n7,12n7,13n" +
            "8,0n8,1n8,12n8,13n8,14n" +
            "9,14n" +
            "10,12n10,13n10,14n10,15n";

    public static void main( final String[] args ) {
        new MazeTest().start();
    }

    public MazeTest() {
        for( int row = 0; row < length; ++row ){
            for( int col = 0; col < width; ++col ){
                mazeData[row][col] = true;
            }
        }
        final String[] coords = testString.split( "n" );
        for( String coord : coords ){
            final String[] tempCoords = coord.split( "," );
            final int col = Integer.parseInt( tempCoords[0] );
            final int row = Integer.parseInt( tempCoords[1] );
            mazeData[row][col] = false;
        }

    // Set RANDOM data
//        for( int row = 0; row < length; ++row ){
//            for( int col = 0; col < width; ++col ){
//                mazeData[row][col] = FastMath.rand.nextBoolean();
//            }
//        }
    }

    @Override
    protected void simpleInitGame() {
        buildMazeWalls();
        buildInnerMaze();
    }

    private void buildMazeWalls() {
        final Quad floor = new Quad( "FloorQuad", width * tileSize, length * tileSize );
        floor.setLocalRotation( new Quaternion().fromAngleAxis( FastMath.HALF_PI, Vector3f.UNIT_X.clone() ) );
        attachSpatial( floor );


        for( int wallCounter = 0; wallCounter < 4; ++wallCounter ){
            Quad wall = null;

            switch( wallCounter ){
                case 0:
                case 1:
                    wall = new Quad( "FloorQuad", length * tileSize, tileSize );
                    break;
                case 2:
                case 3:
                    wall = new Quad( "FloorQuad", width * tileSize, tileSize );
                    break;
            }

            switch( wallCounter ){
                case 0:
                    wall.setLocalRotation( new Quaternion().fromAngleAxis( FastMath.HALF_PI, Vector3f.UNIT_Y.clone() ) );
                    wall.setLocalTranslation( -halfWidth, halfHeight, 0 );
                    break;
                case 1:
                    wall.setLocalRotation( new Quaternion().fromAngleAxis( -FastMath.HALF_PI, Vector3f.UNIT_Y.clone() ) );
                    wall.setLocalTranslation( halfWidth, halfHeight, 0 );
                    break;
                case 2:
                    wall.setLocalTranslation( 0, halfHeight, -halfLength );
                    break;
                case 3:
                    wall.setLocalTranslation( 0, halfHeight, halfLength );
                    break;
            }
            attachSpatial( wall );
        }
    }

    private void buildInnerMaze() {
        // Create tileSize cube that with origin at (0,0,0)
        final Box box = new Box( "mazeBox", Vector3f.ZERO.clone(),
                new Vector3f( tileSize, tileSize, tileSize ) );

        // Attach box to node, so we can use it as a shared node
        final Node boxNode = new Node( "mazeBoxNode" );
        boxNode.attachChild( box );

        for( int row = 0; row < length; ++row ){
            for( int col = 0; col < width; ++col ){
                if( mazeData[row][col] ){
                    final SharedNode sharedBoxNode = new SharedNode( "mazeBox_(" + col + ", " + row + ")", boxNode );
                    sharedBoxNode.setLocalTranslation( col * tileSize - halfWidth, 0, row * tileSize - halfLength );
                    attachSpatial( sharedBoxNode );
                }
            }
        }
    }

    private void attachSpatial( final Spatial spatial ) {
        spatial.setModelBound( new BoundingBox() );
        spatial.updateModelBound();

        rootNode.attachChild( spatial );
        rootNode.updateGeometricState( 0, true );
    }
}



(I was bored...)


i thought that it gonna work like PQTorus and sphere in TestCollisionTree...

The sphere never goes 'inside' the torus, that's the point of the physics.  But what if it started inside a REALLY big torus, the physics solver might go nuts trying to get it on the outside... (thats kinda what I wonder if your model maze is doing)

hey!

thank you for code, no, it's not too late:) i'm still trying:)

even now:D

for(int i=0;  i<=19; i++){
            for(int j=0; j<=19; j++){
                           if(matrix[i][j] == 1){

                                 lab.setLocalTranslation(vm1); //vm1=vector3f(a,b,c)
                                 dodajBoxa(lab);
                              
                              //change x
                              a=a+25;
                              
                           }
                                 
            }
            //change z
            c=c+25;   
            
           }


    protected void dodajBoxa(final Spatial spatial){ //part from your code
        spatial.setModelBound( new BoundingBox() );
        spatial.updateModelBound();

        scene.attachChild( spatial );
        scene.updateGeometricState( 0, true );
    }


i have matrix:
int[][]matrix={{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
    {1,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1},
    {1,1,0,1,0,1,1,0,0,0,1,1,1,0,1,0,0,0,0,1},
    {1,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,0,0,0,1},
    {1,0,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,1},
    {1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1},
    {1,0,1,0,1,1,1,0,1,0,1,1,1,1,0,1,1,1,0,1},
    {1,0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,1},
    {1,0,1,1,1,1,1,0,1,0,0,0,0,1,0,1,1,0,1,1},
    {1,0,0,0,1,0,1,0,1,0,0,1,0,0,0,0,1,0,0,1},
    {1,0,1,0,0,0,1,0,0,0,1,1,1,0,1,0,0,0,1,1},
    {1,0,1,1,1,1,0,0,1,0,0,0,0,0,1,0,1,0,0,1},
    {1,0,1,0,0,0,0,0,1,1,1,1,1,0,1,1,1,1,0,1},
    {1,0,0,0,1,0,0,1,1,0,0,0,1,0,0,0,1,0,0,1},
    {1,0,1,1,1,0,1,0,0,0,1,0,1,1,1,0,0,0,1,1},
    {1,0,0,0,0,0,1,0,1,0,1,0,1,0,1,1,1,0,1,1},
    {1,1,1,0,1,0,1,0,1,0,1,0,0,0,1,0,0,0,0,1},
    {1,0,0,0,1,1,0,0,1,0,1,0,1,0,1,0,1,1,0,1},
    {1,0,0,1,1,0,0,1,1,0,0,0,1,0,1,0,0,0,0,1},
    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},};
and i wanted to add box where 1 is.
but it's adding me just first box, not others... i think i need to 'refresh' vm1, but i don't know why
why i tryed like that even when i have your code..? because i was working on it whole day:))
if i wont be able to fix my code, i will use yours if i can:)
thanks, and regards!

PS lab is a Node, model converted from 3ds to jme, just box with texture.

adrenalbooster in your dodajBoxa() or inside your for loop you need to create a new Box to attach to the scene.



i think you always reuse a reference to the same box :slight_smile:

ha!

i used basixs's code, and use pretty big part of it… all good:) i will paste whole project soon, thanks for help!



http://img95.imageshack.us/img95/107/aaawr0.jpg

Glad to help… the tearing between blocks could be solved by creating your own 'box' models with the sides removed and test the surrounding (directly adjacent) four boxes, for each box around it use the box that has the side removed (accumulating the 'removed' sides).  This would take only 5 'box' models: 1 w/ 4 sides, 1 w/ 3 sides, 2 w/ 2 sides (corner and parallel), 1 w/ 1 side and 1 w/ 0 sides.  Then you just rotate the box into the correct position :).



(you could also create those 5 box 'models' w/ logic pretty easily…)