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

one.empty3.testscopy.tests.test3.waterfall_demo.Waterfall_Demo Maven / Gradle / Ivy

There is a newer version: 2024.5.10
Show newest version
/*
 * Copyright (c) 2023. Manuel Daniel Dahmen
 *
 *
 *    Copyright 2012-2023 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.test3.waterfall_demo;

import one.empty3.library.*;
import one.empty3.library.core.nurbs.CourbeParametriquePolynomialeBezier;
import one.empty3.library.core.nurbs.ParametricCurve;
import one.empty3.library.core.testing.TestObjetSub;

import java.util.ArrayList;
import java.util.List;

/*__
 * Created by manue on 02-02-20.
 *
 *
 * Idées : XTRIX
 * 1) Tetris : les courbes bougent but remplir l'écran
 * 2) Des gouttes ou des blocs tombent le long des courbes, remplir des bacs genre casse-brique
 * 3) Niveaux ? Règles de jeux différentes ?
 *
 */
public class Waterfall_Demo extends TestObjetSub {
    public int CURVE_VERTICAL  = 0;
    public int CURVE_RANDOM  = 1;
    public boolean OPTION_CURVE_CUT = true;

    int nCurves = 20;
    int nodeMeanY = 5;
    private StructureMatrix curves = new StructureMatrix<>(1, ParametricCurve.class);
    private StructureMatrix ts = new StructureMatrix<>(1, Double.class);
    private Double vIncrFrame = 0.01;
    private RepresentableConteneur blocks = new RepresentableConteneur();
    private int curve_shape = 0;
    private boolean option_curve_cut;
    private int nPointsMax = 20;

    public void ginit() {
        int[] height = new int[10];
        for (int curveN = 0; curveN < nCurves; curveN++) {

            List pointsCurveN = new ArrayList();

            pointsCurveN.add(new Point3D(0.,0.,0.));

            pStart(pointsCurveN.get(0));

            int pointN = 1;

            boolean TRUE = true;


            Point3D pointNcandidate = (Point3D) pointsCurveN.get(0).clone();

            while (candidate(pointNcandidate, pointsCurveN, pointN)) {
                    // TODO MAKE IT WORK pointsCurveN.add((Point3D) pointNcandidate.copy());
                pointsCurveN.add(pointNcandidate);
                pointNcandidate = (Point3D) pointNcandidate.clone();
                pointN++;
            }

            //pointsCurveN.add(new Point3D(0., (double) getDimension().y(), 0.));

            Point3D[] c = new Point3D[pointN];

            curves.setElem(new CourbeParametriquePolynomialeBezier(pointsCurveN.toArray(c)), curveN);


            int mlc = 10;
            blocks.add(new Cube(mlc, Point3D.O0));


            ts.setElem(0., curveN);
        }

        curves.data1d.forEach(parametricCurve -> scene().add(parametricCurve));
        scene().add(blocks);

        scene().cameraActive().setEye(new Point3D(0., 0., -Math.max((double) getDimension().x(), (double) getDimension().y()) * 2));
    }

    public void finit() {
        for(int i=0; i1.)
                ts.setElem(0., i);
        }
        for(int i=0; i pointsCurveN, int pointN)
    {
        if(pointsCurveN.size()>=nPointsMax)
            return false;
        Point3D pNext = null;
        switch (curve_shape)
        {
            case 1:

                pNext = pointsCurveN.get(pointN - 1).plus(new Point3D((Math.random() - 0.5) * getDimension().x() / nCurves,
                        (Math.random() - 0.5) * getDimension().y() / nodeMeanY, 0.));
                if(option_curve_cut== OPTION_CURVE_CUT &&!(pNext.getX() >= -this.getDimension().x() && pNext.getX() < this.getDimension().x()&&
                        (pNext.getY() >= -this.getDimension().y() && pNext.getY() < this.getDimension().y())))
                    return false;
                while(!(pNext.getX() >= -this.getDimension().x() && pNext.getX() < this.getDimension().x()&&
                        (pNext.getY() >= -this.getDimension().y() && pNext.getY() < this.getDimension().y())))
                    pNext = pointsCurveN.get(pointN - 1).plus(new Point3D((Math.random() - 0.5) * getDimension().x() / nCurves,
                            (Math.random() - 0.5) * getDimension().y() / nodeMeanY, 0.));
                break;
            case 0:
                pNext = pointsCurveN.get(pointN - 1).plus(new Point3D((Math.random() - 0.5) * getDimension().x() / nCurves,
                        Math.random() * getDimension().y() / nodeMeanY, 0.));
                if(option_curve_cut== OPTION_CURVE_CUT) {
                    if(!(pNext.getX() >= -this.getDimension().x() && pNext.getX() < this.getDimension().x()&&
                        (pNext.getY() >= -this.getDimension().y() && pNext.getY() < this.getDimension().y())))
                            return false;
                }
                if(p.getY()>=getDimension().y())
                    pNext = new Point3D(pointsCurveN.get(pointN - 1).getX(),
                            (double)getDimension().y(), 0.);
                else
                    pNext = pointsCurveN.get(pointN - 1).plus(new Point3D((Math.random() - 0.5) * getDimension().x() / nCurves,
                        Math.random() * getDimension().y() / nodeMeanY, 0.));


                break;
            default:
                break;
        }
        if(pNext==null)
            return false;
        p.changeTo(pNext);
        if(p.getCoordArr().data1d.size()!=3)
            throw new IndexOutOfBoundsException("pNext coordArr size != 3");
        return true;
    }
    public void pStart(Point3D p)
    {
        Point3D pNext;
        switch (curve_shape)
        {
            case 1:
                pNext = new Point3D((Math.random() - 0.5) * getDimension().x(),
                        (Math.random() - 0.5) * getDimension().y(), 0.);
                break;
            case 0:
                pNext = new Point3D(
                        (Math.random() - 0.5) * getDimension().x() * 2,
                        -0. + -getDimension().y(), 0.);
                break;
            default:
                pNext = new Point3D();
                break;
        }
        p.changeTo(pNext);
    }

    public int getCurve_shape() {
        return curve_shape;
    }

    public void setCurve_shape(int curve_shape) {
        this.curve_shape = curve_shape;
    }

    public boolean isOption_curve_cut() {
        return option_curve_cut;
    }

    public void setOption_curve_cut(boolean option_curve_cut) {
        this.option_curve_cut = option_curve_cut;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy