Package com.ardor3d.math

Examples of com.ardor3d.math.Vector3


        // So apply transform
        final double x = _awtBounds.getX(), y = _awtBounds.getY(), width = _awtBounds.getZ(), height = _awtBounds
                .getW();
        final Vector3[] vects = new Vector3[] { //
        //
                new Vector3(x, y, 0), //
                new Vector3(x + width, y, 0), //
                new Vector3(x + width, y + height, 0), //
                new Vector3(x, y + height, 0) //
        };

        // update final bounds info.
        double minX, minY, maxX, maxY;
        minX = minY = Double.POSITIVE_INFINITY;
View Full Code Here


        this.size = size;
    }

    @Override
    public TerrainConfiguration getConfiguration() throws Exception {
        return new TerrainConfiguration(availableClipmapLevels, tileSize, new Vector3(1, 1, 1), 0.0f, 1.0f, true);
    }
View Full Code Here

        }
        Collections.reverse(cacheList);

        final Terrain terrain = new Terrain(camera, cacheList, clipmapTerrainSize, terrainConfiguration);

        terrain.makePickable(BresenhamYUpGridTracer.class, MAX_PICK_CHECKS, new Vector3(1, 0, 1));

        logger.info("client clipmapLevels: " + cacheList.size());

        if (showDebugPanels) {
            final TerrainGridCachePanel panel = new TerrainGridCachePanel(cacheList, cacheSize);
View Full Code Here

        final int tileX = tile.getX();
        final int tileY = tile.getY();

        final int baseClipmapLevel = availableClipmapLevels - clipmapLevel - 1;

        final Vector3 normal = new Vector3();
        textureLock.lock();
        try {
            for (int y = 0; y < tileSize; y++) {
                for (int x = 0; x < tileSize; x++) {
                    if (Thread.interrupted()) {
                        return null;
                    }

                    final int heightX = tileX * tileSize + x;
                    final int heightY = tileY * tileSize + y;

                    normal.setZ(1);
                    final double eval1 = function.eval(heightX - 1 << baseClipmapLevel, heightY << baseClipmapLevel, 0);
                    final double eval2 = function.eval(heightX + 1 << baseClipmapLevel, heightY << baseClipmapLevel, 0);
                    final double eval3 = function.eval(heightX << baseClipmapLevel, heightY - 1 << baseClipmapLevel, 0);
                    final double eval4 = function.eval(heightX << baseClipmapLevel, heightY + 1 << baseClipmapLevel, 0);

                    normal.setX((eval1 - eval2) / 2.);
                    normal.setY((eval3 - eval4) / 2.);
                    normal.normalizeLocal();

                    final int index = (x + y * tileSize) * 3;
                    data.put(index, (byte) (normal.getX() * 255));
                    data.put(index + 1, (byte) (normal.getY() * 255));
                    data.put(index + 2, (byte) (normal.getZ() * 255));
                }
            }
        } finally {
            textureLock.unlock();
        }
View Full Code Here

        _clipmapLevels = levels;
        _tracers = Lists.newArrayList();
        for (int i = 0, max = levels.size(); i < max; i++) {
            final AbstractBresenhamTracer tracer = tracerClass.newInstance();
            final int space = 1 << i;
            final Vector3 vec = new Vector3(initialSpacing).multiplyLocal(space);
            if (vec.getX() == 0) {
                vec.setX(1);
            }
            if (vec.getY() == 0) {
                vec.setY(1);
            }
            if (vec.getZ() == 0) {
                vec.setZ(1);
            }
            tracer.setGridSpacing(vec);
            _tracers.add(tracer);
        }
        _maxChecks = maxChecks;
View Full Code Here

        ClipmapLevel level = _clipmapLevels.get(index);

        // start our tracer
        tracer.startWalk(_workRay);

        final Vector3 intersection = store != null ? store : new Vector3();

        if (tracer.isRayPerpendicularToGrid()) {
            // XXX: "HACK" for perpendicular ray
            level.getCache().getEyeCoords(tileStore, tracer.getGridLocation()[0], tracer.getGridLocation()[1],
                    _workEyePos);
            final float scaledClipSideSize = level.getClipSideSize() * level.getVertexDistance() * 0.5f;

            final float h1 = getWeightedHeight(tileStore[0], tileStore[1], tileStore[2], tileStore[3],
                    scaledClipSideSize);
            final float h2 = getWeightedHeight(tileStore[4], tileStore[5], tileStore[6], tileStore[7],
                    scaledClipSideSize);
            final float h3 = getWeightedHeight(tileStore[8], tileStore[9], tileStore[10], tileStore[11],
                    scaledClipSideSize);
            final float h4 = getWeightedHeight(tileStore[12], tileStore[13], tileStore[14], tileStore[15],
                    scaledClipSideSize);

            final double x = _workEyePos.getX();
            final double z = _workEyePos.getZ();
            final double intOnX = x - Math.floor(x), intOnZ = z - Math.floor(z);
            final double height = MathUtils
                    .lerp(intOnZ, MathUtils.lerp(intOnX, h1, h2), MathUtils.lerp(intOnX, h3, h4));

            intersection.set(x, height, z);
            terrainWorldTransform.applyForward(intersection, intersection);
            return intersection;
        }

        // walk our way along the ray, asking for intersections along the way
        int iter = 0;
        while (iter < _maxChecks) {

            // check the triangles of main square for intersection.
            if (checkTriangles(tracer.getGridLocation()[0], tracer.getGridLocation()[1], intersection, normalStore,
                    tracer, level, _workEyePos)) {
                // we found an intersection, so return that!
                terrainWorldTransform.applyForward(intersection, intersection);
                terrainWorldTransform.applyForward(normalStore, normalStore);
                return intersection;
            }

            // because of how we get our height coords, we will
            // sometimes be off be a grid spot, so we check the next
            // grid space up.
            int dx = 0, dy = 0;
            final Direction d = tracer.getLastStepDirection();
            switch (d) {
                case PositiveX:
                case NegativeX:
                    dx = 0;
                    dy = 1;
                    break;
                case PositiveZ:
                case NegativeZ:
                    dx = 1;
                    dy = 0;
                    break;
            }

            if (checkTriangles(tracer.getGridLocation()[0] + dx, tracer.getGridLocation()[1] + dy, intersection,
                    normalStore, tracer, level, _workEyePos)) {
                // we found an intersection, so return that!
                terrainWorldTransform.applyForward(intersection, intersection);
                terrainWorldTransform.applyForward(normalStore, normalStore);
                return intersection;
            }

            final double dist = tracer.getTotalTraveled();
            // look at where we are and switch to the next cliplevel if needed
            final Vector3 loc = new Vector3(_workRay.getDirection()).multiplyLocal(dist).addLocal(_workRay.getOrigin());
            final int newIndex = findClipIndex(loc.subtract(_workEyePos, null));
            // simple test to see if our next level at least has SOME data. XXX: could look to the tile level.
            if (newIndex != index && _clipmapLevels.get(index).isReady()) {
                _workRay.setOrigin(loc);
                index = newIndex;
                tracer = _tracers.get(index);
View Full Code Here

        if (!_workRay.intersectsTriangle(_gridTriA.getA(), _gridTriA.getB(), _gridTriA.getC(), store)) {
            final boolean intersects = _workRay.intersectsTriangle(_gridTriB.getA(), _gridTriB.getB(),
                    _gridTriB.getC(), store);
            if (intersects && normalStore != null) {
                final Vector3 edge1 = Vector3.fetchTempInstance().set(_gridTriB.getB()).subtractLocal(_gridTriB.getA());
                final Vector3 edge2 = Vector3.fetchTempInstance().set(_gridTriB.getC()).subtractLocal(_gridTriB.getA());
                normalStore.set(edge1).crossLocal(edge2).normalizeLocal();
            }
            return intersects;
        } else {
            if (normalStore != null) {
                final Vector3 edge1 = Vector3.fetchTempInstance().set(_gridTriA.getB()).subtractLocal(_gridTriA.getA());
                final Vector3 edge2 = Vector3.fetchTempInstance().set(_gridTriA.getC()).subtractLocal(_gridTriA.getA());
                normalStore.set(edge1).crossLocal(edge2).normalizeLocal();
            }

            return true;
        }
View Full Code Here

        final float h2 = getWeightedHeight(tileStore[4], tileStore[5], tileStore[6], tileStore[7], scaledClipSideSize);
        final float h3 = getWeightedHeight(tileStore[8], tileStore[9], tileStore[10], tileStore[11], scaledClipSideSize);
        final float h4 = getWeightedHeight(tileStore[12], tileStore[13], tileStore[14], tileStore[15],
                scaledClipSideSize);

        final Vector3 scaleVec = Vector3.fetchTempInstance();
        final Vector3 workVec = Vector3.fetchTempInstance();

        scaleVec.set(tracer.getGridSpacing());

        // First triangle (h1, h3, h2)
        tracer.get3DPoint(gridX, gridY, h1, workVec);
        workVec.multiplyLocal(scaleVec).addLocal(tracer.getGridOrigin());
        _gridTriA.setA(workVec);

        tracer.get3DPoint(gridX, gridY + 1, h3, workVec);
        workVec.multiplyLocal(scaleVec).addLocal(tracer.getGridOrigin());
        _gridTriA.setB(workVec);

        tracer.get3DPoint(gridX + 1, gridY, h2, workVec);
        workVec.multiplyLocal(scaleVec).addLocal(tracer.getGridOrigin());
        _gridTriA.setC(workVec);

        // Second triangle (h2, h3, h4)
        _gridTriB.setA(_gridTriA.getC());
        _gridTriB.setB(_gridTriA.getB());

        tracer.get3DPoint(gridX + 1, gridY + 1, h4, workVec);
        workVec.multiplyLocal(scaleVec).addLocal(tracer.getGridOrigin());
        _gridTriB.setC(workVec);

        Vector3.releaseTempInstance(scaleVec);
        Vector3.releaseTempInstance(workVec);
View Full Code Here

        // simplify access to direction
        final ReadOnlyVector3 direction = _walkRay.getDirection();

        // Move start point to grid space
        final Vector3 start = _walkRay.getOrigin().subtract(_gridOrigin, null);

        _gridLocation[0] = (int) MathUtils.floor(start.getX() / _gridSpacing.getX());
        _gridLocation[1] = (int) MathUtils.floor(start.getY() / _gridSpacing.getY());

        final double invDirX = 1.0 / direction.getX();
        final double invDirY = 1.0 / direction.getY();

        // Check which direction on the X world axis we are moving.
        if (direction.getX() > BresenhamZUpGridTracer.TOLERANCE) {
            _distToNextXIntersection = ((_gridLocation[0] + 1) * _gridSpacing.getX() - start.getX()) * invDirX;
            _distBetweenXIntersections = _gridSpacing.getX() * invDirX;
            _stepXDirection = 1;
        } else if (direction.getX() < -BresenhamZUpGridTracer.TOLERANCE) {
            _distToNextXIntersection = (start.getX() - _gridLocation[0] * _gridSpacing.getX()) * -direction.getX();
            _distBetweenXIntersections = -_gridSpacing.getX() * invDirX;
            _stepXDirection = -1;
        } else {
            _distToNextXIntersection = Double.MAX_VALUE;
            _distBetweenXIntersections = Double.MAX_VALUE;
            _stepXDirection = 0;
        }

        // Check which direction on the Y world axis we are moving.
        if (direction.getY() > BresenhamZUpGridTracer.TOLERANCE) {
            _distToNextYIntersection = ((_gridLocation[1] + 1) * _gridSpacing.getY() - start.getY()) * invDirY;
            _distBetweenYIntersections = _gridSpacing.getY() * invDirY;
            _stepYDirection = 1;
        } else if (direction.getY() < -BresenhamZUpGridTracer.TOLERANCE) {
            _distToNextYIntersection = (start.getY() - _gridLocation[1] * _gridSpacing.getY()) * -direction.getY();
            _distBetweenYIntersections = -_gridSpacing.getY() * invDirY;
            _stepYDirection = -1;
        } else {
            _distToNextYIntersection = Double.MAX_VALUE;
            _distBetweenYIntersections = Double.MAX_VALUE;
View Full Code Here

        return _stepXDirection == 0 && _stepYDirection == 0;
    }

    @Override
    public Vector3 get3DPoint(final double gridX, final double gridY, final double height, final Vector3 store) {
        final Vector3 rVal = store != null ? store : new Vector3();

        return rVal.set(gridX, gridY, height);
    }
View Full Code Here

TOP

Related Classes of com.ardor3d.math.Vector3

Copyright © 2018 www.massapicom. 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.