use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class PlanesGalore method init.
public void init() {
mGaloreMat = new Material();
mGaloreMat.enableTime(true);
mMaterialPlugin = new PlanesGaloreMaterialPlugin();
mGaloreMat.addPlugin(mMaterialPlugin);
setMaterial(mGaloreMat);
final int numPlanes = 2000;
final float planeSize = .3f;
int numVertices = numPlanes * 4;
float[] vertices = new float[numVertices * 3];
float[] textureCoords = new float[numVertices * 2];
float[] normals = new float[numVertices * 3];
float[] planePositions = new float[numVertices * 3];
float[] rotationSpeeds = new float[numVertices];
float[] colors = new float[numVertices * 4];
int[] indices = new int[numPlanes * 6];
for (int i = 0; i < numPlanes; ++i) {
Vector3 r = new Vector3(-10f + (Math.random() * 20f), -10 + (Math.random() * 20f), (Math.random() * 80f));
int randColor = 0xff000000 + (int) (0xffffff * Math.random());
int vIndex = i * 4 * 3;
vertices[vIndex + 0] = -planeSize;
vertices[vIndex + 1] = planeSize;
vertices[vIndex + 2] = 0;
vertices[vIndex + 3] = planeSize;
vertices[vIndex + 4] = planeSize;
vertices[vIndex + 5] = 0;
vertices[vIndex + 6] = planeSize;
vertices[vIndex + 7] = -planeSize;
vertices[vIndex + 8] = 0;
vertices[vIndex + 9] = -planeSize;
vertices[vIndex + 10] = -planeSize;
vertices[vIndex + 11] = 0;
for (int j = 0; j < 12; j += 3) {
normals[vIndex + j] = 0;
normals[vIndex + j + 1] = 0;
normals[vIndex + j + 2] = 1;
planePositions[vIndex + j] = (float) r.x;
planePositions[vIndex + j + 1] = (float) r.y;
planePositions[vIndex + j + 2] = (float) r.z;
}
vIndex = i * 4 * 4;
for (int j = 0; j < 16; j += 4) {
colors[vIndex + j] = Color.red(randColor) / 255f;
colors[vIndex + j + 1] = Color.green(randColor) / 255f;
colors[vIndex + j + 2] = Color.blue(randColor) / 255f;
colors[vIndex + j + 3] = 1.0f;
}
vIndex = i * 4 * 2;
float u1 = .25f * (int) Math.floor(Math.random() * 4f);
float v1 = .25f * (int) Math.floor(Math.random() * 4f);
float u2 = u1 + .25f;
float v2 = v1 + .25f;
textureCoords[vIndex + 0] = u2;
textureCoords[vIndex + 1] = v1;
textureCoords[vIndex + 2] = u1;
textureCoords[vIndex + 3] = v1;
textureCoords[vIndex + 4] = u1;
textureCoords[vIndex + 5] = v2;
textureCoords[vIndex + 6] = u2;
textureCoords[vIndex + 7] = v2;
vIndex = i * 4;
int iindex = i * 6;
indices[iindex + 0] = (short) (vIndex + 0);
indices[iindex + 1] = (short) (vIndex + 1);
indices[iindex + 2] = (short) (vIndex + 3);
indices[iindex + 3] = (short) (vIndex + 1);
indices[iindex + 4] = (short) (vIndex + 2);
indices[iindex + 5] = (short) (vIndex + 3);
float rotationSpeed = -1f + (float) (Math.random() * 2f);
rotationSpeeds[vIndex + 0] = rotationSpeed;
rotationSpeeds[vIndex + 1] = rotationSpeed;
rotationSpeeds[vIndex + 2] = rotationSpeed;
rotationSpeeds[vIndex + 3] = rotationSpeed;
}
setData(vertices, normals, textureCoords, colors, indices, true);
mPlanePositions = ByteBuffer.allocateDirect(planePositions.length * Geometry3D.FLOAT_SIZE_BYTES).order(ByteOrder.nativeOrder()).asFloatBuffer();
mPlanePositions.put(planePositions);
mRotationSpeeds = ByteBuffer.allocateDirect(rotationSpeeds.length * Geometry3D.FLOAT_SIZE_BYTES).order(ByteOrder.nativeOrder()).asFloatBuffer();
mRotationSpeeds.put(rotationSpeeds);
createBuffers();
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class Matrix4Test method testSetTranslationFromVector3.
@Test
public void testSetTranslationFromVector3() throws Exception {
final double[] expected = new double[] { // Col 0
1d, // Col 0
0d, // Col 0
0d, // Col 0
0d, // Col 1
0d, // Col 1
1d, // Col 1
0d, // Col 1
0d, // Col 2
0d, // Col 2
0d, // Col 2
1d, // Col 2
0d, // Col 3
1d, // Col 3
2d, // Col 3
3d, // Col 3
1d };
final Matrix4 m = new Matrix4();
m.identity();
final Matrix4 out = m.setTranslation(new Vector3(1, 2, 3));
assertNotNull(out);
assertTrue(out == m);
final double[] result = m.getDoubleValues();
assertNotNull(result);
for (int i = 0; i < expected.length; ++i) {
assertEquals(expected[i], result[i], 1e-14);
}
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class Matrix4Test method testGetScalingNoArgs.
@Test
public void testGetScalingNoArgs() throws Exception {
final double[] from = new double[] { 1d, 0d, 0d, 0d, 0d, 2d, 0d, 0d, 0d, 0d, 3d, 0d, 0d, 0d, 0d, 1d };
final Vector3 expected = new Vector3(1, 2, 3);
final Matrix4 m = new Matrix4(from);
final Vector3 out = m.getScaling();
assertNotNull(out);
assertTrue(expected.equals(out, 1e-14));
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class Matrix4Test method testNegTranslate.
@Test
public void testNegTranslate() throws Exception {
final double[] expected = new double[] { // Col 0
1d, // Col 0
0d, // Col 0
0d, // Col 0
0d, // Col 1
0d, // Col 1
1d, // Col 1
0d, // Col 1
0d, // Col 2
0d, // Col 2
0d, // Col 2
1d, // Col 2
0d, // Col 3
-1d, // Col 3
-2d, // Col 3
-3d, // Col 3
1d };
final Matrix4 m = new Matrix4();
m.identity();
final Matrix4 out = m.negTranslate(new Vector3(1, 2, 3));
assertNotNull(out);
assertTrue(out == m);
final double[] result = m.getDoubleValues();
assertNotNull(result);
for (int i = 0; i < expected.length; ++i) {
assertEquals(expected[i], result[i], 1e-14);
}
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class Matrix4Test method testProjectAndCreateVector.
@Test
public void testProjectAndCreateVector() throws Exception {
final double[] m = new double[] { 1d, 0d, 0d, 0d, 0d, 1d, 0d, 0d, 0d, 0d, 1d, 1d, 0d, 0d, 0d, 0d };
Vector3 v = new Vector3(2d, 3d, 4d);
final Matrix4 matrix = new Matrix4(m);
final Vector3 out = matrix.projectAndCreateVector(v);
assertNotNull(out);
assertTrue(out != v);
assertEquals(0.5, out.x, 1e-14);
assertEquals(0.75, out.y, 1e-14);
assertEquals(1d, out.z, 1e-14);
}
Aggregations