use of org.joml.Vector3d in project chunkstories-api by Hugobros3.
the class EntityBase method moveWithoutCollisionRestrain.
@Override
public void moveWithoutCollisionRestrain(Vector3dc delta) {
Vector3d pos = new Vector3d(positionComponent.getLocation());
pos.add(delta);
positionComponent.setPosition(pos);
}
use of org.joml.Vector3d in project chunkstories by Hugobros3.
the class PhysicsWireframeDebugger method render.
public void render(RenderingInterface renderer) {
Vector3dc cameraPosition = renderer.getCamera().getCameraPosition();
// int id, data;
int drawDebugDist = 6;
// Iterate over nearby voxels
for (int i = ((int) (double) cameraPosition.x()) - drawDebugDist; i <= ((int) (double) cameraPosition.x()) + drawDebugDist; i++) for (int j = ((int) (double) cameraPosition.y()) - drawDebugDist; j <= ((int) (double) cameraPosition.y()) + drawDebugDist; j++) for (int k = ((int) (double) cameraPosition.z()) - drawDebugDist; k <= ((int) (double) cameraPosition.z()) + drawDebugDist; k++) {
// data = world.peekSimple(i, j, k);
// id = VoxelFormat.id(data);
CellData cell = world.peekSafely(i, j, k);
// System.out.println(i+":"+j+":"+k);
// System.out.println(cell.getX() + ":"+cell.getY()+":"+cell.getZ());
CollisionBox[] tboxes = cell.getTranslatedCollisionBoxes();
// System.out.println(tboxes.length);
if (tboxes != null) {
// Draw all their collision boxes
for (CollisionBox box : tboxes) {
if (cell.getVoxel().getDefinition().isSolid())
// Red if solid
FakeImmediateModeDebugRenderer.renderCollisionBox(box, new Vector4f(1, 0, 0, 1.0f));
else
// Yellow otherwise
FakeImmediateModeDebugRenderer.renderCollisionBox(box, new Vector4f(1, 1, 0, 0.25f));
}
}
}
// Iterate over each entity
Iterator<Entity> ie = world.getAllLoadedEntities();
while (ie.hasNext()) {
Entity e = ie.next();
// Entities with hitboxes see all of those being drawn
if (e instanceof EntityLiving) {
EntityLiving eli = (EntityLiving) e;
for (HitBox hitbox : eli.getHitBoxes()) {
hitbox.draw(renderer);
}
}
// Get the entity bounding box
if (e.getTranslatedBoundingBox().lineIntersection(cameraPosition, new Vector3d(renderer.getCamera().getViewDirection())) != null)
FakeImmediateModeDebugRenderer.renderCollisionBox(e.getTranslatedBoundingBox(), new Vector4f(0, 0, 0.5f, 1.0f));
else
FakeImmediateModeDebugRenderer.renderCollisionBox(e.getTranslatedBoundingBox(), new Vector4f(0, 1f, 1f, 1.0f));
// And the collision box
for (CollisionBox box : e.getCollisionBoxes()) {
box.translate(e.getLocation());
FakeImmediateModeDebugRenderer.renderCollisionBox(box, new Vector4f(0, 1, 0.5f, 1.0f));
}
}
}
use of org.joml.Vector3d in project lwjgl3-demos by LWJGL.
the class SpaceGame method drawParticles.
private void drawParticles() {
particleVertices.clear();
int num = 0;
for (int i = 0; i < particlePositions.length; i++) {
Vector3d particlePosition = particlePositions[i];
Vector4d particleVelocity = particleVelocities[i];
if (particleVelocity.w > 0.0f) {
float x = (float) (particlePosition.x - cam.position.x);
float y = (float) (particlePosition.y - cam.position.y);
float z = (float) (particlePosition.z - cam.position.z);
if (frustumIntersection.testPoint(x, y, z)) {
float w = (float) particleVelocity.w;
viewMatrix.transformPosition(tmp2.set(x, y, z));
particleVertices.put(tmp2.x - particleSize).put(tmp2.y - particleSize).put(tmp2.z).put(w).put(-1).put(-1);
particleVertices.put(tmp2.x + particleSize).put(tmp2.y - particleSize).put(tmp2.z).put(w).put(1).put(-1);
particleVertices.put(tmp2.x + particleSize).put(tmp2.y + particleSize).put(tmp2.z).put(w).put(1).put(1);
particleVertices.put(tmp2.x + particleSize).put(tmp2.y + particleSize).put(tmp2.z).put(w).put(1).put(1);
particleVertices.put(tmp2.x - particleSize).put(tmp2.y + particleSize).put(tmp2.z).put(w).put(-1).put(1);
particleVertices.put(tmp2.x - particleSize).put(tmp2.y - particleSize).put(tmp2.z).put(w).put(-1).put(-1);
num++;
}
}
}
particleVertices.flip();
if (num > 0) {
glUseProgram(particleProgram);
glDepthMask(false);
glEnable(GL_BLEND);
glVertexPointer(4, GL_FLOAT, 6 * 4, particleVertices);
particleVertices.position(4);
glTexCoordPointer(2, GL_FLOAT, 6 * 4, particleVertices);
particleVertices.position(0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDrawArrays(GL_TRIANGLES, 0, num * 6);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_BLEND);
glDepthMask(true);
}
}
use of org.joml.Vector3d in project lwjgl3-demos by LWJGL.
the class SpaceGame method updateParticles.
private void updateParticles(float dt) {
for (int i = 0; i < particlePositions.length; i++) {
Vector4d particleVelocity = particleVelocities[i];
if (particleVelocity.w <= 0.0f)
continue;
particleVelocity.w += dt;
Vector3d particlePosition = particlePositions[i];
newPosition.set(particleVelocity.x, particleVelocity.y, particleVelocity.z).mul(dt).add(particlePosition);
if (particleVelocity.w > maxParticleLifetime) {
particleVelocity.w = 0.0f;
continue;
}
particlePosition.set(newPosition);
}
}
use of org.joml.Vector3d in project chunkstories-api by Hugobros3.
the class PacketParticle method process.
@Override
public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException, PacketProcessingException {
particleName = in.readUTF();
Vector3d position = new Vector3d();
position.x = (in.readDouble());
position.y = (in.readDouble());
position.z = (in.readDouble());
Vector3d velocity = new Vector3d();
if (in.readBoolean()) {
velocity.x = (in.readDouble());
velocity.y = (in.readDouble());
velocity.z = (in.readDouble());
}
if (processor instanceof ClientPacketsProcessor) {
ClientPacketsProcessor cpp = (ClientPacketsProcessor) processor;
cpp.getContext().getParticlesManager().spawnParticleAtPositionWithVelocity(particleName, position, velocity);
}
}
Aggregations