Package net.anzix.fsz.voxelworld.features

Source Code of net.anzix.fsz.voxelworld.features.Box

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package net.anzix.fsz.voxelworld.features;

import com.ardor3d.math.Vector3;
import com.ardor3d.math.type.ReadOnlyVector3;
import net.anzix.fsz.voxelworld.BasicFeature;
import net.anzix.fsz.voxelworld.DetailLevel;
import net.anzix.fsz.voxelworld.FszMatrix4;
import net.anzix.fsz.voxelworld.layers.LayerBlock;

/**
*
* @author kovacsandras
*/
public class Box extends BasicFeature{

    public Box( FszMatrix4 position, double sizeX, double sizeY, double sizeZ) {
        this.halfSizeX = sizeX / 2.0;
        this.halfSizeY = sizeY / 2.0;
        this.halfSizeZ = sizeZ / 2.0;
        this.transform = new FszMatrix4();
        position.invert(transform);
    }

    private double halfSizeX;
    private double halfSizeY;
    private double halfSizeZ;
   
    private final FszMatrix4 transform;
 
    public float getDensity(final ReadOnlyVector3 p, LayerBlock layerBlock, int x, int y, int z, DetailLevel level ) {

        Vector3 pp = transform.applyPost(p, null);
       
        double fx = Math.abs(pp.getX() / halfSizeX);
        double fy = Math.abs(pp.getY() / halfSizeY);
        double fz = Math.abs(pp.getZ() / halfSizeZ);
       
        double f = fx > fy ? ( fx > fz ? 1.0 - fx : 1.0 - fz )
                           : ( fy > fz ? 1.0 - fy : 1.0 - fz );
       
        return (float)f;
    }
}
TOP

Related Classes of net.anzix.fsz.voxelworld.features.Box

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.