Package com.ardor3d.math

Examples of com.ardor3d.math.Vector3


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


     * @param outsideView
     *            If the dome should be viewed from the outside (if not zbuffer is used)
     * @param center
     */
    private void setGeometryData(final boolean outsideView, final Vector3 center) {
        final Vector3 tempVa = Vector3.fetchTempInstance();
        final Vector3 tempVb = Vector3.fetchTempInstance();
        final Vector3 tempVc = Vector3.fetchTempInstance();

        // allocate vertices, we need one extra in each radial to get the
        // correct texture coordinates
        final int verts = ((_planes - 1) * (_radialSamples + 1)) + 1;
        _meshData.setVertexBuffer(BufferUtils.createVector3Buffer(verts));

        // allocate normals
        _meshData.setNormalBuffer(BufferUtils.createVector3Buffer(verts));

        // allocate texture coordinates
        _meshData.setTextureBuffer(BufferUtils.createVector2Buffer(verts), 0);

        // generate geometry
        final double fInvRS = 1.0 / _radialSamples;
        final double fYFactor = 1.0 / (_planes - 1);

        // Generate points on the unit circle to be used in computing the mesh
        // points on a dome slice.
        final double[] afSin = new double[(_radialSamples)];
        final double[] afCos = new double[(_radialSamples)];
        for (int iR = 0; iR < _radialSamples; iR++) {
            final double fAngle = MathUtils.TWO_PI * fInvRS * iR;
            afCos[iR] = MathUtils.cos(fAngle);
            afSin[iR] = MathUtils.sin(fAngle);
        }

        // generate the dome itself
        int i = 0;
        for (int iY = 0; iY < (_planes - 1); iY++) {
            final double fYFraction = fYFactor * iY; // in (0,1)
            final double fY = _radius * fYFraction;
            // compute center of slice
            final Vector3 kSliceCenter = tempVb.set(center);
            kSliceCenter.addLocal(0, fY, 0);

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

            // compute slice vertices
            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], 0, afSin[iR]);
                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

    /**
     * Initialize structures.
     */
    private void init() {
        for (int i = 0; i < _corners.length; i++) {
            _corners[i] = new Vector3();
        }
    }
View Full Code Here

            fFarPlaneHeight = (_frustumTop - _frustumBottom) * 0.5;
            fFarPlaneWidth = (_frustumRight - _frustumLeft) * 0.5;
        }

        final Vector3 vNearPlaneCenter = Vector3.fetchTempInstance();
        final Vector3 vFarPlaneCenter = Vector3.fetchTempInstance();
        final Vector3 direction = Vector3.fetchTempInstance();
        final Vector3 left = Vector3.fetchTempInstance();
        final Vector3 up = Vector3.fetchTempInstance();

        direction.set(getDirection()).multiplyLocal(fNear);
        vNearPlaneCenter.set(getLocation()).addLocal(direction);
        direction.set(getDirection()).multiplyLocal(fFar);
        vFarPlaneCenter.set(getLocation()).addLocal(direction);

        left.set(getLeft()).multiplyLocal(fNearPlaneWidth);
        up.set(getUp()).multiplyLocal(fNearPlaneHeight);
        _corners[0].set(vNearPlaneCenter).subtractLocal(left).subtractLocal(up);
        _corners[1].set(vNearPlaneCenter).subtractLocal(left).addLocal(up);
        _corners[2].set(vNearPlaneCenter).addLocal(left).addLocal(up);
        _corners[3].set(vNearPlaneCenter).addLocal(left).subtractLocal(up);

        left.set(getLeft()).multiplyLocal(fFarPlaneWidth);
        up.set(getUp()).multiplyLocal(fFarPlaneHeight);
        _corners[4].set(vFarPlaneCenter).subtractLocal(left).subtractLocal(up);
        _corners[5].set(vFarPlaneCenter).subtractLocal(left).addLocal(up);
        _corners[6].set(vFarPlaneCenter).addLocal(left).addLocal(up);
        _corners[7].set(vFarPlaneCenter).addLocal(left).subtractLocal(up);

View Full Code Here

        // generate geometry
        final double inverseCircleSamples = 1.0 / _circleSamples;
        final double inverseRadialSamples = 1.0 / _radialSamples;
        int i = 0;
        // generate the cylinder itself
        final Vector3 radialAxis = new Vector3(), torusMiddle = new Vector3(), tempNormal = new Vector3();
        for (int circleCount = 0; circleCount < _circleSamples; circleCount++) {
            // compute center point on torus circle at specified angle
            final double circleFraction = circleCount * inverseCircleSamples;
            final double theta = MathUtils.TWO_PI * circleFraction;
            final double cosTheta = MathUtils.cos(theta);
            final double sinTheta = MathUtils.sin(theta);
            radialAxis.set(cosTheta, sinTheta, 0);
            radialAxis.multiply(_centerRadius, torusMiddle);

            // compute slice vertices with duplication at end point
            final int iSave = i;
            for (int radialCount = 0; radialCount < _radialSamples; radialCount++) {
                final double radialFraction = radialCount * inverseRadialSamples;
                // in [0,1)
                final double phi = MathUtils.TWO_PI * radialFraction;
                final double cosPhi = MathUtils.cos(phi);
                final double sinPhi = MathUtils.sin(phi);
                tempNormal.set(radialAxis).multiplyLocal(cosPhi);
                tempNormal.setZ(tempNormal.getZ() + sinPhi);
                tempNormal.normalizeLocal();
                if (!_viewInside) {
                    _meshData.getNormalBuffer().put((float) tempNormal.getX()).put((float) tempNormal.getY())
                            .put((float) tempNormal.getZ());
                } else {
                    _meshData.getNormalBuffer().put((float) -tempNormal.getX()).put((float) -tempNormal.getY())
                            .put((float) -tempNormal.getZ());
                }

                tempNormal.multiplyLocal(_tubeRadius).addLocal(torusMiddle);
                _meshData.getVertexBuffer().put((float) tempNormal.getX()).put((float) tempNormal.getY())
                        .put((float) tempNormal.getZ());

                _meshData.getTextureCoords(0).getBuffer().put((float) radialFraction).put((float) circleFraction);
                i++;
            }

View Full Code Here

    /**
     * @return a size 8 array of Vectors representing the 8 points of the box.
     */
    public Vector3[] computeVertices() {

        final Vector3 rVal[] = new Vector3[8];
        rVal[0] = _center.add(-_xExtent, -_yExtent, -_zExtent, null);
        rVal[1] = _center.add(_xExtent, -_yExtent, -_zExtent, null);
        rVal[2] = _center.add(_xExtent, _yExtent, -_zExtent, null);
        rVal[3] = _center.add(-_xExtent, _yExtent, -_zExtent, null);
        rVal[4] = _center.add(_xExtent, -_yExtent, _zExtent, null);
View Full Code Here

    public void write(final OutputCapsule capsule) throws IOException {
        super.write(capsule);
        capsule.write(_xExtent, "xExtent", 0);
        capsule.write(_yExtent, "yExtent", 0);
        capsule.write(_zExtent, "zExtent", 0);
        capsule.write(_center, "center", new Vector3(Vector3.ZERO));

    }
View Full Code Here

    public void read(final InputCapsule capsule) throws IOException {
        super.read(capsule);
        _xExtent = capsule.readDouble("xExtent", 0);
        _yExtent = capsule.readDouble("yExtent", 0);
        _zExtent = capsule.readDouble("zExtent", 0);
        _center.set((Vector3) capsule.readSavable("center", new Vector3(Vector3.ZERO)));
    }
View Full Code Here

        _meshData.getTextureCoords(0).getBuffer().put(.5f).put(.5f);

        final double inverseShellLess = 1.0 / shellLess;
        final double inverseRadial = 1.0 / _radialSamples;
        final Vector3 radialFraction = new Vector3();
        final Vector2 texCoord = new Vector2();
        for (int radialCount = 0; radialCount < _radialSamples; radialCount++) {
            final double angle = MathUtils.TWO_PI * inverseRadial * radialCount;
            final double cos = MathUtils.cos(angle);
            final double sin = MathUtils.sin(angle);
            final Vector3 radial = new Vector3(cos, sin, 0);

            for (int shellCount = 1; shellCount < _shellSamples; shellCount++) {
                final double fraction = inverseShellLess * shellCount; // in (0,R]
                radialFraction.set(radial).multiplyLocal(fraction);
                final int i = shellCount + shellLess * radialCount;
 
View Full Code Here

            final double b = 0.2764 * _radius;
            final double c = 0.7236 * _radius;
            final double d = 0.8507 * _radius;
            final double e = 0.5257 * _radius;
            pos++;
            put(new Vector3(0, _radius, 0));
            pos++;
            put(new Vector3(a, y, 0));
            pos++;
            put(new Vector3(b, y, -d));
            pos++;
            put(new Vector3(-c, y, -e));
            pos++;
            put(new Vector3(-c, y, e));
            pos++;
            put(new Vector3(b, y, d));
            pos++;
            put(new Vector3(c, -y, -e));
            pos++;
            put(new Vector3(-b, -y, -d));
            pos++;
            put(new Vector3(-a, -y, 0));
            pos++;
            put(new Vector3(-b, -y, d));
            pos++;
            put(new Vector3(c, -y, e));
            pos++;
            put(new Vector3(0, -_radius, 0));
            final Triangle[] ikosaedron = new Triangle[indices.length / 3];
            for (int i = 0; i < ikosaedron.length; i++) {
                final Triangle triangle = ikosaedron[i] = new Triangle();
                triangle.pt[0] = indices[i * 3];
                triangle.pt[1] = indices[i * 3 + 1];
                triangle.pt[2] = indices[i * 3 + 2];
            }

            old = ikosaedron;
        } else {
            /* Six equidistant points lying on the unit sphere */
            final Vector3 XPLUS = new Vector3(_radius, 0, 0); /* X */
            final Vector3 XMIN = new Vector3(-_radius, 0, 0); /* -X */
            final Vector3 YPLUS = new Vector3(0, _radius, 0); /* Y */
            final Vector3 YMIN = new Vector3(0, -_radius, 0); /* -Y */
            final Vector3 ZPLUS = new Vector3(0, 0, _radius); /* Z */
            final Vector3 ZMIN = new Vector3(0, 0, -_radius); /* -Z */

            final int xplus = pos++;
            put(XPLUS);
            final int xmin = pos++;
            put(XMIN);
            final int yplus = pos++;
            put(YPLUS);
            final int ymin = pos++;
            put(YMIN);
            final int zplus = pos++;
            put(ZPLUS);
            final int zmin = pos++;
            put(ZMIN);

            final Triangle[] octahedron = new Triangle[] { new Triangle(yplus, zplus, xplus),
                    new Triangle(xmin, zplus, yplus), new Triangle(ymin, zplus, xmin),
                    new Triangle(xplus, zplus, ymin), new Triangle(zmin, yplus, xplus),
                    new Triangle(zmin, xmin, yplus), new Triangle(zmin, ymin, xmin), new Triangle(zmin, xplus, ymin) };

            old = octahedron;
        }

        final Vector3 pt0 = new Vector3();
        final Vector3 pt1 = new Vector3();
        final Vector3 pt2 = new Vector3();

        /* Subdivide each starting triangle (maxlevels - 1) times */
        for (int level = 1; level < _maxlevels; level++) {
            /* Allocate a next triangle[] */
            final Triangle[] next = new Triangle[old.length * 4];
            for (int i = 0; i < next.length; i++) {
                next[i] = new Triangle();
            }

            /**
             * Subdivide each polygon in the old approximation and normalize the next points thus generated to lie on
             * the surface of the unit sphere. Each input triangle with vertBuf labeled [0,1,2] as shown below will be
             * turned into four next triangles:
             *
             * <pre>
             * Make next points
             *   a = (0+2)/2
             *   b = (0+1)/2
             *   c = (1+2)/2
             *  
             * 1   /\   Normalize a, b, c
             *    /  \
             * b /____\ c
             *
             * Construct next triangles
             *
             *    /\    /\   [0,b,a]
             *   /  \  /  \  [b,1,c]
             *  /____\/____\ [a,b,c]
             *  0 a 2 [a,c,2]
             * </pre>
             */
            for (int i = 0; i < old.length; i++) {
                int newi = i * 4;
                final Triangle oldt = old[i];
                Triangle newt = next[newi];

                BufferUtils.populateFromBuffer(pt0, vertBuf, oldt.pt[0]);
                BufferUtils.populateFromBuffer(pt1, vertBuf, oldt.pt[1]);
                BufferUtils.populateFromBuffer(pt2, vertBuf, oldt.pt[2]);
                final Vector3 av = createMidpoint(pt0, pt2).normalizeLocal().multiplyLocal(_radius);
                final Vector3 bv = createMidpoint(pt0, pt1).normalizeLocal().multiplyLocal(_radius);
                final Vector3 cv = createMidpoint(pt1, pt2).normalizeLocal().multiplyLocal(_radius);
                final int a = pos++;
                put(av);
                final int b = pos++;
                put(bv);
                final int c = pos++;
                put(cv);

                newt.pt[0] = oldt.pt[0];
                newt.pt[1] = b;
                newt.pt[2] = a;
                newt = next[++newi];

                newt.pt[0] = b;
                newt.pt[1] = oldt.pt[1];
                newt.pt[2] = c;
                newt = next[++newi];

                newt.pt[0] = a;
                newt.pt[1] = b;
                newt.pt[2] = c;
                newt = next[++newi];

                newt.pt[0] = a;
                newt.pt[1] = c;
                newt.pt[2] = oldt.pt[2];
            }

            /* Continue subdividing next triangles */
            old = next;
        }

        final IndexBufferData<?> indexBuffer = BufferUtils.createIndexBufferData(tris * 3, verts - 1);
        _meshData.setIndices(indexBuffer);

        int carryIntIndex = _meshData.getVertexBuffer().position() / 3;
        for (final Triangle triangle : old) {
            for (final int aPt : triangle.pt) {
                final Vector3 point = new Vector3();
                BufferUtils.populateFromBuffer(point, _meshData.getVertexBuffer(), aPt);
                if (point.getX() > 0 && point.getY() == 0) {
                    // Find out which 'y' side the triangle is on
                    final double yCenter = (_meshData.getVertexBuffer().get(triangle.pt[0] * 3 + 1)
                            + _meshData.getVertexBuffer().get(triangle.pt[1] * 3 + 1) + _meshData.getVertexBuffer()
                            .get(triangle.pt[2] * 3 + 1)) / 3.0;
                    if (yCenter > 0.0) {
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.