org.joml.Vector4f Java Examples

The following examples show how to use org.joml.Vector4f. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MD5Loader.java    From lwjglbook with Apache License 2.0 6 votes vote down vote up
private static void handleTexture(Mesh mesh, MD5Mesh md5Mesh, Vector4f defaultColour) throws Exception {
    String texturePath = md5Mesh.getTexture();
    if (texturePath != null && texturePath.length() > 0) {
        Texture texture = new Texture(texturePath);
        Material material = new Material(texture);

        // Handle normal Maps;
        int pos = texturePath.lastIndexOf(".");
        if (pos > 0) {
            String basePath = texturePath.substring(0, pos);
            String extension = texturePath.substring(pos, texturePath.length());
            String normalMapFileName = basePath + "_local" + extension;
            if (Utils.existsResourceFile(normalMapFileName)) {
                Texture normalMap = new Texture(normalMapFileName);
                material.setNormalMap(normalMap);
            }
        }
        mesh.setMaterial(material);
    } else {
        mesh.setMaterial(new Material(defaultColour, 1));
    }
}
 
Example #2
Source File: MD5Loader.java    From lwjglbook with Apache License 2.0 6 votes vote down vote up
private static void handleTexture(Mesh mesh, MD5Mesh md5Mesh, Vector4f defaultColour) throws Exception {
    String texturePath = md5Mesh.getTexture();
    if (texturePath != null && texturePath.length() > 0) {
        Texture texture = new Texture(texturePath);
        Material material = new Material(texture);

        // Handle normal Maps;
        int pos = texturePath.lastIndexOf(".");
        if (pos > 0) {
            String basePath = texturePath.substring(0, pos);
            String extension = texturePath.substring(pos, texturePath.length());
            String normalMapFileName = basePath + "_local" + extension;
            if (Utils.existsResourceFile(normalMapFileName)) {
                Texture normalMap = new Texture(normalMapFileName);
                material.setNormalMap(normalMap);
            }
        }
        mesh.setMaterial(material);
    } else {
        mesh.setMaterial(new Material(defaultColour, 1));
    }
}
 
Example #3
Source File: MD5Loader.java    From lwjglbook with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs and AnimGameItem instace based on a MD5 Model an MD5 Animation
 *
 * @param md5Model The MD5 Model
 * @param animModel The MD5 Animation
 * @param defaultColour Default colour to use if there are no textures
 * @return
 * @throws Exception
 */
public static AnimGameItem process(MD5Model md5Model, MD5AnimModel animModel, Vector4f defaultColour) throws Exception {
    List<Matrix4f> invJointMatrices = calcInJointMatrices(md5Model);
    List<AnimatedFrame> animatedFrames = processAnimationFrames(md5Model, animModel, invJointMatrices);

    List<Mesh> list = new ArrayList<>();
    for (MD5Mesh md5Mesh : md5Model.getMeshes()) {
        Mesh mesh = generateMesh(md5Model, md5Mesh);
        handleTexture(mesh, md5Mesh, defaultColour);
        list.add(mesh);
    }

    Mesh[] meshes = new Mesh[list.size()];
    meshes = list.toArray(meshes);

    AnimGameItem result = new AnimGameItem(meshes, animatedFrames, invJointMatrices);
    return result;
}
 
Example #4
Source File: MouseBoxSelectionDetector.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public MouseBoxSelectionDetector() {
    super();
    invProjectionMatrix = new Matrix4f();
    invViewMatrix = new Matrix4f();
    mouseDir = new Vector3f();
    tmpVec = new Vector4f();
}
 
Example #5
Source File: ShadowCascade.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public ShadowCascade(float zNear, float zFar) {
    this.zNear = zNear;
    this.zFar = zFar;
    this.projViewMatrix = new Matrix4f();
    this.orthoProjMatrix = new Matrix4f();
    this.centroid = new Vector3f();
    this.lightViewMatrix = new Matrix4f();
    this.frustumCorners = new Vector3f[FRUSTUM_CORNERS];
    for (int i = 0; i < FRUSTUM_CORNERS; i++) {
        frustumCorners[i] = new Vector3f();
    }
    tmpVec = new Vector4f();
}
 
Example #6
Source File: Material.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public Material(Vector4f ambientColour, Vector4f diffuseColour, Vector4f specularColour, Texture texture, float reflectance) {
    this.ambientColour = ambientColour;
    this.diffuseColour = diffuseColour;
    this.specularColour = specularColour;
    this.texture = texture;
    this.reflectance = reflectance;
}
 
Example #7
Source File: Material.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public Material(Vector4f ambientColour, Vector4f diffuseColour, Vector4f specularColour, Texture texture, float reflectance) {
    this.ambientColour = ambientColour;
    this.diffuseColour = diffuseColour;
    this.specularColour = specularColour;
    this.texture = texture;
    this.reflectance = reflectance;
}
 
Example #8
Source File: MouseBoxSelectionDetector.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public MouseBoxSelectionDetector() {
    super();
    invProjectionMatrix = new Matrix4f();
    invViewMatrix = new Matrix4f();
    mouseDir = new Vector3f();
    tmpVec = new Vector4f();
}
 
Example #9
Source File: DummyGame.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
@Override
public void init(Window window) throws Exception {
    renderer.init(window);

    scene = new Scene();

    Mesh[] houseMesh = StaticMeshesLoader.load("models/house/house.obj", "models/house");
    GameItem house = new GameItem(houseMesh);

    Mesh[] terrainMesh = StaticMeshesLoader.load("models/terrain/terrain.obj", "models/terrain");
    GameItem terrain = new GameItem(terrainMesh);
    terrain.setScale(100.0f);

    scene.setGameItems(new GameItem[]{house, terrain});

    // Shadows
    scene.setRenderShadows(true);

    // Fog
    Vector3f fogColour = new Vector3f(0.5f, 0.5f, 0.5f);
    scene.setFog(new Fog(true, fogColour, 0.02f));

    // Setup  SkyBox
    float skyBoxScale = 100.0f;
    SkyBox skyBox = new SkyBox("models/skybox.obj", new Vector4f(0.65f, 0.65f, 0.65f, 1.0f));
    skyBox.setScale(skyBoxScale);
    scene.setSkyBox(skyBox);

    // Setup Lights
    setupLights();

    camera.getPosition().x = -17.0f;
    camera.getPosition().y =  17.0f;
    camera.getPosition().z = -30.0f;
    camera.getRotation().x = 20.0f;
    camera.getRotation().y = 140.f;
}
 
Example #10
Source File: Material.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public Material(Vector4f ambientColour, Vector4f diffuseColour, Vector4f specularColour, Texture texture, float reflectance) {
    this.ambientColour = ambientColour;
    this.diffuseColour = diffuseColour;
    this.specularColour = specularColour;
    this.texture = texture;
    this.reflectance = reflectance;
}
 
Example #11
Source File: Material.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public Material(Vector4f ambientColour, Vector4f diffuseColour, Vector4f specularColour, Texture texture, float reflectance) {
    this.ambientColour = ambientColour;
    this.diffuseColour = diffuseColour;
    this.specularColour = specularColour;
    this.texture = texture;
    this.reflectance = reflectance;
}
 
Example #12
Source File: Material.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public Material(Vector4f ambientColour, Vector4f diffuseColour, Vector4f specularColour, Texture texture, float reflectance) {
    this.ambientColour = ambientColour;
    this.diffuseColour = diffuseColour;
    this.specularColour = specularColour;
    this.texture = texture;
    this.reflectance = reflectance;
}
 
Example #13
Source File: DummyGame.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
@Override
public void init(Window window) throws Exception {
    renderer.init(window);

    scene = new Scene();

    float reflectance = 1f;

    Mesh quadMesh = OBJLoader.loadMesh("/models/plane.obj");
    Material quadMaterial = new Material(new Vector4f(0.0f, 0.0f, 1.0f, 1.0f), reflectance);
    quadMesh.setMaterial(quadMaterial);
    GameItem quadGameItem = new GameItem(quadMesh);
    quadGameItem.setPosition(0, 0, 0);
    quadGameItem.setScale(2.5f);

    // Setup  GameItems
    MD5Model md5Meshodel = MD5Model.parse("/models/monster.md5mesh");
    GameItem monster = MD5Loader.process(md5Meshodel, new Vector4f(1, 1, 1, 1));
    monster.setScale(0.05f);
    monster.setRotation(90, 0, 0);

    scene.setGameItems(new GameItem[] { quadGameItem, monster} );

    // Setup Lights
    setupLights();

    camera.getPosition().x = 0.25f;
    camera.getPosition().y = 6.5f;
    camera.getPosition().z = 6.5f;
    camera.getRotation().x = 25;
    camera.getRotation().y = -1;
}
 
Example #14
Source File: ShadowCascade.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public ShadowCascade(float zNear, float zFar) {
    this.zNear = zNear;
    this.zFar = zFar;
    this.projViewMatrix = new Matrix4f();
    this.orthoProjMatrix = new Matrix4f();
    this.centroid = new Vector3f();
    this.lightViewMatrix = new Matrix4f();
    this.frustumCorners = new Vector3f[FRUSTUM_CORNERS];
    for (int i = 0; i < FRUSTUM_CORNERS; i++) {
        frustumCorners[i] = new Vector3f();
    }
    tmpVec = new Vector4f();
}
 
Example #15
Source File: SkyBox.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public SkyBox(String objModel, Vector4f colour) throws Exception {
    super();
    Mesh skyBoxMesh = OBJLoader.loadMesh(objModel);
    Material material = new Material(colour, 0);
    skyBoxMesh.setMaterial(material);
    setMesh(skyBoxMesh);
    setPosition(0, 0, 0);
}
 
Example #16
Source File: Material.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public Material(Vector4f ambientColour, Vector4f diffuseColour, Vector4f specularColour, Texture texture, float reflectance) {
    this.ambientColour = ambientColour;
    this.diffuseColour = diffuseColour;
    this.specularColour = specularColour;
    this.texture = texture;
    this.reflectance = reflectance;
}
 
Example #17
Source File: SkyBox.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public SkyBox(String objModel, Vector4f colour) throws Exception {
    super();
    Mesh skyBoxMesh = OBJLoader.loadMesh(objModel);
    Material material = new Material(colour, 0);
    skyBoxMesh.setMaterial(material);
    setMesh(skyBoxMesh);
    setPosition(0, 0, 0);
}
 
Example #18
Source File: Material.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public Material(Vector4f ambientColour, Vector4f diffuseColour, Vector4f specularColour, Texture texture, float reflectance) {
    this.ambientColour = ambientColour;
    this.diffuseColour = diffuseColour;
    this.specularColour = specularColour;
    this.texture = texture;
    this.reflectance = reflectance;
}
 
Example #19
Source File: Material.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public Material(Vector4f ambientColour, Vector4f diffuseColour, Vector4f specularColour, Texture texture, float reflectance) {
    this.ambientColour = ambientColour;
    this.diffuseColour = diffuseColour;
    this.specularColour = specularColour;
    this.texture = texture;
    this.reflectance = reflectance;
}
 
Example #20
Source File: Material.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public Material(Vector4f ambientColour, Vector4f diffuseColour, Vector4f specularColour, Texture texture, float reflectance) {
    this.ambientColour = ambientColour;
    this.diffuseColour = diffuseColour;
    this.specularColour = specularColour;
    this.texture = texture;
    this.reflectance = reflectance;
}
 
Example #21
Source File: Material.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public Material(Vector4f ambientColour, Vector4f diffuseColour, Vector4f specularColour, Texture texture, float reflectance) {
    this.ambientColour = ambientColour;
    this.diffuseColour = diffuseColour;
    this.specularColour = specularColour;
    this.texture = texture;
    this.reflectance = reflectance;
}
 
Example #22
Source File: Material.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public Material(Vector4f ambientColour, Vector4f diffuseColour, Vector4f specularColour, Texture texture, float reflectance) {
    this.ambientColour = ambientColour;
    this.diffuseColour = diffuseColour;
    this.specularColour = specularColour;
    this.texture = texture;
    this.reflectance = reflectance;
}
 
Example #23
Source File: SkyBox.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public SkyBox(String objModel, Vector4f colour) throws Exception {
    super();
    Mesh skyBoxMesh = OBJLoader.loadMesh(objModel);
    Material material = new Material(colour, 0);
    skyBoxMesh.setMaterial(material);
    setMesh(skyBoxMesh);
    setPosition(0, 0, 0);
}
 
Example #24
Source File: ShaderProgram.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
public void setUniform(String uniformName, Vector4f value) {
    glUniform4f(uniforms.get(uniformName), value.x, value.y, value.z, value.w);
}
 
Example #25
Source File: Material.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
public void setDiffuseColour(Vector4f diffuseColour) {
    this.diffuseColour = diffuseColour;
}
 
Example #26
Source File: Material.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
public Vector4f getDiffuseColour() {
    return diffuseColour;
}
 
Example #27
Source File: Material.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
public Vector4f getAmbientColour() {
    return ambientColour;
}
 
Example #28
Source File: Material.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
public Vector4f getDiffuseColour() {
    return diffuseColour;
}
 
Example #29
Source File: Material.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
public Material(Vector4f colour, float reflectance) {
    this(colour, colour, colour, null, reflectance);
}
 
Example #30
Source File: Material.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
public Vector4f getSpecularColour() {
    return specularColour;
}