Package com.ardor3d.math

Examples of com.ardor3d.math.Vector3


     * @param radius
     *            Radius of the sphere.
     * @see #Sphere(java.lang.String, com.ardor3d.math.Vector3, int, int, double)
     */
    public Sphere(final String name, final int zSamples, final int radialSamples, final double radius) {
        this(name, new Vector3(0, 0, 0), zSamples, radialSamples, radius);
    }
View Full Code Here


        afSin[_radialSamples] = afSin[0];
        afCos[_radialSamples] = afCos[0];

        // generate the sphere itself
        int i = 0;
        final Vector3 tempVa = Vector3.fetchTempInstance();
        final Vector3 tempVb = Vector3.fetchTempInstance();
        final Vector3 tempVc = Vector3.fetchTempInstance();
        for (int iZ = 1; iZ < (_zSamples - 1); iZ++) {
            final double fAFraction = MathUtils.HALF_PI * (-1.0f + fZFactor * iZ); // in (-pi/2, pi/2)
            final double fZFraction = MathUtils.sin(fAFraction); // in (-1,1)
            final double fZ = _radius * fZFraction;

            // compute center of slice
            final Vector3 kSliceCenter = tempVb.set(_center);
            kSliceCenter.setZ(kSliceCenter.getZ() + fZ);

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

            // compute slice vertices with duplication at end point
            Vector3 kNormal;
            final int iSave = i;
            for (int iR = 0; iR < _radialSamples; iR++) {
                final double fRadialFraction = iR * fInvRS; // in [0,1)
                final Vector3 kRadial = tempVc.set(afCos[iR], afSin[iR], 0);
                kRadial.multiply(fSliceRadius, tempVa);
                _meshData.getVertexBuffer().put((float) (kSliceCenter.getX() + tempVa.getX()))
                        .put((float) (kSliceCenter.getY() + tempVa.getY()))
                        .put((float) (kSliceCenter.getZ() + tempVa.getZ()));

                BufferUtils.populateFromBuffer(tempVa, _meshData.getVertexBuffer(), i);
View Full Code Here

    public void write(final OutputCapsule capsule) throws IOException {
        super.write(capsule);
        capsule.write(_zSamples, "zSamples", 0);
        capsule.write(_radialSamples, "radialSamples", 0);
        capsule.write(_radius, "radius", 0);
        capsule.write(_center, "center", new Vector3(Vector3.ZERO));
        capsule.write(_textureMode, "textureMode", TextureMode.Linear);
        capsule.write(_viewInside, "viewInside", false);
    }
View Full Code Here

    public void read(final InputCapsule capsule) throws IOException {
        super.read(capsule);
        _zSamples = capsule.readInt("zSamples", 0);
        _radialSamples = capsule.readInt("radialSamples", 0);
        _radius = capsule.readDouble("radius", 0);
        _center.set((Vector3) capsule.readSavable("center", new Vector3(Vector3.ZERO)));
        _textureMode = capsule.readEnum("textureMode", TextureMode.class, TextureMode.Linear);
        _viewInside = capsule.readBoolean("viewInside", false);
    }
View Full Code Here

        indices.put(7).put(10).put(11);
    }

    private void setTextureData() {
        final Vector2 tex = new Vector2();
        final Vector3 vert = new Vector3();
        for (int i = 0; i < NUM_POINTS; i++) {
            BufferUtils.populateFromBuffer(vert, _meshData.getVertexBuffer(), i);
            if (Math.abs(vert.getZ()) < _sideLength) {
                tex.setX(0.5 * (1.0 + Math.atan2(vert.getY(), vert.getX()) * MathUtils.INV_PI));
            } else {
                tex.setX(0.5);
            }
            tex.setY(Math.acos(vert.getZ() / _sideLength) * MathUtils.INV_PI);
            _meshData.getTextureCoords(0).getBuffer().put((float) tex.getX()).put((float) tex.getY());
        }
    }
View Full Code Here

            _meshData.getTextureCoords(0).getBuffer().put((float) tex.getX()).put((float) tex.getY());
        }
    }

    private void setNormalData() {
        final Vector3 norm = new Vector3();
        for (int i = 0; i < NUM_POINTS; i++) {
            BufferUtils.populateFromBuffer(norm, _meshData.getVertexBuffer(), i);
            norm.normalizeLocal();
            BufferUtils.setInBuffer(norm, _meshData.getNormalBuffer(), i);
        }
    }
View Full Code Here

        indices.put(5).put(0).put(3);
    }

    private void setTextureData() {
        final Vector2 tex = new Vector2();
        final Vector3 vert = new Vector3();
        for (int i = 0; i < NUM_POINTS; i++) {
            BufferUtils.populateFromBuffer(vert, _meshData.getVertexBuffer(), i);
            if (Math.abs(vert.getZ()) < _sideLength) {
                tex.setX(0.5 * (1.0 + Math.atan2(vert.getY(), vert.getX()) * MathUtils.INV_PI));
            } else {
                tex.setX(0.5);
            }
            tex.setY(Math.acos(vert.getZ() / _sideLength) * MathUtils.INV_PI);
            _meshData.getTextureCoords(0).getBuffer().put((float) tex.getX()).put((float) tex.getY());
        }
    }
View Full Code Here

            _meshData.getTextureCoords(0).getBuffer().put((float) tex.getX()).put((float) tex.getY());
        }
    }

    private void setNormalData() {
        final Vector3 norm = new Vector3();
        for (int i = 0; i < NUM_POINTS; i++) {
            BufferUtils.populateFromBuffer(norm, _meshData.getVertexBuffer(), i);
            norm.normalizeLocal();
            BufferUtils.setInBuffer(norm, _meshData.getNormalBuffer(), i);
        }
    }
View Full Code Here

        }

        final IndexMode indexMode = shape.getMeshData().getIndexMode(0);

        final int shapeVertices = shapeBuffer.limit() / 3;
        final Vector3 vector = new Vector3();
        final Vector3 direction = new Vector3();
        final Quaternion rotation = new Quaternion();

        for (int i = 0; i < path.size(); i++) {
            final ReadOnlyVector3 point = path.get(i);
            shapeBuffer.rewind();
            if (shapeNormalBuffer != null) {
                shapeNormalBuffer.rewind();
            }
            int shapeVertice = 0;
            do {
                final ReadOnlyVector3 nextPoint = i < path.size() - 1 ? path.get(i + 1) : closed ? path.get(0) : null;
                final ReadOnlyVector3 lastPoint = i > 0 ? path.get(i - 1) : null;
                if (nextPoint != null) {
                    direction.set(nextPoint).subtractLocal(point);
                } else {
                    direction.set(point).subtractLocal(lastPoint);
                }
                rotation.lookAt(direction, up);

                if (shapeNormalBuffer != null && normals != null) {
                    vector.set(shapeNormalBuffer.get(), shapeNormalBuffer.get(), shapeNormalBuffer.get());
View Full Code Here

                }
            }
            // note that a[0]=a[np-1]=0
            // draw
            if (!closed) {
                path.add(new Vector3(d[0][0], d[1][0], d[2][0]));
            }
            final double[] point = new double[3];
            for (int i = closed ? 2 : 1; i <= np - 2; i++) { // loop over
                // intervals
                // between nodes
                for (int j = 1; j <= segments; j++) {
                    for (int dim = 0; dim < 3; dim++) {
                        final double t1 = (h[i] * j) / segments;
                        final double t2 = h[i] - t1;
                        final double v = ((-a[dim][i - 1] / 6 * (t2 + h[i]) * t1 + d[dim][i - 1]) * t2 + (-a[dim][i]
                                / 6 * (t1 + h[i]) * t2 + d[dim][i])
                                * t1)
                                / h[i];
                        // float t = x[i - 1] + t1;
                        point[dim] = v;
                    }
                    path.add(new Vector3(point[0], point[1], point[2]));
                }
            }
        }

        this.updateGeometry(shape, path, closed, up);
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.