Move Mat4f and the Vec3's to objects.math

This commit is contained in:
James Seibel
2021-11-13 19:58:03 -06:00
parent 75c0889ac5
commit aa40313cf2
16 changed files with 220 additions and 11 deletions
@@ -37,12 +37,12 @@ import org.lwjgl.opengl.GL45;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.mojang.blaze3d.systems.RenderSystem;
import com.seibel.lod.builders.bufferBuilding.lodTemplates.Box;
import com.seibel.lod.config.LodConfig;
import com.seibel.lod.enums.config.GpuUploadMethod;
import com.seibel.lod.enums.config.VanillaOverdraw;
import com.seibel.lod.enums.rendering.GlProxyContext;
import com.seibel.lod.lodApi.ClientApi;
import com.seibel.lod.objects.Box;
import com.seibel.lod.objects.PosToRenderContainer;
import com.seibel.lod.objects.lod.LodDimension;
import com.seibel.lod.objects.lod.LodRegion;
@@ -22,6 +22,7 @@ package com.seibel.lod.builders.bufferBuilding.lodTemplates;
import java.util.Map;
import com.seibel.lod.enums.rendering.DebugMode;
import com.seibel.lod.objects.Box;
import com.seibel.lod.objects.opengl.LodBufferBuilder;
import com.seibel.lod.util.ColorUtil;
import com.seibel.lod.wrappers.Block.BlockPosWrapper;
@@ -22,6 +22,7 @@ package com.seibel.lod.builders.bufferBuilding.lodTemplates;
import java.util.Map;
import com.seibel.lod.enums.rendering.DebugMode;
import com.seibel.lod.objects.Box;
import com.seibel.lod.objects.opengl.LodBufferBuilder;
import com.seibel.lod.util.ColorUtil;
import com.seibel.lod.util.DataPointUtil;
@@ -23,6 +23,7 @@ import java.util.Map;
import com.seibel.lod.enums.rendering.DebugMode;
import com.seibel.lod.lodApi.ClientApi;
import com.seibel.lod.objects.Box;
import com.seibel.lod.objects.opengl.LodBufferBuilder;
import com.seibel.lod.wrappers.Block.BlockPosWrapper;
@@ -23,6 +23,7 @@ import java.util.Map;
import com.seibel.lod.enums.rendering.DebugMode;
import com.seibel.lod.lodApi.ClientApi;
import com.seibel.lod.objects.Box;
import com.seibel.lod.objects.opengl.LodBufferBuilder;
import com.seibel.lod.wrappers.Block.BlockPosWrapper;
@@ -25,7 +25,7 @@ import org.apache.logging.log4j.Logger;
import com.seibel.lod.builders.worldGeneration.LodGenWorker;
import com.seibel.lod.config.LodConfig;
import com.seibel.lod.objects.lod.LodDimension;
import com.seibel.lod.objects.rending.Mat4f;
import com.seibel.lod.objects.math.Mat4f;
import com.seibel.lod.proxy.GlProxy;
import com.seibel.lod.render.LodRenderer;
import com.seibel.lod.util.DetailDistanceUtil;
@@ -27,7 +27,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.seibel.lod.lodApi.ClientApi;
import com.seibel.lod.objects.rending.Mat4f;
import com.seibel.lod.objects.math.Mat4f;
import com.seibel.lod.wrappers.McObjectConverter;
import net.minecraft.client.renderer.RenderType;
@@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.lod.builders.bufferBuilding.lodTemplates;
package com.seibel.lod.objects;
import java.util.Arrays;
import java.util.HashMap;
@@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.lod.objects.rending;
package com.seibel.lod.objects.math;
import java.nio.FloatBuffer;
@@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.lod.objects.rending;
package com.seibel.lod.objects.math;
import com.seibel.lod.util.LodUtil;
@@ -0,0 +1,205 @@
/*
* This file is part of the Distant Horizon mod (formerly the LOD Mod),
* licensed under the GNU GPL v3 License.
*
* Copyright (C) 2020 James Seibel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.lod.objects.math;
import com.seibel.lod.util.LodUtil;
import net.minecraft.util.math.vector.Vector3i;
/**
* A (almost) exact copy of Minecraft's 1.16.5
* implementation of a 3 element vector.
*
* @author James Seibel
* @version 11-11-2021
*/
public class Vec3i
{
public static Vec3i XNeg = new Vec3i(-1, 0, 0);
public static Vec3i XPos = new Vec3i(1, 0, 0);
public static Vec3i YNeg = new Vec3i(0, -1, 0);
public static Vec3i YPos = new Vec3i(0, 1, 0);
public static Vec3i ZNeg = new Vec3i(0, 0, -1);
public static Vec3i ZPos = new Vec3i(0, 0, 1);
public int x;
public int y;
public int z;
public Vec3i()
{
}
public Vec3i(int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
else if (obj != null && this.getClass() == obj.getClass())
{
Vec3i Vec3f = (Vec3i) obj;
if (Float.compare(Vec3f.x, this.x) != 0)
{
return false;
}
else if (Float.compare(Vec3f.y, this.y) != 0)
{
return false;
}
else
{
return Float.compare(Vec3f.z, this.z) == 0;
}
}
else
{
return false;
}
}
@Override
public int hashCode()
{
int i = Float.floatToIntBits(this.x);
i = 31 * i + Float.floatToIntBits(this.y);
return 31 * i + Float.floatToIntBits(this.z);
}
public void mul(float scalar)
{
this.x *= scalar;
this.y *= scalar;
this.z *= scalar;
}
public void mul(float x, float y, float z)
{
this.x *= x;
this.y *= y;
this.z *= z;
}
public void clamp(int min, int max)
{
this.x = LodUtil.clamp(min, this.x, max);
this.y = LodUtil.clamp(min, this.y, max);
this.z = LodUtil.clamp(min, this.z, max);
}
public void set(int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
}
public void add(int x, int y, int z)
{
this.x += x;
this.y += y;
this.z += z;
}
public void add(Vec3i vector)
{
this.x += vector.x;
this.y += vector.y;
this.z += vector.z;
}
public void subtract(Vec3i vector)
{
this.x -= vector.x;
this.y -= vector.y;
this.z -= vector.z;
}
public double distSqr(double x, double y, double z, boolean centerOfBlock)
{
double offset = centerOfBlock ? 0.5 : 0.0;
double xAdd = this.x + offset - x;
double yAdd = this.y + offset - y;
double zAdd = this.z + offset - z;
return (xAdd * xAdd) + (yAdd * yAdd) + (zAdd * zAdd);
}
public int distManhattan(Vector3i otherVec)
{
float xSub = Math.abs(otherVec.getX() - this.x);
float ySub = Math.abs(otherVec.getY() - this.y);
float zSub = Math.abs(otherVec.getZ() - this.z);
return (int) (xSub + ySub + zSub);
}
/** inner product */
public float dotProduct(Vec3i vector)
{
return (this.x * vector.x) + (this.y * vector.y) + (this.z * vector.z);
}
/** Cross product */
public Vec3i cross(Vec3i otherVec)
{
return new Vec3i(
(this.y * otherVec.z) - (this.z * otherVec.y),
(this.z * otherVec.x) - (this.x * otherVec.z),
(this.x * otherVec.y) - (this.y * otherVec.x));
}
public Vec3i copy()
{
return new Vec3i(this.x, this.y, this.z);
}
@Override
public String toString()
{
return "[" + this.x + ", " + this.y + ", " + this.z + "]";
}
// Forge start
public Vec3i(int[] values)
{
set(values);
}
public void set(int[] values)
{
this.x = values[0];
this.y = values[1];
this.z = values[2];
}
}
@@ -38,8 +38,8 @@ import com.seibel.lod.handlers.ReflectionHandler;
import com.seibel.lod.lodApi.ApiShared;
import com.seibel.lod.objects.lod.LodDimension;
import com.seibel.lod.objects.lod.RegionPos;
import com.seibel.lod.objects.math.Mat4f;
import com.seibel.lod.objects.opengl.LodVertexBuffer;
import com.seibel.lod.objects.rending.Mat4f;
import com.seibel.lod.objects.rending.NearFarFogSettings;
import com.seibel.lod.proxy.GlProxy;
import com.seibel.lod.render.shader.LodShaderProgram;
@@ -24,7 +24,7 @@ import java.nio.FloatBuffer;
import org.lwjgl.opengl.GL20;
import org.lwjgl.system.MemoryStack;
import com.seibel.lod.objects.rending.Mat4f;
import com.seibel.lod.objects.math.Mat4f;
/**
@@ -23,10 +23,10 @@ import java.awt.Color;
import java.io.File;
import java.util.HashSet;
import com.seibel.lod.builders.bufferBuilding.lodTemplates.Box;
import com.seibel.lod.config.LodConfig;
import com.seibel.lod.enums.config.HorizontalResolution;
import com.seibel.lod.enums.config.VanillaOverdraw;
import com.seibel.lod.objects.Box;
import com.seibel.lod.objects.lod.LodDimension;
import com.seibel.lod.objects.lod.RegionPos;
import com.seibel.lod.objects.opengl.DefaultLodVertexFormats;
@@ -25,7 +25,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import com.seibel.lod.builders.bufferBuilding.lodTemplates.Box;
import com.seibel.lod.objects.Box;
import net.minecraft.util.Direction;
@@ -21,7 +21,7 @@ package com.seibel.lod.wrappers;
import java.nio.FloatBuffer;
import com.seibel.lod.objects.rending.Mat4f;
import com.seibel.lod.objects.math.Mat4f;
import net.minecraft.util.math.vector.Matrix4f;