Search in sources :

Example 21 with Matrix4f

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;
}
Also used : Matrix4f(com.jme3.math.Matrix4f) TempVars(com.jme3.util.TempVars)

Example 22 with Matrix4f

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++);
    }
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Uniform(com.jme3.shader.Uniform) PointLight(com.jme3.light.PointLight) SpotLight(com.jme3.light.SpotLight)

Example 23 with Matrix4f

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);
}
Also used : Matrix4f(com.jme3.math.Matrix4f) Renderer(com.jme3.renderer.Renderer)

Example 24 with Matrix4f

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;
}
Also used : TempVars(com.jme3.util.TempVars)

Example 25 with Matrix4f

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;
}
Also used : Matrix4f(com.jme3.math.Matrix4f)

Aggregations

Matrix4f (com.jme3.math.Matrix4f)36 TempVars (com.jme3.util.TempVars)24 Vector3f (com.jme3.math.Vector3f)15 FloatBuffer (java.nio.FloatBuffer)7 BoundingBox (com.jme3.bounding.BoundingBox)6 Transform (com.jme3.math.Transform)6 Bone (com.jme3.animation.Bone)4 CollisionResult (com.jme3.collision.CollisionResult)3 Spatial (com.jme3.scene.Spatial)3 BoundingVolume (com.jme3.bounding.BoundingVolume)2 Material (com.jme3.material.Material)2 Quaternion (com.jme3.math.Quaternion)2 Geometry (com.jme3.scene.Geometry)2 BoneContext (com.jme3.scene.plugins.blender.animations.BoneContext)2 Structure (com.jme3.scene.plugins.blender.file.Structure)2 FbxId (com.jme3.scene.plugins.fbx.file.FbxId)2 FrameBuffer (com.jme3.texture.FrameBuffer)2 Texture2D (com.jme3.texture.Texture2D)2 Picture (com.jme3.ui.Picture)2 ByteBuffer (java.nio.ByteBuffer)2