Package com.ardor3d.math

Examples of com.ardor3d.math.Vector3


     * @param b
     *            second vector
     * @return the average of two points
     */
    protected Vector3 createMidpoint(final Vector3 a, final Vector3 b) {
        return new Vector3((a.getX() + b.getX()) * 0.5, (a.getY() + b.getY()) * 0.5, (a.getZ() + b.getZ()) * 0.5);
    }
View Full Code Here


        } else {
            _splitTexCoords = null;
        }
        _splitNormals = new Vector3[_destVerts.size()];
        for (int j = 0; j < _splitNormals.length; j++) {
            _splitNormals[j] = new Vector3();
        }
        int numTris = 0;
        for (final LinkedList<Triangle> tris : _splitMeshes) {
            numTris += tris.size();
        }
View Full Code Here

            sin[radialCount] = MathUtils.sin(angle);
        }
        sin[radialSamples] = sin[0];
        cos[radialSamples] = cos[0];

        final Vector3 tempA = new Vector3();

        // top point.
        verts.put(0).put((float) (radius + halfHeight)).put(0);
        norms.put(0).put(1).put(0);
        texs.put(1).put(1);

        // generating the top dome.
        for (int i = 0; i < sphereSamples; i++) {
            final double center = radius * (1 - (i + 1) * (inverseSphere));
            final double lengthFraction = (center + height + radius) / (height + 2 * radius);

            // compute radius of slice
            final double fSliceRadius = Math.sqrt(Math.abs(radius * radius - center * center));

            for (int j = 0; j <= radialSamples; j++) {
                final Vector3 kRadial = tempA.set(cos[j], 0, sin[j]);
                kRadial.multiplyLocal(fSliceRadius);
                verts.put(kRadial.getXf()).put((float) (center + halfHeight)).put(kRadial.getZf());
                kRadial.setY(center);
                kRadial.normalizeLocal();
                norms.put(kRadial.getXf()).put(kRadial.getYf()).put(kRadial.getZf());
                final double radialFraction = 1 - (j * inverseRadial); // in [0,1)
                texs.put((float) radialFraction).put((float) lengthFraction);
            }
        }

        // generate cylinder... but no need to add points for first and last
        // samples as they are already part of domes.
        for (int i = 1; i < axisSamples; i++) {
            final double center = halfHeight - (i * height / axisSamples);
            final double lengthFraction = (center + halfHeight + radius) / (height + 2 * radius);

            for (int j = 0; j <= radialSamples; j++) {
                final Vector3 kRadial = tempA.set(cos[j], 0, sin[j]);
                kRadial.multiplyLocal(radius);
                verts.put(kRadial.getXf()).put((float) center).put(kRadial.getZf());
                kRadial.normalizeLocal();
                norms.put(kRadial.getXf()).put(kRadial.getYf()).put(kRadial.getZf());
                final double radialFraction = 1 - (j * inverseRadial); // in [0,1)
                texs.put((float) radialFraction).put((float) lengthFraction);
            }

        }

        // generating the bottom dome.
        for (int i = 0; i < sphereSamples; i++) {
            final double center = i * (radius / sphereSamples);
            final double lengthFraction = (radius - center) / (height + 2 * radius);

            // compute radius of slice
            final double fSliceRadius = Math.sqrt(Math.abs(radius * radius - center * center));

            for (int j = 0; j <= radialSamples; j++) {
                final Vector3 kRadial = tempA.set(cos[j], 0, sin[j]);
                kRadial.multiplyLocal(fSliceRadius);
                verts.put(kRadial.getXf()).put((float) (-center - halfHeight)).put(kRadial.getZf());
                kRadial.setY(-center);
                kRadial.normalizeLocal();
                norms.put(kRadial.getXf()).put(kRadial.getYf()).put(kRadial.getZf());
                final double radialFraction = 1 - (j * inverseRadial); // in [0,1)
                texs.put((float) radialFraction).put((float) lengthFraction);
            }
        }

View Full Code Here

        }
    }

    public void reconstruct(final Vector3 top, final Vector3 bottom, final double radius) {
        // our temp vars
        final Vector3 localTranslation = Vector3.fetchTempInstance();
        final Vector3 capsuleUp = Vector3.fetchTempInstance();

        // first make the capsule the right shape
        height = top.distance(bottom);
        this.radius = radius;
        setGeometryData();
View Full Code Here

                        }

                        final double value = getBooleanConfig(type, ConfigKeys.FrameAverage.name(), false) ? sample
                                .getStatValue(type).getAverageValue() : sample.getStatValue(type).getAccumulatedValue();

                        final Vector3 point = new Vector3(i, value, 0);
                        // Now, add
                        entry.verts.add(point);

                        // Update min/max
                        if (entry.max < value) {
                            entry.max = value;
                        }

                        entry.visited = true;
                    } else {
                        final LineEntry entry = _entries.get(type);
                        if (entry != null) {
                            entry.verts.add(new Vector3(i, 0, 0));
                        }
                    }
                }
            }
        }

        for (final Iterator<StatType> i = _entries.keySet().iterator(); i.hasNext();) {
            final LineEntry entry = _entries.get(i.next());
            // - Go through the entries list and remove any that were not visited.
            if (!entry.visited) {
                entry.line.removeFromParent();
                entry.point.removeFromParent();
                i.remove();
                continue;
            }

            // - Update the Point and Line params with the verts and count.
            final FloatBuffer fb = BufferUtils.createFloatBuffer(entry.verts.toArray(new Vector3[entry.verts.size()]));
            entry.point.getMeshData().setVertexBuffer(fb);
            final double scaleWidth = texWidth / (StatCollector.getMaxSamples() - 1.0);
            final double scaleHeight = texHeight / (entry.max * 1.02);
            entry.point.setScale(new Vector3(scaleWidth, scaleHeight, 1));
            entry.line.getMeshData().setVertexBuffer(fb);
            entry.line.setScale(new Vector3(scaleWidth, scaleHeight, 1));
            fb.rewind();

            // - attach point/line to root as needed
            if (!_graphRoot.equals(entry.line.getParent())) {
                _graphRoot.attachChild(entry.line);
View Full Code Here

    }

    public Line updateLineKey(final StatType type, Line lineKey) {
        if (lineKey == null) {
            lineKey = new Line("lk", BufferUtils.createVector3Buffer(2), null, null, null);
            final FloatBuffer fb = BufferUtils.createFloatBuffer(new Vector3[] { new Vector3(0, 0, 0),
                    new Vector3(30, 0, 0) });
            fb.rewind();
            lineKey.getMeshData().setVertexBuffer(fb);
        }

        lineKey.getSceneHints().setRenderBucketType(RenderBucketType.Ortho);
View Full Code Here

     */
    public OrientedBox(final String name) {
        super(name);
        _vectorStore = new Vector3[8];
        for (int i = 0; i < _vectorStore.length; i++) {
            _vectorStore[i] = new Vector3();
        }
        _texTopRight = new Vector2(1, 1);
        _texTopLeft = new Vector2(1, 0);
        _texBotRight = new Vector2(0, 1);
        _texBotLeft = new Vector2(0, 0);
        _center = new Vector3(0, 0, 0);
        _correctCorners = false;
        computeInformation();
    }
View Full Code Here

     * Sets the vectorStore information to the 8 corners of the box.
     */
    public void computeCorners() {
        _correctCorners = true;

        final Vector3 tempVa = Vector3.fetchTempInstance();
        final Vector3 tempVb = Vector3.fetchTempInstance();
        final Vector3 tempVc = Vector3.fetchTempInstance();
        tempVa.set(_xAxis).multiplyLocal(_extent.getX());
        tempVb.set(_yAxis).multiplyLocal(_extent.getY());
        tempVc.set(_zAxis).multiplyLocal(_extent.getZ());

        _vectorStore[0].set(_center).addLocal(tempVa).addLocal(tempVb).addLocal(tempVc);
        _vectorStore[1].set(_center).addLocal(tempVa).subtractLocal(tempVb).addLocal(tempVc);
        _vectorStore[2].set(_center).addLocal(tempVa).addLocal(tempVb).subtractLocal(tempVc);
        _vectorStore[3].set(_center).subtractLocal(tempVa).addLocal(tempVb).addLocal(tempVc);
View Full Code Here

        final int triangleCount = meshData.getTotalPrimitiveCount();

        final Vector3[] tan1 = new Vector3[vertexCount];
        final Vector3[] tan2 = new Vector3[vertexCount];
        for (int i = 0; i < vertexCount; i++) {
            tan1[i] = new Vector3();
            tan2[i] = new Vector3();
        }

        final Vector3[] vertex = BufferUtils.getVector3Array(vertexBuffer);
        final Vector3[] normal = BufferUtils.getVector3Array(normalBuffer);
        final Vector2[] texcoord = BufferUtils.getVector2Array(textureBuffer);

        for (int a = 0; a < triangleCount; a++) {
            final int i1 = indexBuffer.get(a * 3);
            final int i2 = indexBuffer.get(a * 3 + 1);
            final int i3 = indexBuffer.get(a * 3 + 2);

            final Vector3 v1 = vertex[i1];
            final Vector3 v2 = vertex[i2];
            final Vector3 v3 = vertex[i3];

            final Vector2 w1 = texcoord[i1];
            final Vector2 w2 = texcoord[i2];
            final Vector2 w3 = texcoord[i3];

            final float x1 = v2.getXf() - v1.getXf();
            final float x2 = v3.getXf() - v1.getXf();
            final float y1 = v2.getYf() - v1.getYf();
            final float y2 = v3.getYf() - v1.getYf();
            final float z1 = v2.getZf() - v1.getZf();
            final float z2 = v3.getZf() - v1.getZf();

            final float s1 = w2.getXf() - w1.getXf();
            final float s2 = w3.getXf() - w1.getXf();
            final float t1 = w2.getYf() - w1.getYf();
            final float t2 = w3.getYf() - w1.getYf();

            final float r = 1.0F / (s1 * t2 - s2 * t1);
            if (Float.isNaN(r) || Float.isInfinite(r)) {
                continue;
            }
            final Vector3 sdir = new Vector3((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r);
            final Vector3 tdir = new Vector3((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r);

            tan1[i1].addLocal(sdir);
            tan1[i2].addLocal(sdir);
            tan1[i3].addLocal(sdir);

            tan2[i1].addLocal(tdir);
            tan2[i2].addLocal(tdir);
            tan2[i3].addLocal(tdir);
        }

        final FloatBuffer tangentBuffer = BufferUtils.createVector4Buffer(vertexCount);

        final Vector3 calc1 = new Vector3();
        final Vector3 calc2 = new Vector3();
        for (int a = 0; a < vertexCount; a++) {
            final Vector3 n = normal[a];
            final Vector3 t = tan1[a];

            // Gram-Schmidt orthogonalize
            double dot = n.dot(t);
            calc1.set(t).subtractLocal(n.multiply(dot, calc2)).normalizeLocal();
            tangentBuffer.put(calc1.getXf()).put(calc1.getYf()).put(calc1.getZf());
View Full Code Here

    }

    @Override
    public void write(final OutputCapsule capsule) throws IOException {
        super.write(capsule);
        capsule.write(_center, "center", new Vector3(Vector3.ZERO));
        capsule.write(_xAxis, "_xAxis", new Vector3(Vector3.UNIT_X));
        capsule.write(_yAxis, "yAxis", new Vector3(Vector3.UNIT_Y));
        capsule.write(_zAxis, "zAxis", new Vector3(Vector3.UNIT_Z));
        capsule.write(_extent, "extent", new Vector3(Vector3.ZERO));
        capsule.write(_texTopRight, "texTopRight", new Vector2(1, 1));
        capsule.write(_texTopLeft, "texTopLeft", new Vector2(1, 0));
        capsule.write(_texBotRight, "texBotRight", new Vector2(0, 1));
        capsule.write(_texBotLeft, "texBotLeft", new Vector2(0, 0));
        capsule.write(_vectorStore, "vectorStore", new Vector3[8]);
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.