use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class Vector3Test method testDistanceToFromDoublesXyz.
@Test
public void testDistanceToFromDoublesXyz() throws Exception {
final Vector3 v1 = new Vector3(0d, 1d, 2d);
final Vector3 v2 = new Vector3(3d, 5d, 7d);
final double distance1 = v1.distanceTo(3d, 5d, 7d);
final double distance2 = v2.distanceTo(0d, 1d, 2d);
assertEquals(7.07106781186548, distance1, 1e-14);
assertEquals(7.07106781186548, distance2, 1e-14);
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class Vector3Test method testCrossAndSet.
@Test
public void testCrossAndSet() throws Exception {
final Vector3 t = new Vector3();
final Vector3 u = new Vector3(1d, 2d, 3d);
final Vector3 v = new Vector3(4d, 5d, 6d);
final Vector3 out = t.crossAndSet(u, v);
assertNotNull(out);
assertTrue(out == t);
assertEquals(-3d, t.x, 0);
assertEquals(6d, t.y, 0);
assertEquals(-3d, t.z, 0);
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class Vector3Test method testSubtractAndCreate.
@Test
public void testSubtractAndCreate() throws Exception {
final Vector3 u = new Vector3(1.1d, 2.2d, 3.3d);
final Vector3 v = new Vector3(0.1d, 0.2d, 0.3d);
final Vector3 t = Vector3.subtractAndCreate(u, v);
assertNotNull(t);
assertEquals(1d, t.x, 0);
assertEquals(2d, t.y, 0);
assertEquals(3d, t.z, 0);
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class LoaderMD5Anim method buildFrameSkeleton.
private void buildFrameSkeleton(float[] frameData, Skeleton skeleton) {
for (int i = 0; i < mNumJoints; ++i) {
SkeletonJoint joint = new SkeletonJoint(mBaseFrame[i]);
SkeletonJoint jointInfo = mJoints[i];
joint.setParentIndex(jointInfo.getParentIndex());
int j = 0;
int startIndex = jointInfo.getStartIndex();
if ((jointInfo.getFlags() & 1) == 1)
joint.getPosition().x = frameData[startIndex + j++];
if ((jointInfo.getFlags() & 2) == 2)
joint.getPosition().z = frameData[startIndex + j++];
if ((jointInfo.getFlags() & 4) == 4)
joint.getPosition().y = frameData[startIndex + j++];
if ((jointInfo.getFlags() & 8) == 8)
joint.getOrientation().x = frameData[startIndex + j++];
if ((jointInfo.getFlags() & 16) == 16)
joint.getOrientation().z = frameData[startIndex + j++];
if ((jointInfo.getFlags() & 32) == 32)
joint.getOrientation().y = frameData[startIndex + j++];
joint.getOrientation().computeW();
if (// Has a parent joint
joint.getParentIndex() >= 0) {
SkeletonJoint parentJoint = skeleton.getJoint(joint.getParentIndex());
Vector3 rotPos = parentJoint.getOrientation().multiply(joint.getPosition());
//We don't clone here because nothing will be able to use the quaternion scratch before we do
joint.getPosition().setAll(Vector3.addAndCreate(parentJoint.getPosition(), rotPos));
joint.getOrientation().multiply(parentJoint.getOrientation());
joint.getOrientation().normalize();
}
skeleton.setJoint(i, joint);
}
}
use of org.rajawali3d.math.vector.Vector3 in project Rajawali by Rajawali.
the class LoaderMD5Mesh method calculateNormals.
private void calculateNormals() {
for (int i = 0; i < mNumMeshes; ++i) {
SkeletonMeshData mesh = mMeshes[i];
int numTriangles = mesh.numTriangles;
mesh.indices = new int[numTriangles * 3];
int index = 0;
for (int j = 0; j < numTriangles; ++j) {
int[] triangle = mesh.triangles[j];
int index0 = triangle[0];
int index1 = triangle[2];
int index2 = triangle[1];
mesh.indices[index++] = index0;
mesh.indices[index++] = index1;
mesh.indices[index++] = index2;
int index03 = index0 * 3;
int index13 = index1 * 3;
int index23 = index2 * 3;
Vector3 v0 = new Vector3(mesh.vertices[index03], mesh.vertices[index03 + 1], mesh.vertices[index03 + 2]);
Vector3 v1 = new Vector3(mesh.vertices[index13], mesh.vertices[index13 + 1], mesh.vertices[index13 + 2]);
Vector3 v2 = new Vector3(mesh.vertices[index23], mesh.vertices[index23 + 1], mesh.vertices[index23 + 2]);
Vector3 normal = Vector3.crossAndCreate(Vector3.subtractAndCreate(v2, v0), Vector3.subtractAndCreate(v1, v0));
normal.inverse();
mesh.boneVertices[index0].normal.add(normal);
mesh.boneVertices[index1].normal.add(normal);
mesh.boneVertices[index2].normal.add(normal);
}
int numVertices = mesh.numVertices;
if (mesh.normals == null)
mesh.normals = new float[numVertices * 3];
for (int j = 0; j < numVertices; ++j) {
BoneVertex vert = mesh.boneVertices[j];
Vector3 normal = vert.normal.clone();
vert.normal.normalize();
normal.normalize();
int normIndex = j * 3;
mesh.normals[normIndex] = (float) normal.x;
mesh.normals[normIndex + 1] = (float) normal.y;
mesh.normals[normIndex + 2] = (float) normal.z;
vert.normal.setAll(0, 0, 0);
// so the animated normal can be computed faster
for (int k = 0; k < vert.numWeights; ++k) {
BoneWeight weight = mesh.boneWeights[vert.weightIndex + k];
SkeletonJoint joint = mJoints[weight.jointIndex];
//We don't clone here because nothing will be able to use the quaternion scratch before we do
vert.normal.add(Vector3.scaleAndCreate(joint.getOrientation().multiply(normal), weight.weightValue));
}
}
}
}
Aggregations