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

one.empty3.library1.shader.Vec 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.library1.shader;

import java.util.Objects;

import one.empty3.library.Point3D;
import one.empty3.library.StructureMatrix;
import org.jetbrains.annotations.NotNull;

public class Vec {
    private int dims;
    private final StructureMatrix vecVal
            = new StructureMatrix<>(1, Double.class);

    private final StructureMatrix vec
            = new StructureMatrix<>(1, Vec.class);

    public Vec(Point3D p) {
        for (int i = 0; i < 3; i++) {

            vecVal.add(p.get(i));
        }
    }

    public Vec(Double d) {
        vecVal.getData1d().add(d);
    }

    public Vec(int d) {
        for (int i = 0; i < d; d++)
            vecVal.getData1d().add(0.0);
    }

    public Vec(Double... comps) {
        for (Double d : comps) {
            vecVal.add(1, d);
        }
    }
    public Vec(double[] comps) {
        for (Double d : comps) {
            vecVal.add(1, d);
        }
    }

    public Vec(Vec... comps) {
        for (Vec comp : comps) {
            vec.add(comp);

            for (int j = 0; j < comp.size(); j++) {

                vecVal.add(1, comp.get(j));
            }

        }
    }

    public double get(int i) {
        return vecVal.getElem(i);
    }


    public int getDims() {
        int dims = 0;
        if (!vecVal.getData1d().isEmpty()) {
            dims += vecVal.getData1d().size();
        }
        return dims;


    }

    @NotNull
    public String toString() {
        StringBuilder s = new StringBuilder("vec (" + getDims() + ") " +
                "(");
        if (!vecVal.getData1d().isEmpty())
            for (int i = 0; i < vecVal.getData1d().size();
                 i++)
                s.append(vecVal.
                        getElem(i)).append(", ");
        else
            for (int i = 0; i < vec.getData1d().size();
                 i++)
                s.append(vec.
                        getElem(i).toString()).append(", ");
        s.append(")");
        return s.toString();
    }

    public double norme() {
        double d = 0.0;
        for (int i = 0; i < vecVal.getData1d().size(); i++)
            d += vecVal.getData1d().get(i) * vecVal.getData1d().get(i);
        return Math.sqrt(d);
    }

    /*
       public Double value(int i, int j) {
            if(i>=0 && i0) {
            da = new Double[getDims() ];
            int i = 0;
            for(i=0;i getVecVal() {
        return vecVal;
    }

    public StructureMatrix getVec() {
        return vec;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy