use of com.jme3.math.Matrix4f in project jmonkeyengine by jMonkeyEngine.
the class SimpleBatchNode method getTransformMatrix.
@Override
protected Matrix4f getTransformMatrix(Geometry g) {
// Compute the Local matrix for the geometry
cachedLocalMat.loadIdentity();
cachedLocalMat.setRotationQuaternion(g.localTransform.getRotation());
cachedLocalMat.setTranslation(g.localTransform.getTranslation());
TempVars vars = TempVars.get();
Matrix4f scaleMat = vars.tempMat4;
scaleMat.loadIdentity();
scaleMat.scale(g.localTransform.getScale());
cachedLocalMat.multLocal(scaleMat);
vars.release();
return cachedLocalMat;
}
use of com.jme3.math.Matrix4f in project jmonkeyengine by jMonkeyEngine.
the class StaticPassLightingLogic method updateLightListUniforms.
private void updateLightListUniforms(Matrix4f viewMatrix, Shader shader, LightList lights) {
Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
ambientColor.setValue(VarType.Vector4, getAmbientColor(lights, true, ambientLightColor));
Uniform lightData = shader.getUniform("g_LightData");
int totalSize = tempDirLights.size() * 2 + tempPointLights.size() * 2 + tempSpotLights.size() * 3;
lightData.setVector4Length(totalSize);
int index = 0;
for (DirectionalLight light : tempDirLights) {
ColorRGBA color = light.getColor();
tempDirection.set(light.getDirection());
transformDirection(viewMatrix, tempDirection);
lightData.setVector4InArray(color.r, color.g, color.b, 1f, index++);
lightData.setVector4InArray(tempDirection.x, tempDirection.y, tempDirection.z, 1f, index++);
}
for (PointLight light : tempPointLights) {
ColorRGBA color = light.getColor();
tempPosition.set(light.getPosition());
float invRadius = light.getInvRadius();
transformPosition(viewMatrix, tempPosition);
lightData.setVector4InArray(color.r, color.g, color.b, 1f, index++);
lightData.setVector4InArray(tempPosition.x, tempPosition.y, tempPosition.z, invRadius, index++);
}
for (SpotLight light : tempSpotLights) {
ColorRGBA color = light.getColor();
Vector3f pos = light.getPosition();
Vector3f dir = light.getDirection();
tempPosition.set(light.getPosition());
tempDirection.set(light.getDirection());
transformPosition(viewMatrix, tempPosition);
transformDirection(viewMatrix, tempDirection);
float invRange = light.getInvSpotRange();
float spotAngleCos = light.getPackedAngleCos();
lightData.setVector4InArray(color.r, color.g, color.b, 1f, index++);
lightData.setVector4InArray(tempPosition.x, tempPosition.y, tempPosition.z, invRange, index++);
lightData.setVector4InArray(tempDirection.x, tempDirection.y, tempDirection.z, spotAngleCos, index++);
}
}
use of com.jme3.math.Matrix4f in project jmonkeyengine by jMonkeyEngine.
the class StaticPassLightingLogic method render.
@Override
public void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights, int lastTexUnit) {
Renderer renderer = renderManager.getRenderer();
Matrix4f viewMatrix = renderManager.getCurrentCamera().getViewMatrix();
updateLightListUniforms(viewMatrix, shader, lights);
renderer.setShader(shader);
renderMeshFromGeometry(renderer, geometry);
}
use of com.jme3.math.Matrix4f in project jmonkeyengine by jMonkeyEngine.
the class Quaternion method toRotationMatrix.
/**
* <code>toRotationMatrix</code> converts this quaternion to a rotational
* matrix. The result is stored in result. 4th row and 4th column values are
* untouched. Note: the result is created from a normalized version of this quat.
*
* @param result
* The Matrix4f to store the result in.
* @return the rotation matrix representation of this quaternion.
*/
public Matrix4f toRotationMatrix(Matrix4f result) {
TempVars tempv = TempVars.get();
Vector3f originalScale = tempv.vect1;
result.toScaleVector(originalScale);
result.setScale(1, 1, 1);
float norm = norm();
// we explicitly test norm against one here, saving a division
// at the cost of a test and branch. Is it worth it?
float s = (norm == 1f) ? 2f : (norm > 0f) ? 2f / norm : 0;
// compute xs/ys/zs first to save 6 multiplications, since xs/ys/zs
// will be used 2-4 times each.
float xs = x * s;
float ys = y * s;
float zs = z * s;
float xx = x * xs;
float xy = x * ys;
float xz = x * zs;
float xw = w * xs;
float yy = y * ys;
float yz = y * zs;
float yw = w * ys;
float zz = z * zs;
float zw = w * zs;
// using s=2/norm (instead of 1/norm) saves 9 multiplications by 2 here
result.m00 = 1 - (yy + zz);
result.m01 = (xy - zw);
result.m02 = (xz + yw);
result.m10 = (xy + zw);
result.m11 = 1 - (xx + zz);
result.m12 = (yz - xw);
result.m20 = (xz - yw);
result.m21 = (yz + xw);
result.m22 = 1 - (xx + yy);
result.setScale(originalScale);
tempv.release();
return result;
}
use of com.jme3.math.Matrix4f in project jmonkeyengine by jMonkeyEngine.
the class FbxBindPose method buildTransform.
private static Matrix4f buildTransform(double[] transform) {
float[] m = new float[transform.length];
for (int i = 0; i < transform.length; ++i) m[i] = (float) transform[i];
Matrix4f matrix = new Matrix4f();
matrix.set(m, false);
return matrix;
}
Aggregations