本文整理汇总了Java中org.joml.Matrix4f类的典型用法代码示例。如果您正苦于以下问题:Java Matrix4f类的具体用法?Java Matrix4f怎么用?Java Matrix4f使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Matrix4f类属于org.joml包,在下文中一共展示了Matrix4f类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderTile
import org.joml.Matrix4f; //导入依赖的package包/类
public void renderTile(Tile tile, int x, int y, Shader shader, Matrix4f world, Camera camera) {
shader.bind();
if (tile_textures.containsKey(tile.getTexture() ))
tile_textures.get(tile.getTexture()).bind(0);
Matrix4f tile_position = new Matrix4f().translate(new Vector3f(x * 2, y * 2, 0));
Matrix4f target = new Matrix4f();
camera.getProjection().mul(world, target);
target.mul(tile_position);
shader.setUniform("sampler", 0);
shader.setUniform("projection", target);
model.render();
}
示例2: renderNonInstancedMeshes
import org.joml.Matrix4f; //导入依赖的package包/类
/**
*
* @param scene
*/
private void renderNonInstancedMeshes(Scene scene) {
this.defaultShaderProgram.setUniform(("isInstanced"), 0);
// Render each mesh
Map<Mesh, List<Entity>> mapMeshes = scene.getEntityMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
this.defaultShaderProgram.setUniform("material", mesh.getMaterial());
Texture texture = mesh.getMaterial().getTexture();
if (texture != null) {
this.defaultShaderProgram.setUniform(("numCols"), texture.getNumCols());
this.defaultShaderProgram.setUniform(("numRows"), texture.getNumRows());
}
this.shadowRenderer.bindTextures(GL_TEXTURE2);
mesh.renderList(mapMeshes.get(mesh), (Entity entity) -> {
this.defaultShaderProgram.setUniform(("selectedNonInstanced"), entity.isSelected() ? 1.0f : 0.0f);
Matrix4f modelMatrix = this.transformation.buildModelMatrix(entity);
this.defaultShaderProgram.setUniform(("modelNonInstancedMatrix"), modelMatrix);
if (entity instanceof AnimatedEntity) {
// TODO: If its animated render the shadows differently.
// Oskar Mendel - 2017-07-03
}
});
}
}
示例3: renderNonInstancedMeshes
import org.joml.Matrix4f; //导入依赖的package包/类
/**
*
* @param scene
* @param transformation
*/
public void renderNonInstancedMeshes(Scene scene, Transformation transformation) {
depthShaderProgram.setUniform(("isInstanced"), 0);
Map<Mesh, List<Entity>> mapMeshes = scene.getEntityMeshes();
for (Mesh mesh : mapMeshes.keySet()) {
mesh.renderList(mapMeshes.get(mesh), (Entity entity) -> {
Matrix4f modelMatrix = transformation.buildModelMatrix(entity);
depthShaderProgram.setUniform(("modelNonInstancedMatrix"), modelMatrix);
if (entity instanceof AnimatedEntity) {
// TODO: If its animated render the shadows differently.
// Oskar Mendel - 2017-07-01
}
});
}
}
示例4: ShadowCascade
import org.joml.Matrix4f; //导入依赖的package包/类
/**
*
* @param zNear
* @param zFar
*/
public ShadowCascade(float zNear, float zFar) {
this.zNear = zNear;
this.zFar = zFar;
this.projectionViewMatrix = new Matrix4f();
this.orthoProjectionMatrix = new Matrix4f();
this.lightViewMatrix = new Matrix4f();
this.centr = new Vector3f();
this.frustumCorners = new Vector3f[FRUSTUM_CORNERS];
for (int i = 0; i < FRUSTUM_CORNERS; i++) {
frustumCorners[i] = new Vector3f();
}
this.tmpVec = new Vector4f();
}
示例5: ConsoleBase
import org.joml.Matrix4f; //导入依赖的package包/类
public ConsoleBase(Console console, Transform transform, Asset<TextureAtlas> textureAtlas, int width, int height)
{
this.console = console;
this.transform = transform;
this.view = new RasterizedView(width, height).setTextureAtlas(textureAtlas);
this.background = new RasterizedView(width, height).setTextureAtlas(textureAtlas);
this.backgroundOffset = new Matrix4f().translate(0.0625F, -0.0625F, 0);
this.view.forEach((vector2ic, character, integer) ->
this.view.draw(vector2ic.x(), vector2ic.y(), 'A', 0xFFFFFF));
this.background.forEach((vector2ic, character, integer) ->
this.background.draw(vector2ic.x(), vector2ic.y(), 'A', 0x888888));
//this.view.clear((byte) 0, 0xFFFFFF);
//this.background.clear((byte) 0, 0x888888);
Console.getConsole().getInputEngine().getDefaultContext()
.registerEvent("newline",
Console.getConsole().getInputEngine().getKeyboard().getButton(GLFW.GLFW_KEY_ENTER)::getAction);
this.textHandler = Console.getConsole().getInputEngine().getText();
this.initialize();
}
示例6: selectGameItem
import org.joml.Matrix4f; //导入依赖的package包/类
public boolean selectGameItem(GameItem[] gameItems, Window window, Vector2d mousePos, Camera camera) {
// Transform mouse coordinates into normalized spaze [-1, 1]
int wdwWitdh = window.getWidth();
int wdwHeight = window.getHeight();
float x = (float) (2 * mousePos.x) / (float) wdwWitdh - 1.0f;
float y = 1.0f - (float) (2 * mousePos.y) / (float) wdwHeight;
float z = -1.0f;
invProjectionMatrix.set(window.getProjectionMatrix());
invProjectionMatrix.invert();
tmpVec.set(x, y, z, 1.0f);
tmpVec.mul(invProjectionMatrix);
tmpVec.z = -1.0f;
tmpVec.w = 0.0f;
Matrix4f viewMatrix = camera.getViewMatrix();
invViewMatrix.set(viewMatrix);
invViewMatrix.invert();
tmpVec.mul(invViewMatrix);
mouseDir.set(tmpVec.x, tmpVec.y, tmpVec.z);
return selectGameItem(gameItems, camera.getPosition(), mouseDir);
}
示例7: process
import org.joml.Matrix4f; //导入依赖的package包/类
/**
* 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, Vector3f 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;
}
示例8: renderScene
import org.joml.Matrix4f; //导入依赖的package包/类
public void renderScene(Window window, Camera camera, Scene scene) {
sceneShaderProgram.bind();
Matrix4f projectionMatrix = window.getProjectionMatrix();
sceneShaderProgram.setUniform("projectionMatrix", projectionMatrix);
Matrix4f orthoProjMatrix = transformation.getOrthoProjectionMatrix();
sceneShaderProgram.setUniform("orthoProjectionMatrix", orthoProjMatrix);
Matrix4f lightViewMatrix = transformation.getLightViewMatrix();
Matrix4f viewMatrix = camera.getViewMatrix();
SceneLight sceneLight = scene.getSceneLight();
renderLights(viewMatrix, sceneLight);
sceneShaderProgram.setUniform("fog", scene.getFog());
sceneShaderProgram.setUniform("texture_sampler", 0);
sceneShaderProgram.setUniform("normalMap", 1);
sceneShaderProgram.setUniform("shadowMap", 2);
sceneShaderProgram.setUniform("renderShadow", scene.isRenderShadows() ? 1 : 0);
renderNonInstancedMeshes(scene, sceneShaderProgram, viewMatrix, lightViewMatrix);
renderInstancedMeshes(scene, sceneShaderProgram, viewMatrix, lightViewMatrix);
sceneShaderProgram.unbind();
}
示例9: World
import org.joml.Matrix4f; //导入依赖的package包/类
public World() {
width = 64;
height = 64;
scale = 16;
tiles = new byte[width * height];
bounding_boxes = new AABB[width * height];
world = new Matrix4f().setTranslation(new Vector3f(0));
world.scale(scale);
}
示例10: setUniform
import org.joml.Matrix4f; //导入依赖的package包/类
public void setUniform(String name, Matrix4f value) {
int location = glGetUniformLocation(program, name);
// Allows us to hold in all the4 information regarding translation, dilation, and rotations
FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
value.get(buffer);
if (location != -1)
glUniformMatrix4fv(location, false, buffer);
}
示例11: renderTile
import org.joml.Matrix4f; //导入依赖的package包/类
public void renderTile(Tile tile, int x, int y, Shader shader, Matrix4f world, Camera cam) {
shader.bind();
if (tileTextures.containsKey(tile.getTexture())) tileTextures.get(tile.getTexture()).bind(0);
Matrix4f tile_pos = new Matrix4f().translate(new Vector3f(x * 2, y * 2, 0));
Matrix4f target = new Matrix4f();
cam.getProjection().mul(world, target);
target.mul(tile_pos);
shader.setUniform("sampler", 0);
shader.setUniform("projection", target);
tileModel.render();
}
示例12: renderSkyBox
import org.joml.Matrix4f; //导入依赖的package包/类
/**
*
* @param screen
* @param camera
* @param scene
*/
private void renderSkyBox(Screen screen, Camera camera, Scene scene) {
SkyBox skyBox = scene.getSkyBox();
if (skyBox != null) {
this.skyBoxShaderProgram.use();
this.skyBoxShaderProgram.setUniform(("texture_sampler"), 0);
Matrix4f projectionMatrix = screen.getProjectionMatrix();
this.skyBoxShaderProgram.setUniform(("projectionMatrix"), projectionMatrix);
Matrix4f viewMatrix = camera.getViewMatrix();
float m30 = viewMatrix.m30();
viewMatrix.m30(0);
float m31 = viewMatrix.m31();
viewMatrix.m31(0);
float m32 = viewMatrix.m32();
viewMatrix.m32(0);
Mesh mesh = skyBox.getMesh();
Matrix4f modelViewMatrix = this.transformation.buildModelViewMatrix(skyBox, viewMatrix);
this.skyBoxShaderProgram.setUniform(("modelViewMatrix"), modelViewMatrix);
this.skyBoxShaderProgram.setUniform(("ambientLight"), scene.getSceneLight().getAmbientLight());
this.skyBoxShaderProgram.setUniform(("color"), mesh.getMaterial().getAmbientColor());
this.skyBoxShaderProgram.setUniform(("hasTexture"), mesh.getMaterial().isTextured() ? 1 : 0);
mesh.render();
viewMatrix.m30(m30);
viewMatrix.m31(m31);
viewMatrix.m32(m32);
this.skyBoxShaderProgram.stopUse();
}
}
示例13: renderScene
import org.joml.Matrix4f; //导入依赖的package包/类
/**
*
* @param screen
* @param camera
* @param scene
*/
private void renderScene(Screen screen, Camera camera, Scene scene) {
this.defaultShaderProgram.use();
Matrix4f viewMatrix = camera.getViewMatrix();
Matrix4f projectionMatrix = screen.getProjectionMatrix();
this.defaultShaderProgram.setUniform(("viewMatrix"), viewMatrix);
this.defaultShaderProgram.setUniform(("projectionMatrix"), projectionMatrix);
List<ShadowCascade> shadowCascades = this.shadowRenderer.getShadowCascades();
for (int i = 0; i < ShadowRenderer.NUM_CASCADES; i++) {
ShadowCascade shadowCascade = shadowCascades.get(i);
this.defaultShaderProgram.setUniform("orthoProjectionMatrix", shadowCascade.getOrthoProjectionMatrix(), i);
this.defaultShaderProgram.setUniform("cascadeFarPlanes", ShadowRenderer.CASCADE_SPLITS[i], i);
this.defaultShaderProgram.setUniform("lightViewMatrix", shadowCascade.getLightViewMatrix(), i);
}
SceneLight sceneLight = scene.getSceneLight();
renderLights(viewMatrix, sceneLight);
this.defaultShaderProgram.setUniform("fog", scene.getFog());
this.defaultShaderProgram.setUniform(("texture_sampler"), 0);
this.defaultShaderProgram.setUniform(("normalMap"), 1);
int start = 2;
for (int i = 0; i < ShadowRenderer.NUM_CASCADES; i++) {
this.defaultShaderProgram.setUniform(("shadowMap_" + i), start + i);
}
this.defaultShaderProgram.setUniform(("renderShadow"), scene.isRenderShadows() ? 1 : 0);
renderNonInstancedMeshes(scene);
renderInstancedMeshes(scene, viewMatrix);
this.defaultShaderProgram.stopUse();
}
示例14: setUniform
import org.joml.Matrix4f; //导入依赖的package包/类
/**
* Sets the uniform variable at the specified location.
*
* @param location - Uniform location.
* @param value - Value to set at the specified location.
*/
public void setUniform(String location, Matrix4f value) {
try (MemoryStack stack = MemoryStack.stackPush()) {
FloatBuffer floatBuffer = stack.mallocFloat(4*4);
value.get(floatBuffer);
glUniformMatrix4fv(uniformLocations.get(location), false, floatBuffer);
}
}
示例15: GameItem
import org.joml.Matrix4f; //导入依赖的package包/类
public GameItem(Mesh mesh) {
this.mesh = mesh;
position = new Vector3f(0, 0, 0);
scale = 1;
rotation = new Matrix4f();
rotation.identity();
}