Search in sources :

Example 51 with Vector3

use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.

the class BoundingBox method calculateMinMaxVertices.

/**
     * Traverses the vertices, to find the minimum and maximum x,y,z coordinates.
     * If the vertices are null, the mMin and mMax remain un affected
     *
     * @param vertices can be null
     * @param mMin mutable vertex that contains a point, will get updated to the minimum coordinate
     *             of given vertices
     * @param mMax mutable vertex that contains a point, will get updated to the maximum coordinate
     *             of given vertices
     */
private void calculateMinMaxVertices(FloatBuffer vertices, Vector3 mMin, Vector3 mMax) {
    if (vertices == null)
        return;
    vertices.rewind();
    Vector3 vertex = new Vector3();
    while (vertices.hasRemaining()) {
        vertex.x = vertices.get();
        vertex.y = vertices.get();
        vertex.z = vertices.get();
        if (vertex.x < mMin.x)
            mMin.x = vertex.x;
        if (vertex.y < mMin.y)
            mMin.y = vertex.y;
        if (vertex.z < mMin.z)
            mMin.z = vertex.z;
        if (vertex.x > mMax.x)
            mMax.x = vertex.x;
        if (vertex.y > mMax.y)
            mMax.y = vertex.y;
        if (vertex.z > mMax.z)
            mMax.z = vertex.z;
    }
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3)

Example 52 with Vector3

use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.

the class BoundingSphere method calculateBounds.

public void calculateBounds(Geometry3D geometry) {
    double radius = 0, maxRadius = 0;
    Vector3 vertex = new Vector3();
    FloatBuffer vertices = geometry.getVertices();
    vertices.rewind();
    while (vertices.hasRemaining()) {
        vertex.x = vertices.get();
        vertex.y = vertices.get();
        vertex.z = vertices.get();
        radius = vertex.length();
        if (radius > maxRadius)
            maxRadius = radius;
    }
    mRadius = maxRadius;
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3) FloatBuffer(java.nio.FloatBuffer)

Example 53 with Vector3

use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.

the class GridFloor method createGridFloor.

private void createGridFloor() {
    final float sizeHalf = mSize * 0.5f;
    final float spacing = mSize / mNumLines;
    mPoints = new Stack<>();
    for (float z = -sizeHalf; z <= sizeHalf; z += spacing) {
        mPoints.add(new Vector3(-sizeHalf, 0, z));
        mPoints.add(new Vector3(sizeHalf, 0, z));
    }
    for (float x = -sizeHalf; x <= sizeHalf; x += spacing) {
        mPoints.add(new Vector3(x, 0, -sizeHalf));
        mPoints.add(new Vector3(x, 0, sizeHalf));
    }
    setMaterial(new Material());
    init(true);
    setDrawingMode(GLES20.GL_LINES);
}
Also used : Vector3(org.rajawali3d.math.vector.Vector3) Material(org.rajawali3d.materials.Material)

Example 54 with Vector3

use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.

the class Loader3DSMax method readFaces.

protected void readFaces(InputStream buffer) throws IOException {
    int triangles = readShort(buffer);
    Vector3[] normals = new Vector3[triangles];
    ArrayList<Integer> indices = new ArrayList<Integer>();
    for (int i = 0; i < triangles; i++) {
        int[] vertexIDs = new int[3];
        vertexIDs[0] = readShort(buffer);
        vertexIDs[1] = readShort(buffer);
        vertexIDs[2] = readShort(buffer);
        readShort(buffer);
        indices.add(vertexIDs[0]);
        indices.add(vertexIDs[1]);
        indices.add(vertexIDs[2]);
        Vector3 normal = calculateFaceNormal(vertexIDs);
        normals[i] = normal;
    }
    mNormals.add(new Vector3[triangles]);
    mIndices.add(indices);
    int numVertices = mVertices.get(mObjects).size();
    int numIndices = indices.size();
    ArrayList<Vector3> vertNormals = new ArrayList<Vector3>();
    for (int i = 0; i < numVertices; i++) {
        Vector3 vertexNormal = new Vector3();
        for (int j = 0; j < numIndices; j += 3) {
            int id1 = indices.get(j);
            int id2 = indices.get(j + 1);
            int id3 = indices.get(j + 2);
            if (id1 == i || id2 == i || id3 == i) {
                vertexNormal.add(normals[j / 3]);
            }
        }
        vertexNormal.normalize();
        vertNormals.add(vertexNormal);
    }
    mVertNormals.add(vertNormals);
}
Also used : ArrayList(java.util.ArrayList) Vector3(org.rajawali3d.math.vector.Vector3)

Example 55 with Vector3

use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.

the class ArcballCamera method applyRotation.

private void applyRotation() {
    if (mIsRotating) {
        mapToSphere((float) mPrevScreenCoord.getX(), (float) mPrevScreenCoord.getY(), mPrevSphereCoord);
        mapToSphere((float) mCurrScreenCoord.getX(), (float) mCurrScreenCoord.getY(), mCurrSphereCoord);
        Vector3 rotationAxis = mPrevSphereCoord.clone();
        rotationAxis.cross(mCurrSphereCoord);
        rotationAxis.normalize();
        double rotationAngle = Math.acos(Math.min(1, mPrevSphereCoord.dot(mCurrSphereCoord)));
        mCurrentOrientation.fromAngleAxis(rotationAxis, MathUtil.radiansToDegrees(rotationAngle));
        mCurrentOrientation.normalize();
        Quaternion q = new Quaternion(mStartOrientation);
        q.multiply(mCurrentOrientation);
        mEmpty.setOrientation(q);
    }
}
Also used : Quaternion(org.rajawali3d.math.Quaternion) Vector3(org.rajawali3d.math.vector.Vector3)

Aggregations

Vector3 (org.rajawali3d.math.vector.Vector3)166 SmallTest (android.test.suitebuilder.annotation.SmallTest)106 Test (org.junit.Test)106 Material (org.rajawali3d.materials.Material)9 SkeletonJoint (org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint)6 Matrix4 (org.rajawali3d.math.Matrix4)6 Object3D (org.rajawali3d.Object3D)5 BoundingBox (org.rajawali3d.bounds.BoundingBox)5 DiffuseMethod (org.rajawali3d.materials.methods.DiffuseMethod)4 Quaternion (org.rajawali3d.math.Quaternion)4 ArrayList (java.util.ArrayList)3 DirectionalLight (org.rajawali3d.lights.DirectionalLight)3 ParsingException (org.rajawali3d.loader.ParsingException)3 FileNotFoundException (java.io.FileNotFoundException)2 FloatBuffer (java.nio.FloatBuffer)2 Stack (java.util.Stack)2 BoneVertex (org.rajawali3d.animation.mesh.SkeletalAnimationChildObject3D.BoneVertex)2 BoneWeight (org.rajawali3d.animation.mesh.SkeletalAnimationChildObject3D.BoneWeight)2 BoundingSphere (org.rajawali3d.bounds.BoundingSphere)2 IBoundingVolume (org.rajawali3d.bounds.IBoundingVolume)2