Hello everyone! New to the forum, all help is appreciated!
I’m working on a P3D project and am drawing boxes with a stroke on the edges. The issue that I noticed is that when I move around them (I’m using queasycam) the stroke and the fill of the shapes clip around one another. Is there anything that I can do to prevent this?
Is this happening always, or just when you bump into them?
Without seeing the collision code it’s hard to say, but there’s two solutions that come to mind, add to the collision distance check, or reduce the stroke weight.
The clipping of the edges (what makes them look all jagged) is something that constantly happens, it’s just that when I move around it, the clipping is much more noticeable—honestly it’s easier to see on video.
And sorry I don’t actually know what the collision distance check is, I couldn’t really find anything about it on the forums
I may end up reducing the strokeWeight, but if possible I’d prefer to keep it as is
Yeah I might just end up reducing the stroke weight, that seems like the solution everyone is pointing towards
This code is part of a bigger project that I’m working on (I’m kind of new and wanted to challenge myself and make some sort of voxel game similar to Minecraft), so I can’t share the whole thing—but I’ve rewritten the code of this part into its own sketch (make sure you have QueasyCam installed):
//Queasycam
import queasycam.*;
QueasyCam cam;
//rendering settings
float fov = PI/3.0;
float cameraZ = (height/2.0) / tan(fov/2.0);
float nearClippingDistance = 0.01; // default is cameraZ/10.0
ArrayList<PVector> blocks = new ArrayList<PVector>();
void setup() {
size(1920, 1080, P3D);
fullScreen();
colorMode(HSB, 360, 100, 100, 255);
//setup boxes
for (int x = 0; x < 6; x++) {
for (int y = 0; y < 6; y++) {
for (int z = 0; z < 6; z++) {
if (random(1) > 0.5) blocks.add(new PVector(x, y, z));
}
}
}
//cam
cam = new QueasyCam(this);
cam.speed = 5;
cam.sensitivity = 1;
noCursor();
}
void draw() {
background(0, 0, 100);
//rendering settings
lights();
noSmooth();
perspective(fov, float(width)/float(height), nearClippingDistance, cameraZ*1000.0); //camera perspective
pushMatrix();
float blockSize = 100;
scale(blockSize);
for (PVector p : blocks) {
pushMatrix();
translate(p.x, p.y, p.z);
//fill & stroke
fill(100, 80, 100);
stroke(100, 80, 0.4*100);
strokeWeight(0.1);
box(0.9);
popMatrix();
}
popMatrix();
}
@glv Thank you!
This is actually my second attempt at making Minecraft! The main aim of this one is to create cleaner/readable and more expandable code (as well as infinite worlds, better world gen, menus, saving worlds, etc).
My first had code that was practically unreadable (except for me…). However, it did produce some cool terrain!
I won’t post the source for the old one because it’s so bad lol
Oh that’s strange, I don’t really know what scale would change to make the edges not clip. I think this is the approach that I will follow, thanks everyone!
Also it looks like pasteboard is down right now, so that’s why the link in the first post is broken
If I continue to use the strokes on the edges of blocks, I probably won’t use scale.
However, scaling was pretty useful because I could have a coordinate system very similar to the real Minecraft (I did scale(blockSize, -blockSize, blockSize); so that I could reverse y, and have every block be one unit ).
So if I end up going back to using scale, I may just use textures instead of the fill/stroke design that I’m using right now so I don’t have to deal with the clipping.
Although, I’m not so sure how the performance will be to loading a tileset, then drawing a texture for each block every frame—I’ll just have to see how it turns out, I suppose.