use of org.joml.Vector4f in project chunkstories-core by Hugobros3.
the class EntityPlayer method drawEntityOverlay.
@Override
public void drawEntityOverlay(RenderingInterface renderer) {
// super.drawEntityOverlay(renderer);
if (this.equals(((WorldClient) getWorld()).getClient().getPlayer().getControlledEntity())) {
float scale = 2.0f;
renderer.textures().getTexture("./textures/gui/hud/hud_survival.png").setLinearFiltering(false);
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(renderer.getWindow().getWidth() / 2 - 256 * 0.5f * scale, 64 + 64 + 16 - 32 * 0.5f * scale, 256 * scale, 32 * scale, 0, 32f / 256f, 1, 0, renderer.textures().getTexture("./textures/gui/hud/hud_survival.png"), false, true, null);
// Health bar
int horizontalBitsToDraw = (int) (8 + 118 * Math2.clamp(getHealth() / getMaxHealth(), 0.0, 1.0));
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(renderer.getWindow().getWidth() / 2 - 128 * scale, 64 + 64 + 16 - 32 * 0.5f * scale, horizontalBitsToDraw * scale, 32 * scale, 0, 64f / 256f, horizontalBitsToDraw / 256f, 32f / 256f, renderer.textures().getTexture("./textures/gui/hud/hud_survival.png"), false, true, new Vector4f(1.0f, 1.0f, 1.0f, 0.75f));
// Food bar
horizontalBitsToDraw = (int) (0 + 126 * Math2.clamp(getFoodLevel() / 100f, 0.0, 1.0));
renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(renderer.getWindow().getWidth() / 2 + 0 * 128 * scale + 0, 64 + 64 + 16 - 32 * 0.5f * scale, horizontalBitsToDraw * scale, 32 * scale, 0.5f, 64f / 256f, 0.5f + horizontalBitsToDraw / 256f, 32f / 256f, renderer.textures().getTexture("./textures/gui/hud/hud_survival.png"), false, true, new Vector4f(1.0f, 1.0f, 1.0f, 0.75f));
// If we're using an item that can render an overlay
if (this.getSelectedItemComponent().getSelectedItem() != null) {
ItemPile pile = this.getSelectedItemComponent().getSelectedItem();
if (pile.getItem() instanceof ItemOverlay)
((ItemOverlay) pile.getItem()).drawItemOverlay(renderer, pile);
}
// We don't want to render our own tag do we ?
return;
}
// Renders the nametag above the player heads
Vector3d pos = getLocation();
// don't render tags too far out
if (pos.distance(renderer.getCamera().getCameraPosition()) > 32f)
return;
// Don't render a dead player tag
if (this.getHealth() <= 0)
return;
Vector3fc posOnScreen = renderer.getCamera().transform3DCoordinate(new Vector3f((float) (double) pos.x(), (float) (double) pos.y() + 2.0f, (float) (double) pos.z()));
float scale = posOnScreen.z();
// + rotH;
String txt = name.getName();
float dekal = renderer.getFontRenderer().defaultFont().getWidth(txt) * 16 * scale;
// System.out.println("dekal"+dekal);
if (scale > 0)
renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().defaultFont(), posOnScreen.x() - dekal / 2, posOnScreen.y(), txt, 16 * scale, 16 * scale, new Vector4f(1, 1, 1, 1));
}
use of org.joml.Vector4f in project chunkstories-core by Hugobros3.
the class ItemFirearm method drawScope.
private void drawScope(RenderingInterface renderingInterface) {
// Temp, rendering interface should provide us
int min = Math.min(renderingInterface.getWindow().getWidth(), renderingInterface.getWindow().getHeight());
int max = Math.max(renderingInterface.getWindow().getWidth(), renderingInterface.getWindow().getHeight());
int bandwidth = (max - min) / 2;
int x = 0;
renderingInterface.getGuiRenderer().drawBoxWindowsSpace(x, 0, x += bandwidth, renderingInterface.getWindow().getHeight(), 0, 0, 0, 0, null, false, false, new Vector4f(0.0f, 0.0f, 0.0f, 1.0f));
renderingInterface.getGuiRenderer().drawBoxWindowsSpace(x, 0, x += min, renderingInterface.getWindow().getHeight(), 0, 1, 1, 0, renderingInterface.textures().getTexture(scopeTexture), false, false, null);
renderingInterface.getGuiRenderer().drawBoxWindowsSpace(x, 0, x += bandwidth, renderingInterface.getWindow().getHeight(), 0, 0, 0, 0, null, false, false, new Vector4f(0.0f, 0.0f, 0.0f, 1.0f));
}
use of org.joml.Vector4f in project chunkstories-core by Hugobros3.
the class NearbyVoxelsVolumeTexture method update.
public void update(RenderingInterface renderingContext) {
if (test == null) {
test = renderingContext.newTexture3D(TextureFormat.RGBA_8BPP, 32, 32, 32);
}
final int SIZE = size;
final int mod = SIZE / 32;
int offCenter = SIZE / 2;
int chunkX = (int) ((renderingContext.getCamera().getCameraPosition().x() - offCenter) / 32);
int chunkY = (int) ((renderingContext.getCamera().getCameraPosition().y() - offCenter) / 32);
int chunkZ = (int) ((renderingContext.getCamera().getCameraPosition().z() - offCenter) / 32);
offsetX = chunkX % mod;
offsetY = chunkY % mod;
offsetZ = chunkZ % mod;
if (bx != chunkX || by != chunkY || bz != chunkZ) {
bx = chunkX;
by = chunkY;
bz = chunkZ;
ByteBuffer bb = ByteBuffer.allocateDirect(4 * SIZE * SIZE * SIZE);
byte[] empty = { 0, 0, 0, 0 };
Chunk zChunk = null;
Vector4f col = new Vector4f();
for (int a = 0; a * 32 < SIZE; a++) for (int b = 0; b * 32 < SIZE; b++) for (int c = 0; c * 32 < SIZE; c++) {
zChunk = worldRenderer.getWorld().getChunk(chunkX + a, chunkY + b, chunkZ + c);
if (zChunk != null) {
for (int z = 0; z < 32; z++) for (int y = 0; y < 32; y++) {
int dx = (0 + a) % mod;
int dy = (0 + b) % mod;
int dz = (0 + c) % mod;
bb.position(4 * ((dz * 32 + z) * SIZE * SIZE + (dy * 32 + y) * SIZE + 0 + dx * 32));
for (int x = 0; x < 32; x++) {
CellData cell = zChunk.peek(x, y, z);
// zChunk.peekSimple(x, y, z);
Voxel voxel = cell.getVoxel();
if (voxel.isAir() || voxel.getName().startsWith("glass") || voxel instanceof VoxelPane || (!voxel.getDefinition().isSolid() && !voxel.getDefinition().isLiquid() && voxel.getDefinition().getEmittedLightLevel() == 0)) {
bb.put(empty);
} else {
col.set(voxel.getVoxelTexture(VoxelSide.TOP, cell).getColor());
if (col.w() < 1.0) {
col.mul(new Vector4f(0.1f, 0.5f, 0.1f, 1.0f));
}
if (voxel.getDefinition().getEmittedLightLevel() > 0) {
Vector4f emits = new Vector4f(1.0f, 1.0f, 1.0f, 1.0f);
float alpha = col.w;
// if(alpha <= 0.0f)
alpha = 1.0f;
if (voxel.getName().contains("torch"))
alpha = 2f;
bb.put((byte) (int) Math.max(0.0, col.x() * 255.0 * alpha));
bb.put((byte) (int) Math.max(0.0, col.y() * 255.0 * alpha));
bb.put((byte) (int) Math.max(0.0, col.z() * 255.0 * alpha));
bb.put((byte) 20);
} else {
bb.put((byte) (int) (col.x() * 255));
bb.put((byte) (int) (col.y() * 255));
bb.put((byte) (int) (col.z() * 255));
bb.put((byte) 1);
}
}
}
}
}
}
bb.position(0);
bb.limit(bb.capacity());
test.uploadTextureData(SIZE, SIZE, SIZE, bb);
test.setTextureWrapping(true);
System.out.println("do an upload");
// MemoryUtil.memFree(bb);
}
}
use of org.joml.Vector4f in project IDEProgram by Itay2805.
the class GLContext method texImage2D.
/**
* Specify the pixels for a texture image
*/
public void texImage2D(int target, int width, int height, int type, ByteBuffer data) {
if (this.beginMode != -1) {
this.err = INVALID_OPERATION;
return;
}
if (target != TEXTURE_2D) {
this.err = INVALID_ENUM;
return;
}
if (type != BYTE && type != FLOAT) {
this.err = INVALID_ENUM;
return;
}
Texture texture = textures.get(curTexture);
texture.pixels = new Vector4f[width * height];
texture.w = width;
texture.h = height;
int size = width * height;
for (int i = 0; i < size; i++) {
texture.pixels[i] = new Vector4f();
texture.pixels[i].x = (type == BYTE ? data.get(i * 4 + 0) / 255 : data.getFloat((i * 4 + 0) * 4) / 1.0f);
texture.pixels[i].y = (type == BYTE ? data.get(i * 4 + 1) / 255 : data.getFloat((i * 4 + 1) * 4) / 1.0f);
texture.pixels[i].z = (type == BYTE ? data.get(i * 4 + 2) / 255 : data.getFloat((i * 4 + 2) * 4) / 1.0f);
texture.pixels[i].w = (type == BYTE ? data.get(i * 4 + 3) / 255 : data.getFloat((i * 4 + 3) * 4) / 1.0f);
}
}
use of org.joml.Vector4f in project IDEProgram by Itay2805.
the class GLContext method end.
/**
* Finish specification of vertices;
*/
public void end() {
if (this.beginMode == -1) {
this.err = INVALID_OPERATION;
return;
}
// Transform vertices and map them to window coordinates
for (int i = 0; i < beginVertices.size(); i++) {
Vertex vertex = beginVertices.get(i);
// Transform vertex into eye space
Vector4f vec = new Vector4f(vertex.coord.x, vertex.coord.y, vertex.coord.z, 1.0f);
vec.mul(matModelView);
// Perform backface culling - if enabled
if (this.cullingEnabled && ((this.beginMode == GL.QUADS && i % 4 == 0) || (this.beginMode == GL.TRIANGLES && i % 3 == 0))) {
Vector3f side1 = new Vector3f();
beginVertices.get(i).coord.sub(beginVertices.get(i + 1).coord, side1);
Vector3f side2 = new Vector3f();
beginVertices.get(i).coord.sub(beginVertices.get(i + 2).coord, side2);
Vector3f normal = new Vector3f();
side1.cross(side2, normal);
float dot = normal.dot(beginVertices.get(i).coord);
// If dot > 0, then the face is facing away from the camera
vertex.cull = dot <= 0;
}
// Transform vertex into clip space
vec.mul(matProj);
// Calculate normalized device coordinates
Vector3f norm = new Vector3f();
norm.x = vec.x / vec.w;
norm.y = vec.y / vec.w;
norm.z = vec.z / vec.w;
vertex.coord.x = (norm.x + 1) / 2 * this.w;
vertex.coord.y = (1 - norm.y) / 2 * this.h;
vertex.coord.z = norm.z;
// beginVertices.set(i, vertex);
}
// Assemble primitives
if (beginMode == POINTS) {
for (int i = 0; i < this.beginVertices.size(); i++) {
drawPoint(beginVertices.get(i), this.bufColor, this.bufDepth, this);
}
} else if (beginMode == LINES && beginVertices.size() >= 2) {
} else if (beginMode == TRIANGLES && beginVertices.size() >= 3) {
for (int i = 0; i < this.beginVertices.size(); i += 3) {
drawTriangle(new Vertex[] { beginVertices.get(i + 0), beginVertices.get(i + 1), beginVertices.get(i + 2) }, this.bufColor, this.bufDepth, this);
}
} else if (beginMode == QUADS && beginVertices.size() >= 4) {
for (int i = 0; i < this.beginVertices.size(); i += 4) {
drawQuad(new Vertex[] { beginVertices.get(i + 0), beginVertices.get(i + 1), beginVertices.get(i + 2), beginVertices.get(i + 3) }, this.bufColor, this.bufDepth, this);
}
}
this.beginMode = -1;
this.beginVertices.clear();
}
Aggregations