Package net.anzix.fsz.voxelworld

Source Code of net.anzix.fsz.voxelworld.BasicFeature

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

package net.anzix.fsz.voxelworld;

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

/**
*
* @author kovacsandras
*/

public abstract class BasicFeature extends Feature {
     public abstract float getDensity(final ReadOnlyVector3 p, LayerBlock layerBlock, int x, int y, int z, DetailLevel level) ;

     public void applyDensities(ReadOnlyVector3 basePosition, float densities[][][], Feature densitySources[][][], DetailLevel level, LayerBlock layerBlock) {

        int minX, minY, minZ, maxX, maxY, maxZ;

        double scale = level.getScale();
        int blockSize = VoxelWorld.BLOCK_SIZE;

        if (hasBoundingBox()) {
            Vector3 lower = getLowerBound();
            lower.subtractLocal(basePosition);
            Vector3 upper = getUpperBound();
            upper.subtractLocal(basePosition);
            minX = Math.max(0,(int)Math.floor(lower.getX() / scale));
            minY = Math.max(0,(int)Math.floor(lower.getY() / scale));
            minZ = Math.max(0,(int)Math.floor(lower.getZ() / scale));
            maxX = Math.min(blockSize+1,(int)Math.ceil(upper.getX() / scale));
            maxY = Math.min(blockSize+1,(int)Math.ceil(upper.getY() / scale));
            maxZ = Math.min(blockSize+1,(int)Math.ceil(upper.getZ() / scale));
        } else {
            minX = 0;
            minY = 0;
            minZ = 0;
            maxX = blockSize+1;
            maxY = blockSize+1;
            maxZ = blockSize+1;
        }


        Vector3 localPos = new Vector3();

        for (int x =minX; x <= maxX; x++) {
            for (int y = minY; y <= maxY; y++) {
                for (int z = minZ; z <= maxZ; z++) {
                    localPos.set(x*scale,y*scale,z*scale);
                    localPos.addLocal(basePosition);
                    float newDensity = getDensity(localPos, layerBlock, x,y,z,level);
                    if (newDensity >= densities[x][y][z]) {
                        densities[x][y][z] = newDensity;
                        densitySources[x][y][z] = this;
                    }
                }
            }
        }
    }
}
TOP

Related Classes of net.anzix.fsz.voxelworld.BasicFeature

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.