I am working on a small game that uses Minecraft style blocks as models for rendering dungeons. I’m using a simple 3d array to store block data, for clipping, instanced meshes etc. I’m using this array for clipping because the number of blocks bogs down raycasting.
Everything actually works pretty well, but I am looking for a clean way to offset x and z index in the block array based on the direction of the camera, and I want to keep it simple in terms of human readability. A.k.a I want to get the facing direction and translate it into north, north east, east, south east, south… etc.
I’m learning trig as I need it, but I’m also trying to avoid as many calculations as possible.
My code is simple. I get the world direction from the camera, I rotate that direction to get left, right, and backward. I take the position + direction and round it to get an array accessor. It’s always close, but for left and right clipping, it is always off by one on either x or z. And thus allows clipping into blocks sometimes.
My thought is if I have a cardinal direction test i.e. facingNorth it becomes easy to adjust the array index for x and z.
I am working under limited resources, and can post code if it is a must, but I currently only have internet on a cheap android and it would be painful to get the code published.
Thanks for any help.
In the spirit of sharing, and because my laptop arrived today, I pushed my code and it can be seen. Keep in mind the controls are target strictly at a phone in this version and I need to add keyboard and mouse support.
https://zekenaulty.github.io/maze-quest/experiments/basic_room/
The array filtering still needs to be reworked to avoid looping over every block, and instead access the data based on x,y,z offsets from the player, but this is still very early in development.
Also, I’m using Sphax PureBD Craft textures which are the sole property of https://bdcraft.net