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;
}
}
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;
}
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);
}
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);
}
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);
}
}
Aggregations