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

one.empty3.library.Rotation 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 java.util.HashMap;

/*__
 * Created by Win on 26-01-16.
 */
public class Rotation implements MatrixPropertiesObject {
    protected StructureMatrix rot;
    protected StructureMatrix centreRot;
    protected boolean unmodified = true;

    public Rotation(Point3D vU, Point3D position, double a) {
        rot = new StructureMatrix<>(0, Matrix33.class);
        centreRot = new StructureMatrix<>(0, Point3D.class);
        this.rot.setElem(Matrix33.I);
        this.centreRot.setElem(Point3D.O0);
    }

    public Rotation(Matrix33 rot, Point3D centreRot) {
        if (rot == null)
            rot = Matrix33.I;
        if (centreRot == null)
            centreRot = Point3D.O0;
       /* if(this.rot==null||this.rot.getElem()==null)
            this.rot = rot1;
        if(this.centreRot==null||this.centreRot.getElem()==null)
            this.centreRot = centreRot1;
            */
        this.rot.setElem(rot);
        this.centreRot.setElem(centreRot);
    }

    public boolean isUnmodified() {
        return unmodified;
    }

    public void setUnmodified(boolean unmodified) {
        this.unmodified = unmodified;
    }

    public Point3D rotation(Point3D p) {
        if (p != null && centreRot != null && rot != null) {
            try {
                return centreRot.getElem().plus(rot.getElem().mult(p.moins(centreRot.getElem())));
            } catch (NullPointerException ex) {
                ex.printStackTrace();
            }
        }
        return p;
    }

    public Point3D rotate(Point3D p) {
        if (p != null && centreRot != null && rot != null) {
            try {
                return centreRot.getElem().plus(rot.getElem().mult(p.moins(centreRot.getElem())));
            } catch (NullPointerException ex) {
                ex.printStackTrace();
            }
        }
        return p;
    }

    public Point3D rotationAxe(Point3D p, int axe, double angle) {

        return Matrix33.rotationX(angle).mult(p);
    }

    public StructureMatrix getRot() {
        return rot;
    }

    public void setRot(StructureMatrix rot) {
        this.rot = rot;
    }

    public StructureMatrix getCentreRot() {
        return centreRot;
    }

    public void setCentreRot(StructureMatrix centreRot) {
        this.centreRot = centreRot;
    }

    private HashMap declaredDataStructures = new HashMap<>();

    @Override
    public StructureMatrix getDeclaredProperty(String name) {
        return declaredDataStructures.get(name);
    }

    @Override
    public void declareProperties() {
        declaredDataStructures.put("rot/Matrice de rotation 3x3", getRot());
        declaredDataStructures.put("centreRot/Centre de rotation", getCentreRot());
    }

    @Override
    public HashMap declarations() {
        declareProperties();
        return declaredDataStructures;
    }

    @Override
    public MatrixPropertiesObject copy() throws CopyRepresentableError, IllegalAccessException, InstantiationException {
        return new Rotation((Matrix33) getRot().copy().getElem(), (Point3D) (getCentreRot().copy().getElem()));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy