All Downloads are FREE. Search and download functionalities are using the official Maven repository.

one.empty3.testscopy.tests.test4.Balade1 Maven / Gradle / Ivy

Go to download

3D rendering engine. Plus modelling. Expected glsl textures 3d and 2d rendering3D primitives, and a lot of scenes' samples to test.+ Game Jogl reworked, Calculator (numbers and vectors). Java code parser implementation starts (<=1.2)

The newest version!
/*
 *
 *  * Copyright (c) 2024. Manuel Daniel Dahmen
 *  *
 *  *
 *  *    Copyright 2024 Manuel Daniel Dahmen
 *  *
 *  *    Licensed under the Apache License, Version 2.0 (the "License");
 *  *    you may not use this file except in compliance with the License.
 *  *    You may obtain a copy of the License at
 *  *
 *  *        http://www.apache.org/licenses/LICENSE-2.0
 *  *
 *  *    Unless required by applicable law or agreed to in writing, software
 *  *    distributed under the License is distributed on an "AS IS" BASIS,
 *  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  *    See the License for the specific language governing permissions and
 *  *    limitations under the License.
 *
 *
 */

package one.empty3.testscopy.tests.test4;

import one.empty3.library.*;
import one.empty3.library.core.nurbs.CourbeParametriquePolynomialeBezier;
import one.empty3.library.core.nurbs.FctXY;
import one.empty3.library.core.testing.Resolution;
import one.empty3.library.core.testing.TestObjetSub;
import one.empty3.library.core.tribase.Tubulaire3refined;
import javax.imageio.ImageIO;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.Objects;

public class Balade1 extends TestObjetSub {

    private static final int VUE_1 = 30;
    private static final int FPS = 50;
    Tubulaire3refined polygonSol = new Tubulaire3refined();
    ImageTexture imageTextureTrunk;
    private boolean useRecursive;

    public static void main(String[] args) {
        Balade1 balade1 = new Balade1();
        balade1.loop(true);
        balade1.setMaxFrames(VUE_1*FPS);
        balade1.setDimension(new Resolution(1920, 1080));
        //balade1.setDimension(new Resolution(320, 200));
        //balade1.setDimension(new Resolution(640, 480));
        new Thread(balade1).start();
    }

    @Override
    public void ginit() {
        useRecursive = false;
        super.ginit();
        ITexture ciel_ensoleille = new ColorTexture(Color.BLUE);
        ITexture sol_sableux = new ColorTexture(new Color(104, 78, 51));
        try {
            imageTextureTrunk = new ImageTexture(new ECBufferedImage(Objects.requireNonNull(ImageIO.read(new File("resources/img/CIMG0454-modif-cs4.jpg")))));
            ciel_ensoleille = new ImageTexture(new ECBufferedImage(Objects.requireNonNull(ImageIO.read(new File("resources/ciel_ensoleille.jpg")))));
            sol_sableux = new ImageTexture(new ECBufferedImage(Objects.requireNonNull(ImageIO.read(new File("res/img/planets2/others/8k_saturn_ring_alpha.png")))));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        polygonSol = new Tubulaire3refined();
        polygonSol.getSoulCurve().setElem(
                new CourbeParametriquePolynomialeBezier());

        for(int i=0; i<5; i++) {
            polygonSol.getSoulCurve().getElem().getCoefficients().setElem(Point3D.random(10.0), i);
        }
        polygonSol.getDiameterFunction().setElem(new FctXY() {
            @Override
            public double result(double input) {
                return 2.0;
            }
        });
        polygonSol.setIncrU(0.002);
        polygonSol.setIncrV(0.002);


        polygonSol.texture(sol_sableux);

        scene().add(polygonSol);

        frame = 0;
    }

    @Override
    public void finit() throws Exception {
        super.finit();

            setZ(new ZBufferImpl(z.la(), z.ha()));
            z().scene(scene());
        //z().setDisplayType(ZBufferImpl.SURFACE_DISPLAY_LINES);
        z().setDisplayType(ZBufferImpl.SURFACE_DISPLAY_COL_QUADS);
        if (frame() < VUE_1 * FPS) {
            Point3D a = polygonSol.getSoulCurve().getElem().calculerPoint3D((frame() * 1.0) /getMaxFrames());
            Point3D b = polygonSol.getSoulCurve().getElem().calculerPoint3D((frame() + 2.0) /getMaxFrames());

            Point3D y  = polygonSol.calculerPoint3D(0.25, 1.0*frame()/getMaxFrames());
            Point3D ym = polygonSol.calculerPoint3D(0.75, 1.0*frame()/getMaxFrames());


            Camera camera = new Camera(a, b, y.moins(ym).mult(1.0/Point3D.distance(y, ym)));

            camera.getScale().setElem(100.0);
            scene().cameraActive(camera);

            //z().setDisplayType(Representable.DISPLAY_ALL);
            z().texture(new ColorTexture(Color.BLACK));
            StructureMatrix mat = new StructureMatrix<>(2, Point.class);
            mat.setElem(new Point3D(-10d, 0d, -10d), 0, 0);
            mat.setElem(new Point3D(10d, 0d, -10d), 1, 0);
            mat.setElem(new Point3D(10d, 0d, 10d), 1, 1);
            mat.setElem(new Point3D(-10d, 0d, 10d), 0, 1);

            Point3D[] vects = new Point3D[]{mat.getElem(0, 0), mat.getElem(0, 1), mat.getElem(1, 0)};

            StructureMatrix[] v = new StructureMatrix[] {
                    new StructureMatrix(0, Point3D.class),
                    new StructureMatrix(0, Point3D.class),
                    new StructureMatrix(0, Point3D.class)};


            v[0].setElem(vects[0]);
            v[1].setElem(vects[1]);
            v[2].setElem(vects[2]);

            StructureMatrix[] v1 = new StructureMatrix[] {
                    new StructureMatrix(0, Point3D.class),
                    new StructureMatrix(0, Point3D.class),
                    new StructureMatrix(0, Point3D.class)};


            v1[0].setElem(vects[0].plus(Point3D.Y));
            v1[1].setElem(vects[1].plus(Point3D.Y));
            v1[2].setElem(vects[2].plus(Point3D.Y));


        }

    }

    private boolean useRecursive() {
        return useRecursive;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy