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

one.empty3.library.VecHeightMap 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.library;

import one.empty3.feature.QuadTransform2D;
import one.empty3.library.core.nurbs.ParametricSurface;
import one.empty3.library.core.nurbs.Point2Point;
import one.empty3.library.core.nurbs.SurfaceParametriquePolynomialeBezier;
import one.empty3.library1.shader.Vec;

public class VecHeightMap extends ParametricSurface {
    private final StructureMatrix vec = new StructureMatrix<>(1, Vec.class);
    private StructureMatrix surfaceParametriquePolynomialeBezier
            = new StructureMatrix<>(0, SurfaceParametriquePolynomialeBezier.class);
    private StructureMatrix  columnsCount = new StructureMatrix<>(0, Integer.class);
    private StructureMatrix parametricSurface = new StructureMatrix<>(0, ParametricSurface.class);

    public VecHeightMap(ParametricSurface parametricSurface, Vec map, int columnsCount) {
        terminalU.setElem(parametricSurface.getTerminalU().getElem());
        terminalV.setElem(parametricSurface.getTerminalV().getElem());
        this.vec.setElem(map);
        this.columnsCount.setElem(columnsCount);
        this.parametricSurface.setElem(parametricSurface);

        init();

    }

    private void init() {
        Point3D[][] ps = new Point3D[columnsCount.getElem()][vec.getElem().size() / columnsCount.getElem()];
        try {
            for (int i = 0; i < vec.getElem().size(); i++) {
                ps[i % columnsCount.getElem()][i / columnsCount.getElem()] = new Point3D(vec.getElem().get(i), 0.0, 0.0);
            }
            surfaceParametriquePolynomialeBezier.setElem(new SurfaceParametriquePolynomialeBezier(ps));
        } catch (ArrayIndexOutOfBoundsException ex) {
            ex.printStackTrace();
        }

    }

    @Override
    public Point3D calculerPoint3D(double u, double v) {
        int i = (int) (u * columnsCount.getElem())+vec.getElem().size()*2;
        int j = (int) (v * ((vec.getElem().size() / columnsCount.getElem())))+vec.getElem().size()*2;

        i = Math.round(i);
        j = Math.round(j);

        i = i % (columnsCount.getElem());
        j = j % (vec.getElem().size()/columnsCount.getElem());


        if(surfaceParametriquePolynomialeBezier.getElem()!=null) {
            return parametricSurface.getElem().calculerPoint3D(u, v)
                    .plus(parametricSurface.getElem().calculerNormale3D(u, v)
                            .mult(surfaceParametriquePolynomialeBezier.getElem().calculerPoint3D(u, v)));

        } else {
            Double round = getControlAt(i, j);
            if (round != null) {
                return parametricSurface.getElem().calculerPoint3D(u, v)
                        .plus(parametricSurface.getElem().calculerNormale3D(u, v)
                                .mult(round));
            }
            return null;
        }
    }

    public Double getControlAt(int x, int y) {
        Double v = null;
        if(y*columnsCount.getElem()+x=0
                &&x>=0&&y>=0&&x




© 2015 - 2025 Weber Informatics LLC | Privacy Policy