Search in sources :

Example 1 with Box

use of javafx.scene.shape.Box in project Labyrinthe3d by FauconFan.

the class Init method makeWalls.

/**
 * Dessine les murs du Maze
 * @return Le groupe contenant les murs
 */
public static Group makeWalls(Scale sc, MainMaze maze) {
    Material mat;
    try {
        String texturePath = maze.getContentMazeCurrentLevel().getTexturePath();
        if (texturePath == null) {
            // Default
            texturePath = "assets/Brick_wall_002_COLOR.jpg";
        }
        Image img = new Image(new FileInputStream(texturePath), 400, 400, true, false);
        mat = new PhongMaterial(Color.WHITE, img, null, null, null);
    } catch (Exception e) {
        mat = new PhongMaterial(Color.GREEN);
    }
    Group walls = new Group();
    // On scale les murs
    walls.getTransforms().add(sc);
    final float delta = 0.001f;
    ContentMaze[] cms = maze.getContentMaze();
    for (int i = 0; i < cms.length; i++) {
        for (LineWall l : cms[i].getLineWalls()) {
            LineWall[] broken = LineWall.breakWallsIntoSimpleOnes(l);
            for (int j = 0; j < broken.length; j++) {
                Box w = new Box();
                Consumer<Float> setEpais;
                Consumer<Float> setLarg;
                float largeur;
                double trX;
                double trZ;
                float isStart = (j == 0) ? broken[j].getEpaisseur() / 2 - delta : 0;
                float isEnd = (j == broken.length - 1) ? broken[j].getEpaisseur() / 2 - delta : 0;
                if (// Mur "vertical" dans le plan
                !broken[j].isHorizontal()) {
                    largeur = broken[j].getY2() - broken[j].getY1();
                    setLarg = w::setDepth;
                    setEpais = w::setWidth;
                    trX = broken[j].getX1();
                    trZ = broken[j].getY1() + largeur / 2.0;
                } else // Mur horizontal
                {
                    largeur = broken[j].getX2() - broken[j].getX1();
                    setLarg = w::setWidth;
                    setEpais = w::setDepth;
                    trX = broken[j].getX1() + largeur / 2.0;
                    trZ = broken[j].getY1();
                }
                w.setHeight(1);
                setEpais.accept(broken[j].getEpaisseur());
                setLarg.accept(largeur + isStart + isEnd);
                w.setTranslateX(trX);
                w.setTranslateZ(trZ);
                w.setTranslateY(-i - 0.5);
                w.setMaterial(mat);
                walls.getChildren().add(w);
            }
        }
    }
    return (walls);
}
Also used : Group(javafx.scene.Group) Material(javafx.scene.paint.Material) PhongMaterial(javafx.scene.paint.PhongMaterial) LineWall(src.model.board.LineWall) Box(javafx.scene.shape.Box) Image(javafx.scene.image.Image) ContentMaze(src.model.ContentMaze) FileInputStream(java.io.FileInputStream) View(src.view.View) PhongMaterial(javafx.scene.paint.PhongMaterial)

Example 2 with Box

use of javafx.scene.shape.Box in project Labyrinthe3d by FauconFan.

the class Init method makeSpecialCases.

// Une camera avec les bons attributs pour la déplacer, et une lumière associée
public static Group makeSpecialCases(Scale sc, MainMaze maze) {
    Group spc = new Group();
    ContentMaze[] cms = maze.getContentMaze();
    for (int i = 0; i < cms.length; i++) {
        for (Case ec : cms[i].getSpecialCases()) {
            final float tailleCase = 1f;
            final Box res = new Box(tailleCase, 0.025f, tailleCase);
            switch(ec.type) {
                case MESSAGE:
                    Text message = new Text("Welcome");
                    message.setTranslateX(ec.getX());
                    message.setTranslateZ(ec.getY());
                    // message.setTextFill(Color.web("#0076a3"));
                    message.setFont(new Font("Arial", 8));
                    spc.getChildren().add(message);
                    break;
                default:
                    res.setTranslateZ(ec.getY() + tailleCase / 2.0);
                    res.setTranslateX(ec.getX() + tailleCase / 2.0);
                    res.setTranslateY(-i - 0.025);
                    res.setMaterial(new PhongMaterial(CaseColor.getColor(ec.type)));
                    spc.getChildren().add(res);
                    break;
            }
        }
    }
    spc.getTransforms().add(sc);
    return (spc);
}
Also used : Group(javafx.scene.Group) Box(javafx.scene.shape.Box) Text(javafx.scene.text.Text) ContentMaze(src.model.ContentMaze) PhongMaterial(javafx.scene.paint.PhongMaterial) Font(javafx.scene.text.Font) Case(src.model.board.Case)

Example 3 with Box

use of javafx.scene.shape.Box in project Labyrinthe3d by FauconFan.

the class Init method makeFloors.

/**
 * Dessine le sol
 * @return Un groupe contenant le sol
 */
public static Group makeFloors(Scale sc, MainMaze maze) {
    final Group floors = new Group();
    floors.getTransforms().add(sc);
    ContentMaze[] cms = maze.getContentMaze();
    for (int i = 0; i < cms.length; i++) {
        for (MazeDimension.RectInMaze md : cms[i].getMazeDimension().list_rectmaze) {
            final int w = md.x2 - md.x1;
            final int h = md.y2 - md.y1;
            Box f = new Box(w, 0.05, h);
            f.setTranslateX(md.x1 + w / 2.0);
            f.setTranslateZ(md.y1 + h / 2.0);
            f.setMaterial(new PhongMaterial(Color.color(0.15, 0.15, 0.15)));
            f.setTranslateY(-i);
            floors.getChildren().add(f);
        }
    }
    return (floors);
}
Also used : Group(javafx.scene.Group) Box(javafx.scene.shape.Box) MazeDimension(src.model.MazeDimension) ContentMaze(src.model.ContentMaze) PhongMaterial(javafx.scene.paint.PhongMaterial)

Example 4 with Box

use of javafx.scene.shape.Box in project narchy by automenta.

the class ThreeDView method buildAxes.

private void buildAxes() {
    final PhongMaterial redMaterial = new PhongMaterial();
    redMaterial.setDiffuseColor(Color.DARKRED);
    redMaterial.setSpecularColor(Color.RED);
    final PhongMaterial greenMaterial = new PhongMaterial();
    greenMaterial.setDiffuseColor(Color.DARKGREEN);
    greenMaterial.setSpecularColor(Color.GREEN);
    final PhongMaterial blueMaterial = new PhongMaterial();
    blueMaterial.setDiffuseColor(Color.DARKBLUE);
    blueMaterial.setSpecularColor(Color.BLUE);
    final Box xAxis = new Box(240.0, 1, 1);
    final Box yAxis = new Box(1, 240.0, 1);
    final Box zAxis = new Box(1, 1, 240.0);
    xAxis.setMaterial(redMaterial);
    yAxis.setMaterial(greenMaterial);
    zAxis.setMaterial(blueMaterial);
    axisGroup.getChildren().addAll(xAxis, yAxis, zAxis);
    world.getChildren().addAll(axisGroup);
}
Also used : Box(javafx.scene.shape.Box) PhongMaterial(javafx.scene.paint.PhongMaterial)

Example 5 with Box

use of javafx.scene.shape.Box in project Gargoyle by callakrsos.

the class Drag3DObject method start.

/*
	 *   
	 Add to Root ->-> Run ->-> Enjoy! 
	 
	 Depends how you want to move your object, but assuming this : 
	
	 when the mouse moves up or down, the object moves vertically parallel to the screen. 
	
	 when the mouse moves left or right, the object moves horizontally parallel to the screen. 
	
	 To do this, you only need a couple of informations. 
	
	 1. Relative displacement of the mouse. 
	 2. The Up and Right axis of the view. 
	
	 When you got that, if your mouse as some horizontal movement you do : 
	
	 objPos += mouseMovementx*scale*RightAxis 
	
	 scale maps the screen mouse coordinates to your software display units. 
	
	 Simply replace mouseMovementX by mouseMovementY and RightAxis by UpAxis to get vertical motion. 
	 
	 
	 scale could simply be the ratio of viewvolume dimension over the screen dimension. This has some problem if you are using a perspective projection, because if your object is far away the ratio will be incorrect because the dimension are bigger and the object won't stay under the mouse. But it work correctly for an ortho projection. 
	
	 Some concrete numbers. Say you are using an ortho project with with following values : 
	
	 left = -100, right = 100, top = 100, bottom = -100, near and far do not matter. The view volume dimension will always be : 
	
	 horizontally abs( left - right ) = 200 in our case 
	 vertically abs( top - bottom ) = 200 in our case 
	
	 And your screen dimension are 1024 X 768. So our movement scale is horizontally = 200 / 1024 and 200/768. 
	
	 Great, now if your mouse moves 300 units to the left and 100 units up. 
	 
	 objPos += ( cameraRightAxis*300*200/1024 ) + ( cameraUpAxis*100*200/1024 ) 
	 
	 That is for an ortho projection.  
	 
	 For a perspective projection, we need to adjust the scale depending on the distance of the object to the near plane. I won't put any number, it should become obvious now. 
	 ViewFrustum = ( left, right, bottom, top, znear, zfar ) 
	 
	 XScale = abs( left - right ) / XScreenDimension * ( distance( object, camera )  / znear ) 
	 YScale = abs( top - bottom ) / YScreenDimension * ( distance( object, camera )  / znear ) 
	 */
@Override
public void start(Stage stage) {
    Box floor = new Box(1000, 10, 1000);
    floor.setTranslateY(150);
    root.getChildren().add(floor);
    Sphere s = new Sphere(150);
    s.setTranslateX(5);
    s.setPickOnBounds(true);
    root.getChildren().add(s);
    showStage(stage);
}
Also used : Sphere(javafx.scene.shape.Sphere) Box(javafx.scene.shape.Box)

Aggregations

Box (javafx.scene.shape.Box)8 PhongMaterial (javafx.scene.paint.PhongMaterial)6 Group (javafx.scene.Group)5 Sphere (javafx.scene.shape.Sphere)4 ContentMaze (src.model.ContentMaze)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Bounds (javafx.geometry.Bounds)2 PerspectiveCamera (javafx.scene.PerspectiveCamera)2 PointLight (javafx.scene.PointLight)2 Scene (javafx.scene.Scene)2 KeyCode (javafx.scene.input.KeyCode)2 MouseEvent (javafx.scene.input.MouseEvent)2 Cylinder (javafx.scene.shape.Cylinder)2 Rotate (javafx.scene.transform.Rotate)2 Translate (javafx.scene.transform.Translate)2 Axes (org.fxyz.utils.Axes)2 FileInputStream (java.io.FileInputStream)1 Point3D (javafx.geometry.Point3D)1 AmbientLight (javafx.scene.AmbientLight)1 Image (javafx.scene.image.Image)1