use of org.lwjgl.util.vector.Matrix4f in project lwjgl by LWJGL.
the class GLMatrix method glLoadIdentity.
public static void glLoadIdentity() {
final Matrix4f m = getCurrentMatrix();
m.setIdentity();
}
use of org.lwjgl.util.vector.Matrix4f in project Galacticraft by micdoodle8.
the class GuiCelestialSelection method drawCelestialBodies.
public HashMap<CelestialBody, Matrix4f> drawCelestialBodies(Matrix4f worldMatrix) {
GL11.glColor3f(1, 1, 1);
FloatBuffer fb = BufferUtils.createFloatBuffer(16 * Float.SIZE);
HashMap<CelestialBody, Matrix4f> matrixMap = Maps.newHashMap();
for (SolarSystem solarSystem : GalaxyRegistry.getRegisteredSolarSystems().values()) {
Star star = solarSystem.getMainStar();
if (star != null && star.getBodyIcon() != null) {
GL11.glPushMatrix();
Matrix4f worldMatrix0 = new Matrix4f(worldMatrix);
Matrix4f.translate(this.getCelestialBodyPosition(star), worldMatrix0, worldMatrix0);
Matrix4f worldMatrix1 = new Matrix4f();
Matrix4f.rotate((float) Math.toRadians(45), new Vector3f(0, 0, 1), worldMatrix1, worldMatrix1);
Matrix4f.rotate((float) Math.toRadians(-55), new Vector3f(1, 0, 0), worldMatrix1, worldMatrix1);
worldMatrix1 = Matrix4f.mul(worldMatrix0, worldMatrix1, worldMatrix1);
fb.rewind();
worldMatrix1.store(fb);
fb.flip();
GL11.glMultMatrix(fb);
float alpha = 1.0F;
if (this.selectedBody != null && this.selectedBody != star && this.isZoomed()) {
alpha = 1.0F - Math.min(this.ticksSinceSelection / 25.0F, 1.0F);
}
if (this.selectedBody != null && this.isZoomed()) {
if (star != this.selectedBody) {
alpha = 1.0F - Math.min(this.ticksSinceSelection / 25.0F, 1.0F);
if (!(this.lastSelectedBody instanceof Star) && this.lastSelectedBody != null) {
alpha = 0.0F;
}
}
}
if (alpha != 0) {
CelestialBodyRenderEvent.Pre preEvent = new CelestialBodyRenderEvent.Pre(star, star.getBodyIcon(), 8);
MinecraftForge.EVENT_BUS.post(preEvent);
GL11.glColor4f(1, 1, 1, alpha);
if (preEvent.celestialBodyTexture != null) {
this.mc.renderEngine.bindTexture(preEvent.celestialBodyTexture);
}
if (!preEvent.isCanceled()) {
int size = getWidthForCelestialBodyStatic(star);
if (star == this.selectedBody && this.selectionState == EnumSelection.SELECTED) {
size /= 2;
size *= 3;
}
this.drawTexturedModalRect(-size / 2, -size / 2, size, size, 0, 0, preEvent.textureSize, preEvent.textureSize, false, false, preEvent.textureSize, preEvent.textureSize);
matrixMap.put(star, worldMatrix1);
}
CelestialBodyRenderEvent.Post postEvent = new CelestialBodyRenderEvent.Post(star);
MinecraftForge.EVENT_BUS.post(postEvent);
}
fb.clear();
GL11.glPopMatrix();
}
}
for (Planet planet : GalaxyRegistry.getRegisteredPlanets().values()) {
if (planet.getBodyIcon() != null) {
GL11.glPushMatrix();
Matrix4f worldMatrix0 = new Matrix4f(worldMatrix);
Matrix4f.translate(this.getCelestialBodyPosition(planet), worldMatrix0, worldMatrix0);
Matrix4f worldMatrix1 = new Matrix4f();
Matrix4f.rotate((float) Math.toRadians(45), new Vector3f(0, 0, 1), worldMatrix1, worldMatrix1);
Matrix4f.rotate((float) Math.toRadians(-55), new Vector3f(1, 0, 0), worldMatrix1, worldMatrix1);
worldMatrix1 = Matrix4f.mul(worldMatrix0, worldMatrix1, worldMatrix1);
fb.rewind();
worldMatrix1.store(fb);
fb.flip();
GL11.glMultMatrix(fb);
float alpha = 1.0F;
if ((this.selectedBody instanceof IChildBody && ((IChildBody) this.selectedBody).getParentPlanet() != planet) || (this.selectedBody instanceof Planet && this.selectedBody != planet && this.isZoomed())) {
if (this.lastSelectedBody == null && !(this.selectedBody instanceof IChildBody)) {
alpha = 1.0F - Math.min(this.ticksSinceSelection / 25.0F, 1.0F);
} else {
alpha = 0.0F;
}
}
if (alpha != 0) {
CelestialBodyRenderEvent.Pre preEvent = new CelestialBodyRenderEvent.Pre(planet, planet.getBodyIcon(), 12);
MinecraftForge.EVENT_BUS.post(preEvent);
GL11.glColor4f(1, 1, 1, alpha);
if (preEvent.celestialBodyTexture != null) {
this.mc.renderEngine.bindTexture(preEvent.celestialBodyTexture);
}
if (!preEvent.isCanceled()) {
int size = getWidthForCelestialBodyStatic(planet);
// Celestial body textures are 12x12 in a 16x16 .png
this.drawTexturedModalRect(-size / 2, -size / 2, size, size, 0, 0, preEvent.textureSize, preEvent.textureSize, false, false, 16, 16);
matrixMap.put(planet, worldMatrix1);
}
CelestialBodyRenderEvent.Post postEvent = new CelestialBodyRenderEvent.Post(planet);
MinecraftForge.EVENT_BUS.post(postEvent);
}
fb.clear();
GL11.glPopMatrix();
}
}
if (this.selectedBody != null) {
Matrix4f worldMatrix0 = new Matrix4f(worldMatrix);
for (Moon moon : GalaxyRegistry.getRegisteredMoons().values()) {
if ((moon == this.selectedBody || (moon.getParentPlanet() == this.selectedBody && this.selectionState != EnumSelection.SELECTED)) && (this.ticksSinceSelection > 35 || this.selectedBody == moon || (this.lastSelectedBody instanceof Moon && GalaxyRegistry.getMoonsForPlanet(((Moon) this.lastSelectedBody).getParentPlanet()).contains(moon))) || getSiblings(this.selectedBody).contains(moon)) {
GL11.glPushMatrix();
Matrix4f worldMatrix1 = new Matrix4f(worldMatrix0);
Matrix4f.translate(this.getCelestialBodyPosition(moon), worldMatrix1, worldMatrix1);
Matrix4f worldMatrix2 = new Matrix4f();
Matrix4f.rotate((float) Math.toRadians(45), new Vector3f(0, 0, 1), worldMatrix2, worldMatrix2);
Matrix4f.rotate((float) Math.toRadians(-55), new Vector3f(1, 0, 0), worldMatrix2, worldMatrix2);
Matrix4f.scale(new Vector3f(0.25F, 0.25F, 1.0F), worldMatrix2, worldMatrix2);
worldMatrix2 = Matrix4f.mul(worldMatrix1, worldMatrix2, worldMatrix2);
fb.rewind();
worldMatrix2.store(fb);
fb.flip();
GL11.glMultMatrix(fb);
CelestialBodyRenderEvent.Pre preEvent = new CelestialBodyRenderEvent.Pre(moon, moon.getBodyIcon(), 8);
MinecraftForge.EVENT_BUS.post(preEvent);
GL11.glColor4f(1, 1, 1, 1);
if (preEvent.celestialBodyTexture != null) {
this.mc.renderEngine.bindTexture(preEvent.celestialBodyTexture);
}
if (!preEvent.isCanceled()) {
int size = getWidthForCelestialBodyStatic(moon);
this.drawTexturedModalRect(-size / 2, -size / 2, size, size, 0, 0, preEvent.textureSize, preEvent.textureSize, false, false, preEvent.textureSize, preEvent.textureSize);
matrixMap.put(moon, worldMatrix1);
}
CelestialBodyRenderEvent.Post postEvent = new CelestialBodyRenderEvent.Post(moon);
MinecraftForge.EVENT_BUS.post(postEvent);
fb.clear();
GL11.glPopMatrix();
}
}
}
if (this.selectedBody != null) {
Matrix4f worldMatrix0 = new Matrix4f(worldMatrix);
for (Satellite satellite : GalaxyRegistry.getRegisteredSatellites().values()) {
if (this.possibleBodies != null && this.possibleBodies.contains(satellite)) {
if ((satellite == this.selectedBody || (satellite.getParentPlanet() == this.selectedBody && this.selectionState != EnumSelection.SELECTED)) && (this.ticksSinceSelection > 35 || this.selectedBody == satellite || (this.lastSelectedBody instanceof Satellite && GalaxyRegistry.getSatellitesForCelestialBody(((Satellite) this.lastSelectedBody).getParentPlanet()).contains(satellite)))) {
GL11.glPushMatrix();
Matrix4f worldMatrix1 = new Matrix4f(worldMatrix0);
Matrix4f.translate(this.getCelestialBodyPosition(satellite), worldMatrix1, worldMatrix1);
Matrix4f worldMatrix2 = new Matrix4f();
Matrix4f.rotate((float) Math.toRadians(45), new Vector3f(0, 0, 1), worldMatrix2, worldMatrix2);
Matrix4f.rotate((float) Math.toRadians(-55), new Vector3f(1, 0, 0), worldMatrix2, worldMatrix2);
Matrix4f.scale(new Vector3f(0.25F, 0.25F, 1.0F), worldMatrix2, worldMatrix2);
worldMatrix2 = Matrix4f.mul(worldMatrix1, worldMatrix2, worldMatrix2);
fb.rewind();
worldMatrix2.store(fb);
fb.flip();
GL11.glMultMatrix(fb);
CelestialBodyRenderEvent.Pre preEvent = new CelestialBodyRenderEvent.Pre(satellite, satellite.getBodyIcon(), 8);
MinecraftForge.EVENT_BUS.post(preEvent);
GL11.glColor4f(1, 1, 1, 1);
this.mc.renderEngine.bindTexture(preEvent.celestialBodyTexture);
if (!preEvent.isCanceled()) {
int size = getWidthForCelestialBodyStatic(satellite);
this.drawTexturedModalRect(-size / 2, -size / 2, size, size, 0, 0, preEvent.textureSize, preEvent.textureSize, false, false, preEvent.textureSize, preEvent.textureSize);
matrixMap.put(satellite, worldMatrix1);
}
CelestialBodyRenderEvent.Post postEvent = new CelestialBodyRenderEvent.Post(satellite);
MinecraftForge.EVENT_BUS.post(postEvent);
fb.clear();
GL11.glPopMatrix();
}
}
}
}
return matrixMap;
}
use of org.lwjgl.util.vector.Matrix4f in project j6dof-flight-sim by chris-ali.
the class EntityRenderer method prepareInstance.
private void prepareInstance(Entity entity) {
Matrix4f transformationMatrix = RenderingUtilities.createTransformationMatrix(entity.getPosition(), entity.getRotX(), entity.getRotY(), entity.getRotZ(), entity.getScale());
shader.loadTransformationMatrix(transformationMatrix);
shader.loadOffset(entity.getTextureXOffset(), entity.getTextureYOffset());
}
use of org.lwjgl.util.vector.Matrix4f in project j6dof-flight-sim by chris-ali.
the class InterfaceRenderer method render.
public void render(List<InterfaceTexture> interfaceTextures) {
shader.start();
GL30.glBindVertexArray(quad.getVaoID());
GL20.glEnableVertexAttribArray(0);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glDisable(GL11.GL_DEPTH_TEST);
for (InterfaceTexture interfaceTexture : interfaceTextures) {
GL13.glActiveTexture(GL13.GL_TEXTURE0);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, interfaceTexture.getTexture());
Matrix4f matrix = RenderingUtilities.createTransformationMatrix(interfaceTexture.getPosition(), interfaceTexture.getRotation(), interfaceTexture.getScale());
shader.loadTransformation(matrix);
GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, quad.getVertexCount());
}
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_BLEND);
GL20.glDisableVertexAttribArray(0);
GL30.glBindVertexArray(0);
shader.stop();
}
use of org.lwjgl.util.vector.Matrix4f in project j6dof-flight-sim by chris-ali.
the class MasterRenderer method createProjectionMatrix.
private void createProjectionMatrix() {
float aspectRatio = DisplayManager.getAspectRatio();
float y_scale = (float) ((1f / Math.tan(Math.toRadians(fov / 2f))) * aspectRatio);
float x_scale = y_scale / aspectRatio;
float frustum_length = farPlane - nearPlane;
projectionMatrix = new Matrix4f();
projectionMatrix.m00 = x_scale;
projectionMatrix.m11 = y_scale;
projectionMatrix.m22 = -((farPlane + nearPlane) / frustum_length);
projectionMatrix.m23 = -1;
projectionMatrix.m32 = -((2 * nearPlane * farPlane) / frustum_length);
projectionMatrix.m33 = 0;
}
Aggregations