use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class TangentBinormalGenerator method processTriangle.
public static TriangleData processTriangle(int[] index, Vector3f[] v, Vector2f[] t) {
TempVars tmp = TempVars.get();
try {
Vector3f edge1 = tmp.vect1;
Vector3f edge2 = tmp.vect2;
Vector2f edge1uv = tmp.vect2d;
Vector2f edge2uv = tmp.vect2d2;
Vector3f tangent = tmp.vect3;
Vector3f binormal = tmp.vect4;
Vector3f normal = tmp.vect5;
t[1].subtract(t[0], edge1uv);
t[2].subtract(t[0], edge2uv);
float det = edge1uv.x * edge2uv.y - edge1uv.y * edge2uv.x;
boolean normalize = false;
if (Math.abs(det) < ZERO_TOLERANCE) {
log.log(Level.WARNING, "Colinear uv coordinates for triangle " + "[{0}, {1}, {2}]; tex0 = [{3}, {4}], " + "tex1 = [{5}, {6}], tex2 = [{7}, {8}]", new Object[] { index[0], index[1], index[2], t[0].x, t[0].y, t[1].x, t[1].y, t[2].x, t[2].y });
det = 1;
normalize = true;
}
v[1].subtract(v[0], edge1);
v[2].subtract(v[0], edge2);
tangent.set(edge1);
tangent.normalizeLocal();
binormal.set(edge2);
binormal.normalizeLocal();
if (Math.abs(Math.abs(tangent.dot(binormal)) - 1) < ZERO_TOLERANCE) {
log.log(Level.WARNING, "Vertices are on the same line " + "for triangle [{0}, {1}, {2}].", new Object[] { index[0], index[1], index[2] });
}
float factor = 1 / det;
tangent.x = (edge2uv.y * edge1.x - edge1uv.y * edge2.x) * factor;
tangent.y = (edge2uv.y * edge1.y - edge1uv.y * edge2.y) * factor;
tangent.z = (edge2uv.y * edge1.z - edge1uv.y * edge2.z) * factor;
if (normalize) {
tangent.normalizeLocal();
}
binormal.x = (edge1uv.x * edge2.x - edge2uv.x * edge1.x) * factor;
binormal.y = (edge1uv.x * edge2.y - edge2uv.x * edge1.y) * factor;
binormal.z = (edge1uv.x * edge2.z - edge2uv.x * edge1.z) * factor;
if (normalize) {
binormal.normalizeLocal();
}
tangent.cross(binormal, normal);
normal.normalizeLocal();
return new TriangleData(tangent.clone(), binormal.clone(), normal.clone());
} finally {
tmp.release();
}
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class BufferUtils method equals.
/**
* Checks to see if the given Vector2f is equals to the data stored in the
* buffer at the given data index.
*
* @param check
* the vector to check against - null will return false.
* @param buf
* the buffer to compare data with
* @param index
* the position (in terms of vectors, not floats) of the vector
* in the buffer to check against
* @return true if the data is equivalent, otherwise false.
*/
public static boolean equals(Vector2f check, FloatBuffer buf, int index) {
TempVars vars = TempVars.get();
Vector2f tempVec2 = vars.vect2d;
populateFromBuffer(tempVec2, buf, index);
boolean eq = tempVec2.equals(check);
vars.release();
return eq;
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class BufferUtils method createFloatBuffer.
// // -- VECTOR2F METHODS -- ////
/**
* Generate a new FloatBuffer using the given array of Vector2f objects. The
* FloatBuffer will be 2 * data.length long and contain the vector data as
* data[0].x, data[0].y, data[1].x... etc.
*
* @param data
* array of Vector2f objects to place into a new FloatBuffer
*/
public static FloatBuffer createFloatBuffer(Vector2f... data) {
if (data == null) {
return null;
}
FloatBuffer buff = createFloatBuffer(2 * data.length);
for (Vector2f element : data) {
if (element != null) {
buff.put(element.x).put(element.y);
} else {
buff.put(0).put(0);
}
}
buff.flip();
return buff;
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class BufferUtils method getVector2Array.
/**
* Generates a Vector2f array from the given FloatBuffer.
*
* @param buff
* the FloatBuffer to read from
* @return a newly generated array of Vector2f objects
*/
public static Vector2f[] getVector2Array(FloatBuffer buff) {
buff.clear();
Vector2f[] verts = new Vector2f[buff.limit() / 2];
for (int x = 0; x < verts.length; x++) {
Vector2f v = new Vector2f(buff.get(), buff.get());
verts[x] = v;
}
return verts;
}
use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.
the class TestAnisotropicFilter method simpleInitApp.
@Override
public void simpleInitApp() {
maxAniso = renderer.getLimits().get(Limits.TextureAnisotropy);
flyCam.setDragToRotate(true);
flyCam.setMoveSpeed(100);
cam.setLocation(new Vector3f(197.02617f, 4.6769195f, -194.89545f));
cam.setRotation(new Quaternion(0.07921988f, 0.8992258f, -0.18292196f, 0.38943136f));
Quad q = new Quad(1000, 1000);
q.scaleTextureCoordinates(new Vector2f(1000, 1000));
Geometry geom = new Geometry("quad", q);
geom.rotate(-FastMath.HALF_PI, 0, 0);
geom.setMaterial(createCheckerBoardMaterial(assetManager));
rootNode.attachChild(geom);
inputManager.addMapping("higher", new KeyTrigger(KeyInput.KEY_1));
inputManager.addMapping("lower", new KeyTrigger(KeyInput.KEY_2));
inputManager.addListener(this, "higher");
inputManager.addListener(this, "lower");
}
Aggregations