Initial Commit

This commit is contained in:
Speiger 2021-08-27 06:07:15 +02:00
commit e1cb8cf71f
412 changed files with 44175 additions and 0 deletions

32
.classpath Normal file
View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="bin/main" path="src/main/java">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/main" path="src/main/resources">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/test" path="src/test/java">
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/test" path="src/test/resources">
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>

6
.gitattributes vendored Normal file
View File

@ -0,0 +1,6 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# These are explicitly windows files and should use crlf
*.bat text eol=crlf

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
# Ignore Gradle project-specific cache directory
.gradle
# Ignore Gradle build output directory
build
/bin/

23
.project Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SimpleJavaEngine</name>
<comment>Project SimpleJavaEngine created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,2 @@
connection.project.dir=
eclipse.preferences.version=1

41
build.gradle Normal file
View File

@ -0,0 +1,41 @@
apply plugin: 'java'
apply plugin: 'eclipse'
eclipse {
classpath {
downloadJavadoc = true
downloadSources = true
}
}
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven {
url = "https://maven.speiger.com/repository/main"
}
}
dependencies {
//LWJGL 3
compile platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
compile "org.lwjgl:lwjgl"
compile "org.lwjgl:lwjgl-glfw"
compile "org.lwjgl:lwjgl-jemalloc"
compile "org.lwjgl:lwjgl-openal"
compile "org.lwjgl:lwjgl-opengl"
compile "org.lwjgl:lwjgl-stb"
compile "org.lwjgl:lwjgl::$lwjglNatives"
compile "org.lwjgl:lwjgl-glfw::$lwjglNatives"
compile "org.lwjgl:lwjgl-jemalloc::$lwjglNatives"
compile "org.lwjgl:lwjgl-openal::$lwjglNatives"
compile "org.lwjgl:lwjgl-opengl::$lwjglNatives"
compile "org.lwjgl:lwjgl-stb::$lwjglNatives"
//Gson
compile 'com.google.code.gson:gson:2.8.6'
//Primitive Collections
compile 'de.speiger:Primitive-Collections:0.3.4'
}

4
gradle.properties Normal file
View File

@ -0,0 +1,4 @@
org.gradle.jvmargs=-Xmx2G
lwjglVersion = 3.3.0-SNAPSHOT
lwjglNatives = natives-windows

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

183
gradlew vendored Normal file
View File

@ -0,0 +1,183 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"

103
gradlew.bat vendored Normal file
View File

@ -0,0 +1,103 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

10
settings.gradle Normal file
View File

@ -0,0 +1,10 @@
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user manual at https://docs.gradle.org/6.3/userguide/multi_project_builds.html
*/
rootProject.name = 'SimpleJavaEngine'

View File

@ -0,0 +1,92 @@
package speiger.src.coreengine.assets;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import speiger.src.collections.objects.maps.impl.hash.Object2ObjectOpenHashMap;
import speiger.src.collections.objects.utils.maps.Object2ObjectMaps;
public final class AssetLocation
{
static final Map<String, AssetLocation> LOCATION = Object2ObjectMaps.synchronize(new Object2ObjectOpenHashMap<String, AssetLocation>());
static final Function<String, AssetLocation> BUILDER = AssetLocation::compute;
final String domain;
final String location;
private AssetLocation() {throw new UnsupportedOperationException("use AssetLocation.of instead");}
private AssetLocation(String domain, String location)
{
this.domain = domain;
this.location = location;
}
public String getDomain()
{
return domain;
}
public String getLocation()
{
return location;
}
public String getActualLocation()
{
return "assets/"+domain+"/"+location;
}
public AssetLocation subAsset(String subPath)
{
return of(domain+":"+location + "/" + subPath);
}
@Override
public String toString()
{
return domain+":"+location;
}
@Override
public int hashCode()
{
return Objects.hash(domain, location);
}
@Override
public boolean equals(Object obj)
{
if(obj == this)
{
return true;
}
if(obj instanceof AssetLocation)
{
AssetLocation location = (AssetLocation)obj;
return location.domain.equals(domain) && location.location.equals(this.location);
}
return false;
}
public boolean matches(AssetLocation location)
{
return location.domain.equals(domain) && location.location.equals(this.location);
}
public static final AssetLocation of(String domain, String location)
{
return of((domain == null || domain.isEmpty() ? "base" : domain)+":"+location);
}
public static final AssetLocation of(String location)
{
return LOCATION.computeIfAbsent(location.indexOf(":") == -1 ? "base:"+location : location, BUILDER);
}
private static final AssetLocation compute(String s)
{
int index = s.indexOf(":");
return new AssetLocation(s.substring(0, index), s.substring(index+1, s.length()));
}
}

View File

@ -0,0 +1,186 @@
package speiger.src.coreengine.assets;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.ZipFile;
import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.collections.objects.maps.impl.hash.Object2ObjectLinkedOpenHashMap;
import speiger.src.coreengine.assets.impl.FolderAssetPackage;
import speiger.src.coreengine.assets.impl.ZipAssetPackage;
import speiger.src.coreengine.assets.reloader.IReloadableResource;
public class AssetManager implements IReloadableResource
{
Map<String, DomainAssets> domains = new Object2ObjectLinkedOpenHashMap<String, DomainAssets>();
File file;
public AssetManager(File file)
{
this.file = file;
}
public File getMainAsset()
{
return file;
}
@Override
public void reload()
{
domains.clear();
loadAssetPackage(file);
}
public void loadAssetPackage(File file)
{
if(file.isDirectory())
{
loadAssets(new FolderAssetPackage(file));
}
else if(isZipFile(file))
{
loadAssets(new ZipAssetPackage(file));
}
}
public void loadAssets(IAssetPackage packages)
{
for(String s : packages.getDomains())
{
DomainAssets entry = domains.get(s);
if(entry == null)
{
entry = new DomainAssets();
domains.put(s, entry);
}
entry.addAssets(packages);
}
}
public Set<String> getDomains()
{
return domains.keySet();
}
public IAsset getAsset(AssetLocation location) throws IOException
{
DomainAssets asset = domains.get(location.getDomain());
if(asset == null)
{
throw new FileNotFoundException("File["+location.toString()+"] not found");
}
return asset.getAsset(location);
}
public MultiAsset getAssets(AssetLocation...locations)
{
IAsset[] asset = new IAsset[locations.length];
for(int i = 0,m=locations.length;i<m;i++)
{
try
{
asset[i] = getAsset(locations[i]);
}
catch(Exception e) {e.printStackTrace();}
}
return new MultiAsset(asset);
}
public MultiAsset getMultiAsset(AssetLocation location, AssetLocation...subLocations) throws IOException
{
DomainAssets asset = domains.get(location.getDomain());
if(asset == null)
{
throw new FileNotFoundException("File["+location.toString()+"] not found");
}
return asset.getMultiAsset(location, subLocations);
}
public MultiAsset getAllAsset(AssetLocation location) throws IOException
{
DomainAssets asset = domains.get(location.getDomain());
if(asset == null)
{
throw new FileNotFoundException("File["+location.toString()+"] not found");
}
return asset.getAllAssets(location);
}
protected boolean isZipFile(File file)
{
try(ZipFile zip = new ZipFile(file))
{
return true;
}
catch(Exception e)
{
}
return false;
}
static class DomainAssets
{
List<IAssetPackage> packages = new ObjectArrayList<IAssetPackage>();
public void addAssets(IAssetPackage assets)
{
packages.add(assets);
}
public IAsset getAsset(AssetLocation location) throws IOException
{
for(int i = packages.size() - 1;i>=0;i--)
{
IAsset asset = packages.get(i).getAsset(location);
if(asset != null)
{
return asset;
}
}
throw new FileNotFoundException("File["+location.toString()+"] not found");
}
public MultiAsset getMultiAsset(AssetLocation location, AssetLocation[] subLocations)
{
for(int i = packages.size() - 1;i>=0;i--)
{
IAssetPackage entry = packages.get(i);
IAsset asset = entry.getAsset(location);
if(asset != null)
{
IAsset[] result = new IAsset[1 + subLocations.length];
result[0] = asset;
for(int x = 0;x<subLocations.length;x++)
{
result[x+1] = entry.getAsset(subLocations[x]);
}
return new MultiAsset(result);
}
}
return null;
}
public MultiAsset getAllAssets(AssetLocation location) throws IOException
{
List<IAsset> assets = new ObjectArrayList<IAsset>();
for(IAssetPackage entry : packages)
{
IAsset asset = entry.getAsset(location);
if(asset != null)
{
assets.add(asset);
}
}
if(assets.isEmpty())
{
throw new FileNotFoundException("File["+location.toString()+"] not found");
}
return new MultiAsset(assets.toArray(new IAsset[assets.size()]));
}
}
}

View File

@ -0,0 +1,22 @@
package speiger.src.coreengine.assets;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import com.google.gson.JsonObject;
public interface IAsset extends Closeable
{
public AssetLocation getLocation();
public InputStream getStream() throws IOException;
public BufferedImage getTexture() throws Exception;
public BufferedReader getStringReader() throws IOException;
public JsonObject getJsonObject() throws IOException;
}

View File

@ -0,0 +1,10 @@
package speiger.src.coreengine.assets;
import java.util.List;
public interface IAssetPackage
{
public List<String> getDomains();
public IAsset getAsset(AssetLocation location);
}

View File

@ -0,0 +1,41 @@
package speiger.src.coreengine.assets;
import java.io.Closeable;
import java.io.IOException;
public class MultiAsset implements Closeable
{
IAsset[] assets;
public MultiAsset(IAsset[] assets)
{
this.assets = assets;
}
@Override
public void close() throws IOException
{
if(assets != null)
{
for(int i = 0,m=assets.length;i<m;i++)
{
if(assets[i] != null)
{
assets[i].close();
}
}
assets = null;
}
}
public int size()
{
return assets.length;
}
public IAsset getAsset(int index)
{
return assets[index];
}
}

View File

@ -0,0 +1,87 @@
package speiger.src.coreengine.assets.impl;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import com.google.gson.JsonObject;
import speiger.src.coreengine.assets.AssetLocation;
import speiger.src.coreengine.assets.IAsset;
import speiger.src.coreengine.utils.helpers.JsonUtil;
public class FileAsset implements IAsset
{
File file;
AssetLocation location;
List<Closeable> toClose = new ArrayList<Closeable>();
public FileAsset(File file, AssetLocation location)
{
this.file = file;
this.location = location;
}
@Override
public void close() throws IOException
{
for(Closeable close : toClose)
{
try
{
close.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
toClose.clear();
}
@Override
public AssetLocation getLocation()
{
return location;
}
@Override
public InputStream getStream() throws IOException
{
return new BufferedInputStream(markClosed(new FileInputStream(file)));
}
@Override
public BufferedReader getStringReader() throws IOException
{
return new BufferedReader(markClosed(new FileReader(file)));
}
@Override
public BufferedImage getTexture() throws Exception
{
return ImageIO.read(file);
}
@Override
public JsonObject getJsonObject() throws IOException
{
return JsonUtil.loadFile(file);
}
protected <T extends Closeable> T markClosed(T value)
{
toClose.add(value);
return value;
}
}

View File

@ -0,0 +1,47 @@
package speiger.src.coreengine.assets.impl;
import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.List;
import speiger.src.coreengine.assets.AssetLocation;
import speiger.src.coreengine.assets.IAsset;
import speiger.src.coreengine.assets.IAssetPackage;
public class FolderAssetPackage implements IAssetPackage
{
static final FileFilter FOLDER_FILTER = new FileFilter(){
@Override
public boolean accept(File f)
{
return f.isDirectory();
}
};
File file;
public FolderAssetPackage(File file)
{
this.file = file;
}
@Override
public List<String> getDomains()
{
List<String> result = new ArrayList<String>();
File asset = new File(file, "assets/");
for(File file : asset.listFiles(FOLDER_FILTER))
{
result.add(file.getAbsolutePath().substring(asset.getAbsolutePath().length() + 1).replace("\\", "/").replace("\"", "/"));
}
return result;
}
@Override
public IAsset getAsset(AssetLocation location)
{
File asset = new File(file, location.getActualLocation());
return asset.isFile() ? new FileAsset(asset, location) : null;
}
}

View File

@ -0,0 +1,75 @@
package speiger.src.coreengine.assets.impl;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.imageio.ImageIO;
import com.google.gson.JsonObject;
import speiger.src.coreengine.assets.AssetLocation;
import speiger.src.coreengine.assets.IAsset;
import speiger.src.coreengine.utils.helpers.JsonUtil;
public class ZipAsset implements IAsset
{
ZipFile file;
ZipEntry entry;
AssetLocation location;
Runnable runnable;
public ZipAsset(ZipFile file, ZipEntry entry, AssetLocation location, Runnable runnable)
{
this.file = file;
this.entry = entry;
this.location = location;
this.runnable = runnable;
}
@Override
public void close() throws IOException
{
if(runnable != null)
{
runnable.run();
runnable = null;
}
}
@Override
public AssetLocation getLocation()
{
return location;
}
@Override
public InputStream getStream() throws IOException
{
return new BufferedInputStream(file.getInputStream(entry));
}
@Override
public BufferedImage getTexture() throws Exception
{
return ImageIO.read(file.getInputStream(entry));
}
@Override
public BufferedReader getStringReader() throws IOException
{
return new BufferedReader(new InputStreamReader(file.getInputStream(entry)));
}
@Override
public JsonObject getJsonObject() throws IOException
{
return JsonUtil.loadFile(file.getInputStream(entry));
}
}

View File

@ -0,0 +1,111 @@
package speiger.src.coreengine.assets.impl;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import speiger.src.coreengine.assets.AssetLocation;
import speiger.src.coreengine.assets.IAsset;
import speiger.src.coreengine.assets.IAssetPackage;
import speiger.src.coreengine.utils.collections.iterators.IterableWrapper;
public class ZipAssetPackage implements IAssetPackage
{
public static final int ASSET_OFFSET = "assets/".length();
File file;
ZipFile cache = null;
AtomicInteger usedReferences = new AtomicInteger();
public ZipAssetPackage(File file)
{
this.file = file;
}
protected ZipFile getReference() throws IOException
{
usedReferences.getAndIncrement();
if(cache == null) cache = new ZipFile(file);
return cache;
}
protected void onReferenceClosed()
{
int left = usedReferences.decrementAndGet();
if(left == 0 && cache != null)
{
try
{
cache.close();
}
catch(Exception e) {e.printStackTrace();}
cache = null;
}
else if(left < 0)
{
usedReferences.set(0);
}
}
@Override
public List<String> getDomains()
{
try
{
List<String> result = new ArrayList<String>();
ZipFile zip = new ZipFile(file);
for(ZipEntry entry : IterableWrapper.wrap(zip.entries()))
{
String name = entry.getName();
if(isPathValid(name))
{
result.add(name.substring(ASSET_OFFSET, name.length() - 1));
}
}
zip.close();
return result;
}
catch(IOException e)
{
e.printStackTrace();
return Collections.emptyList();
}
}
private boolean isPathValid(String input)
{
if(input.startsWith("assets/"))
{
int index = input.indexOf("/", ASSET_OFFSET);
if(index != -1 && input.length() - index <= 1)
{
return true;
}
}
return false;
}
@Override
public IAsset getAsset(AssetLocation location)
{
try
{
ZipFile zip = getReference();
ZipEntry entry = zip.getEntry(location.getActualLocation());
if(entry != null)
{
return new ZipAsset(zip, entry, location, this::onReferenceClosed);
}
}
catch(Exception e)
{
e.printStackTrace();
}
onReferenceClosed();
return null;
}
}

View File

@ -0,0 +1,16 @@
package speiger.src.coreengine.assets.language;
public class I18n
{
static Language CURRENT_LANGUAGE;
public static String translate(String key)
{
return CURRENT_LANGUAGE.translate(key);
}
public String translate(String key, Object...args)
{
return CURRENT_LANGUAGE.translate(key, args);
}
}

View File

@ -0,0 +1,47 @@
package speiger.src.coreengine.assets.language;
import java.util.Map;
public class Language
{
String language;
String code;
Map<String, String> translations;
public Language(String code, String language)
{
this.code = code;
this.language = language;
}
public void load(Map<String, String> data)
{
translations = data;
}
public void clear()
{
translations = null;
}
public String translate(String key)
{
String result = translations.get(key);
return result == null ? key : result;
}
public String translate(String key, Object...args)
{
return String.format(translate(key), args);
}
public String getCode()
{
return code;
}
public String getLanguage()
{
return language;
}
}

View File

@ -0,0 +1,151 @@
package speiger.src.coreengine.assets.language;
import java.util.Map;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import speiger.src.collections.objects.maps.impl.hash.Object2ObjectOpenHashMap;
import speiger.src.collections.objects.utils.maps.Object2ObjectMaps;
import speiger.src.coreengine.assets.AssetLocation;
import speiger.src.coreengine.assets.AssetManager;
import speiger.src.coreengine.assets.MultiAsset;
import speiger.src.coreengine.assets.reloader.IReloadableResource;
import speiger.src.coreengine.utils.collections.iterators.IterableWrapper;
public class LanguageManager implements IReloadableResource
{
final AssetLocation location = AssetLocation.of("lang");
Map<String, Language> languages = new Object2ObjectOpenHashMap<String, Language>();
AssetManager assets;
String currentLanguage;
@Override
public void reload()
{
languages.clear();
try(MultiAsset langs = assets.getAllAsset(location.subAsset("langs.json")))
{
for(int i = 0,m=langs.size();i<m;i++)
{
preLoadLanguage(langs.getAsset(i).getJsonObject());
}
}
catch(Exception e)
{
e.printStackTrace();
}
if(loadLanguage(currentLanguage))
{
I18n.CURRENT_LANGUAGE = languages.get(currentLanguage);
}
else
{
Language dummy = new Language("en_US", "English");
dummy.load(Object2ObjectMaps.empty());
I18n.CURRENT_LANGUAGE = dummy;
}
}
public boolean setLanguage(String lang)
{
if(loadLanguage(lang))
{
I18n.CURRENT_LANGUAGE = languages.get(lang);
currentLanguage = lang;
Language currentLang = languages.get(currentLanguage);
if(currentLang != null)
{
currentLang.clear();
}
return true;
}
return false;
}
protected boolean loadLanguage(String loadingLang)
{
Language lang = languages.get(loadingLang);
if(lang == null)
{
return false;
}
Map<String, String> map = new Object2ObjectOpenHashMap<String, String>();
loadLanguage(loadingLang, map);
if(loadingLang != "en_US")
{
loadLanguage("en_US", map);
}
lang.load(map);
return true;
}
protected void loadLanguage(String lang, Map<String, String> data)
{
try(MultiAsset language = assets.getAllAsset(location.subAsset(lang+".lang")))
{
for(int i = 0,m=language.size();i<m;i++)
{
try
{
for(String line : IterableWrapper.wrap(language.getAsset(i).getStringReader()))
{
if(line.isEmpty() || line.startsWith("#") || line.startsWith("//"))
{
continue;
}
String[] split = line.split("=", 1);
if(split.length == 2)
{
data.putIfAbsent(split[0].trim(), split[1].trim());
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
protected void preLoadLanguage(JsonObject object)
{
try
{
JsonArray array = object.getAsJsonArray("languages");
if(array == null)
{
return;
}
for(int i = 0,m=array.size();i<m;i++)
{
JsonArray subArray = array.get(i).getAsJsonArray();
if(subArray.size() != 2)
{
continue;
}
String key = subArray.get(0).getAsString();
String value = subArray.get(1).getAsString();
if(key.length() != 2 || value.length() > 16)
{
continue;
}
Language lang = languages.get(key);
if(lang == null)
{
languages.put(key, new Language(key, value));
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,8 @@
package speiger.src.coreengine.assets.reloader;
public interface IReloadableResource
{
public void reload();
public default void destroy() {};
}

View File

@ -0,0 +1,62 @@
package speiger.src.coreengine.assets.reloader;
import java.util.Set;
import speiger.src.collections.objects.sets.ObjectLinkedOpenHashSet;
public class ResourceReloader
{
// public static ResourceReloader INSTANCE = new ResourceReloader();
Set<IReloadableResource> resources = new ObjectLinkedOpenHashSet<IReloadableResource>();
boolean globalRemoval = false;
boolean reloading = false;
public <T extends IReloadableResource> T addReloadableResource(T resource)
{
return addReloadableResource(resource, false);
}
public <T extends IReloadableResource> T addReloadableResource(T resource, boolean init)
{
if(resources.add(resource) && init)
{
resource.reload();
}
return resource;
}
public void removeReloadableResource(IReloadableResource resource)
{
if(globalRemoval || reloading)
{
return;
}
resources.remove(resource);
}
public boolean isReloading()
{
return reloading;
}
public void reloadResources()
{
reloading = true;
for(IReloadableResource resource : resources)
{
resource.reload();
}
reloading = false;
}
public void deleteResources()
{
globalRemoval = true;
for(IReloadableResource resource : resources)
{
resource.destroy();
}
resources.clear();
globalRemoval = false;
}
}

View File

@ -0,0 +1,76 @@
package speiger.src.coreengine.math;
import java.util.Arrays;
import java.util.List;
import speiger.src.collections.ints.lists.IntList;
import speiger.src.collections.objects.lists.ObjectArrayList;
public class ArrayUtil
{
public static int[] fromTo(int from, int to)
{
int[] result = new int[to - from];
for(int i = 0,m=result.length;i<m;i++)
{
result[i] = from + i;
}
return result;
}
public static int sum(int...values)
{
int result = 0;
for(int index : values)
{
result += index;
}
return result;
}
public static byte[] fill(byte[] array, byte value)
{
Arrays.fill(array, value);
return array;
}
public static short[] fill(short[] array, short value)
{
Arrays.fill(array, value);
return array;
}
public static int[] fill(int[] array, int value)
{
Arrays.fill(array, value);
return array;
}
public static long[] fill(long[] array, long value)
{
Arrays.fill(array, value);
return array;
}
public static float[] fill(float[] array, float value)
{
Arrays.fill(array, value);
return array;
}
public static double[] fill(double[] array, double value)
{
Arrays.fill(array, value);
return array;
}
public static <T> List<T> makeList(IntList indexes, List<T> entries)
{
List<T> result = new ObjectArrayList<T>(indexes.size());
for(int i = 0,m=indexes.size();i<m;i++)
{
result.add(entries.get(indexes.getInt(i)));
}
return result;
}
}

View File

@ -0,0 +1,61 @@
package speiger.src.coreengine.math;
import speiger.src.coreengine.math.vector.ints.Vec2i;
public class BitUtil
{
public static long toLong(long firstShort, long secondShort)
{
return (firstShort << 32) | (secondShort & 0xFFFFFFFFL);
}
public static int toFirstInt(long value)
{
return (int)((value >> 32) & 0xFFFFFFFFL);
}
public static int toSecondInt(long value)
{
return (int)(value & 0xFFFFFFFFL);
}
public static long addToLong(long value, long x, long z)
{
return ((x + toFirstInt(value)) & 0xFFFFFFFFL) << 32 | (((z + toSecondInt(value)) & 0xFFFFFFFFL));
}
public static int toInt(int firstShort, int secondShort)
{
return (firstShort & 0xFFFF) << 16 | (secondShort & 0xFFFF);
}
public static int toFirstShort(int value)
{
return (short)(value >> 16 & 0xFFFF);
}
public static int toSecondShort(int value)
{
return (short)(value & 0xFFFF);
}
public static int addToInt(int value, int x, int z)
{
return ((x + toFirstShort(value)) & 0xFFFF) << 16 | ((z + toSecondShort(value)) & 0xFFFF);
}
public static int addToInt(int value, Vec2i offset)
{
return ((offset.getX() + toFirstShort(value)) & 0xFFFF) << 16 | ((offset.getY() + toSecondShort(value)) & 0xFFFF);
}
public static int pack_2_10_10_10_int_rev(float x, float y, float z, float w)
{
return (Math.round(w * 3F) & 3) << 30 | (Math.round(((z * 0.5F) + 0.5F) * 1023F) & 1023) << 20 | (Math.round(((y * 0.5F) + 0.5F) * 1023F) & 1023) << 10 | (Math.round(((x * 0.5F) + 0.5F) * 1023F) & 1023);
}
public static int pack_10_10_10_2_int(float x, float y, float z, float w)
{
return (Math.round(((x * 0.5F) + 0.5F) * 1023F) & 1023) << 22 | (Math.round(((y * 0.5F) + 0.5F) * 1023F) & 1023) << 12 | (Math.round(((z * 0.5F) + 0.5F) * 1023F) & 1023) << 2 | (Math.round(w * 3F) & 3);
}
}

View File

@ -0,0 +1,171 @@
package speiger.src.coreengine.math;
public class MathUtils
{
private static final float[] SIN_TABLE;
private static final float[] COS_TABLE;
private static final float TABLE_MASK;
private static final int SIN_MASK;
public static final double PI_INVERSION = 180D / Math.PI;
public static float sin(float a)
{
return SIN_TABLE[(int)(a * TABLE_MASK) & SIN_MASK];
}
public static float sin(double a)
{
return SIN_TABLE[(int)(a * TABLE_MASK) & SIN_MASK];
}
public static float cos(float a)
{
return COS_TABLE[(int)(a * TABLE_MASK) & SIN_MASK];
}
public static float cos(double a)
{
return COS_TABLE[(int)(a * TABLE_MASK) & SIN_MASK];
}
public static byte clamp(byte min, byte max, byte current)
{
return current < min ? min : (current > max ? max : current);
}
public static short clamp(short min, short max, short current)
{
return current < min ? min : (current > max ? max : current);
}
public static int clamp(int min, int max, int current)
{
return current < min ? min : (current > max ? max : current);
}
public static float clamp(float min, float max, float current)
{
return current < min ? min : (current > max ? max : current);
}
public static double clamp(double min, double max, double current)
{
return current < min ? min : (current > max ? max : current);
}
public static long clamp(long min, long max, long current)
{
return current < min ? min : (current > max ? max : current);
}
public static byte sign(byte value)
{
return value > 0 ? 1 : (value < 0 ? -1 : (byte)0);
}
public static short sign(short value)
{
return value > 0 ? 1 : (value < 0 ? -1 : (short)0);
}
public static int sign(int value)
{
return value > 0 ? 1 : (value < 0 ? -1 : 0);
}
public static long sign(long value)
{
return value > 0 ? 1 : (value < 0 ? -1 : 0);
}
public static float sign(float value)
{
return value > 0 ? 1F : (value < 0 ? -1F : 0F);
}
public static double sign(double value)
{
return value > 0 ? 1D : (value < 0 ? -1D : 0D);
}
public static int ceil(double value)
{
int i = (int)value;
return value > i ? i + 1 : i;
}
public static int ceil(float value)
{
int i = (int)value;
return value > i ? i + 1 : i;
}
public static int floor(float value)
{
int i = (int)value;
return value < i ? i - 1 : i;
}
public static int floor(double value)
{
int i = (int)value;
return value < i ? i - 1 : i;
}
public static int pow(int base, int exp)
{
return (int)Math.pow(base, exp);
}
public static float lerp(float start, float end, float progress)
{
return start + ((end - start) * progress);
}
public static double lerp(double start, double end, float progress)
{
return start + ((end - start) * progress);
}
public static float smoothLerp(float start, float end, float progress)
{
float cosProgress = (1F - MathUtils.cos(progress * Math.PI)) * 0.5F;
return start * (1F - cosProgress) + end * cosProgress;
}
public static float quadraticCurve(float start, float median, float end, float progress)
{
return lerp(lerp(start, median, progress), lerp(median, end, progress), progress);
}
public static float smoothQuadraticCurve(float start, float median, float end, float progress)
{
return smoothLerp(smoothLerp(start, median, progress), smoothLerp(median, end, progress), progress);
}
static
{
SIN_MASK = ~(-1 << 12);
int SIN_COUNT = SIN_MASK + 1;
float radFull = (float)(Math.PI * 2D);
float degFull = (float)(360.0);
float radToIndex = SIN_COUNT / radFull;
float degToIndex = SIN_COUNT / degFull;
TABLE_MASK = radToIndex;
SIN_TABLE = new float[SIN_COUNT];
COS_TABLE = new float[SIN_COUNT];
for(int i = 0;i < SIN_COUNT;i++)
{
SIN_TABLE[i] = (float)Math.sin((i + 0.5f) / SIN_COUNT * radFull);
COS_TABLE[i] = (float)Math.cos((i + 0.5f) / SIN_COUNT * radFull);
}
for(int i = 0;i < 360;i += 90)
{
SIN_TABLE[(int)(i * degToIndex) & SIN_MASK] = (float)Math.sin(i * Math.PI / 180D);
COS_TABLE[(int)(i * degToIndex) & SIN_MASK] = (float)Math.cos(i * Math.PI / 180D);
}
}
}

View File

@ -0,0 +1,23 @@
package speiger.src.coreengine.math;
import speiger.src.coreengine.math.vector.ints.Vec2i;
public class ShapeUtil
{
public static boolean isInCircle(int position, int radius, int testX, int testZ)
{
return isInCircle(BitUtil.toFirstShort(position), BitUtil.toSecondShort(position), radius, testX, testZ);
}
public static boolean isInCircle(Vec2i position, int radius, int testX, int testZ)
{
return isInCircle(position.getX(), position.getY(), radius, testX, testZ);
}
public static boolean isInCircle(int posX, int posZ, int radius, int testX, int testZ)
{
posX -= testX;
posZ -= testZ;
return (posX * posX) + (posZ * posZ) < radius * radius;
}
}

View File

@ -0,0 +1,91 @@
package speiger.src.coreengine.math.collision2d;
import java.util.Iterator;
import speiger.src.coreengine.math.vector.ints.Vec2i;
import speiger.src.coreengine.math.vector.ints.Vec3i;
public class Circle implements I2DCollision
{
final Vec2i center;
final int radius;
public Circle(int x, int y, int radius)
{
center = Vec2i.newVec(x, y);
this.radius = radius;
}
public Circle(Vec2i center, int radius)
{
this.center = center.asImmutable();
this.radius = radius;
}
public Circle(Vec3i data)
{
this(data.getX(), data.getY(), data.getZ());
}
public Vec2i getCenter()
{
return center;
}
public int getRadius()
{
return radius;
}
@Override
public boolean isColliding(int x, int y)
{
int xDiff = center.getX() - x;
int yDiff = center.getY() - y;
return ((xDiff * xDiff) + (yDiff * yDiff)) < radius * radius;
}
@Override
public Iterator<Vec2i> iterator()
{
return new Iterator<Vec2i>(){
Vec2i iter = step(Vec2i.newMutable(center).sub(radius));
Vec2i result = Vec2i.newMutable();
@Override
public boolean hasNext()
{
return iter != null;
}
@Override
public Vec2i next()
{
result.set(iter);
iter = step(iter);
return result;
}
Vec2i step(Vec2i iter)
{
while(iter != null)
{
iter.add(1, 0);
if(iter.getX() >= center.getX() + radius)
{
iter.sub((radius * 2), 0).add(0, 1);
if(iter.getY() >= center.getY() + radius)
{
iter = null;
}
}
if(iter != null && isColliding(iter))
{
break;
}
}
return iter;
}
};
}
}

View File

@ -0,0 +1,12 @@
package speiger.src.coreengine.math.collision2d;
import speiger.src.coreengine.math.BitUtil;
import speiger.src.coreengine.math.vector.ints.Vec2i;
public interface I2DCollision extends Iterable<Vec2i>
{
public default boolean isMixedCollision() {return false;}
public default boolean isColliding(int position){return isColliding(BitUtil.toFirstShort(position), BitUtil.toSecondShort(position));}
public default boolean isColliding(Vec2i pos){return isColliding(pos.getX(), pos.getY());}
public boolean isColliding(int x, int y);
}

View File

@ -0,0 +1,72 @@
package speiger.src.coreengine.math.collision2d;
import java.util.Iterator;
import speiger.src.coreengine.math.vector.ints.Vec2i;
public class Mixed2DCollision implements I2DCollision
{
I2DCollision mainBox;
I2DCollision[] subBoxes;
public Mixed2DCollision(I2DCollision mainBox, I2DCollision...subBoxes)
{
this.mainBox = mainBox;
this.subBoxes = subBoxes;
}
@Override
public boolean isColliding(int x, int y)
{
return mainBox.isColliding(x, y) && isCollidingInSubBox(x, y);
}
public boolean isCollidingInSubBox(int x, int y)
{
for(int i = 0,m=subBoxes.length;i<m;i++)
{
if(!subBoxes[i].isColliding(x, y))
{
return false;
}
}
return true;
}
@Override
public Iterator<Vec2i> iterator()
{
return new Iterator<Vec2i>(){
Iterator<Vec2i> mainIter = mainBox.iterator();
Vec2i cache = findNext(Vec2i.newMutable());
Vec2i result = Vec2i.newMutable();
@Override
public boolean hasNext()
{
return cache != null;
}
@Override
public Vec2i next()
{
result.set(cache);
cache = findNext(cache);
return result;
}
Vec2i findNext(Vec2i input)
{
while(mainIter.hasNext())
{
Vec2i next = mainIter.next();
if(isCollidingInSubBox(next.getX(), next.getY()))
{
return input.set(next);
}
}
return null;
}
};
}
}

View File

@ -0,0 +1,104 @@
package speiger.src.coreengine.math.collision2d;
import java.util.Iterator;
import speiger.src.coreengine.math.vector.ints.Vec2i;
public class Plane implements I2DCollision
{
Vec2i min;
Vec2i max;
public Plane()
{
this(0, 0, 0, 0);
}
public Plane(int minX, int minY, int maxX, int maxY)
{
this(Vec2i.newMutable(minX, minY), Vec2i.newMutable(maxX, maxY));
}
public Plane(Vec2i center, int radius)
{
this(center.sub(radius), center.add(radius));
}
public Plane(Vec2i min, Vec2i max)
{
this.min = min;
this.max = max;
}
public Plane set(Plane other)
{
min.set(other.getMin());
max.set(other.getMax());
return this;
}
public Plane set(int minX, int minY, int maxX, int maxY)
{
min.set(minX, minY);
max.set(maxX, maxY);
return this;
}
@Override
public boolean isColliding(int x, int y)
{
return x >= min.getX() && y >= min.getY() && x < max.getX() && y < max.getY();
}
public boolean isIntersecting(Plane plane)
{
return isIntersecting(plane.getMinX(), plane.getMinY(), plane.getMaxX(), plane.getMaxY());
}
public boolean isIntersecting(int minX, int minY, int maxX, int maxY)
{
return min.getX() <= maxX && max.getX() >= minX && min.getY() <= maxY && max.getY() >= minY;
}
public Vec2i getMin(){return min;}
public Vec2i getMax(){return max;}
public int getWidth(){return max.getX() - min.getX();}
public int getHeight(){return max.getY() - min.getY();}
public int getMinX(){return min.getX();}
public int getMinY(){return min.getY();}
public int getMaxX(){return max.getX();}
public int getMaxY(){return max.getY();}
@Override
public Iterator<Vec2i> iterator()
{
return new Iterator<Vec2i>(){
Vec2i iter = Vec2i.newMutable(min);
Vec2i result = Vec2i.newMutable();
@Override
public boolean hasNext()
{
return iter != null;
}
@Override
public Vec2i next()
{
result.set(iter);
iter.add(1, 0);
if(iter.getX() == max.getX())
{
iter.set(min.getX(), iter.getY() + 1);
if(iter.getY() == max.getY())
{
iter = null;
}
}
return result;
}
};
}
}

View File

@ -0,0 +1,381 @@
package speiger.src.coreengine.math.misc;
import java.awt.Color;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import speiger.src.collections.floats.lists.FloatList;
public class ColorObject
{
static final float DEVIDER = 1F / 255F;
public static final int R = 0xFF << 16;
public static final int G = 0xFF << 8;
public static final int B = 0xFF;
public static final int A = 0xFF << 24;
public static final long SIGN = 0x00000000FFFFFFFFL;
static final int ALL = 0xFFFFFFFF;
public static final ColorObject WHITE = new ColorObject(255, 255, 255);
public static final ColorObject LIGHT_GRAY = new ColorObject(192, 192, 192);
public static final ColorObject GRAY = new ColorObject(128, 128, 128);
public static final ColorObject DARK_GRAY = new ColorObject(64, 64, 64);
public static final ColorObject BLACK = new ColorObject(0, 0, 0);
public static final ColorObject RED = new ColorObject(255, 0, 0);
public static final ColorObject PINK = new ColorObject(255, 175, 175);
public static final ColorObject PURPLE = new ColorObject(106, 13, 173);
public static final ColorObject ORANGE = new ColorObject(255, 200, 0);
public static final ColorObject YELLOW = new ColorObject(255, 255, 0);
public static final ColorObject GREEN = new ColorObject(0, 255, 0);
public static final ColorObject DARK_GREEN = new ColorObject(7, 161, 0);
public static final ColorObject MAGENTA = new ColorObject(255, 0, 255);
public static final ColorObject CYAN = new ColorObject(0, 255, 255);
public static final ColorObject BLUE = new ColorObject(0, 0, 255);
public static final ColorObject LIGHT_BLUE = new ColorObject(0, 150, 255);
//Specialized Components that get reused
public static final ColorObject INVISIBLE = new ColorObject(0, 0, 0, 0);
public static final ColorObject TEXT_DEFAULT_BACKGROUND = new ColorObject(80, 80, 80, 144);
public static final ColorObject WINDOW_DEFAULT_BACKGROUND = new ColorObject(64, 64, 64, 128);
public static final ColorObject POPUP_DEFAULT_BACKGROUND = new ColorObject(85, 85, 85);
public static final ColorObject DESTRUCTION = new ColorObject(255, 0, 0, 128);
int rgba;
public ColorObject(int rgba)
{
this.rgba = rgba;
}
public ColorObject(int r, int g, int b)
{
rgba = A | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF);
}
public ColorObject(int r, int g, int b, int a)
{
rgba = ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF);
}
public static ColorObject rgb(int rgb)
{
return new ColorObject(rgb | (255 << 24));
}
public ColorObject copy()
{
return new ColorObject(rgba);
}
public ColorObject setRGB(int rgba)
{
this.rgba = rgba;
return this;
}
public ColorObject setRed(int r)
{
rgba = rgba & ~R | ((r & 0xFF) << 16);
return this;
}
public ColorObject setGreen(int g)
{
rgba = rgba & ~G | ((g & 0xFF) << 8);
return this;
}
public ColorObject setBlue(int b)
{
rgba = rgba & ~B | (b & 0xFF);
return this;
}
public ColorObject setAlpha(int a)
{
rgba = rgba & ~A | ((a & 0xFF) << 24);
return this;
}
public ColorObject setRed(float r)
{
return setRed((int)(r * 255F + 0.5F));
}
public ColorObject setGreen(float g)
{
return setGreen((int)(g * 255F + 0.5F));
}
public ColorObject setBlue(float b)
{
return setBlue((int)(b * 255F + 0.5F));
}
public ColorObject setAlpha(float a)
{
return setAlpha((int)(a * 255F + 0.5F));
}
public ColorObject setRGB(float hue, float brightness, float saturation, int alpha)
{
return setRGB(Color.HSBtoRGB(hue, saturation, brightness) | alpha << 24);
}
public int getRGB()
{
return rgba;
}
public int getRed()
{
return (rgba >> 16) & 0xFF;
}
public int getGreen()
{
return (rgba >> 8) & 0xFF;
}
public int getBlue()
{
return rgba & 0xFF;
}
public int getAlpha()
{
return (rgba >> 24) & 0xFF;
}
public float getRedFloat()
{
return ((rgba >> 16) & 0xFF) * DEVIDER;
}
public float getGreenFloat()
{
return ((rgba >> 8) & 0xFF) * DEVIDER;
}
public float getBlueFloat()
{
return (rgba & 0xFF) * DEVIDER;
}
public float getAlphaFloat()
{
return ((rgba >> 24) & 0xFF) * DEVIDER;
}
public String getHexCode(boolean alpha)
{
return "0x"+(alpha ? Long.toHexString(1 << 32 | rgba & SIGN) : Integer.toHexString((1 << 24) | (rgba & ~A))).substring(1);
}
public String getHTMLCode(boolean alpha)
{
return "#"+(alpha ? Long.toHexString(1 << 32 | rgba & SIGN) : Integer.toHexString((1 << 24) | (rgba & ~A))).substring(1);
}
public boolean needsDarkColor()
{
return getBrightness() >= 130;
}
public int getBrightness()
{
return getBrightness(rgba);
}
public Color toColor()
{
return new Color(rgba);
}
public float[] toHue()
{
return Color.RGBtoHSB(getRed(), getGreen(), getBlue(), new float[3]);
}
public ColorObject brighter()
{
return brighter(0.7F);
}
public ColorObject brighter(float factor)
{
rgba = brighter(rgba, factor);
return this;
}
public ColorObject darker()
{
return darker(0.7F);
}
public ColorObject darker(float factor)
{
rgba = darker(rgba, factor);
return this;
}
public ColorObject mix(ColorObject to, float factor)
{
rgba = mix(rgba, to.rgba, factor);
return this;
}
public ColorObject mix(ColorObject from, ColorObject to, float factor)
{
rgba = mix(from.rgba, to.rgba, factor);
return this;
}
public ColorObject write(FloatBuffer buffer, boolean alpha)
{
buffer.put(getRedFloat()).put(getGreenFloat()).put(getBlueFloat());
if(alpha)
{
buffer.put(getAlphaFloat());
}
return this;
}
public ColorObject read(FloatBuffer buffer, boolean alpha)
{
setRed(buffer.get()).setGreen(buffer.get()).setBlue(buffer.get());
if(alpha)
{
setAlpha(buffer.get());
}
return this;
}
public ColorObject write(ByteBuffer buffer, boolean alpha)
{
pack(rgba, alpha, buffer);
return this;
}
public ColorObject read(ByteBuffer buffer, boolean alpha)
{
setRed(buffer.get()).setGreen(buffer.get()).setBlue(buffer.get());
if(alpha)
{
setAlpha(buffer.get());
}
return this;
}
public ColorObject write(FloatList buffer, boolean alpha)
{
buffer.add(getRedFloat());
buffer.add(getGreenFloat());
buffer.add(getBlueFloat());
if(alpha)
{
buffer.add(getAlphaFloat());
}
return this;
}
public ColorObject writeFloat(ByteBuffer buffer, boolean alpha)
{
buffer.putFloat(getRedFloat()).putFloat(getGreenFloat()).putFloat(getBlueFloat());
if(alpha)
{
buffer.putFloat(getAlphaFloat());
}
return this;
}
@Override
public int hashCode()
{
return rgba;
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof ColorObject)
{
return ((ColorObject)obj).rgba == rgba;
}
return false;
}
@Override
public String toString()
{
return "Color[r=" + getRed() + ", g=" + getGreen() + ", b=" + getBlue() + ", a=" + getAlpha() + "]";
}
public String getFloatColor()
{
return "Color[r=" + getRedFloat() + ", g=" + getGreenFloat() + ", b=" + getBlueFloat() + ", a=" + getAlphaFloat() + "]";
}
public static void pack(int color, boolean alpha, ByteBuffer buffer)
{
buffer.put((byte)((color >> 16) & 0xFF)).put((byte)((color >> 8) & 0xFF)).put((byte)(color & 0xFF));
if(alpha)
{
buffer.put((byte)((color >> 24) & 0xFF));
}
}
public static void packFloat(int color, boolean alpha, FloatBuffer buffer)
{
buffer.put(((color >> 16) & 0xFF) * DEVIDER).put(((color >> 8) & 0xFF) * DEVIDER).put((color & 0xFF) * DEVIDER);
if(alpha)
{
buffer.put(((color >> 24) & 0xFF) * DEVIDER);
}
}
public static int getBrightness(int rgba)
{
return getBrightness((rgba >> 16) & 0xFF, (rgba >> 8) & 0xFF, rgba & 0xFF);
}
public static int getBrightness(int r, int g, int b)
{
return (int)Math.sqrt((r * r * 0.241F) + (g * g * 0.691F) + (b * b * 0.068F));
}
public static int mix(int from, int to, float factor)
{
float weight0 = (1F - factor);
float weight1 = factor;
int r = (int)((((from >> 16) & 0xFF) * weight0) + (((to >> 16) & 0xFF) * weight1));
int g = (int)((((from >> 8) & 0xFF) * weight0) + (((to >> 8) & 0xFF) * weight1));
int b = (int)(((from & 0xFF) * weight0) + ((to & 0xFF) * weight1));
int a = (int)((((from >> 24) & 0xFF) * weight0) + (((to >> 24) & 0xFF) * weight1));
return ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | b & 0xFF;
}
public static int darker(int color, float factor)
{
int r = Math.max(0, (int)(((color >> 16) & 0xFF) * factor));
int g = Math.max(0, (int)(((color >> 8) & 0xFF) * factor));
int b = Math.max(0, (int)((color & 0xFF) * factor));
return (color & A) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF);
}
public static int brighter(int color, float factor)
{
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = color & 0xFF;
int i = (int)(1.0 / (1.0 - factor));
if(r == 0 && g == 0 && b == 0)
{
return (color & A) | ((i & 0xFF) << 16) | ((i & 0xFF) << 8) | (i & 0xFF);
}
if(r > 0 && r < i) r = i;
if(g > 0 && g < i) g = i;
if(b > 0 && b < i) b = i;
return (color & A) | Math.min(255, (int)(r / factor)) << 16 | Math.min(255, (int)(g / factor)) << 8 | Math.min(255, (int)(b / factor));
}
}

View File

@ -0,0 +1,194 @@
package speiger.src.coreengine.math.misc;
import java.util.function.Predicate;
import speiger.src.coreengine.math.vector.ints.Vec2i;
public enum Facing
{
NORTH(0, 2, "North", Axis.VERTICAL, Vec2i.newVec(0, 1)),
EAST(1, 3, "East", Axis.HORIZONTAL, Vec2i.newVec(1, 0)),
SOUTH(2, 0, "South", Axis.VERTICAL, Vec2i.newVec(0, -1)),
WEST(3, 1, "West", Axis.HORIZONTAL, Vec2i.newVec(-1, 0));
private static final Facing[] VALUES;
private static final Facing[] ROTATIONS;
final int index;
final int rotationIndex;
final String name;
final Axis axis;
final Vec2i offset;
final boolean positive;
private Facing(int direction, int rotation, String display, Axis axis, Vec2i offset)
{
index = direction;
rotationIndex = rotation;
name = display;
this.axis = axis;
this.offset = offset;
positive = index < 2;
}
public int getIndex()
{
return index;
}
public boolean isXAxis()
{
return axis == Axis.HORIZONTAL;
}
public boolean isZAxis()
{
return axis == Axis.VERTICAL;
}
public Axis getAxis()
{
return axis;
}
public boolean isPositive()
{
return positive;
}
public Vec2i getOffset()
{
return offset;
}
public float getMultiplier()
{
return positive ? 1F : -1F;
}
public String getName()
{
return name;
}
public int getRotationIndex()
{
return rotationIndex;
}
public int getRotation()
{
return rotationIndex * 90;
}
public int getRotation(Facing other)
{
if(other == backwards()) return getRotation() - 45;
else if(other == forward()) return getRotation() + 45;
return getRotation();
}
public Facing rotate(int amount)
{
return byIndex(index + amount);
}
public Facing forward()
{
return byIndex(index + 1);
}
public Facing backwards()
{
return byIndex(index - 1);
}
public Facing opposite()
{
return byIndex(index + 2);
}
@Override
public String toString()
{
return getName()+": "+offset;
}
public static Facing byIndex(int index)
{
return VALUES[index & 3];
}
public static Facing byRotationIndex(int index)
{
return ROTATIONS[index & 3];
}
public static Facing byYaw(float value)
{
return byRotationIndex((int)(value / 90) & 3);
}
static
{
Facing[] values = values();
VALUES = new Facing[values.length];
ROTATIONS = new Facing[values.length];
for(Facing entry : values)
{
VALUES[entry.getIndex()] = entry;
ROTATIONS[entry.getRotationIndex()] = entry;
}
}
public static enum Rotation
{
NONE(Facing.NORTH),
CLOCKWISE(Facing.EAST),
OPPOSITE(Facing.SOUTH),
COUNTER_CLOCKWISE(Facing.WEST);
static final Rotation[] ROTATION = Rotation.values();
Facing facing;
private Rotation(Facing facing)
{
this.facing = facing;
}
public static Rotation fromFacing(Facing facing)
{
return ROTATION[facing.getIndex()];
}
public Facing toFacing()
{
return facing;
}
}
public static enum Axis implements Predicate<Facing>
{
HORIZONTAL(5),
VERTICAL(10);
int code;
private Axis(int code)
{
this.code = code;
}
public int getCode()
{
return code;
}
@Override
public boolean test(Facing t)
{
return t.getAxis() == this;
}
}
}

View File

@ -0,0 +1,312 @@
package speiger.src.coreengine.math.misc;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.Set;
import java.util.StringJoiner;
import java.util.function.Predicate;
import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.collections.objects.lists.ObjectList;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.misc.Facing.Axis;
import speiger.src.coreengine.math.vector.ints.Vec2i;
public final class FacingList implements Iterable<Facing>, Predicate<Facing>
{
static final FacingList[] FACINGS = createArray();
public static final FacingList EMPTY = ofNumber(0);
public static final FacingList NORTH = ofFacings(Facing.NORTH);
public static final FacingList EAST = ofFacings(Facing.EAST);
public static final FacingList SOUTH = ofFacings(Facing.SOUTH);
public static final FacingList WEST = ofFacings(Facing.WEST);
public static final FacingList NORTH_EAST = ofFacings(Facing.NORTH, Facing.EAST);
public static final FacingList SOUTH_EAST = ofFacings(Facing.EAST, Facing.SOUTH);
public static final FacingList SOUTH_WEST = ofFacings(Facing.SOUTH, Facing.WEST);
public static final FacingList NORTH_WEST = ofFacings(Facing.WEST, Facing.NORTH);
public static final FacingList VERTICAL = ofFacings(Facing.NORTH, Facing.SOUTH);
public static final FacingList HORIZONTAL = ofFacings(Facing.EAST, Facing.WEST);
public static final FacingList ALL = ofFacings(Facing.NORTH, Facing.SOUTH, Facing.EAST, Facing.WEST);
final byte code;
final byte next;
final byte opposite;
final byte prev;
final byte count;
final Vec2i offset;
final Facing[] array;
private FacingList(int initCode)
{
code = (byte)MathUtils.clamp(0, 15, initCode);
Vec2i pos = Vec2i.newMutable();
ObjectList<Facing> facings = new ObjectArrayList<Facing>();
for(int i = 0;i<4;i++)
{
if((code & 1 << i) != 0)
{
pos.add(Facing.byIndex(i).getOffset());
facings.add(Facing.byIndex(i));
}
}
int[] data = new int[3];
for(int i = 0,m=facings.size();i<m;i++)
{
Facing face = facings.get(i);
data[0] |= 1 << face.forward().getIndex();
data[1] |= 1 << face.opposite().getIndex();
data[2] |= 1 << face.backwards().getIndex();
}
next = (byte)MathUtils.clamp(0, 15, data[0]);
opposite = (byte)MathUtils.clamp(0, 15, data[1]);
prev = (byte)MathUtils.clamp(0, 15, data[2]);
offset = pos.asImmutable();
count = (byte)facings.size();
array = facings.toArray(new Facing[facings.size()]);
}
public static FacingList ofFacing(Facing facing)
{
return FACINGS[1 << facing.getIndex()];
}
public static FacingList ofFacings(Facing... facings)
{
return FACINGS[toNumber(facings)];
}
public static FacingList ofFlags(boolean[] facings)
{
return FACINGS[toNumber(facings)];
}
public static FacingList ofNumber(int value)
{
return FACINGS[value & 15];
}
public static FacingList ofAxis(Axis axis)
{
return FACINGS[axis.getCode()];
}
public static FacingList fromVec(Vec2i value)
{
value = value.clamp(-1, 1);
for(int i = 0;i<16;i++)
{
if(FACINGS[i].getOffset().equals(value))
{
return FACINGS[i];
}
}
return FACINGS[0];
}
public Set<Facing> toFacings()
{
return isEmpty() ? EnumSet.noneOf(Facing.class) : EnumSet.copyOf(ObjectArrayList.wrap(array));
}
public boolean[] toFlags()
{
return toFlags(array);
}
public int getRotation()
{
switch(count)
{
case 1: return array[0].getRotation();
case 2: return array[0].getRotation(array[1]);
default: return 0;
}
}
public FacingList rotate(int amount)
{
switch(amount & 3)
{
case 1: return FACINGS[next];
case 2: return FACINGS[opposite];
case 3: return FACINGS[prev];
default: return this;
}
}
public FacingList invert()
{
return FACINGS[15 - code];
}
public FacingList opposite()
{
return FACINGS[opposite];
}
public FacingList add(Facing facing)
{
return FACINGS[code | (1 << facing.getIndex())];
}
public FacingList add(FacingList facings)
{
return FACINGS[code | facings.code];
}
public FacingList remove(Facing facing)
{
return FACINGS[code & ~(1 << facing.getIndex())];
}
public FacingList remove(FacingList facings)
{
return FACINGS[code & ~facings.code];
}
public boolean contains(Facing direction)
{
return (code & 1 << direction.getIndex()) != 0;
}
public boolean contains(FacingList facings)
{
return (code & facings.code) == facings.code;
}
public boolean containsAny(FacingList facings)
{
return (code & facings.code) != 0;
}
public boolean notContains(Facing direction)
{
return (code & 1 << direction.getIndex()) == 0;
}
public boolean notContains(FacingList facings)
{
return (code & facings.code) != facings.code;
}
public FacingList flipFacing(Facing facing)
{
return contains(facing) ? remove(facing).add(facing.opposite()) : this;
}
public FacingList flipAxis(Axis axis)
{
FacingList result = this;
for(int i = 0,m=array.length;i<m;i++)
{
if(array[i].getAxis() == axis)
{
result = result.remove(array[i]).add(array[i].opposite());
}
}
return result;
}
public Vec2i getOffset()
{
return offset;
}
public Facing getFacing(int index)
{
return array[index];
}
public int getCode()
{
return code;
}
public int size()
{
return count;
}
public boolean isEmpty()
{
return code == 0;
}
public boolean isFull()
{
return code == 15;
}
@Override
public String toString()
{
StringJoiner joiner = new StringJoiner(",", "[", "]");
for(int i = 0,m=array.length;i<m;i++)
{
joiner.add(array[i].getName());
}
return joiner.toString();
}
@Override
public boolean test(Facing t)
{
return (code & 1 << t.getIndex()) != 0;
}
@Override
public Iterator<Facing> iterator()
{
return new Iterator<Facing>(){
int index = 0;
@Override
public boolean hasNext()
{
return index < size();
}
@Override
public Facing next()
{
return array[index++];
}
};
}
public static int toNumber(Facing...facings)
{
int value = 0;
for(int i = 0,m=facings.length;i<m;i++)
{
value |= (1 << facings[i].getIndex());
}
return value & 15;
}
public static int toNumber(boolean[] facings)
{
return (facings[0] ? 1 : 0) << 0 | (facings[1] ? 1 : 0) << 1 | (facings[2] ? 1 : 0) << 2 | (facings[3] ? 1 : 0) << 3;
}
public static boolean[] toFlags(Facing...facings)
{
boolean[] array = new boolean[4];
for(int i = 0,m=facings.length;i<m;i++)
{
array[facings[i].getIndex()] = true;
}
return array;
}
private static FacingList[] createArray()
{
FacingList[] facings = new FacingList[16];
for(int i = 0;i<16;i++)
{
facings[i] = new FacingList(i);
}
return facings;
}
}

View File

@ -0,0 +1,31 @@
package speiger.src.coreengine.math.smooth;
public class SmoothFloat
{
protected float value;
protected float target;
protected float agility;
public SmoothFloat(float agility)
{
this.agility = agility;
}
public SmoothFloat(float value, float agility)
{
this.value = value;
target = value;
this.agility = agility;
}
public boolean isDone(){return Math.abs(target - value) <= 0.5F;}
public void update(float delta){value += (target - value) * agility * delta;}
public void setTarget(float value){target = value;}
public void addTarget(float value){target += value;}
public void forceFinish(){value = target;}
public float getValue(){return value;}
public float getTarget(){return target;}
}

View File

@ -0,0 +1,44 @@
package speiger.src.coreengine.math.smooth;
import speiger.src.coreengine.math.vector.floats.Vec3f;
public class SmoothVec3f
{
Vec3f value = Vec3f.newMutable();
Vec3f target = Vec3f.newMutable();
Vec3f helper = Vec3f.newMutable();
float agility = 0F;
public SmoothVec3f(float agility)
{
this.agility = agility;
}
public SmoothVec3f(Vec3f vec, float agility)
{
value.set(vec);
target.set(vec);
this.agility = agility;
}
public boolean isDone()
{
return target.distanceToSquared(value) <= 0.005F;
}
public void update(float delta)
{
value.add(target.difference(value, helper).multiply(agility * delta));
}
public void setTarget(Vec3f value){setTarget(value.getX(), value.getY(), value.getZ());}
public void setTarget(float x, float y, float z) {target.set(x, y, z);}
public void addTarget(Vec3f value){addTarget(value.getX(), value.getY(), value.getZ());}
public void addTarget(float x, float y, float z) {target.add(x, y, z);}
public Vec3f getTarget(){return target.copy();}
public Vec3f getValue(){return value.copy();}
public void forceFinish(){value.set(target);}
}

View File

@ -0,0 +1,29 @@
package speiger.src.coreengine.math.value;
public class ConstantValue extends Value
{
public static final IValue MINUS_ONE = new ConstantValue(-1F);
public static final IValue ZERO = new ConstantValue(0F);
public static final IValue ONE = new ConstantValue(1F);
final float value;
public ConstantValue(float value)
{
super(0F, 0F);
this.value = value;
update(-1F);
}
@Override
protected float calculateProgress(float time)
{
return value;
}
@Override
protected void onInitialValueSet()
{
finishProgress();
}
}

View File

@ -0,0 +1,59 @@
package speiger.src.coreengine.math.value;
import speiger.src.coreengine.math.MathUtils;
public class CubicValue extends Value
{
final float startValue;
final float startHelperValue;
final float endHelperValue;
final float endValue;
boolean smooth = false;
public CubicValue(float duration, float startValue, float startHelper, float endHelper, float endValue)
{
this(0F, duration, startValue, startHelper, endHelper, endValue);
}
public CubicValue(float start, float duration, float startValue, float startHelper, float endHelper, float endValue)
{
super(start, duration);
this.startValue = startValue;
startHelperValue = startHelper;
endHelperValue = endHelper;
this.endValue = endValue;
}
public CubicValue setSmooth()
{
smooth = true;
return this;
}
public CubicValue setSmooth(boolean smooth)
{
this.smooth = smooth;
return this;
}
@Override
protected float calculateProgress(float time)
{
if(smooth)
{
float first = MathUtils.smoothQuadraticCurve(startValue, startHelperValue, endHelperValue, time);
float second = MathUtils.smoothQuadraticCurve(startHelperValue, endHelperValue, endValue, time);
return MathUtils.smoothLerp(first, second, time);
}
float first = MathUtils.quadraticCurve(startValue, startHelperValue, endHelperValue, time);
float second = MathUtils.quadraticCurve(startHelperValue, endHelperValue, endValue, time);
return MathUtils.lerp(first, second, time);
}
@Override
protected void onFinished()
{
finishProgress();
}
}

View File

@ -0,0 +1,15 @@
package speiger.src.coreengine.math.value;
public interface IValue
{
public float get();
public default float get(float min, float max)
{
return min + ((max - min) * get());
}
public float update(float particalTicks);
public boolean isDone();
}

View File

@ -0,0 +1,46 @@
package speiger.src.coreengine.math.value;
import speiger.src.coreengine.math.MathUtils;
public class LiniarValue extends Value
{
final float startValue;
final float endValue;
boolean smooth = false;
public LiniarValue(float duration, float startValue, float endValue)
{
this(0F, duration, startValue, endValue);
}
public LiniarValue(float start, float duration, float startValue, float endValue)
{
super(start, duration);
this.startValue = startValue;
this.endValue = endValue;
}
public LiniarValue setSmooth()
{
smooth = true;
return this;
}
public LiniarValue setSmooth(boolean smooth)
{
this.smooth = smooth;
return this;
}
@Override
protected float calculateProgress(float time)
{
return smooth ? MathUtils.smoothLerp(startValue, endValue, time) : MathUtils.lerp(startValue, endValue, time);
}
@Override
protected void onFinished()
{
finishProgress();
}
}

View File

@ -0,0 +1,48 @@
package speiger.src.coreengine.math.value;
import speiger.src.coreengine.math.MathUtils;
public class QuadraticValue extends Value
{
final float startValue;
final float medianValue;
final float endValue;
boolean smooth;
public QuadraticValue(float duration, float startValue, float medianValue, float endValue)
{
this(0F, duration, startValue, medianValue, endValue);
}
public QuadraticValue(float start, float duration, float startValue, float medianValue, float endValue)
{
super(start, duration);
this.startValue = startValue;
this.medianValue = medianValue;
this.endValue = endValue;
}
public QuadraticValue setSmooth()
{
smooth = true;
return this;
}
public QuadraticValue setSmooth(boolean smooth)
{
this.smooth = smooth;
return this;
}
@Override
protected float calculateProgress(float time)
{
return smooth ? MathUtils.smoothQuadraticCurve(startValue, medianValue, endValue, time) : MathUtils.quadraticCurve(startValue, medianValue, endValue, time);
}
@Override
protected void onFinished()
{
finishProgress();
}
}

View File

@ -0,0 +1,79 @@
package speiger.src.coreengine.math.value;
public abstract class Value implements IValue
{
final float start;
final float duration;
byte flags = 0;
int done = 0;
float progress = 0F;
float value;
public Value(float duration)
{
this(0F, duration);
}
public Value(float start, float duration)
{
this.duration = duration;
this.start = start;
}
@Override
public float update(float particleTime)
{
if((flags & 2) != 0)
{
return value;
}
progress += particleTime;
if(progress < start)
{
if((flags & 1) == 0)
{
value = calculateProgress(0F);
onInitialValueSet();
}
return value;
}
value = calculateProgress((progress - start) / duration);
if(progress >= start + duration)
{
onFinished();
}
return value;
}
@Override
public float get()
{
return value;
}
@Override
public boolean isDone()
{
return done > 0;
}
protected abstract float calculateProgress(float time);
protected void onFinished()
{
progress = start;
done++;
}
protected void onInitialValueSet()
{
flags |= 1;
}
protected void finishProgress()
{
flags |= 2;
done++;
}
}

View File

@ -0,0 +1,26 @@
package speiger.src.coreengine.math.vector;
import java.nio.ByteBuffer;
public interface Vec
{
public static final int X = 1;
public static final int Y = 2;
public static final int Z = 4;
public static final int W = 8;
public static final int ALL = X | Y | Z | W;
public Vec copy();
public Vec abs();
public Vec negate();
public Vec invert();
public Vec store(ByteBuffer buffer);
public Vec load(ByteBuffer buffer);
public boolean isMutable();
public Vec asMutable();
public Vec copyAsMutable();
public Vec asImmutable();
public Vec copyAsImmutable();
}

View File

@ -0,0 +1,21 @@
package speiger.src.coreengine.math.vector;
import speiger.src.coreengine.math.vector.floats.Vec2f;
import speiger.src.coreengine.math.vector.floats.Vec3f;
public class VectorUtil
{
public static float barryCentric(Vec3f p1, Vec3f p2, Vec3f p3, Vec2f pos)
{
float det = (p2.getZ() - p3.getZ()) * (p1.getX() - p3.getX()) + (p3.getX() - p2.getX()) * (p1.getZ() - p3.getZ());
float l1 = ((p2.getZ() - p3.getZ()) * (pos.getX() - p3.getX()) + (p3.getX() - p2.getX()) * (pos.getY() - p3.getZ())) / det;
float l2 = ((p3.getZ() - p1.getZ()) * (pos.getX() - p3.getX()) + (p1.getX() - p3.getX()) * (pos.getY() - p3.getZ())) / det;
float l3 = 1.0f - l1 - l2;
return l1 * p1.getY() + l2 * p2.getY() + l3 * p3.getY();
}
public static float fma(float x, float y, float z)
{
return x * y + z;
}
}

View File

@ -0,0 +1,149 @@
package speiger.src.coreengine.math.vector.bytes;
import java.nio.ByteBuffer;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.doubles.Vec2d;
import speiger.src.coreengine.math.vector.floats.Vec2f;
import speiger.src.coreengine.math.vector.ints.Vec2i;
import speiger.src.coreengine.math.vector.longs.Vec2l;
import speiger.src.coreengine.math.vector.shorts.Vec2s;
public interface Vec2b extends Vecb
{
public static final Vec2b ZERO = newVec();
public static final Vec2b MINUS_ONE = newVec((byte)-1);
public static final Vec2b ONE = newVec((byte)1);
public static Vec2b newMutable(){return new Vec2bMutable();}
public static Vec2b newMutable(byte value){return new Vec2bMutable(value);}
public static Vec2b newMutable(byte x, byte y){return new Vec2bMutable(x, y);}
public static Vec2b newMutable(Vec2b value){return newMutable(value.getX(), value.getY());}
public static Vec2b newVec(){return new Vec2bImmutable();}
public static Vec2b newVec(byte value){return new Vec2bImmutable(value);}
public static Vec2b newVec(byte x, byte y){return new Vec2bImmutable(x, y);}
public static Vec2b newVec(Vec2b value){return newVec(value.getX(), value.getY());}
public byte getX();
public byte getY();
public Vec2b setX(byte x);
public Vec2b setY(byte y);
@Override
public default byte[] asArray(){return new byte[]{getX(), getY()};}
@Override
public Vec2b copy();
@Override
public default Vec2b abs(){return set((byte)Math.abs(getX()), (byte)Math.abs(getY()));}
@Override
public default Vec2b negate(){return set((byte)0, (byte)0);}
@Override
public default Vec2b invert(){return set((byte)(-getX()), (byte)(-getY()));};
@Override
public default Vec2b add(byte value) {return add(value, value);}
public default Vec2b add(Vec2b value) {return add(value.getX(), value.getY());}
public default Vec2b add(byte x, byte y) {return set((byte)(x + getX()), (byte)(y + getY()));}
@Override
public default Vec2b sub(byte value){return sub(value, value);}
public default Vec2b sub(Vec2b value){return sub(value.getX(), value.getY());}
public default Vec2b sub(byte x, byte y) {return set((byte)(getX() - x), (byte)(getY() - y));}
@Override
public default Vec2b multiply(byte value){return multiply(value, value);}
public default Vec2b multiply(Vec2b value){return multiply(value.getX(), value.getY());}
public default Vec2b multiply(byte x, byte y) {return set((byte)(x * getX()), (byte)(y * getY()));}
@Override
public default Vec2b devide(byte value){return devide(value, value);}
public default Vec2b devide(Vec2b value){return devide(value.getX(), value.getY());}
public default Vec2b devide(byte x, byte y){return set((byte)(getX() / x), (byte)(getY() / y));}
@Override
public default Vec2b set(byte value){return set(value, value);};
public default Vec2b set(Vec2b value){return set(value.getX(), value.getY());}
public Vec2b set(byte x, byte y);
public default double distanceTo(Vec2b value){return distanceTo(value.getX(), value.getY());}
public default double distanceTo(byte x, byte y){return Math.sqrt(distanceToSquared(x, y));}
public default long distanceToSquared(Vec2b value){return distanceToSquared(value.getX(), value.getY());}
public default long distanceToSquared(byte x, byte y)
{
long xPos = getX() - x;
long yPos = getY() - y;
return (xPos * xPos) + (yPos * yPos);
}
@Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY());}
public default long dotProduct(Vec2b value){return dotProduct(value.getX(), value.getY());}
public default long dotProduct(byte x, byte y){return (getX() * x) + (getY() * y);}
public default Vec2b rotate(byte angle, Vec2b center){return rotate(angle, center.getX(), center.getY());}
public default Vec2b rotate(byte angle, byte x, byte y)
{
byte xPos = (byte)(getX() - x);
byte yPos = (byte)(getY() - y);
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
return set((byte)((xPos * cos) + (yPos * sin) + x), (byte)(-(xPos * sin) + (yPos * cos) + y));
}
public default Vec2b min(Vec2b other) {return min(other, this);}
public default Vec2b min(Vec2b other, Vec2b result){return min(other.getX(), other.getY(), result);}
public default Vec2b min(byte x, byte y) {return min(x, y, this);}
public default Vec2b min(byte x, byte y, Vec2b result){return result.set((byte)Math.min(getX(), x), (byte)Math.min(getY(), y));}
public default Vec2b max(Vec2b other) {return max(other, this);}
public default Vec2b max(Vec2b other, Vec2b result){return max(other.getX(), other.getY(), result);}
public default Vec2b max(byte x, byte y) {return max(x, y, this);}
public default Vec2b max(byte x, byte y, Vec2b result){return result.set((byte)Math.max(getX(), x), (byte)Math.max(getY(), y));}
public default Vec2b difference(Vec2b other) {return difference(other, this);}
public default Vec2b difference(Vec2b other, Vec2b result){return difference(other.getX(), other.getY(), result);}
public default Vec2b difference(byte x, byte y) {return difference(x, y, this);}
public default Vec2b difference(byte x, byte y, Vec2b result){return result.set((byte)(getX() - x), (byte)(getY() - y));}
@Override
public default Vec2b clamp(byte min, byte max){return clamp(min, max, ALL);}
public default Vec2b clamp(byte min, byte max, Vec2b result){return clamp(min, max, result, ALL);}
@Override
public default Vec2b clamp(byte min, byte max, int filter){return clamp(min, max, this, filter);}
public default Vec2b clamp(byte min, byte max, Vec2b result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()));}
@Override
public default Vec2b store(ByteBuffer buffer)
{
buffer.put(getX()).put(getY());
return this;
}
@Override
public default Vec2b load(ByteBuffer buffer)
{
return set(buffer.get(), buffer.get());
}
@Override
public default Vec2s asShort(){return isMutable() ? Vec2s.newMutable(getX(), getY()) : Vec2s.newVec(getX(), getY());}
@Override
public default Vec2i asInt(){return isMutable() ? Vec2i.newMutable(getX(), getY()) : Vec2i.newVec(getX(), getY());}
@Override
public default Vec2l asLong(){return isMutable() ? Vec2l.newMutable(getX(), getY()) : Vec2l.newVec(getX(), getY());}
@Override
public default Vec2f asFloat() {return isMutable() ? Vec2f.newMutable(getX(), getY()) : Vec2f.newVec(getX(), getY());}
@Override
public default Vec2d asDouble(){return isMutable() ? Vec2d.newMutable(getX(), getY()) : Vec2d.newVec(getX(), getY());}
@Override
public default Vec2b asMutable(){return isMutable() ? this : newMutable(this);}
@Override
public default Vec2b asImmutable(){return isMutable() ? newVec(this) : this;}
@Override
public default Vec2b copyAsMutable(){return newMutable(this);}
@Override
public default Vec2b copyAsImmutable(){return newVec(this);}
}

View File

@ -0,0 +1,92 @@
package speiger.src.coreengine.math.vector.bytes;
import java.util.Objects;
public class Vec2bImmutable implements Vec2b
{
final byte x;
final byte y;
public Vec2bImmutable()
{
x = 0;
y = 0;
}
public Vec2bImmutable(byte value)
{
x = value;
y = value;
}
public Vec2bImmutable(byte x, byte y)
{
this.x = x;
this.y = y;
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public byte getX()
{
return x;
}
@Override
public byte getY()
{
return y;
}
@Override
public Vec2b setX(byte x)
{
return this.x == x ? this : Vec2b.newVec(x, y);
}
@Override
public Vec2b setY(byte y)
{
return this.y == y ? this : Vec2b.newVec(x, y);
}
@Override
public Vec2b copy()
{
return Vec2b.newVec(this);
}
@Override
public Vec2b set(byte x, byte y)
{
return this.x == x && this.y == y ? this : Vec2b.newVec(x, y);
}
@Override
public int hashCode()
{
return Objects.hash(x, y);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec2b)
{
Vec2b vec = (Vec2b)obj;
return vec.getX() == x && vec.getY() == y;
}
return false;
}
@Override
public String toString()
{
return "Vec2b[x="+x+", y="+y+"]";
}
}

View File

@ -0,0 +1,94 @@
package speiger.src.coreengine.math.vector.bytes;
import java.util.Objects;
public class Vec2bMutable implements Vec2b
{
byte x;
byte y;
public Vec2bMutable()
{
}
public Vec2bMutable(byte value)
{
x = value;
y = value;
}
public Vec2bMutable(byte x, byte y)
{
this.x = x;
this.y = y;
}
@Override
public boolean isMutable()
{
return true;
}
@Override
public byte getX()
{
return x;
}
@Override
public byte getY()
{
return y;
}
@Override
public Vec2b setX(byte x)
{
this.x = x;
return this;
}
@Override
public Vec2b setY(byte y)
{
this.y = y;
return this;
}
@Override
public Vec2b copy()
{
return Vec2b.newMutable(this);
}
@Override
public Vec2b set(byte x, byte y)
{
this.x = x;
this.y = y;
return this;
}
@Override
public int hashCode()
{
return Objects.hash(x, y);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec2b)
{
Vec2b vec = (Vec2b)obj;
return vec.getX() == x && vec.getY() == y;
}
return false;
}
@Override
public String toString()
{
return "Vec2b[x="+x+", y="+y+"]";
}
}

View File

@ -0,0 +1,141 @@
package speiger.src.coreengine.math.vector.bytes;
import java.nio.ByteBuffer;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.doubles.Vec3d;
import speiger.src.coreengine.math.vector.floats.Vec3f;
import speiger.src.coreengine.math.vector.ints.Vec3i;
import speiger.src.coreengine.math.vector.longs.Vec3l;
import speiger.src.coreengine.math.vector.shorts.Vec3s;
public interface Vec3b extends Vecb
{
public static final Vec3b ZERO = newVec();
public static final Vec3b MINUS_ONE = newVec((byte)-1);
public static final Vec3b ONE = newVec((byte)1);
public static Vec3b newMutable(){return new Vec3bMutable();}
public static Vec3b newMutable(byte value){return new Vec3bMutable(value);}
public static Vec3b newMutable(byte x, byte y, byte z){return new Vec3bMutable(x, y, z);}
public static Vec3b newMutable(Vec3b vec){return newMutable(vec.getX(), vec.getY(), vec.getZ());}
public static Vec3b newVec(){return new Vec3bImmutable();}
public static Vec3b newVec(byte value){return new Vec3bImmutable(value);}
public static Vec3b newVec(byte x, byte y, byte z){return new Vec3bImmutable(x, y, z);}
public static Vec3b newVec(Vec3b vec){return newVec(vec.getX(), vec.getY(), vec.getZ());}
public byte getX();
public byte getY();
public byte getZ();
public Vec3b setX(byte x);
public Vec3b setY(byte y);
public Vec3b setZ(byte z);
@Override
public default byte[] asArray(){return new byte[]{getX(), getY(), getZ()};}
@Override
public Vec3b copy();
@Override
public default Vec3b abs(){return set((byte)Math.abs(getX()), (byte)Math.abs(getY()), (byte)Math.abs(getZ()));}
@Override
public default Vec3b negate(){return set((byte)0, (byte)0, (byte)0);}
@Override
public default Vec3b invert(){return set((byte)-getX(), (byte)-getY(), (byte)-getZ());}
@Override
public default Vec3b add(byte value){return add(value, value, value);}
public default Vec3b add(Vec3b value){return add(value.getX(), value.getY(), value.getZ());}
public default Vec3b add(byte x, byte y, byte z){return set((byte)(getX() + x), (byte)(getY() + y), (byte)(getZ() + z));}
@Override
public default Vec3b sub(byte value){return sub(value, value, value);}
public default Vec3b sub(Vec3b value){return sub(value.getX(), value.getY(), value.getZ());}
public default Vec3b sub(byte x, byte y, byte z){return set((byte)(getX() - x), (byte)(getY() - y), (byte)(getZ() - z));}
@Override
public default Vec3b multiply(byte value){return multiply(value, value, value);}
public default Vec3b multiply(Vec3b value){return multiply(value.getX(), value.getY(), value.getZ());}
public default Vec3b multiply(byte x, byte y, byte z){return set((byte)(getX() * x), (byte)(getY() * y), (byte)(getZ() * z));}
@Override
public default Vec3b devide(byte value){return devide(value, value, value);}
public default Vec3b devide(Vec3b value){return devide(value.getX(), value.getY(), value.getZ());}
public default Vec3b devide(byte x, byte y, byte z){return set((byte)(getX() / x), (byte)(getY() / y), (byte)(getZ() / z));}
@Override
public default Vec3b set(byte value){return set(value, value, value);}
public default Vec3b set(Vec3b value){return set(value.getX(), value.getY(), value.getZ());}
public Vec3b set(byte x, byte y, byte z);
public default double distanceTo(Vec3b value){return distanceTo(value.getX(), value.getY(), value.getZ());}
public default double distanceTo(byte x, byte y, byte z){return Math.sqrt(distanceToSquared(x, y, z));}
public default long distanceToSquared(Vec3b value){return distanceToSquared(value.getX(), value.getY(), value.getZ());}
public default long distanceToSquared(byte x, byte y, byte z)
{
long xPos = getX() - x;
long yPos = getY() - y;
long zPos = getZ() - z;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
}
@Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());}
public default long dotProduct(Vec3b value){return dotProduct(value.getX(), value.getY(), value.getZ());}
public default long dotProduct(byte x, byte y, byte z){return (getX() * x) + (getY() * y) + (getZ() * z);}
public default Vec3b min(Vec3b other) {return min(other, this);}
public default Vec3b min(Vec3b other, Vec3b result){return min(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3b min(byte x, byte y, byte z) {return min(x, y, z, this);}
public default Vec3b min(byte x, byte y, byte z, Vec3b result){return result.set((byte)Math.min(getX(), x), (byte)Math.min(getY(), y), (byte)Math.min(getZ(), z));}
public default Vec3b max(Vec3b other) {return max(other, this);}
public default Vec3b max(Vec3b other, Vec3b result){return max(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3b max(byte x, byte y, byte z) {return max(x, y, z, this);}
public default Vec3b max(byte x, byte y, byte z, Vec3b result){return result.set((byte)Math.max(getX(), x), (byte)Math.max(getY(), y), (byte)Math.max(getZ(), z));}
public default Vec3b difference(Vec3b other) {return difference(other, this);}
public default Vec3b difference(Vec3b other, Vec3b result){return difference(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3b difference(byte x, byte y, byte z) {return difference(x, y, z, this);}
public default Vec3b difference(byte x, byte y, byte z, Vec3b result){return result.set((byte)(getX() - x), (byte)(getY() - y), (byte)(getZ() - z));}
@Override
public default Vec3b clamp(byte min, byte max){return clamp(min, max, ALL);}
public default Vec3b clamp(byte min, byte max, Vec3b result){return clamp(min, max, result, ALL);}
@Override
public default Vec3b clamp(byte min, byte max, int filter){return clamp(min, max, this, filter);}
public default Vec3b clamp(byte min, byte max, Vec3b result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()));}
@Override
public default Vec3b store(ByteBuffer buffer)
{
buffer.put(getX()).put(getY()).put(getZ());
return this;
}
@Override
public default Vec3b load(ByteBuffer buffer)
{
return set(buffer.get(), buffer.get(), buffer.get());
}
@Override
public default Vec3s asShort(){return isMutable() ? Vec3s.newMutable(getX(), getY(), getZ()) : Vec3s.newVec(getX(), getY(), getZ());}
@Override
public default Vec3i asInt(){return isMutable() ? Vec3i.newMutable(getX(), getY(), getZ()) : Vec3i.newVec(getX(), getY(), getZ());}
@Override
public default Vec3l asLong(){return isMutable() ? Vec3l.newMutable(getX(), getY(), getZ()) : Vec3l.newVec(getX(), getY(), getZ());}
@Override
public default Vec3f asFloat() {return isMutable() ? Vec3f.newMutable(getX(), getY(), getZ()) : Vec3f.newVec(getX(), getY(), getZ());}
@Override
public default Vec3d asDouble(){return isMutable() ? Vec3d.newMutable(getX(), getY(), getZ()) : Vec3d.newVec(getX(), getY(), getZ());}
@Override
public default Vec3b asMutable(){return isMutable() ? this : newMutable(this);}
@Override
public default Vec3b asImmutable(){return isMutable() ? newVec(this) : this;}
@Override
public default Vec3b copyAsMutable(){return newMutable(this);}
@Override
public default Vec3b copyAsImmutable(){return newVec(this);}
}

View File

@ -0,0 +1,108 @@
package speiger.src.coreengine.math.vector.bytes;
import java.util.Objects;
public class Vec3bImmutable implements Vec3b
{
final byte x;
final byte y;
final byte z;
public Vec3bImmutable()
{
x = 0;
y = 0;
z = 0;
}
public Vec3bImmutable(byte value)
{
x = value;
y = value;
z = value;
}
public Vec3bImmutable(byte x, byte y, byte z)
{
this.x = x;
this.y = y;
this.z = z;
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public byte getX()
{
return x;
}
@Override
public byte getY()
{
return y;
}
@Override
public byte getZ()
{
return z;
}
@Override
public Vec3b setX(byte x)
{
return this.x == x ? this : Vec3b.newVec(x, y, z);
}
@Override
public Vec3b setY(byte y)
{
return this.y == y ? this : Vec3b.newVec(x, y, z);
}
@Override
public Vec3b setZ(byte z)
{
return this.z == z ? this : Vec3b.newVec(x, y, z);
}
@Override
public Vec3b copy()
{
return Vec3b.newVec(this);
}
@Override
public Vec3b set(byte x, byte y, byte z)
{
return this.x == x && this.y == y && this.z == z ? this : Vec3b.newVec(x, y, z);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec3b)
{
Vec3b vec = (Vec3b)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
}
return false;
}
@Override
public String toString()
{
return "Vec3b[x="+x+", y="+y+", z="+z+"]";
}
}

View File

@ -0,0 +1,111 @@
package speiger.src.coreengine.math.vector.bytes;
import java.util.Objects;
public class Vec3bMutable implements Vec3b
{
byte x;
byte y;
byte z;
public Vec3bMutable()
{
}
public Vec3bMutable(byte value)
{
x = value;
y = value;
z = value;
}
public Vec3bMutable(byte x, byte y, byte z)
{
this.x = x;
this.y = y;
this.z = z;
}
@Override
public boolean isMutable()
{
return true;
}
@Override
public byte getX()
{
return x;
}
@Override
public byte getY()
{
return y;
}
@Override
public byte getZ()
{
return z;
}
@Override
public Vec3b setX(byte x)
{
this.x = x;
return this;
}
@Override
public Vec3b setY(byte y)
{
this.y = y;
return this;
}
@Override
public Vec3b setZ(byte z)
{
this.z = z;
return this;
}
@Override
public Vec3b copy()
{
return Vec3b.newMutable(this);
}
@Override
public Vec3b set(byte x, byte y, byte z)
{
this.x = x;
this.y = y;
this.z = z;
return this;
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec3b)
{
Vec3b vec = (Vec3b)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
}
return false;
}
@Override
public String toString()
{
return "Vec3b[x="+x+", y="+y+", z="+z+"]";
}
}

View File

@ -0,0 +1,145 @@
package speiger.src.coreengine.math.vector.bytes;
import java.nio.ByteBuffer;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.doubles.Vec4d;
import speiger.src.coreengine.math.vector.floats.Vec4f;
import speiger.src.coreengine.math.vector.ints.Vec4i;
import speiger.src.coreengine.math.vector.longs.Vec4l;
import speiger.src.coreengine.math.vector.shorts.Vec4s;
public interface Vec4b extends Vecb
{
public static final Vec4b ZERO = newVec();
public static final Vec4b MINUS_ONE = newVec((byte)-1);
public static final Vec4b ONE = newVec((byte)1);
public static Vec4b newMutable(){return new Vec4bMutable();}
public static Vec4b newMutable(byte value){return new Vec4bMutable(value);}
public static Vec4b newMutable(byte x, byte y, byte z, byte w){return new Vec4bMutable(x, y, z, w);}
public static Vec4b newMutable(Vec4b vec){return newMutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW());}
public static Vec4b newVec(){return new Vec4bImmutable();}
public static Vec4b newVec(byte value){return new Vec4bImmutable(value);}
public static Vec4b newVec(byte x, byte y, byte z, byte w){return new Vec4bImmutable(x, y, z, w);}
public static Vec4b newVec(Vec4b vec){return newVec(vec.getX(), vec.getY(), vec.getZ(), vec.getW());}
public byte getX();
public byte getY();
public byte getZ();
public byte getW();
public Vec4b setX(byte x);
public Vec4b setY(byte y);
public Vec4b setZ(byte z);
public Vec4b setW(byte w);
@Override
public default byte[] asArray(){return new byte[]{getX(), getY(), getZ(), getW()};}
@Override
public Vec4b copy();
@Override
public default Vec4b abs(){return set((byte)Math.abs(getX()), (byte)Math.abs(getY()), (byte)Math.abs(getZ()), (byte)Math.abs(getW()));}
@Override
public default Vec4b negate(){return set((byte)0, (byte)0, (byte)0, (byte)0);}
@Override
public default Vec4b invert(){return set((byte)-getX(), (byte)-getY(), (byte)-getZ(), (byte)-getW());}
@Override
public default Vec4b add(byte value){return add(value, value, value, value);}
public default Vec4b add(Vec4b value){return add(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4b add(byte x, byte y, byte z, byte w){return set((byte)(getX() + x), (byte)(getY() + y), (byte)(getZ() + z), (byte)(getW() + w));}
@Override
public default Vec4b sub(byte value){return sub(value, value, value, value);}
public default Vec4b sub(Vec4b value){return sub(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4b sub(byte x, byte y, byte z, byte w){return set((byte)(getX() - x), (byte)(getY() - y), (byte)(getZ() - z), (byte)(getW() - w));}
@Override
public default Vec4b multiply(byte value){return multiply(value, value, value, value);}
public default Vec4b multiply(Vec4b value){return multiply(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4b multiply(byte x, byte y, byte z, byte w){return set((byte)(getX() * x), (byte)(getY() * y), (byte)(getZ() * z), (byte)(getW() * w));}
@Override
public default Vec4b devide(byte value){return devide(value, value, value, value);}
public default Vec4b devide(Vec4b value){return devide(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4b devide(byte x, byte y, byte z, byte w){return set((byte)(getX() / x), (byte)(getY() / y), (byte)(getZ() / z), (byte)(getW() / w));}
@Override
public default Vec4b set(byte value){return set(value, value, value, value);}
public default Vec4b set(Vec4b value){return set(value.getX(), value.getY(), value.getZ(), value.getW());}
public Vec4b set(byte x, byte y, byte z, byte w);
public default double distanceTo(Vec4b value){return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW());}
public default double distanceTo(byte x, byte y, byte z, byte w){return Math.sqrt(distanceTo(x, y, z, w));}
public default long distanceToSquared(Vec4b value){return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW());}
public default long distanceToSquared(byte x, byte y, byte z, byte w)
{
long xPos = getX() - x;
long yPos = getY() - y;
long zPos = getZ() - z;
long wPos = getW() - w;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
}
@Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW());}
public default long dotProduct(Vec4b value){return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW());}
public default long dotProduct(byte x, byte y, byte z, byte w){return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w);};
public default Vec4b min(Vec4b other) {return min(other, this);}
public default Vec4b min(Vec4b other, Vec4b result){return min(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4b min(byte x, byte y, byte z, byte w) {return min(x, y, z, w, this);}
public default Vec4b min(byte x, byte y, byte z, byte w, Vec4b result){return result.set((byte)Math.min(getX(), x), (byte)Math.min(getY(), y), (byte)Math.min(getZ(), z), (byte)Math.min(getW(), w));}
public default Vec4b max(Vec4b other) {return max(other, this);}
public default Vec4b max(Vec4b other, Vec4b result){return max(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4b max(byte x, byte y, byte z, byte w) {return max(x, y, z, w, this);}
public default Vec4b max(byte x, byte y, byte z, byte w, Vec4b result){return result.set((byte)Math.max(getX(), x), (byte)Math.max(getY(), y), (byte)Math.max(getZ(), z), (byte)Math.max(getZ(), z));}
public default Vec4b difference(Vec4b other) {return difference(other, this);}
public default Vec4b difference(Vec4b other, Vec4b result){return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4b difference(byte x, byte y, byte z, byte w) {return difference(x, y, z, w, this);}
public default Vec4b difference(byte x, byte y, byte z, byte w, Vec4b result){return result.set((byte)(getX() - x), (byte)(getY() - y), (byte)(getZ() - z), (byte)(getW() - w));}
@Override
public default Vec4b clamp(byte min, byte max){return clamp(min, max, ALL);}
public default Vec4b clamp(byte min, byte max, Vec4b result){return clamp(min, max, result, ALL);}
@Override
public default Vec4b clamp(byte min, byte max, int filter){return clamp(min, max, this, filter);}
public default Vec4b clamp(byte min, byte max, Vec4b result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW()));}
@Override
public default Vec4b store(ByteBuffer buffer)
{
buffer.put(getX()).put(getY()).put(getZ()).put(getW());
return this;
}
@Override
public default Vec4b load(ByteBuffer buffer)
{
return set(buffer.get(), buffer.get(), buffer.get(), buffer.get());
}
@Override
public default Vec4s asShort(){return isMutable() ? Vec4s.newMutable(getX(), getY(), getZ(), getW()) : Vec4s.newVec(getX(), getY(), getZ(), getW());}
@Override
public default Vec4i asInt(){return isMutable() ? Vec4i.newMutable(getX(), getY(), getZ(), getW()) : Vec4i.newVec(getX(), getY(), getZ(), getW());}
@Override
public default Vec4l asLong(){return isMutable() ? Vec4l.newMutable(getX(), getY(), getZ(), getW()) : Vec4l.newVec(getX(), getY(), getZ(), getW());}
@Override
public default Vec4f asFloat() {return isMutable() ? Vec4f.newMutable(getX(), getY(), getZ(), getW()) : Vec4f.newVec(getX(), getY(), getZ(), getW());}
@Override
public default Vec4d asDouble(){return isMutable() ? Vec4d.newMutable(getX(), getY(), getZ(), getW()) : Vec4d.newVec(getX(), getY(), getZ(), getW());}
@Override
public default Vec4b asMutable(){return isMutable() ? this : newMutable(this);}
@Override
public default Vec4b asImmutable(){return isMutable() ? newVec(this) : this;}
@Override
public default Vec4b copyAsMutable(){return newMutable(this);}
@Override
public default Vec4b copyAsImmutable(){return newVec(this);}
}

View File

@ -0,0 +1,124 @@
package speiger.src.coreengine.math.vector.bytes;
import java.util.Objects;
public class Vec4bImmutable implements Vec4b
{
final byte x;
final byte y;
final byte z;
final byte w;
public Vec4bImmutable()
{
x = 0;
y = 0;
z = 0;
w = 0;
}
public Vec4bImmutable(byte value)
{
x = value;
y = value;
z = value;
w = value;
}
public Vec4bImmutable(byte x, byte y, byte z, byte w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public byte getX()
{
return x;
}
@Override
public byte getY()
{
return y;
}
@Override
public byte getZ()
{
return z;
}
@Override
public byte getW()
{
return w;
}
@Override
public Vec4b setX(byte x)
{
return this.x == x ? this : Vec4b.newVec(x, y, z, w);
}
@Override
public Vec4b setY(byte y)
{
return this.y == y ? this : Vec4b.newVec(x, y, z, w);
}
@Override
public Vec4b setZ(byte z)
{
return this.z == z ? this : Vec4b.newVec(x, y, z, w);
}
@Override
public Vec4b setW(byte w)
{
return this.w == w ? this : Vec4b.newVec(x, y, z, w);
}
@Override
public Vec4b copy()
{
return Vec4b.newVec(this);
}
@Override
public Vec4b set(byte x, byte y, byte z, byte w)
{
return this.x == x && this.y == y && this.z == z && this.w == w ? this : Vec4b.newVec(x, y, z, w);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z, w);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec4b)
{
Vec4b vec = (Vec4b)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
}
return false;
}
@Override
public String toString()
{
return "Vec4b[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
}

View File

@ -0,0 +1,129 @@
package speiger.src.coreengine.math.vector.bytes;
import java.util.Objects;
public class Vec4bMutable implements Vec4b
{
byte x;
byte y;
byte z;
byte w;
public Vec4bMutable()
{
}
public Vec4bMutable(byte value)
{
x = value;
y = value;
z = value;
w = value;
}
public Vec4bMutable(byte x, byte y, byte z, byte w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
@Override
public boolean isMutable()
{
return true;
}
@Override
public byte getX()
{
return x;
}
@Override
public byte getY()
{
return y;
}
@Override
public byte getZ()
{
return z;
}
@Override
public byte getW()
{
return w;
}
@Override
public Vec4b setX(byte x)
{
this.x = x;
return this;
}
@Override
public Vec4b setY(byte y)
{
this.y = y;
return this;
}
@Override
public Vec4b setZ(byte z)
{
this.z = z;
return this;
}
@Override
public Vec4b setW(byte w)
{
this.w = w;
return this;
}
@Override
public Vec4b copy()
{
return Vec4b.newMutable(this);
}
@Override
public Vec4b set(byte x, byte y, byte z, byte w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
return this;
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z, w);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec4b)
{
Vec4b vec = (Vec4b)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
}
return false;
}
@Override
public String toString()
{
return "Vec4b[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
}

View File

@ -0,0 +1,29 @@
package speiger.src.coreengine.math.vector.bytes;
import speiger.src.coreengine.math.vector.Vec;
import speiger.src.coreengine.math.vector.doubles.Vecd;
import speiger.src.coreengine.math.vector.floats.Vecf;
import speiger.src.coreengine.math.vector.ints.Veci;
import speiger.src.coreengine.math.vector.longs.Vecl;
import speiger.src.coreengine.math.vector.shorts.Vecs;
public interface Vecb extends Vec
{
public Vecb set(byte value);
public Vecb add(byte value);
public Vecb sub(byte value);
public Vecb multiply(byte value);
public Vecb devide(byte value);
public Vecb clamp(byte min, byte max);
public Vecb clamp(byte min, byte max, int filter);
public long lengthSquared();
public default double length(){return Math.sqrt(lengthSquared());}
public byte[] asArray();
public Vecs asShort();
public Veci asInt();
public Vecl asLong();
public Vecf asFloat();
public Vecd asDouble();
}

View File

@ -0,0 +1,187 @@
package speiger.src.coreengine.math.vector.doubles;
import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.bytes.Vec2b;
import speiger.src.coreengine.math.vector.floats.Vec2f;
import speiger.src.coreengine.math.vector.ints.Vec2i;
import speiger.src.coreengine.math.vector.longs.Vec2l;
import speiger.src.coreengine.math.vector.shorts.Vec2s;
public interface Vec2d extends Vecd
{
public static final Vec2d ZERO = newVec();
public static final Vec2d MINUS_ONE = newVec(-1D);
public static final Vec2d ONE = newVec(1D);
public static Vec2d newMutable(){return new Vec2dMutable();}
public static Vec2d newMutable(double value){return new Vec2dMutable(value);}
public static Vec2d newMutable(double x, double y){return new Vec2dMutable(x, y);}
public static Vec2d newMutable(Vec2d value){return newMutable(value.getX(), value.getY());}
public static Vec2d newVec(){return new Vec2dImmutable();}
public static Vec2d newVec(double value){return new Vec2dImmutable(value);}
public static Vec2d newVec(double x, double y){return new Vec2dImmutable(x, y);}
public static Vec2d newVec(Vec2d value){return newVec(value.getX(), value.getY());}
public double getX();
public double getY();
public Vec2d setX(double x);
public Vec2d setY(double y);
@Override
public default double[] asArray(){return new double[]{getX(), getY()};}
@Override
public Vec2d copy();
@Override
public default Vec2d abs(){return set(Math.abs(getX()), Math.abs(getY()));}
@Override
public default Vec2d negate(){return set(0D, 0D);}
@Override
public default Vec2d invert(){return set(-getX(), -getY());};
public default Vec2d normalize()
{
double l = length();
return l == 0D ? this : multiply(1D / l);
}
@Override
public default Vec2d add(double value) {return add(value, value);}
public default Vec2d add(Vec2d value) {return add(value.getX(), value.getY());}
public default Vec2d add(double x, double y) {return set(x + getX(), y + getY());}
@Override
public default Vec2d sub(double value){return sub(value, value);}
public default Vec2d sub(Vec2d value){return sub(value.getX(), value.getY());}
public default Vec2d sub(double x, double y) {return set(getX() - x, getY() - y);}
@Override
public default Vec2d multiply(double value){return multiply(value, value);}
public default Vec2d multiply(Vec2d value){return multiply(value.getX(), value.getY());}
public default Vec2d multiply(double x, double y) {return set(x * getX(), y * getY());}
@Override
public default Vec2d devide(double value){return devide(value, value);}
public default Vec2d devide(Vec2d value){return devide(value.getX(), value.getY());}
public default Vec2d devide(double x, double y){return set(getX() / x, getY() / y);}
@Override
public default Vec2d set(double value){return set(value, value);};
public default Vec2d set(Vec2d value){return set(value.getX(), value.getY());}
public Vec2d set(double x, double y);
public default double distanceTo(Vec2d value){return distanceTo(value.getX(), value.getY());}
public default double distanceTo(double x, double y){return Math.sqrt(distanceToSquared(x, y));}
public default double distanceToSquared(Vec2d value){return distanceToSquared(value.getX(), value.getY());}
public default double distanceToSquared(double x, double y)
{
double xPos = getX() - x;
double yPos = getY() - y;
return (xPos * xPos) + (yPos * yPos);
}
@Override
public default double lengthSquared() {return (getX() * getX()) + (getY() * getY());}
public default double dotProduct(Vec2d value){return dotProduct(value.getX(), value.getY());}
public default double dotProduct(double x, double y){return (getX() * x) + (getY() * y);}
public default Vec2d lerp(Vec2d value, float progress, Vec2d result){return lerp(value.getX(), value.getY(), progress, result);}
public default Vec2d lerp(double x, double y, float progress, Vec2d result){return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress));};
public default double angle(Vec2d value){return angle(value.getX(), value.getY());}
public default double angle(double x, double y){return (float)Math.atan2((getX() * y) - (getY() * x), (getX() * x) + (getY() * y));}
public default double directionAngle(Vec2d value){return directionAngle(value.getX(), value.getY());}
public default double directionAngle(double x, double y){return (float)(-Math.toDegrees(Math.atan2(getX() - x, getY() - y)) % 360D);}
public default Vec2d reflect(Vec2d value){return reflect(value.getX(), value.getY(), this);}
public default Vec2d reflect(double x, double y){return reflect(x, y, this);};
public default Vec2d reflect(Vec2d value, Vec2d result){return reflect(value.getX(), value.getY(), result);}
public default Vec2d reflect(double x, double y, Vec2d result)
{
double dot = dotProduct(x, y);
double x2 = (float)((dot + dot) * x);
double y2 = (float)((dot + dot) * y);
return result.set(getX() - x2, getY() - y2);
}
public default Vec2d rotate(double angle, Vec2d center){return rotate(angle, center.getX(), center.getY());}
public default Vec2d rotate(double angle, double x, double y)
{
double xPos = getX() - x;
double yPos = getY() - y;
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
return set((float)((xPos * cos) + (yPos * sin) + x), (float)(-(xPos * sin) + (yPos * cos) + y));
}
public default Vec2d min(Vec2d other) {return min(other, this);}
public default Vec2d min(Vec2d other, Vec2d result){return min(other.getX(), other.getY(), result);}
public default Vec2d min(double x, double y) {return min(x, y, this);}
public default Vec2d min(double x, double y, Vec2d result){return result.set(Math.min(getX(), x), Math.min(getY(), y));}
public default Vec2d max(Vec2d other) {return max(other, this);}
public default Vec2d max(Vec2d other, Vec2d result){return max(other.getX(), other.getY(), result);}
public default Vec2d max(double x, double y) {return max(x, y, this);}
public default Vec2d max(double x, double y, Vec2d result){return result.set(Math.max(getX(), x), Math.max(getY(), y));}
public default Vec2d difference(Vec2d other) {return difference(other, this);}
public default Vec2d difference(Vec2d other, Vec2d result){return difference(other.getX(), other.getY(), result);}
public default Vec2d difference(double x, double y) {return difference(x, y, this);}
public default Vec2d difference(double x, double y, Vec2d result){return result.set(getX() - x, getY() - y);}
@Override
public default Vec2d clamp(double min, double max){return clamp(min, max, ALL);}
public default Vec2d clamp(double min, double max, Vec2d result){return clamp(min, max, result, ALL);}
@Override
public default Vec2d clamp(double min, double max, int filter){return clamp(min, max, this, filter);}
public default Vec2d clamp(double min, double max, Vec2d result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()));}
@Override
public default Vec2d store(ByteBuffer buffer)
{
buffer.putDouble(getX()).putDouble(getY());
return this;
}
@Override
public default Vec2d load(ByteBuffer buffer)
{
return set(buffer.getDouble(), buffer.getDouble());
}
@Override
public default Vec2d store(DoubleBuffer buffer)
{
buffer.put(getX()).put(getY());
return this;
}
@Override
public default Vec2d load(DoubleBuffer buffer)
{
return set(buffer.get(), buffer.get());
}
@Override
public default Vec2b asByte(){return isMutable() ? Vec2b.newMutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY())) : Vec2b.newVec((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()));}
@Override
public default Vec2s asShort(){return isMutable() ? Vec2s.newMutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY())) : Vec2s.newVec((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()));}
@Override
public default Vec2i asInt(){return isMutable() ? Vec2i.newMutable(MathUtils.floor(getX()), MathUtils.floor(getY())) : Vec2i.newVec(MathUtils.floor(getX()), MathUtils.floor(getY()));}
@Override
public default Vec2l asLong() {return isMutable() ? Vec2l.newMutable(MathUtils.floor(getX()), MathUtils.floor(getY())) : Vec2l.newVec(MathUtils.floor(getX()), MathUtils.floor(getY()));}
@Override
public default Vec2f asFloat(){return isMutable() ? Vec2f.newMutable((float)getX(), (float)getY()) : Vec2f.newVec((float)getX(), (float)getY());}
@Override
public default Vec2d asMutable(){return isMutable() ? this : newMutable(this);}
@Override
public default Vec2d asImmutable(){return isMutable() ? newVec(this) : this;}
@Override
public default Vec2d copyAsMutable(){return newMutable(this);}
@Override
public default Vec2d copyAsImmutable(){return newVec(this);}
}

View File

@ -0,0 +1,92 @@
package speiger.src.coreengine.math.vector.doubles;
import java.util.Objects;
public class Vec2dImmutable implements Vec2d
{
final double x;
final double y;
public Vec2dImmutable()
{
x = 0D;
y = 0D;
}
public Vec2dImmutable(double value)
{
x = value;
y = value;
}
public Vec2dImmutable(double x, double y)
{
this.x = x;
this.y = y;
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public double getX()
{
return x;
}
@Override
public double getY()
{
return y;
}
@Override
public Vec2d setX(double x)
{
return this.x == x ? this : Vec2d.newVec(x, y);
}
@Override
public Vec2d setY(double y)
{
return this.y == y ? this : Vec2d.newVec(x, y);
}
@Override
public Vec2d copy()
{
return Vec2d.newVec(this);
}
@Override
public Vec2d set(double x, double y)
{
return this.x == x && this.y == y ? this : Vec2d.newVec(x, y);
}
@Override
public int hashCode()
{
return Objects.hash(x, y);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec2d)
{
Vec2d vec = (Vec2d)obj;
return vec.getX() == x && vec.getY() == y;
}
return false;
}
@Override
public String toString()
{
return "Vec2d[x="+x+", y="+y+"]";
}
}

View File

@ -0,0 +1,96 @@
package speiger.src.coreengine.math.vector.doubles;
import java.util.Objects;
public class Vec2dMutable implements Vec2d
{
double x;
double y;
public Vec2dMutable()
{
x = 0D;
y = 0D;
}
public Vec2dMutable(double value)
{
x = value;
y = value;
}
public Vec2dMutable(double x, double y)
{
this.x = x;
this.y = y;
}
@Override
public boolean isMutable()
{
return true;
}
@Override
public double getX()
{
return x;
}
@Override
public double getY()
{
return y;
}
@Override
public Vec2d setX(double x)
{
this.x = x;
return this;
}
@Override
public Vec2d setY(double y)
{
this.y = y;
return this;
}
@Override
public Vec2d copy()
{
return Vec2d.newMutable(this);
}
@Override
public Vec2d set(double x, double y)
{
this.x = x;
this.y = y;
return this;
}
@Override
public int hashCode()
{
return Objects.hash(x, y);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec2d)
{
Vec2d vec = (Vec2d)obj;
return vec.getX() == x && vec.getY() == y;
}
return false;
}
@Override
public String toString()
{
return "Vec2d[x="+x+", y="+y+"]";
}
}

View File

@ -0,0 +1,241 @@
package speiger.src.coreengine.math.vector.doubles;
import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.bytes.Vec3b;
import speiger.src.coreengine.math.vector.floats.Vec3f;
import speiger.src.coreengine.math.vector.ints.Vec3i;
import speiger.src.coreengine.math.vector.longs.Vec3l;
import speiger.src.coreengine.math.vector.shorts.Vec3s;
public interface Vec3d extends Vecd
{
public static final Vec3d ZERO = newVec();
public static final Vec3d MINUS_ONE = newVec(-1D);
public static final Vec3d ONE = newVec(1D);
public static Vec3d newMutable(){return new Vec3dMutable();}
public static Vec3d newMutable(double value){return new Vec3dMutable(value);}
public static Vec3d newMutable(double x, double y, double z){return new Vec3dMutable(x, y, z);}
public static Vec3d newMutable(Vec3d vec){return newMutable(vec.getX(), vec.getY(), vec.getZ());}
public static Vec3d newVec(){return new Vec3dImmutable();}
public static Vec3d newVec(double value){return new Vec3dImmutable(value);}
public static Vec3d newVec(double x, double y, double z){return new Vec3dImmutable(x, y, z);}
public static Vec3d newVec(Vec3d vec){return newVec(vec.getX(), vec.getY(), vec.getZ());}
public double getX();
public double getY();
public double getZ();
public Vec3d setX(double x);
public Vec3d setY(double y);
public Vec3d setZ(double z);
@Override
public default double[] asArray(){return new double[]{getX(), getY(), getZ()};}
@Override
public Vec3d copy();
@Override
public default Vec3d abs(){return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()));}
@Override
public default Vec3d negate(){return set(0D, 0D, 0D);}
@Override
public default Vec3d invert(){return set(-getX(), -getY(), -getZ());}
public default Vec3d normalize()
{
double l = length();
return l == 0D ? this : multiply(1.0D / l);
}
@Override
public default Vec3d add(double value){return add(value, value, value);}
public default Vec3d add(Vec3d value){return add(value.getX(), value.getY(), value.getZ());}
public default Vec3d add(double x, double y, double z){return set(getX() + x, getY() + y, getZ() + z);}
@Override
public default Vec3d sub(double value){return sub(value, value, value);}
public default Vec3d sub(Vec3d value){return sub(value.getX(), value.getY(), value.getZ());}
public default Vec3d sub(double x, double y, double z){return set(getX() - x, getY() - y, getZ() - z);}
@Override
public default Vec3d multiply(double value){return multiply(value, value, value);}
public default Vec3d multiply(Vec3d value){return multiply(value.getX(), value.getY(), value.getZ());}
public default Vec3d multiply(double x, double y, double z){return set(getX() * x, getY() * y, getZ() * z);}
@Override
public default Vec3d devide(double value){return devide(value, value, value);}
public default Vec3d devide(Vec3d value){return devide(value.getX(), value.getY(), value.getZ());}
public default Vec3d devide(double x, double y, double z){return set(getX() / x, getY() / y, getZ() / z);}
@Override
public default Vec3d set(double value){return set(value, value, value);}
public default Vec3d set(Vec3d value){return set(value.getX(), value.getY(), value.getZ());}
public Vec3d set(double x, double y, double z);
public default double distanceTo(Vec3d value){return distanceTo(value.getX(), value.getY(), value.getZ());}
public default double distanceTo(double x, double y, double z){return Math.sqrt(distanceToSquared(x, y, z));}
public default double distanceToSquared(Vec3d value){return distanceToSquared(value.getX(), value.getY(), value.getZ());}
public default double distanceToSquared(double x, double y, double z)
{
double xPos = getX() - x;
double yPos = getY() - y;
double zPos = getZ() - z;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
}
@Override
public default double lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());}
public default double dotProduct(Vec3d value){return dotProduct(value.getX(), value.getY(), value.getZ());}
public default double dotProduct(double x, double y, double z){return (getX() * x) + (getY() * y) + (getZ() * z);}
public default Vec3d lerp(Vec3d value, float progress, Vec3d result){return lerp(value.getX(), value.getY(), value.getZ(), progress, result);}
public default Vec3d lerp(double x, double y, double z, float progress, Vec3d result){return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress), MathUtils.lerp(getZ(), z, progress));}
public default double angle(Vec3d value){return angle(value.getX(), value.getY(), value.getZ());}
public default double angle(double x, double y, double z){return Math.acos(MathUtils.clamp(-1, 1, angleCos(x, y, z)));}
public default double angleCos(Vec3d value){return angleCos(value.getX(), value.getY(), value.getZ());}
public default double angleCos(double x, double y, double z)
{
double myLength = (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());
double otherLength = (x * x) + (y * y) + (z * z);
double dot = (getX() * x) + (getY() * y) + (getZ() * z);
return dot / (Math.sqrt(myLength * otherLength));
}
public default Vec3d crossProduct(Vec3d value){return crossProduct(value.getX(), value.getY(), value.getZ(), this);}
public default Vec3d crossProduct(Vec3d value, Vec3d result){return crossProduct(value.getX(), value.getY(), value.getZ(), result);}
public default Vec3d crossProduct(double x, double y, double z){return crossProduct(x, y, z, this);}
public default Vec3d crossProduct(double x, double y, double z, Vec3d result){return result.set((getY() * z) - (getZ() * y), (getZ() * x) - (getX() * z), (getX() * y) - (getY() * x));}
public default Vec3d reflect(Vec3d value){return reflect(value.getX(), value.getY(), value.getZ(), this);}
public default Vec3d reflect(Vec3d value, Vec3d result){return reflect(value.getX(), value.getY(), value.getZ(), result);}
public default Vec3d reflect(double x, double y, double z){return reflect(x, y, z, this);}
public default Vec3d reflect(double x, double y, double z, Vec3d result)
{
double dot = dotProduct(x, y, z) * 2D;
return result.set(getX() - dot * x, getY() - dot * y, getZ() - dot * z);
}
public default Vec3d rotate(double angle, Vec3d axis){return rotate(angle, axis.getX(), axis.getY(), axis.getZ());}
public default Vec3d rotate(double angle, Vec3d axis, Vec3d result){return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), result);}
public default Vec3d rotate(double angle, double x, double y, double z){return rotate(angle, x, y, z, this);}
public default Vec3d rotate(double angle, double x, double y, double z, Vec3d result)
{
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
double dot = dotProduct(x, y, z);
double xPos = x * dot * (1D - cos) + (getX() * cos) + (-z * getY() + y * getZ()) * sin;
double yPos = y * dot * (1D - cos) + (getY() * cos) + (z * getX() - x * getZ()) * sin;
double zPos = z * dot * (1D - cos) + (getZ() * cos) + (-y * getX() + x * getY()) * sin;
return result.set(xPos, yPos, zPos);
}
public default Vec3d rotateX(double angle){return rotateX(angle, this);}
public default Vec3d rotateX(double angle, Vec3d result)
{
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
double y = getY() * cos + getZ() * sin;
double z = getZ() * cos - getY() * sin;
return result.set(getX(), y, z);
}
public default Vec3d rotateY(double angle){return rotateY(angle, this);}
public default Vec3d rotateY(double angle, Vec3d result)
{
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
double x = getX() * cos + getZ() * sin;
double z = getZ() * cos - getX() * sin;
return result.set(x, getY(), z);
}
public default Vec3d rotateZ(double angle){return rotateZ(angle, this);}
public default Vec3d rotateZ(double angle, Vec3d result)
{
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
double x = cos * getX() - sin * getY();
double y = sin * getX() + cos * getY();
return result.set(x, y, getZ());
}
public default Vec3d smoothStep(Vec3d value, float progress, Vec3d result){return smoothStep(value.getX(), value.getY(), value.getZ(), progress, result);}
public default Vec3d smoothStep(double x, double y, double z, float progress, Vec3d result)
{
double t2 = progress * progress;
double t3 = t2 * progress;
double xPos = ((getX() + getX() - x - x) * t3 + (3.0D * x - 3.0D * getX()) * t2 + getX() * progress + getX());
double yPos = ((getY() + getY() - y - y) * t3 + (3.0D * y - 3.0D * getY()) * t2 + getY() * progress + getY());
double zPos = ((getZ() + getZ() - z - z) * t3 + (3.0D * z - 3.0D * getZ()) * t2 + getZ() * progress + getZ());
return result.set(xPos, yPos, zPos);
}
public default Vec3d min(Vec3d other) {return min(other, this);}
public default Vec3d min(Vec3d other, Vec3d result){return min(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3d min(double x, double y, double z) {return min(x, y, z, this);}
public default Vec3d min(double x, double y, double z, Vec3d result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z));}
public default Vec3d max(Vec3d other) {return max(other, this);}
public default Vec3d max(Vec3d other, Vec3d result){return max(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3d max(double x, double y, double z) {return max(x, y, z, this);}
public default Vec3d max(double x, double y, double z, Vec3d result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z));}
public default Vec3d difference(Vec3d other) {return difference(other, this);}
public default Vec3d difference(Vec3d other, Vec3d result){return difference(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3d difference(double x, double y, double z) {return difference(x, y, z, this);}
public default Vec3d difference(double x, double y, double z, Vec3d result){return result.set(getX() - x, getY() - y, getZ() - z);}
@Override
public default Vec3d clamp(double min, double max){return clamp(min, max, ALL);}
public default Vec3d clamp(double min, double max, Vec3d result){return clamp(min, max, result, ALL);}
@Override
public default Vec3d clamp(double min, double max, int filter){return clamp(min, max, this, filter);}
public default Vec3d clamp(double min, double max, Vec3d result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()));}
@Override
public default Vec3d store(ByteBuffer buffer)
{
buffer.putDouble(getX()).putDouble(getY()).putDouble(getZ());
return this;
}
@Override
public default Vec3d load(ByteBuffer buffer)
{
return set(buffer.getDouble(), buffer.getDouble(), buffer.getDouble());
}
@Override
public default Vec3d store(DoubleBuffer buffer)
{
buffer.put(getX()).put(getY()).put(getZ());
return this;
}
@Override
public default Vec3d load(DoubleBuffer buffer)
{
return set(buffer.get(), buffer.get(), buffer.get());
}
@Override
public default Vec3b asByte(){return isMutable() ? Vec3b.newMutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ())) : Vec3b.newVec((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()));}
@Override
public default Vec3s asShort(){return isMutable() ? Vec3s.newMutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ())) : Vec3s.newVec((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()));}
@Override
public default Vec3i asInt(){return isMutable() ? Vec3i.newMutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())) : Vec3i.newVec(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()));}
@Override
public default Vec3l asLong() {return isMutable() ? Vec3l.newMutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())) : Vec3l.newVec(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()));}
@Override
public default Vec3f asFloat(){return isMutable() ? Vec3f.newMutable((float)getX(), (float)getY(), (float)getZ()) : Vec3f.newVec((float)getX(), (float)getY(), (float)getZ());}
@Override
public default Vec3d asMutable(){return isMutable() ? this : newMutable(this);}
@Override
public default Vec3d asImmutable(){return isMutable() ? newVec(this) : this;}
@Override
public default Vec3d copyAsMutable(){return newMutable(this);}
@Override
public default Vec3d copyAsImmutable(){return newVec(this);}
}

View File

@ -0,0 +1,108 @@
package speiger.src.coreengine.math.vector.doubles;
import java.util.Objects;
public class Vec3dImmutable implements Vec3d
{
final double x;
final double y;
final double z;
public Vec3dImmutable()
{
x = 0;
y = 0;
z = 0;
}
public Vec3dImmutable(double value)
{
x = value;
y = value;
z = value;
}
public Vec3dImmutable(double x, double y, double z)
{
this.x = x;
this.y = y;
this.z = z;
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public double getX()
{
return x;
}
@Override
public double getY()
{
return y;
}
@Override
public double getZ()
{
return z;
}
@Override
public Vec3d setX(double x)
{
return this.x == x ? this : Vec3d.newVec(x, y, z);
}
@Override
public Vec3d setY(double y)
{
return this.y == y ? this : Vec3d.newVec(x, y, z);
}
@Override
public Vec3d setZ(double z)
{
return this.z == z ? this : Vec3d.newVec(x, y, z);
}
@Override
public Vec3d copy()
{
return Vec3d.newVec(this);
}
@Override
public Vec3d set(double x, double y, double z)
{
return this.x == x && this.y == y && this.z == z ? this : Vec3d.newVec(x, y, z);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec3d)
{
Vec3d vec = (Vec3d)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
}
return false;
}
@Override
public String toString()
{
return "Vec3d[x="+x+", y="+y+", z="+z+"]";
}
}

View File

@ -0,0 +1,114 @@
package speiger.src.coreengine.math.vector.doubles;
import java.util.Objects;
public class Vec3dMutable implements Vec3d
{
double x;
double y;
double z;
public Vec3dMutable()
{
x = 0;
y = 0;
z = 0;
}
public Vec3dMutable(double value)
{
x = value;
y = value;
z = value;
}
public Vec3dMutable(double x, double y, double z)
{
this.x = x;
this.y = y;
this.z = z;
}
@Override
public boolean isMutable()
{
return true;
}
@Override
public double getX()
{
return x;
}
@Override
public double getY()
{
return y;
}
@Override
public double getZ()
{
return z;
}
@Override
public Vec3d setX(double x)
{
this.x = x;
return this;
}
@Override
public Vec3d setY(double y)
{
this.y = y;
return this;
}
@Override
public Vec3d setZ(double z)
{
this.z = z;
return this;
}
@Override
public Vec3d copy()
{
return Vec3d.newMutable(this);
}
@Override
public Vec3d set(double x, double y, double z)
{
this.x = x;
this.y = y;
this.z = z;
return this;
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec3d)
{
Vec3d vec = (Vec3d)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
}
return false;
}
@Override
public String toString()
{
return "Vec3d[x="+x+", y="+y+", z="+z+"]";
}
}

View File

@ -0,0 +1,231 @@
package speiger.src.coreengine.math.vector.doubles;
import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.bytes.Vec4b;
import speiger.src.coreengine.math.vector.floats.Vec4f;
import speiger.src.coreengine.math.vector.ints.Vec4i;
import speiger.src.coreengine.math.vector.longs.Vec4l;
import speiger.src.coreengine.math.vector.shorts.Vec4s;
public interface Vec4d extends Vecd
{
public static final Vec4d ZERO = newVec();
public static final Vec4d MINUS_ONE = newVec(-1D);
public static final Vec4d ONE = newVec(1D);
public static Vec4d newMutable(){return new Vec4dMutable();}
public static Vec4d newMutable(double value){return new Vec4dMutable(value);}
public static Vec4d newMutable(double x, double y, double z, double w){return new Vec4dMutable(x, y, z, w);}
public static Vec4d newMutable(Vec4d vec){return newMutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW());}
public static Vec4d newVec(){return new Vec4dImmutable();}
public static Vec4d newVec(double value){return new Vec4dImmutable(value);}
public static Vec4d newVec(double x, double y, double z, double w){return new Vec4dImmutable(x, y, z, w);}
public static Vec4d newVec(Vec4d vec){return newVec(vec.getX(), vec.getY(), vec.getZ(), vec.getW());}
public double getX();
public double getY();
public double getZ();
public double getW();
public Vec4d setX(double x);
public Vec4d setY(double y);
public Vec4d setZ(double z);
public Vec4d setW(double w);
@Override
public default double[] asArray(){return new double[]{getX(), getY(), getZ(), getW()};}
@Override
public Vec4d copy();
@Override
public default Vec4d abs(){return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()), Math.abs(getW()));}
@Override
public default Vec4d negate(){return set(0D, 0D, 0D, 0D);}
@Override
public default Vec4d invert(){return set(-getX(), -getY(), -getZ(), -getW());}
public default Vec4d normalize()
{
double l = length();
return l == 0D ? this : multiply(1.0D / l);
}
public default Vec4d normalize3D()
{
double value = (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());
return value == 0D ? this : multiply(1D / value);
}
@Override
public default Vec4d add(double value){return add(value, value, value, value);}
public default Vec4d add(Vec4d value){return add(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4d add(double x, double y, double z, double w){return set(getX() + x, getY() + y, getZ() + z, getW() + w);}
@Override
public default Vec4d sub(double value){return sub(value, value, value, value);}
public default Vec4d sub(Vec4d value){return sub(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4d sub(double x, double y, double z, double w){return set(getX() - x, getY() - y, getZ() - z, getW() - w);}
@Override
public default Vec4d multiply(double value){return multiply(value, value, value, value);}
public default Vec4d multiply(Vec4d value){return multiply(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4d multiply(double x, double y, double z, double w){return set(getX() * x, getY() * y, getZ() * z, getW() * w);}
@Override
public default Vec4d devide(double value){return devide(value, value, value, value);}
public default Vec4d devide(Vec4d value){return devide(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4d devide(double x, double y, double z, double w){return set(getX() / x, getY() / y, getZ() / z, getW() / w);}
@Override
public default Vec4d set(double value){return set(value, value, value, value);}
public default Vec4d set(Vec4d value){return set(value.getX(), value.getY(), value.getZ(), value.getW());}
public Vec4d set(double x, double y, double z, double w);
public default double distanceTo(Vec4d value){return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW());}
public default double distanceTo(double x, double y, double z, double w){return Math.sqrt(distanceTo(x, y, z, w));}
public default double distanceToSquared(Vec4d value){return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW());}
public default double distanceToSquared(double x, double y, double z, double w)
{
double xPos = getX() - x;
double yPos = getY() - y;
double zPos = getZ() - z;
double wPos = getW() - w;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
}
@Override
public default double lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW());}
public default double dotProduct(Vec4d value){return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW());}
public default double dotProduct(double x, double y, double z, double w){return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w);};
public default Vec4d lerp(Vec4d value, float progress, Vec4d result){return lerp(value.getX(), value.getY(), value.getZ(), value.getW(), progress, result);}
public default Vec4d lerp(double x, double y, double z, double w, float progress, Vec4d result){return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress), MathUtils.lerp(getZ(), z, progress), MathUtils.lerp(getW(), w, progress));}
public default double angle(Vec4d value){return angle(value.getX(), value.getY(), value.getZ(), value.getW());}
public default double angle(double x, double y, double z, double w){return Math.acos(MathUtils.clamp(-1D, 1D, angleCos(x, y, z, w)));}
public default double angleCos(Vec4d value){return angleCos(value.getX(), value.getY(), value.getZ(), value.getW());}
public default double angleCos(double x, double y, double z, double w){return dotProduct(x, y, z, w) / Math.sqrt(lengthSquared() * (x * x) + (y * y) + (z * z) + (w * w));}
public default Vec4d rotate(double angle, Vec4d axis){return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), axis.getW());}
public default Vec4d rotate(double angle, Vec4d axis, Vec4d result){return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), axis.getW(), result);}
public default Vec4d rotate(double angle, double x, double y, double z, double w){return rotate(angle, x, y, z, w, this);}
public default Vec4d rotate(double angle, double x, double y, double z, double w, Vec4d result)
{
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
double dot = dotProduct(x, y, z, w);
double xPos = x * dot * (1D - cos) + (getX() * cos) + (-z * getY() + y * getZ()) * sin;
double yPos = y * dot * (1D - cos) + (getY() * cos) + (z * getX() - x * getZ()) * sin;
double zPos = z * dot * (1D - cos) + (getZ() * cos) + (-y * getX() + x * getY()) * sin;
return result.set(xPos, yPos, zPos, getW());
}
public default Vec4d rotateX(double angle){return rotateX(angle, this);}
public default Vec4d rotateX(double angle, Vec4d result)
{
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
double y = getY() * cos + getZ() * sin;
double z = getZ() * cos - getY() * sin;
return result.set(getX(), y, z, getW());
}
public default Vec4d rotateY(double angle){return rotateY(angle, this);}
public default Vec4d rotateY(double angle, Vec4d result)
{
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
double x = getX() * cos + getZ() * sin;
double z = getZ() * cos - getX() * sin;
return result.set(x, getY(), z, getW());
}
public default Vec4d rotateZ(double angle){return rotateZ(angle, this);}
public default Vec4d rotateZ(double angle, Vec4d result)
{
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
double x = cos * getX() - sin * getY();
double y = sin * getX() + cos * getY();
return result.set(x, y, getZ(), getW());
}
public default Vec4d smoothStep(Vec4d value, float progress, Vec4d result){return smoothStep(value.getX(), value.getY(), value.getZ(), value.getW(), progress, result);}
public default Vec4d smoothStep(double x, double y, double z, double w, float progress, Vec4d result)
{
double t2 = progress * progress;
double t3 = t2 * progress;
double xPos = ((getX() + getX() - x - x) * t3 + (3.0D * x - 3.0D * getX()) * t2 + getX() * progress + getX());
double yPos = ((getY() + getY() - y - y) * t3 + (3.0D * y - 3.0D * getY()) * t2 + getY() * progress + getY());
double zPos = ((getZ() + getZ() - z - z) * t3 + (3.0D * z - 3.0D * getZ()) * t2 + getZ() * progress + getZ());
double wPos = ((getW() + getW() - w - w) * t3 + (3.0D * w - 3.0D * getW()) * t2 + getW() * progress + getW());
return result.set(xPos, yPos, zPos, wPos);
}
public default Vec4d min(Vec4d other) {return min(other, this);}
public default Vec4d min(Vec4d other, Vec4d result){return min(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4d min(double x, double y, double z, double w) {return min(x, y, z, w, this);}
public default Vec4d min(double x, double y, double z, double w, Vec4d result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z), Math.min(getW(), w));}
public default Vec4d max(Vec4d other) {return max(other, this);}
public default Vec4d max(Vec4d other, Vec4d result){return max(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4d max(double x, double y, double z, double w) {return max(x, y, z, w, this);}
public default Vec4d max(double x, double y, double z, double w, Vec4d result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z), Math.max(getZ(), z));}
public default Vec4d difference(Vec4d other) {return difference(other, this);}
public default Vec4d difference(Vec4d other, Vec4d result){return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4d difference(double x, double y, double z, double w) {return difference(x, y, z, w, this);}
public default Vec4d difference(double x, double y, double z, double w, Vec4d result){return result.set(getX() - x, getY() - y, getZ() - z, getW() - w);}
@Override
public default Vec4d clamp(double min, double max){return clamp(min, max, ALL);}
public default Vec4d clamp(double min, double max, Vec4d result){return clamp(min, max, result, ALL);}
@Override
public default Vec4d clamp(double min, double max, int filter){return clamp(min, max, this, filter);}
public default Vec4d clamp(double min, double max, Vec4d result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW()));}
@Override
public default Vec4d store(ByteBuffer buffer)
{
buffer.putDouble(getX()).putDouble(getY()).putDouble(getZ()).putDouble(getW());
return this;
}
@Override
public default Vec4d load(ByteBuffer buffer)
{
return set(buffer.getDouble(), buffer.getDouble(), buffer.getDouble(), buffer.getDouble());
}
@Override
public default Vec4d store(DoubleBuffer buffer)
{
buffer.put(getX()).put(getY()).put(getZ()).put(getW());
return this;
}
@Override
public default Vec4d load(DoubleBuffer buffer)
{
return set(buffer.get(), buffer.get(), buffer.get(), buffer.get());
}
@Override
public default Vec4b asByte(){return isMutable() ? Vec4b.newMutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()), (byte)MathUtils.floor(getW())) : Vec4b.newVec((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()), (byte)MathUtils.floor(getW()));}
@Override
public default Vec4s asShort(){return isMutable() ? Vec4s.newMutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()), (short)MathUtils.floor(getW())) : Vec4s.newVec((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()), (short)MathUtils.floor(getW()));}
@Override
public default Vec4i asInt(){return isMutable() ? Vec4i.newMutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())) : Vec4i.newVec(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW()));}
@Override
public default Vec4l asLong() {return isMutable() ? Vec4l.newMutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())) : Vec4l.newVec(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW()));}
@Override
public default Vec4f asFloat(){return isMutable() ? Vec4f.newMutable((float)getX(), (float)getY(), (float)getZ(), (float)getW()) : Vec4f.newVec((float)getX(), (float)getY(), (float)getZ(), (float)getW());}
@Override
public default Vec4d asMutable(){return isMutable() ? this : newMutable(this);}
@Override
public default Vec4d asImmutable(){return isMutable() ? newVec(this) : this;}
@Override
public default Vec4d copyAsMutable(){return newMutable(this);}
@Override
public default Vec4d copyAsImmutable(){return newVec(this);}
}

View File

@ -0,0 +1,124 @@
package speiger.src.coreengine.math.vector.doubles;
import java.util.Objects;
public class Vec4dImmutable implements Vec4d
{
final double x;
final double y;
final double z;
final double w;
public Vec4dImmutable()
{
x = 0;
y = 0;
z = 0;
w = 0;
}
public Vec4dImmutable(double value)
{
x = value;
y = value;
z = value;
w = value;
}
public Vec4dImmutable(double x, double y, double z, double w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public double getX()
{
return x;
}
@Override
public double getY()
{
return y;
}
@Override
public double getZ()
{
return z;
}
@Override
public double getW()
{
return w;
}
@Override
public Vec4d setX(double x)
{
return this.x == x ? this : Vec4d.newVec(x, y, z, w);
}
@Override
public Vec4d setY(double y)
{
return this.y == y ? this : Vec4d.newVec(x, y, z, w);
}
@Override
public Vec4d setZ(double z)
{
return this.z == z ? this : Vec4d.newVec(x, y, z, w);
}
@Override
public Vec4d setW(double w)
{
return this.w == w ? this : Vec4d.newVec(x, y, z, w);
}
@Override
public Vec4d copy()
{
return Vec4d.newVec(this);
}
@Override
public Vec4d set(double x, double y, double z, double w)
{
return this.x == x && this.y == y && this.z == z && this.w == w ? this : Vec4d.newVec(x, y, z, w);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z, w);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec4d)
{
Vec4d vec = (Vec4d)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
}
return false;
}
@Override
public String toString()
{
return "Vec4d[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
}

View File

@ -0,0 +1,128 @@
package speiger.src.coreengine.math.vector.doubles;
import java.util.Objects;
public class Vec4dMutable implements Vec4d
{
double x;
double y;
double z;
double w;
public Vec4dMutable()
{
}
public Vec4dMutable(double value)
{
x = value;
y = value;
z = value;
w = value;
}
public Vec4dMutable(double x, double y, double z, double w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
@Override
public boolean isMutable()
{
return true;
}
@Override
public double getX()
{
return x;
}
@Override
public double getY()
{
return y;
}
@Override
public double getZ()
{
return z;
}
@Override
public double getW()
{
return w;
}
@Override
public Vec4d setX(double x)
{
this.x = x;
return this;
}
@Override
public Vec4d setY(double y)
{
this.y = y;
return this;
}
@Override
public Vec4d setZ(double z)
{
this.z = z;
return this;
}
@Override
public Vec4d setW(double w)
{
this.w = w;
return this;
}
@Override
public Vec4d copy()
{
return Vec4d.newMutable(this);
}
@Override
public Vec4d set(double x, double y, double z, double w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
return this;
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z, w);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec4d)
{
Vec4d vec = (Vec4d)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
}
return false;
}
@Override
public String toString()
{
return "Vec4d[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
}

View File

@ -0,0 +1,33 @@
package speiger.src.coreengine.math.vector.doubles;
import java.nio.DoubleBuffer;
import speiger.src.coreengine.math.vector.Vec;
import speiger.src.coreengine.math.vector.bytes.Vecb;
import speiger.src.coreengine.math.vector.floats.Vecf;
import speiger.src.coreengine.math.vector.ints.Veci;
import speiger.src.coreengine.math.vector.longs.Vecl;
import speiger.src.coreengine.math.vector.shorts.Vecs;
public interface Vecd extends Vec
{
public Vecd set(double value);
public Vecd add(double value);
public Vecd sub(double value);
public Vecd multiply(double value);
public Vecd devide(double value);
public Vecd clamp(double min, double max);
public Vecd clamp(double min, double max, int filter);
public double lengthSquared();
public default double length(){return Math.sqrt(lengthSquared());}
public Vecd store(DoubleBuffer buffer);
public Vecd load(DoubleBuffer buffer);
public double[] asArray();
public Vecb asByte();
public Vecs asShort();
public Veci asInt();
public Vecl asLong();
public Vecf asFloat();
}

View File

@ -0,0 +1,187 @@
package speiger.src.coreengine.math.vector.floats;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.bytes.Vec2b;
import speiger.src.coreengine.math.vector.doubles.Vec2d;
import speiger.src.coreengine.math.vector.ints.Vec2i;
import speiger.src.coreengine.math.vector.longs.Vec2l;
import speiger.src.coreengine.math.vector.shorts.Vec2s;
public interface Vec2f extends Vecf
{
public static final Vec2f ZERO = newVec();
public static final Vec2f MINUS_ONE = newVec(-1F);
public static final Vec2f ONE = newVec(1F);
public static Vec2f newMutable(){return new Vec2fMutable();}
public static Vec2f newMutable(float value){return new Vec2fMutable(value);}
public static Vec2f newMutable(float x, float y){return new Vec2fMutable(x, y);}
public static Vec2f newMutable(Vec2f value){return newMutable(value.getX(), value.getY());}
public static Vec2f newVec(){return new Vec2fImmutable();}
public static Vec2f newVec(float value){return new Vec2fImmutable(value);}
public static Vec2f newVec(float x, float y){return new Vec2fImmutable(x, y);}
public static Vec2f newVec(Vec2f value){return newVec(value.getX(), value.getY());}
public float getX();
public float getY();
public Vec2f setX(float x);
public Vec2f setY(float y);
@Override
public default float[] asArray(){return new float[]{getX(), getY()};}
@Override
public Vec2f copy();
@Override
public default Vec2f abs(){return set(Math.abs(getX()), Math.abs(getY()));}
@Override
public default Vec2f negate(){return set(0F, 0F);}
@Override
public default Vec2f invert(){return set(-getX(), -getY());};
public default Vec2f normalize()
{
float l = length();
return l == 0F ? this : multiply(1F / l);
}
@Override
public default Vec2f add(float value) {return add(value, value);}
public default Vec2f add(Vec2f value) {return add(value.getX(), value.getY());}
public default Vec2f add(float x, float y) {return set(x + getX(), y + getY());}
@Override
public default Vec2f sub(float value){return sub(value, value);}
public default Vec2f sub(Vec2f value){return sub(value.getX(), value.getY());}
public default Vec2f sub(float x, float y) {return set(getX() - x, getY() - y);}
@Override
public default Vec2f multiply(float value){return multiply(value, value);}
public default Vec2f multiply(Vec2f value){return multiply(value.getX(), value.getY());}
public default Vec2f multiply(float x, float y) {return set(x * getX(), y * getY());}
@Override
public default Vec2f devide(float value){return devide(value, value);}
public default Vec2f devide(Vec2f value){return devide(value.getX(), value.getY());}
public default Vec2f devide(float x, float y){return set(getX() / x, getY() / y);}
@Override
public default Vec2f set(float value){return set(value, value);};
public default Vec2f set(Vec2f value){return set(value.getX(), value.getY());}
public Vec2f set(float x, float y);
public default double distanceTo(Vec2f value){return distanceTo(value.getX(), value.getY());}
public default double distanceTo(float x, float y){return Math.sqrt(distanceToSquared(x, y));}
public default double distanceToSquared(Vec2f value){return distanceToSquared(value.getX(), value.getY());}
public default double distanceToSquared(float x, float y)
{
double xPos = getX() - x;
double yPos = getY() - y;
return (xPos * xPos) + (yPos * yPos);
}
@Override
public default float lengthSquared() {return (getX() * getX()) + (getY() * getY());}
public default double dotProduct(Vec2f value){return dotProduct(value.getX(), value.getY());}
public default double dotProduct(float x, float y){return (getX() * x) + (getY() * y);}
public default Vec2f lerp(Vec2f value, float progress, Vec2f result){return lerp(value.getX(), value.getY(), progress, result);}
public default Vec2f lerp(float x, float y, float progress, Vec2f result){return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress));};
public default float angle(Vec2f value){return angle(value.getX(), value.getY());}
public default float angle(float x, float y){return (float)Math.atan2((getX() * y) - (getY() * x), (getX() * x) + (getY() * y));}
public default float directionAngle(Vec2f value){return directionAngle(value.getX(), value.getY());}
public default float directionAngle(float x, float y){return (float)(-Math.toDegrees(Math.atan2(getX() - x, getY() - y)) % 360D);}
public default Vec2f reflect(Vec2f value){return reflect(value.getX(), value.getY(), this);}
public default Vec2f reflect(float x, float y){return reflect(x, y, this);};
public default Vec2f reflect(Vec2f value, Vec2f result){return reflect(value.getX(), value.getY(), result);}
public default Vec2f reflect(float x, float y, Vec2f result)
{
double dot = dotProduct(x, y);
float x2 = (float)((dot + dot) * x);
float y2 = (float)((dot + dot) * y);
return result.set(getX() - x2, getY() - y2);
}
public default Vec2f rotate(float angle, Vec2f center){return rotate(angle, center.getX(), center.getY());}
public default Vec2f rotate(float angle, float x, float y)
{
float xPos = getX() - x;
float yPos = getY() - y;
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
return set((float)((xPos * cos) + (yPos * sin) + x), (float)(-(xPos * sin) + (yPos * cos) + y));
}
public default Vec2f min(Vec2f other) {return min(other, this);}
public default Vec2f min(Vec2f other, Vec2f result){return min(other.getX(), other.getY(), result);}
public default Vec2f min(float x, float y) {return min(x, y, this);}
public default Vec2f min(float x, float y, Vec2f result){return result.set(Math.min(getX(), x), Math.min(getY(), y));}
public default Vec2f max(Vec2f other) {return max(other, this);}
public default Vec2f max(Vec2f other, Vec2f result){return max(other.getX(), other.getY(), result);}
public default Vec2f max(float x, float y) {return max(x, y, this);}
public default Vec2f max(float x, float y, Vec2f result){return result.set(Math.max(getX(), x), Math.max(getY(), y));}
public default Vec2f difference(Vec2f other) {return difference(other, this);}
public default Vec2f difference(Vec2f other, Vec2f result){return difference(other.getX(), other.getY(), result);}
public default Vec2f difference(float x, float y) {return difference(x, y, this);}
public default Vec2f difference(float x, float y, Vec2f result){return result.set(getX() - x, getY() - y);}
@Override
public default Vec2f clamp(float min, float max){return clamp(min, max, ALL);}
public default Vec2f clamp(float min, float max, Vec2f result){return clamp(min, max, result, ALL);}
@Override
public default Vec2f clamp(float min, float max, int filter){return clamp(min, max, this, filter);}
public default Vec2f clamp(float min, float max, Vec2f result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()));}
@Override
public default Vec2f store(ByteBuffer buffer)
{
buffer.putFloat(getX()).putFloat(getY());
return this;
}
@Override
public default Vec2f load(ByteBuffer buffer)
{
return set(buffer.getFloat(), buffer.getFloat());
}
@Override
public default Vec2f store(FloatBuffer buffer)
{
buffer.put(getX()).put(getY());
return this;
}
@Override
public default Vec2f load(FloatBuffer buffer)
{
return set(buffer.get(), buffer.get());
}
@Override
public default Vec2b asByte(){return isMutable() ? Vec2b.newMutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY())) : Vec2b.newVec((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()));}
@Override
public default Vec2s asShort(){return isMutable() ? Vec2s.newMutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY())) : Vec2s.newVec((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()));}
@Override
public default Vec2i asInt(){return isMutable() ? Vec2i.newMutable(MathUtils.floor(getX()), MathUtils.floor(getY())) : Vec2i.newVec(MathUtils.floor(getX()), MathUtils.floor(getY()));}
@Override
public default Vec2l asLong() {return isMutable() ? Vec2l.newMutable(MathUtils.floor(getX()), MathUtils.floor(getY())) : Vec2l.newVec(MathUtils.floor(getX()), MathUtils.floor(getY()));}
@Override
public default Vec2d asDouble(){return isMutable() ? Vec2d.newMutable(getX(), getY()) : Vec2d.newVec(getX(), getY());}
@Override
public default Vec2f asMutable(){return isMutable() ? this : newMutable(this);}
@Override
public default Vec2f asImmutable(){return isMutable() ? newVec(this) : this;}
@Override
public default Vec2f copyAsMutable(){return newMutable(this);}
@Override
public default Vec2f copyAsImmutable(){return newVec(this);}
}

View File

@ -0,0 +1,92 @@
package speiger.src.coreengine.math.vector.floats;
import java.util.Objects;
public class Vec2fImmutable implements Vec2f
{
final float x;
final float y;
public Vec2fImmutable()
{
x = 0F;
y = 0F;
}
public Vec2fImmutable(float value)
{
x = value;
y = value;
}
public Vec2fImmutable(float x, float y)
{
this.x = x;
this.y = y;
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public float getX()
{
return x;
}
@Override
public float getY()
{
return y;
}
@Override
public Vec2f setX(float x)
{
return this.x == x ? this : Vec2f.newVec(x, y);
}
@Override
public Vec2f setY(float y)
{
return this.y == y ? this : Vec2f.newVec(x, y);
}
@Override
public Vec2f copy()
{
return Vec2f.newVec(x, y);
}
@Override
public Vec2f set(float x, float y)
{
return this.x == x && this.y == y ? this : Vec2f.newVec(x, y);
}
@Override
public int hashCode()
{
return Objects.hash(x, y);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec2f)
{
Vec2f vec = (Vec2f)obj;
return vec.getX() == x && vec.getY() == y;
}
return false;
}
@Override
public String toString()
{
return "Vec2f[x="+x+", y="+y+"]";
}
}

View File

@ -0,0 +1,94 @@
package speiger.src.coreengine.math.vector.floats;
import java.util.Objects;
public class Vec2fMutable implements Vec2f
{
float x;
float y;
public Vec2fMutable()
{
}
public Vec2fMutable(float value)
{
x = value;
y = value;
}
public Vec2fMutable(float x, float y)
{
this.x = x;
this.y = y;
}
@Override
public boolean isMutable()
{
return true;
}
@Override
public float getX()
{
return x;
}
@Override
public float getY()
{
return y;
}
@Override
public Vec2f setX(float x)
{
this.x = x;
return this;
}
@Override
public Vec2f setY(float y)
{
this.y = y;
return this;
}
@Override
public Vec2f copy()
{
return Vec2f.newMutable(this);
}
@Override
public Vec2f set(float x, float y)
{
this.x = x;
this.y = y;
return this;
}
@Override
public int hashCode()
{
return Objects.hash(x, y);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec2f)
{
Vec2f vec = (Vec2f)obj;
return vec.getX() == x && vec.getY() == y;
}
return false;
}
@Override
public String toString()
{
return "Vec2f[x="+x+", y="+y+"]";
}
}

View File

@ -0,0 +1,242 @@
package speiger.src.coreengine.math.vector.floats;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.bytes.Vec3b;
import speiger.src.coreengine.math.vector.doubles.Vec3d;
import speiger.src.coreengine.math.vector.ints.Vec3i;
import speiger.src.coreengine.math.vector.longs.Vec3l;
import speiger.src.coreengine.math.vector.shorts.Vec3s;
public interface Vec3f extends Vecf
{
public static final Vec3f ZERO = newVec();
public static final Vec3f MINUS_ONE = newVec(-1F);
public static final Vec3f ONE = newVec(1F);
public static Vec3f newMutable(){return new Vec3fMutable();}
public static Vec3f newMutable(float value){return new Vec3fMutable(value);}
public static Vec3f newMutable(float x, float y, float z){return new Vec3fMutable(x, y, z);}
public static Vec3f newMutable(Vec3f vec){return newMutable(vec.getX(), vec.getY(), vec.getZ());}
public static Vec3f newVec(){return new Vec3fImmutable();}
public static Vec3f newVec(float value){return new Vec3fImmutable(value);}
public static Vec3f newVec(float x, float y, float z){return new Vec3fImmutable(x, y, z);}
public static Vec3f newVec(Vec3f vec){return newVec(vec.getX(), vec.getY(), vec.getZ());}
public float getX();
public float getY();
public float getZ();
public Vec3f setX(float x);
public Vec3f setY(float y);
public Vec3f setZ(float z);
@Override
public default float[] asArray(){return new float[]{getX(), getY(), getZ()};}
@Override
public Vec3f copy();
@Override
public default Vec3f abs(){return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()));}
@Override
public default Vec3f negate(){return set(0F, 0F, 0F);}
@Override
public default Vec3f invert(){return set(-getX(), -getY(), -getZ());}
public default Vec3f normalize()
{
float l = length();
return l == 0F ? this : multiply(1.0F / l);
}
@Override
public default Vec3f add(float value){return add(value, value, value);}
public default Vec3f add(Vec3f value){return add(value.getX(), value.getY(), value.getZ());}
public default Vec3f add(float x, float y, float z){return set(getX() + x, getY() + y, getZ() + z);}
@Override
public default Vec3f sub(float value){return sub(value, value, value);}
public default Vec3f sub(Vec3f value){return sub(value.getX(), value.getY(), value.getZ());}
public default Vec3f sub(float x, float y, float z){return set(getX() - x, getY() - y, getZ() - z);}
@Override
public default Vec3f multiply(float value){return multiply(value, value, value);}
public default Vec3f multiply(Vec3f value){return multiply(value.getX(), value.getY(), value.getZ());}
public default Vec3f multiply(float x, float y, float z){return set(getX() * x, getY() * y, getZ() * z);}
@Override
public default Vec3f devide(float value){return devide(value, value, value);}
public default Vec3f devide(Vec3f value){return devide(value.getX(), value.getY(), value.getZ());}
public default Vec3f devide(float x, float y, float z){return set(getX() / x, getY() / y, getZ() / z);}
@Override
public default Vec3f set(float value){return set(value, value, value);}
public default Vec3f set(Vec3f value){return set(value.getX(), value.getY(), value.getZ());}
public Vec3f set(float x, float y, float z);
public default double distanceTo(Vec3f value){return distanceTo(value.getX(), value.getY(), value.getZ());}
public default double distanceTo(float x, float y, float z){return Math.sqrt(distanceToSquared(x, y, z));}
public default double distanceToSquared(Vec3f value){return distanceToSquared(value.getX(), value.getY(), value.getZ());}
public default double distanceToSquared(float x, float y, float z)
{
double xPos = getX() - x;
double yPos = getY() - y;
double zPos = getZ() - z;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
}
@Override
public default float lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());}
public default double dotProduct(Vec3f value){return dotProduct(value.getX(), value.getY(), value.getZ());}
public default double dotProduct(float x, float y, float z){return (getX() * x) + (getY() * y) + (getZ() * z);}
public default Vec3f lerp(Vec3f value, float progress, Vec3f result){return lerp(value.getX(), value.getY(), value.getZ(), progress, result);}
public default Vec3f lerp(float x, float y, float z, float progress, Vec3f result){return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress), MathUtils.lerp(getZ(), z, progress));}
public default float angle(Vec3f value){return angle(value.getX(), value.getY(), value.getZ());}
public default float angle(float x, float y, float z){return (float)Math.acos(MathUtils.clamp(-1, 1, angleCos(x, y, z)));}
public default float angleCos(Vec3f value){return angleCos(value.getX(), value.getY(), value.getZ());}
public default float angleCos(float x, float y, float z)
{
double myLength = (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());
double otherLength = (x * x) + (y * y) + (z * z);
float dot = (getX() * x) + (getY() * y) + (getZ() * z);
return dot / (float)(Math.sqrt(myLength * otherLength));
}
public default Vec3f crossProduct(Vec3f value){return crossProduct(value.getX(), value.getY(), value.getZ(), this);}
public default Vec3f crossProduct(Vec3f value, Vec3f result){return crossProduct(value.getX(), value.getY(), value.getZ(), result);}
public default Vec3f crossProduct(float x, float y, float z){return crossProduct(x, y, z, this);}
public default Vec3f crossProduct(float x, float y, float z, Vec3f result){return result.set((getY() * z) - (getZ() * y), (getZ() * x) - (getX() * z), (getX() * y) - (getY() * x));}
public default Vec3f reflect(Vec3f value){return reflect(value.getX(), value.getY(), value.getZ(), this);}
public default Vec3f reflect(Vec3f value, Vec3f result){return reflect(value.getX(), value.getY(), value.getZ(), result);}
public default Vec3f reflect(float x, float y, float z){return reflect(x, y, z, this);}
public default Vec3f reflect(float x, float y, float z, Vec3f result)
{
double dot = dotProduct(x, y, z) * 2D;
return result.set(getX() - (float)(dot * x), getY() - (float)(dot * y), getZ() - (float)(dot * z));
}
public default Vec3f rotate(float angle, Vec3f axis){return rotate(angle, axis.getX(), axis.getY(), axis.getZ());}
public default Vec3f rotate(float angle, Vec3f axis, Vec3f result){return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), result);}
public default Vec3f rotate(float angle, float x, float y, float z){return rotate(angle, x, y, z, this);}
public default Vec3f rotate(float angle, float x, float y, float z, Vec3f result)
{
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
double dot = dotProduct(x, y, z);
double xPos = x * dot * (1D - cos) + (getX() * cos) + (-z * getY() + y * getZ()) * sin;
double yPos = y * dot * (1D - cos) + (getY() * cos) + (z * getX() - x * getZ()) * sin;
double zPos = z * dot * (1D - cos) + (getZ() * cos) + (-y * getX() + x * getY()) * sin;
return result.set((float)xPos, (float)yPos, (float)zPos);
}
public default Vec3f rotateX(float angle){return rotateX(angle, this);}
public default Vec3f rotateX(float angle, Vec3f result)
{
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
double y = getY() * cos + getZ() * sin;
double z = getZ() * cos - getY() * sin;
return result.set(getX(), (float)y, (float)z);
}
public default Vec3f rotateY(float angle){return rotateY(angle, this);}
public default Vec3f rotateY(float angle, Vec3f result)
{
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
double x = getX() * cos + getZ() * sin;
double z = getZ() * cos - getX() * sin;
return result.set((float)x, getY(), (float)z);
}
public default Vec3f rotateZ(float angle){return rotateZ(angle, this);}
public default Vec3f rotateZ(float angle, Vec3f result)
{
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
double x = cos * getX() - sin * getY();
double y = sin * getX() + cos * getY();
return result.set((float)x, (float)y, getZ());
}
public default Vec3f smoothStep(Vec3f value, float progress, Vec3f result){return smoothStep(value.getX(), value.getY(), value.getZ(), progress, result);}
public default Vec3f smoothStep(float x, float y, float z, float progress, Vec3f result)
{
float t2 = progress * progress;
float t3 = t2 * progress;
float xPos = ((getX() + getX() - x - x) * t3 + (3.0F * x - 3.0F * getX()) * t2 + getX() * progress + getX());
float yPos = ((getY() + getY() - y - y) * t3 + (3.0F * y - 3.0F * getY()) * t2 + getY() * progress + getY());
float zPos = ((getZ() + getZ() - z - z) * t3 + (3.0F * z - 3.0F * getZ()) * t2 + getZ() * progress + getZ());
return result.set(xPos, yPos, zPos);
}
public default Vec3f min(Vec3f other) {return min(other, this);}
public default Vec3f min(Vec3f other, Vec3f result){return min(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3f min(float x, float y, float z) {return min(x, y, z, this);}
public default Vec3f min(float x, float y, float z, Vec3f result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z));}
public default Vec3f max(Vec3f other) {return max(other, this);}
public default Vec3f max(Vec3f other, Vec3f result){return max(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3f max(float x, float y, float z) {return max(x, y, z, this);}
public default Vec3f max(float x, float y, float z, Vec3f result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z));}
public default Vec3f difference(Vec3f other) {return difference(other, this);}
public default Vec3f difference(Vec3f other, Vec3f result){return difference(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3f difference(float x, float y, float z) {return difference(x, y, z, this);}
public default Vec3f difference(float x, float y, float z, Vec3f result){return result.set(getX() - x, getY() - y, getZ() - z);}
@Override
public default Vec3f clamp(float min, float max){return clamp(min, max, ALL);}
public default Vec3f clamp(float min, float max, Vec3f result){return clamp(min, max, result, ALL);}
@Override
public default Vec3f clamp(float min, float max, int filter){return clamp(min, max, this, filter);}
public default Vec3f clamp(float min, float max, Vec3f result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()));}
@Override
public default Vec3f store(ByteBuffer buffer)
{
buffer.putFloat(getX()).putFloat(getY()).putFloat(getZ());
return this;
}
@Override
public default Vec3f load(ByteBuffer buffer)
{
return set(buffer.getFloat(), buffer.getFloat(), buffer.getFloat());
}
@Override
public default Vec3f store(FloatBuffer buffer)
{
buffer.put(getX()).put(getY()).put(getZ());
return this;
}
@Override
public default Vec3f load(FloatBuffer buffer)
{
return set(buffer.get(), buffer.get(), buffer.get());
}
@Override
public default Vec3b asByte(){return isMutable() ? Vec3b.newMutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ())) : Vec3b.newVec((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()));}
@Override
public default Vec3s asShort(){return isMutable() ? Vec3s.newMutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ())) : Vec3s.newVec((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()));}
@Override
public default Vec3i asInt(){return isMutable() ? Vec3i.newMutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())) : Vec3i.newVec(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()));}
@Override
public default Vec3l asLong() {return isMutable() ? Vec3l.newMutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ())) : Vec3l.newVec(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()));}
@Override
public default Vec3d asDouble(){return isMutable() ? Vec3d.newMutable(getX(), getY(), getZ()) : Vec3d.newVec(getX(), getY(), getZ());}
@Override
public default Vec3f asMutable(){return isMutable() ? this : newMutable(this);}
@Override
public default Vec3f asImmutable(){return isMutable() ? newVec(this) : this;}
@Override
public default Vec3f copyAsMutable(){return newMutable(this);}
@Override
public default Vec3f copyAsImmutable(){return newVec(this);}
}

View File

@ -0,0 +1,108 @@
package speiger.src.coreengine.math.vector.floats;
import java.util.Objects;
public class Vec3fImmutable implements Vec3f
{
final float x;
final float y;
final float z;
public Vec3fImmutable()
{
x = 0F;
y = 0F;
z = 0F;
}
public Vec3fImmutable(float value)
{
x = value;
y = value;
z = value;
}
public Vec3fImmutable(float x, float y, float z)
{
this.x = x;
this.y = y;
this.z = z;
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public float getX()
{
return x;
}
@Override
public float getY()
{
return y;
}
@Override
public float getZ()
{
return z;
}
@Override
public Vec3f setX(float x)
{
return this.x == x ? this : Vec3f.newVec(x, y, z);
}
@Override
public Vec3f setY(float y)
{
return this.y == y ? this : Vec3f.newVec(x, y, z);
}
@Override
public Vec3f setZ(float z)
{
return this.z == z ? this : Vec3f.newVec(x, y, z);
}
@Override
public Vec3f copy()
{
return Vec3f.newVec(this);
}
@Override
public Vec3f set(float x, float y, float z)
{
return this.x == x && this.y == y && this.z == z ? this : Vec3f.newVec(x, y, z);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec3f)
{
Vec3f vec = (Vec3f)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
}
return false;
}
@Override
public String toString()
{
return "Vec3f[x="+x+", y="+y+", z="+z+"]";
}
}

View File

@ -0,0 +1,111 @@
package speiger.src.coreengine.math.vector.floats;
import java.util.Objects;
public class Vec3fMutable implements Vec3f
{
float x;
float y;
float z;
public Vec3fMutable()
{
}
public Vec3fMutable(float value)
{
x = value;
y = value;
z = value;
}
public Vec3fMutable(float x, float y, float z)
{
this.x = x;
this.y = y;
this.z = z;
}
@Override
public boolean isMutable()
{
return true;
}
@Override
public float getX()
{
return x;
}
@Override
public float getY()
{
return y;
}
@Override
public float getZ()
{
return z;
}
@Override
public Vec3f setX(float x)
{
this.x = x;
return this;
}
@Override
public Vec3f setY(float y)
{
this.y = y;
return this;
}
@Override
public Vec3f setZ(float z)
{
this.z = z;
return this;
}
@Override
public Vec3f copy()
{
return Vec3f.newMutable(this);
}
@Override
public Vec3f set(float x, float y, float z)
{
this.x = x;
this.y = y;
this.z = z;
return this;
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec3f)
{
Vec3f vec = (Vec3f)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
}
return false;
}
@Override
public String toString()
{
return "Vec3f[x="+x+", y="+y+", z="+z+"]";
}
}

View File

@ -0,0 +1,232 @@
package speiger.src.coreengine.math.vector.floats;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.bytes.Vec4b;
import speiger.src.coreengine.math.vector.doubles.Vec4d;
import speiger.src.coreengine.math.vector.ints.Vec4i;
import speiger.src.coreengine.math.vector.longs.Vec4l;
import speiger.src.coreengine.math.vector.shorts.Vec4s;
public interface Vec4f extends Vecf
{
public static final Vec4f ZERO = newVec();
public static final Vec4f MINUS_ONE = newVec(-1F);
public static final Vec4f ONE = newVec(1F);
public static Vec4f newMutable(){return new Vec4fMutable();}
public static Vec4f newMutable(float value){return new Vec4fMutable(value);}
public static Vec4f newMutable(float x, float y, float z, float w){return new Vec4fMutable(x, y, z, w);}
public static Vec4f newMutable(Vec4f vec){return newMutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW());}
public static Vec4f newVec(){return new Vec4fImmutable();}
public static Vec4f newVec(float value){return new Vec4fImmutable(value);}
public static Vec4f newVec(float x, float y, float z, float w){return new Vec4fImmutable(x, y, z, w);}
public static Vec4f newVec(Vec4f vec){return newVec(vec.getX(), vec.getY(), vec.getZ(), vec.getW());}
public float getX();
public float getY();
public float getZ();
public float getW();
public Vec4f setX(float x);
public Vec4f setY(float y);
public Vec4f setZ(float z);
public Vec4f setW(float w);
@Override
public default float[] asArray(){return new float[]{getX(), getY(), getZ(), getW()};}
@Override
public Vec4f copy();
@Override
public default Vec4f abs(){return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()), Math.abs(getW()));}
@Override
public default Vec4f negate(){return set(0F, 0F, 0F, 0F);}
@Override
public default Vec4f invert(){return set(-getX(), -getY(), -getZ(), -getW());}
public default Vec4f normalize()
{
float l = length();
return l == 0F ? this : multiply(1.0F / l);
}
public default Vec4f normalize3D()
{
float value = (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());
return value == 0F ? this : multiply(1F / value);
}
@Override
public default Vec4f add(float value){return add(value, value, value, value);}
public default Vec4f add(Vec4f value){return add(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4f add(float x, float y, float z, float w){return set(getX() + x, getY() + y, getZ() + z, getW() + w);}
@Override
public default Vec4f sub(float value){return sub(value, value, value, value);}
public default Vec4f sub(Vec4f value){return sub(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4f sub(float x, float y, float z, float w){return set(getX() - x, getY() - y, getZ() - z, getW() - w);}
@Override
public default Vec4f multiply(float value){return multiply(value, value, value, value);}
public default Vec4f multiply(Vec4f value){return multiply(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4f multiply(float x, float y, float z, float w){return set(getX() * x, getY() * y, getZ() * z, getW() * w);}
@Override
public default Vec4f devide(float value){return devide(value, value, value, value);}
public default Vec4f devide(Vec4f value){return devide(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4f devide(float x, float y, float z, float w){return set(getX() / x, getY() / y, getZ() / z, getW() / w);}
@Override
public default Vec4f set(float value){return set(value, value, value, value);}
public default Vec4f set(Vec4f value){return set(value.getX(), value.getY(), value.getZ(), value.getW());}
public Vec4f set(float x, float y, float z, float w);
public default double distanceTo(Vec4f value){return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW());}
public default double distanceTo(float x, float y, float z, float w){return Math.sqrt(distanceTo(x, y, z, w));}
public default double distanceToSquared(Vec4f value){return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW());}
public default double distanceToSquared(float x, float y, float z, float w)
{
double xPos = getX() - x;
double yPos = getY() - y;
double zPos = getZ() - z;
double wPos = getW() - w;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
}
@Override
public default float lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW());}
public default double dotProduct(Vec4f value){return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW());}
public default double dotProduct(float x, float y, float z, float w){return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w);};
public default Vec4f lerp(Vec4f value, float progress, Vec4f result){return lerp(value.getX(), value.getY(), value.getZ(), value.getW(), progress, result);}
public default Vec4f lerp(float x, float y, float z, float w, float progress, Vec4f result){return result.set(MathUtils.lerp(getX(), x, progress), MathUtils.lerp(getY(), y, progress), MathUtils.lerp(getZ(), z, progress), MathUtils.lerp(getW(), w, progress));}
public default float angle(Vec4f value){return angle(value.getX(), value.getY(), value.getZ(), value.getW());}
public default float angle(float x, float y, float z, float w){return (float)Math.acos(MathUtils.clamp(-1F, 1F, angleCos(x, y, z, w)));}
public default float angleCos(Vec4f value){return angleCos(value.getX(), value.getY(), value.getZ(), value.getW());}
public default float angleCos(float x, float y, float z, float w){return (float)(dotProduct(x, y, z, w) / Math.sqrt(lengthSquared() * (x * x) + (y * y) + (z * z) + (w * w)));}
public default Vec4f rotate(float angle, Vec4f axis){return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), axis.getW());}
public default Vec4f rotate(float angle, Vec4f axis, Vec4f result){return rotate(angle, axis.getX(), axis.getY(), axis.getZ(), axis.getW(), result);}
public default Vec4f rotate(float angle, float x, float y, float z, float w){return rotate(angle, x, y, z, w, this);}
public default Vec4f rotate(float angle, float x, float y, float z, float w, Vec4f result)
{
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
double dot = dotProduct(x, y, z, w);
double xPos = x * dot * (1D - cos) + (getX() * cos) + (-z * getY() + y * getZ()) * sin;
double yPos = y * dot * (1D - cos) + (getY() * cos) + (z * getX() - x * getZ()) * sin;
double zPos = z * dot * (1D - cos) + (getZ() * cos) + (-y * getX() + x * getY()) * sin;
return result.set((float)xPos, (float)yPos, (float)zPos, getW());
}
public default Vec4f rotateX(float angle){return rotateX(angle, this);}
public default Vec4f rotateX(float angle, Vec4f result)
{
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
double y = getY() * cos + getZ() * sin;
double z = getZ() * cos - getY() * sin;
return result.set(getX(), (float)y, (float)z, getW());
}
public default Vec4f rotateY(float angle){return rotateY(angle, this);}
public default Vec4f rotateY(float angle, Vec4f result)
{
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
double x = getX() * cos + getZ() * sin;
double z = getZ() * cos - getX() * sin;
return result.set((float)x, getY(), (float)z, getW());
}
public default Vec4f rotateZ(float angle){return rotateZ(angle, this);}
public default Vec4f rotateZ(float angle, Vec4f result)
{
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
double x = cos * getX() - sin * getY();
double y = sin * getX() + cos * getY();
return result.set((float)x, (float)y, getZ(), getW());
}
public default Vec4f smoothStep(Vec4f value, float progress, Vec4f result){return smoothStep(value.getX(), value.getY(), value.getZ(), value.getW(), progress, result);}
public default Vec4f smoothStep(float x, float y, float z, float w, float progress, Vec4f result)
{
float t2 = progress * progress;
float t3 = t2 * progress;
float xPos = ((getX() + getX() - x - x) * t3 + (3.0F * x - 3.0F * getX()) * t2 + getX() * progress + getX());
float yPos = ((getY() + getY() - y - y) * t3 + (3.0F * y - 3.0F * getY()) * t2 + getY() * progress + getY());
float zPos = ((getZ() + getZ() - z - z) * t3 + (3.0F * z - 3.0F * getZ()) * t2 + getZ() * progress + getZ());
float wPos = ((getW() + getW() - w - w) * t3 + (3.0F * w - 3.0F * getW()) * t2 + getW() * progress + getW());
return result.set(xPos, yPos, zPos, wPos);
}
public default Vec4f min(Vec4f other) {return min(other, this);}
public default Vec4f min(Vec4f other, Vec4f result){return min(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4f min(float x, float y, float z, float w) {return min(x, y, z, w, this);}
public default Vec4f min(float x, float y, float z, float w, Vec4f result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z), Math.min(getW(), w));}
public default Vec4f max(Vec4f other) {return max(other, this);}
public default Vec4f max(Vec4f other, Vec4f result){return max(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4f max(float x, float y, float z, float w) {return max(x, y, z, w, this);}
public default Vec4f max(float x, float y, float z, float w, Vec4f result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z), Math.max(getZ(), z));}
public default Vec4f difference(Vec4f other) {return difference(other, this);}
public default Vec4f difference(Vec4f other, Vec4f result){return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4f difference(float x, float y, float z, float w) {return difference(x, y, z, w, this);}
public default Vec4f difference(float x, float y, float z, float w, Vec4f result){return result.set(getX() - x, getY() - y, getZ() - z, getW() - w);}
@Override
public default Vec4f clamp(float min, float max){return clamp(min, max, ALL);}
public default Vec4f clamp(float min, float max, Vec4f result){return clamp(min, max, result, ALL);}
@Override
public default Vec4f clamp(float min, float max, int filter){return clamp(min, max, this, filter);}
public default Vec4f clamp(float min, float max, Vec4f result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW()));}
@Override
public default Vec4f store(ByteBuffer buffer)
{
buffer.putFloat(getX()).putFloat(getY()).putFloat(getZ()).putFloat(getW());
return this;
}
@Override
public default Vec4f load(ByteBuffer buffer)
{
return set(buffer.getFloat(), buffer.getFloat(), buffer.getFloat(), buffer.getFloat());
}
@Override
public default Vec4f store(FloatBuffer buffer)
{
buffer.put(getX()).put(getY()).put(getZ()).put(getW());
return this;
}
@Override
public default Vec4f load(FloatBuffer buffer)
{
return set(buffer.get(), buffer.get(), buffer.get(), buffer.get());
}
@Override
public default Vec4b asByte(){return isMutable() ? Vec4b.newMutable((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()), (byte)MathUtils.floor(getW())) : Vec4b.newVec((byte)MathUtils.floor(getX()), (byte)MathUtils.floor(getY()), (byte)MathUtils.floor(getZ()), (byte)MathUtils.floor(getW()));}
@Override
public default Vec4s asShort(){return isMutable() ? Vec4s.newMutable((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()), (short)MathUtils.floor(getW())) : Vec4s.newVec((short)MathUtils.floor(getX()), (short)MathUtils.floor(getY()), (short)MathUtils.floor(getZ()), (short)MathUtils.floor(getW()));}
@Override
public default Vec4i asInt(){return isMutable() ? Vec4i.newMutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())) : Vec4i.newVec(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW()));}
@Override
public default Vec4l asLong() {return isMutable() ? Vec4l.newMutable(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW())) : Vec4l.newVec(MathUtils.floor(getX()), MathUtils.floor(getY()), MathUtils.floor(getZ()), MathUtils.floor(getW()));}
@Override
public default Vec4d asDouble(){return isMutable() ? Vec4d.newMutable(getX(), getY(), getZ(), getW()) : Vec4d.newVec(getX(), getY(), getZ(), getW());}
@Override
public default Vec4f asMutable(){return isMutable() ? this : newMutable(this);}
@Override
public default Vec4f asImmutable(){return isMutable() ? newVec(this) : this;}
@Override
public default Vec4f copyAsMutable(){return newMutable(this);}
@Override
public default Vec4f copyAsImmutable(){return newVec(this);}
}

View File

@ -0,0 +1,124 @@
package speiger.src.coreengine.math.vector.floats;
import java.util.Objects;
public class Vec4fImmutable implements Vec4f
{
final float x;
final float y;
final float z;
final float w;
public Vec4fImmutable()
{
x = 0;
y = 0;
z = 0;
w = 0;
}
public Vec4fImmutable(float value)
{
x = value;
y = value;
z = value;
w = value;
}
public Vec4fImmutable(float x, float y, float z, float w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public float getX()
{
return x;
}
@Override
public float getY()
{
return y;
}
@Override
public float getZ()
{
return z;
}
@Override
public float getW()
{
return w;
}
@Override
public Vec4f setX(float x)
{
return this.x == x ? this : Vec4f.newVec(x, y, z, w);
}
@Override
public Vec4f setY(float y)
{
return this.y == y ? this : Vec4f.newVec(x, y, z, w);
}
@Override
public Vec4f setZ(float z)
{
return this.z == z ? this : Vec4f.newVec(x, y, z, w);
}
@Override
public Vec4f setW(float w)
{
return this.w == w ? this : Vec4f.newVec(x, y, z, w);
}
@Override
public Vec4f copy()
{
return Vec4f.newVec(this);
}
@Override
public Vec4f set(float x, float y, float z, float w)
{
return this.x == x && this.y == y && this.z == z && this.w == w ? this : Vec4f.newVec(x, y, z, w);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z, w);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec4f)
{
Vec4f vec = (Vec4f)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
}
return false;
}
@Override
public String toString()
{
return "Vec4f[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
}

View File

@ -0,0 +1,132 @@
package speiger.src.coreengine.math.vector.floats;
import java.util.Objects;
public class Vec4fMutable implements Vec4f
{
float x;
float y;
float z;
float w;
public Vec4fMutable()
{
x = 0;
y = 0;
z = 0;
w = 0;
}
public Vec4fMutable(float value)
{
x = value;
y = value;
z = value;
w = value;
}
public Vec4fMutable(float x, float y, float z, float w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
@Override
public boolean isMutable()
{
return true;
}
@Override
public float getX()
{
return x;
}
@Override
public float getY()
{
return y;
}
@Override
public float getZ()
{
return z;
}
@Override
public float getW()
{
return w;
}
@Override
public Vec4f setX(float x)
{
this.x = x;
return this;
}
@Override
public Vec4f setY(float y)
{
this.y = y;
return this;
}
@Override
public Vec4f setZ(float z)
{
this.z = z;
return this;
}
@Override
public Vec4f setW(float w)
{
this.w = w;
return this;
}
@Override
public Vec4f copy()
{
return Vec4f.newMutable(this);
}
@Override
public Vec4f set(float x, float y, float z, float w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
return this;
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z, w);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec4f)
{
Vec4f vec = (Vec4f)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
}
return false;
}
@Override
public String toString()
{
return "Vec4f[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
}

View File

@ -0,0 +1,34 @@
package speiger.src.coreengine.math.vector.floats;
import java.nio.FloatBuffer;
import speiger.src.coreengine.math.vector.Vec;
import speiger.src.coreengine.math.vector.bytes.Vecb;
import speiger.src.coreengine.math.vector.doubles.Vecd;
import speiger.src.coreengine.math.vector.ints.Veci;
import speiger.src.coreengine.math.vector.longs.Vecl;
import speiger.src.coreengine.math.vector.shorts.Vecs;
public interface Vecf extends Vec
{
public Vecf set(float value);
public Vecf add(float value);
public Vecf sub(float value);
public Vecf multiply(float value);
public Vecf devide(float value);
public Vecf clamp(float min, float max);
public Vecf clamp(float min, float max, int filter);
public float lengthSquared();
public default float length(){return (float)Math.sqrt(lengthSquared());}
public Vecf store(FloatBuffer buffer);
public Vecf load(FloatBuffer buffer);
public float[] asArray();
public Vecb asByte();
public Vecs asShort();
public Veci asInt();
public Vecl asLong();
public Vecd asDouble();
}

View File

@ -0,0 +1,163 @@
package speiger.src.coreengine.math.vector.ints;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.bytes.Vec2b;
import speiger.src.coreengine.math.vector.doubles.Vec2d;
import speiger.src.coreengine.math.vector.floats.Vec2f;
import speiger.src.coreengine.math.vector.longs.Vec2l;
import speiger.src.coreengine.math.vector.shorts.Vec2s;
public interface Vec2i extends Veci
{
public static final Vec2i ZERO = newVec();
public static final Vec2i MINUS_ONE = newVec(-1);
public static final Vec2i ONE = newVec(1);
public static Vec2i newMutable(){return new Vec2iMutable();}
public static Vec2i newMutable(int value){return new Vec2iMutable(value);}
public static Vec2i newMutable(int x, int y){return new Vec2iMutable(x, y);}
public static Vec2i newMutable(Vec2i value){return newMutable(value.getX(), value.getY());}
public static Vec2i newVec(){return new Vec2iImmutable();}
public static Vec2i newVec(int value){return new Vec2iImmutable(value);}
public static Vec2i newVec(int x, int y){return new Vec2iImmutable(x, y);}
public static Vec2i newVec(Vec2i value){return newVec(value.getX(), value.getY());}
public int getX();
public int getY();
public Vec2i setX(int x);
public Vec2i setY(int y);
@Override
public default int[] asArray(){return new int[]{getX(), getY()};}
@Override
public Vec2i copy();
@Override
public default Vec2i abs(){return set(Math.abs(getX()), Math.abs(getY()));}
@Override
public default Vec2i negate(){return set(0, 0);}
@Override
public default Vec2i invert(){return set(-getX(), -getY());};
@Override
public default Vec2i add(int value) {return add(value, value);}
public default Vec2i add(Vec2i value) {return add(value.getX(), value.getY());}
public default Vec2i add(int x, int y) {return set(x + getX(), y + getY());}
@Override
public default Vec2i sub(int value){return sub(value, value);}
public default Vec2i sub(Vec2i value){return sub(value.getX(), value.getY());}
public default Vec2i sub(int x, int y) {return set(getX() - x, getY() - y);}
@Override
public default Vec2i multiply(int value){return multiply(value, value);}
public default Vec2i multiply(Vec2i value){return multiply(value.getX(), value.getY());}
public default Vec2i multiply(int x, int y) {return set(x * getX(), y * getY());}
@Override
public default Vec2i devide(int value){return devide(value, value);}
public default Vec2i devide(Vec2i value){return devide(value.getX(), value.getY());}
public default Vec2i devide(int x, int y){return set(getX() / x, getY() / y);}
@Override
public default Vec2i set(int value){return set(value, value);};
public default Vec2i set(Vec2i value){return set(value.getX(), value.getY());}
public Vec2i set(int x, int y);
public default double distanceTo(Vec2i value){return distanceTo(value.getX(), value.getY());}
public default double distanceTo(int x, int y){return Math.sqrt(distanceToSquared(x, y));}
public default long distanceToSquared(Vec2i value){return distanceToSquared(value.getX(), value.getY());}
public default long distanceToSquared(int x, int y)
{
long xPos = getX() - x;
long yPos = getY() - y;
return (xPos * xPos) + (yPos * yPos);
}
@Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY());}
public default long dotProduct(Vec2i value){return dotProduct(value.getX(), value.getY());}
public default long dotProduct(int x, int y){return (getX() * x) + (getY() * y);}
public default Vec2i rotate(int angle, Vec2i center){return rotate(angle, center.getX(), center.getY());}
public default Vec2i rotate(int angle, int x, int y)
{
int xPos = getX() - x;
int yPos = getY() - y;
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
return set((int)((xPos * cos) + (yPos * sin) + x), (int)(-(xPos * sin) + (yPos * cos) + y));
}
public default Vec2i min(Vec2i other) {return min(other, this);}
public default Vec2i min(Vec2i other, Vec2i result){return min(other.getX(), other.getY(), result);}
public default Vec2i min(int x, int y) {return min(x, y, this);}
public default Vec2i min(int x, int y, Vec2i result){return result.set(Math.min(getX(), x), Math.min(getY(), y));}
public default Vec2i max(Vec2i other) {return max(other, this);}
public default Vec2i max(Vec2i other, Vec2i result){return max(other.getX(), other.getY(), result);}
public default Vec2i max(int x, int y) {return max(x, y, this);}
public default Vec2i max(int x, int y, Vec2i result){return result.set(Math.max(getX(), x), Math.max(getY(), y));}
public default Vec2i difference(Vec2i other) {return difference(other, this);}
public default Vec2i difference(Vec2i other, Vec2i result){return difference(other.getX(), other.getY(), result);}
public default Vec2i difference(int x, int y) {return difference(x, y, this);}
public default Vec2i difference(int x, int y, Vec2i result){return result.set(getX() - x, getY() - y);}
@Override
public default Vec2i clamp(int min, int max){return clamp(min, max, ALL);}
public default Vec2i clamp(int min, int max, Vec2i result){return clamp(min, max, result, ALL);}
@Override
public default Vec2i clamp(int min, int max, int filter){return clamp(min, max, this, filter);}
public default Vec2i clamp(int min, int max, Vec2i result, int filter){return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()));}
@Override
public default Vec2i store(ByteBuffer buffer)
{
buffer.putInt(getX()).putInt(getY());
return this;
}
@Override
public default Vec2i load(ByteBuffer buffer)
{
return set(buffer.getInt(), buffer.getInt());
}
@Override
public default Vec2i store(IntBuffer buffer)
{
buffer.put(getX()).put(getY());
return this;
}
@Override
public default Vec2i load(IntBuffer buffer)
{
return set(buffer.get(), buffer.get());
}
@Override
public default Vec2b asByte(){return isMutable() ? Vec2b.newMutable((byte)getX(), (byte)getY()) : Vec2b.newVec((byte)getX(), (byte)getY());}
@Override
public default Vec2s asShort(){return isMutable() ? Vec2s.newMutable((short)getX(), (short)getY()) : Vec2s.newVec((short)getX(), (short)getY());}
@Override
public default Vec2l asLong(){return isMutable() ? Vec2l.newMutable(getX(), getY()) : Vec2l.newVec(getX(), getY());}
@Override
public default Vec2f asFloat() {return isMutable() ? Vec2f.newMutable(getX(), getY()) : Vec2f.newVec(getX(), getY());}
@Override
public default Vec2d asDouble(){return isMutable() ? Vec2d.newMutable(getX(), getY()) : Vec2d.newVec(getX(), getY());}
@Override
public default Vec2i asMutable(){return isMutable() ? this : newMutable(this);}
@Override
public default Vec2i asImmutable(){return isMutable() ? newVec(this) : this;}
@Override
public default Vec2i copyAsMutable(){return newMutable(this);}
@Override
public default Vec2i copyAsImmutable(){return newVec(this);}
}

View File

@ -0,0 +1,92 @@
package speiger.src.coreengine.math.vector.ints;
import java.util.Objects;
public class Vec2iImmutable implements Vec2i
{
final int x;
final int y;
public Vec2iImmutable()
{
x = 0;
y = 0;
}
public Vec2iImmutable(int value)
{
x = value;
y = value;
}
public Vec2iImmutable(int x, int y)
{
this.x = x;
this.y = y;
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public int getX()
{
return x;
}
@Override
public int getY()
{
return y;
}
@Override
public Vec2i setX(int x)
{
return this.x == x ? this : Vec2i.newVec(x, y);
}
@Override
public Vec2i setY(int y)
{
return this.y == y ? this : Vec2i.newVec(x, y);
}
@Override
public Vec2i copy()
{
return Vec2i.newVec(this);
}
@Override
public Vec2i set(int x, int y)
{
return this.x == x && this.y == y ? this : Vec2i.newVec(x, y);
}
@Override
public int hashCode()
{
return Objects.hash(x, y);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec2i)
{
Vec2i vec = (Vec2i)obj;
return vec.getX() == x && vec.getY() == y;
}
return false;
}
@Override
public String toString()
{
return "Vec2i[x="+x+", y="+y+"]";
}
}

View File

@ -0,0 +1,94 @@
package speiger.src.coreengine.math.vector.ints;
import java.util.Objects;
public class Vec2iMutable implements Vec2i
{
int x;
int y;
public Vec2iMutable()
{
}
public Vec2iMutable(int value)
{
x = value;
y = value;
}
public Vec2iMutable(int x, int y)
{
this.x = x;
this.y = y;
}
@Override
public boolean isMutable()
{
return true;
}
@Override
public int getX()
{
return x;
}
@Override
public int getY()
{
return y;
}
@Override
public Vec2i setX(int x)
{
this.x = x;
return this;
}
@Override
public Vec2i setY(int y)
{
this.y = y;
return this;
}
@Override
public Vec2i copy()
{
return Vec2i.newMutable(this);
}
@Override
public Vec2i set(int x, int y)
{
this.x = x;
this.y = y;
return this;
}
@Override
public int hashCode()
{
return Objects.hash(x, y);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec2i)
{
Vec2i vec = (Vec2i)obj;
return vec.getX() == x && vec.getY() == y;
}
return false;
}
@Override
public String toString()
{
return "Vec2i[x="+x+", y="+y+"]";
}
}

View File

@ -0,0 +1,157 @@
package speiger.src.coreengine.math.vector.ints;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.bytes.Vec3b;
import speiger.src.coreengine.math.vector.doubles.Vec3d;
import speiger.src.coreengine.math.vector.floats.Vec3f;
import speiger.src.coreengine.math.vector.longs.Vec3l;
import speiger.src.coreengine.math.vector.shorts.Vec3s;
public interface Vec3i extends Veci
{
public static final Vec3i ZERO = newVec();
public static final Vec3i MINUS_ONE = newVec(-1);
public static final Vec3i ONE = newVec(1);
public static Vec3i newMutable(){return new Vec3iMutable();}
public static Vec3i newMutable(int value){return new Vec3iMutable(value);}
public static Vec3i newMutable(int x, int y, int z){return new Vec3iMutable(x, y, z);}
public static Vec3i newMutable(Vec3i vec){return newMutable(vec.getX(), vec.getY(), vec.getZ());}
public static Vec3i newVec(){return new Vec3iImmutable();}
public static Vec3i newVec(int value){return new Vec3iImmutable(value);}
public static Vec3i newVec(int x, int y, int z){return new Vec3iImmutable(x, y, z);}
public static Vec3i newVec(Vec3i vec){return newVec(vec.getX(), vec.getY(), vec.getZ());}
public int getX();
public int getY();
public int getZ();
public Vec3i setX(int x);
public Vec3i setY(int y);
public Vec3i setZ(int z);
@Override
public default int[] asArray(){return new int[]{getX(), getY(), getZ()};}
@Override
public Vec3i copy();
@Override
public default Vec3i abs(){return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()));}
@Override
public default Vec3i negate(){return set(0, 0, 0);}
@Override
public default Vec3i invert(){return set(-getX(), -getY(), -getZ());}
@Override
public default Vec3i add(int value){return add(value, value, value);}
public default Vec3i add(Vec3i value){return add(value.getX(), value.getY(), value.getZ());}
public default Vec3i add(int x, int y, int z){return set(getX() + x, getY() + y, getZ() + z);}
@Override
public default Vec3i sub(int value){return sub(value, value, value);}
public default Vec3i sub(Vec3i value){return sub(value.getX(), value.getY(), value.getZ());}
public default Vec3i sub(int x, int y, int z){return set(getX() - x, getY() - y, getZ() - z);}
@Override
public default Vec3i multiply(int value){return multiply(value, value, value);}
public default Vec3i multiply(Vec3i value){return multiply(value.getX(), value.getY(), value.getZ());}
public default Vec3i multiply(int x, int y, int z){return set(getX() * x, getY() * y, getZ() * z);}
@Override
public default Vec3i devide(int value){return devide(value, value, value);}
public default Vec3i devide(Vec3i value){return devide(value.getX(), value.getY(), value.getZ());}
public default Vec3i devide(int x, int y, int z){return set(getX() / x, getY() / y, getZ() / z);}
@Override
public default Vec3i set(int value){return set(value, value, value);}
public default Vec3i set(Vec3i value){return set(value.getX(), value.getY(), value.getZ());}
public Vec3i set(int x, int y, int z);
public default double distanceTo(Vec3i value){return distanceTo(value.getX(), value.getY(), value.getZ());}
public default double distanceTo(int x, int y, int z){return Math.sqrt(distanceToSquared(x, y, z));}
public default long distanceToSquared(Vec3i value){return distanceToSquared(value.getX(), value.getY(), value.getZ());}
public default long distanceToSquared(int x, int y, int z)
{
long xPos = getX() - x;
long yPos = getY() - y;
long zPos = getZ() - z;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
}
@Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());}
public default long dotProduct(Vec3i value){return dotProduct(value.getX(), value.getY(), value.getZ());}
public default long dotProduct(int x, int y, int z){return (getX() * x) + (getY() * y) + (getZ() * z);}
public default Vec3i min(Vec3i other) {return min(other, this);}
public default Vec3i min(Vec3i other, Vec3i result){return min(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3i min(int x, int y, int z) {return min(x, y, z, this);}
public default Vec3i min(int x, int y, int z, Vec3i result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z));}
public default Vec3i max(Vec3i other) {return max(other, this);}
public default Vec3i max(Vec3i other, Vec3i result){return max(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3i max(int x, int y, int z) {return max(x, y, z, this);}
public default Vec3i max(int x, int y, int z, Vec3i result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z));}
public default Vec3i difference(Vec3i other) {return difference(other, this);}
public default Vec3i difference(Vec3i other, Vec3i result){return difference(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3i difference(int x, int y, int z) {return difference(x, y, z, this);}
public default Vec3i difference(int x, int y, int z, Vec3i result){return result.set(getX() - x, getY() - y, getZ() - z);}
@Override
public default Vec3i clamp(int min, int max){return clamp(min, max, ALL);}
public default Vec3i clamp(int min, int max, Vec3i result){return clamp(min, max, result, ALL);}
@Override
public default Vec3i clamp(int min, int max, int filter){return clamp(min, max, this, filter);}
public default Vec3i clamp(int min, int max, Vec3i result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()));}
@Override
public default Vec3i store(ByteBuffer buffer)
{
buffer.putInt(getX()).putInt(getY()).putInt(getZ());
return this;
}
@Override
public default Vec3i load(ByteBuffer buffer)
{
return set(buffer.getInt(), buffer.getInt(), buffer.getInt());
}
@Override
public default Vec3i store(IntBuffer buffer)
{
buffer.put(getX()).put(getY()).put(getZ());
return this;
}
@Override
public default Vec3i load(IntBuffer buffer)
{
return set(buffer.get(), buffer.get(), buffer.get());
}
@Override
public default Vec3b asByte(){return isMutable() ? Vec3b.newMutable((byte)getX(), (byte)getY(), (byte)getZ()) : Vec3b.newVec((byte)getX(), (byte)getY(), (byte)getZ());}
@Override
public default Vec3s asShort(){return isMutable() ? Vec3s.newMutable((short)getX(), (short)getY(), (short)getZ()) : Vec3s.newVec((short)getX(), (short)getY(), (short)getZ());}
@Override
public default Vec3l asLong(){return isMutable() ? Vec3l.newMutable(getX(), getY(), getZ()) : Vec3l.newVec(getX(), getY(), getZ());}
@Override
public default Vec3f asFloat() {return isMutable() ? Vec3f.newMutable(getX(), getY(), getZ()) : Vec3f.newVec(getX(), getY(), getZ());}
@Override
public default Vec3d asDouble(){return isMutable() ? Vec3d.newMutable(getX(), getY(), getZ()) : Vec3d.newVec(getX(), getY(), getZ());}
@Override
public default Vec3i asMutable(){return isMutable() ? this : newMutable(this);}
@Override
public default Vec3i asImmutable(){return isMutable() ? newVec(this) : this;}
@Override
public default Vec3i copyAsMutable(){return newMutable(this);}
@Override
public default Vec3i copyAsImmutable(){return newVec(this);}
}

View File

@ -0,0 +1,108 @@
package speiger.src.coreengine.math.vector.ints;
import java.util.Objects;
public class Vec3iImmutable implements Vec3i
{
final int x;
final int y;
final int z;
public Vec3iImmutable()
{
x = 0;
y = 0;
z = 0;
}
public Vec3iImmutable(int value)
{
x = value;
y = value;
z = value;
}
public Vec3iImmutable(int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public int getX()
{
return x;
}
@Override
public int getY()
{
return y;
}
@Override
public int getZ()
{
return z;
}
@Override
public Vec3i setX(int x)
{
return this.x == x ? this : Vec3i.newVec(x, y, z);
}
@Override
public Vec3i setY(int y)
{
return this.y == y ? this : Vec3i.newVec(x, y, z);
}
@Override
public Vec3i setZ(int z)
{
return this.z == z ? this : Vec3i.newVec(x, y, z);
}
@Override
public Vec3i copy()
{
return Vec3i.newVec(this);
}
@Override
public Vec3i set(int x, int y, int z)
{
return this.x == x && this.y == y && this.z == z ? this : Vec3i.newVec(x, y, z);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec3i)
{
Vec3i vec = (Vec3i)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
}
return false;
}
@Override
public String toString()
{
return "Vec3i[x="+x+", y="+y+", z="+z+"]";
}
}

View File

@ -0,0 +1,111 @@
package speiger.src.coreengine.math.vector.ints;
import java.util.Objects;
public class Vec3iMutable implements Vec3i
{
int x;
int y;
int z;
public Vec3iMutable()
{
}
public Vec3iMutable(int value)
{
x = value;
y = value;
z = value;
}
public Vec3iMutable(int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
}
@Override
public boolean isMutable()
{
return true;
}
@Override
public int getX()
{
return x;
}
@Override
public int getY()
{
return y;
}
@Override
public int getZ()
{
return z;
}
@Override
public Vec3i setX(int x)
{
this.x = x;
return this;
}
@Override
public Vec3i setY(int y)
{
this.y = y;
return this;
}
@Override
public Vec3i setZ(int z)
{
this.z = z;
return this;
}
@Override
public Vec3i copy()
{
return Vec3i.newMutable(this);
}
@Override
public Vec3i set(int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
return this;
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec3i)
{
Vec3i vec = (Vec3i)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
}
return false;
}
@Override
public String toString()
{
return "Vec3i[x="+x+", y="+y+", z="+z+"]";
}
}

View File

@ -0,0 +1,158 @@
package speiger.src.coreengine.math.vector.ints;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.bytes.Vec4b;
import speiger.src.coreengine.math.vector.doubles.Vec4d;
import speiger.src.coreengine.math.vector.floats.Vec4f;
import speiger.src.coreengine.math.vector.longs.Vec4l;
import speiger.src.coreengine.math.vector.shorts.Vec4s;
public interface Vec4i extends Veci
{
public static final Vec4i ZERO = newVec();
public static final Vec4i MINUS_ONE = newVec(-1);
public static final Vec4i ONE = newVec(1);
public static Vec4i newMutable(){return new Vec4iMutable();}
public static Vec4i newMutable(int value){return new Vec4iMutable(value);}
public static Vec4i newMutable(int x, int y, int z, int w){return new Vec4iMutable(x, y, z, w);}
public static Vec4i newMutable(Vec4i vec){return newMutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW());}
public static Vec4i newVec(){return new Vec4iImmutable();}
public static Vec4i newVec(int value){return new Vec4iImmutable(value);}
public static Vec4i newVec(int x, int y, int z, int w){return new Vec4iImmutable(x, y, z, w);}
public static Vec4i newVec(Vec4i vec){return newVec(vec.getX(), vec.getY(), vec.getZ(), vec.getW());}
public int getX();
public int getY();
public int getZ();
public int getW();
public Vec4i setX(int x);
public Vec4i setY(int y);
public Vec4i setZ(int z);
public Vec4i setW(int w);
@Override
public default int[] asArray(){return new int[]{getX(), getY(), getZ(), getW()};}
@Override
public Vec4i copy();
@Override
public default Vec4i abs(){return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()), Math.abs(getW()));}
@Override
public default Vec4i negate(){return set(0, 0, 0, 0);}
@Override
public default Vec4i invert(){return set(-getX(), -getY(), -getZ(), -getW());}
@Override
public default Vec4i add(int value){return add(value, value, value, value);}
public default Vec4i add(Vec4i value){return add(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4i add(int x, int y, int z, int w){return set(getX() + x, getY() + y, getZ() + z, getW() + w);}
@Override
public default Vec4i sub(int value){return sub(value, value, value, value);}
public default Vec4i sub(Vec4i value){return sub(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4i sub(int x, int y, int z, int w){return set(getX() - x, getY() - y, getZ() - z, getW() - w);}
@Override
public default Vec4i multiply(int value){return multiply(value, value, value, value);}
public default Vec4i multiply(Vec4i value){return multiply(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4i multiply(int x, int y, int z, int w){return set(getX() * x, getY() * y, getZ() * z, getW() * w);}
@Override
public default Vec4i devide(int value){return devide(value, value, value, value);}
public default Vec4i devide(Vec4i value){return devide(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4i devide(int x, int y, int z, int w){return set(getX() / x, getY() / y, getZ() / z, getW() / w);}
@Override
public default Vec4i set(int value){return set(value, value, value, value);}
public default Vec4i set(Vec4i value){return set(value.getX(), value.getY(), value.getZ(), value.getW());}
public Vec4i set(int x, int y, int z, int w);
public default double distanceTo(Vec4i value){return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW());}
public default double distanceTo(int x, int y, int z, int w){return Math.sqrt(distanceTo(x, y, z, w));}
public default long distanceToSquared(Vec4i value){return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW());}
public default long distanceToSquared(int x, int y, int z, int w)
{
long xPos = getX() - x;
long yPos = getY() - y;
long zPos = getZ() - z;
long wPos = getW() - w;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
}
@Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW());}
public default long dotProduct(Vec4i value){return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW());}
public default long dotProduct(int x, int y, int z, int w){return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w);};
public default Vec4i min(Vec4i other) {return min(other, this);}
public default Vec4i min(Vec4i other, Vec4i result){return min(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4i min(int x, int y, int z, int w) {return min(x, y, z, w, this);}
public default Vec4i min(int x, int y, int z, int w, Vec4i result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z), Math.min(getW(), w));}
public default Vec4i max(Vec4i other) {return max(other, this);}
public default Vec4i max(Vec4i other, Vec4i result){return max(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4i max(int x, int y, int z, int w) {return max(x, y, z, w, this);}
public default Vec4i max(int x, int y, int z, int w, Vec4i result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z), Math.max(getZ(), z));}
public default Vec4i difference(Vec4i other) {return difference(other, this);}
public default Vec4i difference(Vec4i other, Vec4i result){return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4i difference(int x, int y, int z, int w) {return difference(x, y, z, w, this);}
public default Vec4i difference(int x, int y, int z, int w, Vec4i result){return result.set(getX() - x, getY() - y, getZ() - z, getW() - w);}
@Override
public default Vec4i clamp(int min, int max){return clamp(min, max, ALL);}
public default Vec4i clamp(int min, int max, Vec4i result){return clamp(min, max, result, ALL);}
@Override
public default Vec4i clamp(int min, int max, int filter){return clamp(min, max, this, filter);}
public default Vec4i clamp(int min, int max, Vec4i result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW()));}
@Override
public default Vec4i store(ByteBuffer buffer)
{
buffer.putInt(getX()).putInt(getY()).putInt(getZ()).putInt(getW());
return this;
}
@Override
public default Vec4i load(ByteBuffer buffer)
{
return set(buffer.getInt(), buffer.getInt(), buffer.getInt(), buffer.getInt());
}
@Override
public default Vec4i store(IntBuffer buffer)
{
buffer.put(getX()).put(getY()).put(getZ()).put(getW());
return this;
}
@Override
public default Vec4i load(IntBuffer buffer)
{
return set(buffer.get(), buffer.get(), buffer.get(), buffer.get());
}
@Override
public default Vec4b asByte(){return isMutable() ? Vec4b.newMutable((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW()) : Vec4b.newVec((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW());}
@Override
public default Vec4s asShort(){return isMutable() ? Vec4s.newMutable((short)getX(), (short)getY(), (short)getZ(), (short)getW()) : Vec4s.newVec((short)getX(), (short)getY(), (short)getZ(), (short)getW());}
@Override
public default Vec4l asLong(){return isMutable() ? Vec4l.newMutable(getX(), getY(), getZ(), getW()) : Vec4l.newVec(getX(), getY(), getZ(), getW());}
@Override
public default Vec4f asFloat() {return isMutable() ? Vec4f.newMutable(getX(), getY(), getZ(), getW()) : Vec4f.newVec(getX(), getY(), getZ(), getW());}
@Override
public default Vec4d asDouble(){return isMutable() ? Vec4d.newMutable(getX(), getY(), getZ(), getW()) : Vec4d.newVec(getX(), getY(), getZ(), getW());}
@Override
public default Vec4i asMutable(){return isMutable() ? this : newMutable(this);}
@Override
public default Vec4i asImmutable(){return isMutable() ? newVec(this) : this;}
@Override
public default Vec4i copyAsMutable(){return newMutable(this);}
@Override
public default Vec4i copyAsImmutable(){return newVec(this);}
}

View File

@ -0,0 +1,124 @@
package speiger.src.coreengine.math.vector.ints;
import java.util.Objects;
public class Vec4iImmutable implements Vec4i
{
final int x;
final int y;
final int z;
final int w;
public Vec4iImmutable()
{
x = 0;
y = 0;
z = 0;
w = 0;
}
public Vec4iImmutable(int value)
{
x = value;
y = value;
z = value;
w = value;
}
public Vec4iImmutable(int x, int y, int z, int w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public int getX()
{
return x;
}
@Override
public int getY()
{
return y;
}
@Override
public int getZ()
{
return z;
}
@Override
public int getW()
{
return w;
}
@Override
public Vec4i setX(int x)
{
return this.x == x ? this : Vec4i.newVec(x, y, z, w);
}
@Override
public Vec4i setY(int y)
{
return this.y == y ? this : Vec4i.newVec(x, y, z, w);
}
@Override
public Vec4i setZ(int z)
{
return this.z == z ? this : Vec4i.newVec(x, y, z, w);
}
@Override
public Vec4i setW(int w)
{
return this.w == w ? this : Vec4i.newVec(x, y, z, w);
}
@Override
public Vec4i copy()
{
return Vec4i.newVec(this);
}
@Override
public Vec4i set(int x, int y, int z, int w)
{
return this.x == x && this.y == y && this.z == z && this.w == w ? this : Vec4i.newVec(x, y, z, w);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z, w);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec4i)
{
Vec4i vec = (Vec4i)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
}
return false;
}
@Override
public String toString()
{
return "Vec4i[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
}

View File

@ -0,0 +1,128 @@
package speiger.src.coreengine.math.vector.ints;
import java.util.Objects;
public class Vec4iMutable implements Vec4i
{
int x;
int y;
int z;
int w;
public Vec4iMutable()
{
}
public Vec4iMutable(int value)
{
x = value;
y = value;
z = value;
w = value;
}
public Vec4iMutable(int x, int y, int z, int w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
@Override
public boolean isMutable()
{
return true;
}
@Override
public int getX()
{
return x;
}
@Override
public int getY()
{
return y;
}
@Override
public int getZ()
{
return z;
}
@Override
public int getW()
{
return w;
}
@Override
public Vec4i setX(int x)
{
this.x = x;
return this;
}
@Override
public Vec4i setY(int y)
{
this.y = y;
return this;
}
@Override
public Vec4i setZ(int z)
{
this.z = z;
return this;
}
@Override
public Vec4i setW(int w)
{
this.w = w;
return this;
}
@Override
public Vec4i copy()
{
return Vec4i.newMutable(this);
}
@Override
public Vec4i set(int x, int y, int z, int w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
return this;
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z, w);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec4i)
{
Vec4i vec = (Vec4i)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
}
return false;
}
@Override
public String toString()
{
return "Vec4i[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
}

View File

@ -0,0 +1,34 @@
package speiger.src.coreengine.math.vector.ints;
import java.nio.IntBuffer;
import speiger.src.coreengine.math.vector.Vec;
import speiger.src.coreengine.math.vector.bytes.Vecb;
import speiger.src.coreengine.math.vector.doubles.Vecd;
import speiger.src.coreengine.math.vector.floats.Vecf;
import speiger.src.coreengine.math.vector.longs.Vecl;
import speiger.src.coreengine.math.vector.shorts.Vecs;
public interface Veci extends Vec
{
public Veci set(int value);
public Veci add(int value);
public Veci sub(int value);
public Veci multiply(int value);
public Veci devide(int value);
public Veci clamp(int min, int max);
public Veci clamp(int min, int max, int filter);
public long lengthSquared();
public default double length(){return Math.sqrt(lengthSquared());}
public Veci store(IntBuffer buffer);
public Veci load(IntBuffer buffer);
public int[] asArray();
public Vecb asByte();
public Vecs asShort();
public Vecl asLong();
public Vecf asFloat();
public Vecd asDouble();
}

View File

@ -0,0 +1,163 @@
package speiger.src.coreengine.math.vector.longs;
import java.nio.ByteBuffer;
import java.nio.LongBuffer;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.bytes.Vec2b;
import speiger.src.coreengine.math.vector.doubles.Vec2d;
import speiger.src.coreengine.math.vector.floats.Vec2f;
import speiger.src.coreengine.math.vector.ints.Vec2i;
import speiger.src.coreengine.math.vector.shorts.Vec2s;
public interface Vec2l extends Vecl
{
public static final Vec2l ZERO = newVec();
public static final Vec2l MINUS_ONE = newVec(-1L);
public static final Vec2l ONE = newVec(1L);
public static Vec2l newMutable(){return new Vec2lMutable();}
public static Vec2l newMutable(long value){return new Vec2lMutable(value);}
public static Vec2l newMutable(long x, long y){return new Vec2lMutable(x, y);}
public static Vec2l newMutable(Vec2l value){return newMutable(value.getX(), value.getY());}
public static Vec2l newVec(){return new Vec2lImmutable();}
public static Vec2l newVec(long value){return new Vec2lImmutable(value);}
public static Vec2l newVec(long x, long y){return new Vec2lImmutable(x, y);}
public static Vec2l newVec(Vec2l value){return newVec(value.getX(), value.getY());}
public long getX();
public long getY();
public Vec2l setX(long x);
public Vec2l setY(long y);
@Override
public default long[] asArray(){return new long[]{getX(), getY()};}
@Override
public Vec2l copy();
@Override
public default Vec2l abs(){return set(Math.abs(getX()), Math.abs(getY()));}
@Override
public default Vec2l negate(){return set(0L, 0L);}
@Override
public default Vec2l invert(){return set(-getX(), -getY());};
@Override
public default Vec2l add(long value) {return add(value, value);}
public default Vec2l add(Vec2l value) {return add(value.getX(), value.getY());}
public default Vec2l add(long x, long y) {return set(x + getX(), y + getY());}
@Override
public default Vec2l sub(long value){return sub(value, value);}
public default Vec2l sub(Vec2l value){return sub(value.getX(), value.getY());}
public default Vec2l sub(long x, long y) {return set(getX() - x, getY() - y);}
@Override
public default Vec2l multiply(long value){return multiply(value, value);}
public default Vec2l multiply(Vec2l value){return multiply(value.getX(), value.getY());}
public default Vec2l multiply(long x, long y) {return set(x * getX(), y * getY());}
@Override
public default Vec2l devide(long value){return devide(value, value);}
public default Vec2l devide(Vec2l value){return devide(value.getX(), value.getY());}
public default Vec2l devide(long x, long y){return set(getX() / x, getY() / y);}
@Override
public default Vec2l set(long value){return set(value, value);};
public default Vec2l set(Vec2l value){return set(value.getX(), value.getY());}
public Vec2l set(long x, long y);
public default double distanceTo(Vec2l value){return distanceTo(value.getX(), value.getY());}
public default double distanceTo(long x, long y){return Math.sqrt(distanceToSquared(x, y));}
public default long distanceToSquared(Vec2l value){return distanceToSquared(value.getX(), value.getY());}
public default long distanceToSquared(long x, long y)
{
long xPos = getX() - x;
long yPos = getY() - y;
return (xPos * xPos) + (yPos * yPos);
}
@Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY());}
public default long dotProduct(Vec2l value){return dotProduct(value.getX(), value.getY());}
public default long dotProduct(long x, long y){return (getX() * x) + (getY() * y);}
public default Vec2l rotate(long angle, Vec2l center){return rotate(angle, center.getX(), center.getY());}
public default Vec2l rotate(long angle, long x, long y)
{
long xPos = getX() - x;
long yPos = getY() - y;
double cos = MathUtils.cos(angle);
double sin = MathUtils.sin(angle);
return set((long)((xPos * cos) + (yPos * sin) + x), (long)(-(xPos * sin) + (yPos * cos) + y));
}
public default Vec2l min(Vec2l other) {return min(other, this);}
public default Vec2l min(Vec2l other, Vec2l result){return min(other.getX(), other.getY(), result);}
public default Vec2l min(long x, long y) {return min(x, y, this);}
public default Vec2l min(long x, long y, Vec2l result){return result.set(Math.min(getX(), x), Math.min(getY(), y));}
public default Vec2l max(Vec2l other) {return max(other, this);}
public default Vec2l max(Vec2l other, Vec2l result){return max(other.getX(), other.getY(), result);}
public default Vec2l max(long x, long y) {return max(x, y, this);}
public default Vec2l max(long x, long y, Vec2l result){return result.set(Math.max(getX(), x), Math.max(getY(), y));}
public default Vec2l difference(Vec2l other) {return difference(other, this);}
public default Vec2l difference(Vec2l other, Vec2l result){return difference(other.getX(), other.getY(), result);}
public default Vec2l difference(long x, long y) {return difference(x, y, this);}
public default Vec2l difference(long x, long y, Vec2l result){return result.set(getX() - x, getY() - y);}
@Override
public default Vec2l clamp(long min, long max){return clamp(min, max, ALL);}
public default Vec2l clamp(long min, long max, Vec2l result){return clamp(min, max, result, ALL);}
@Override
public default Vec2l clamp(long min, long max, int filter){return clamp(min, max, this, filter);}
public default Vec2l clamp(long min, long max, Vec2l result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()));}
@Override
public default Vec2l store(ByteBuffer buffer)
{
buffer.putLong(getX()).putLong(getY());
return this;
}
@Override
public default Vec2l load(ByteBuffer buffer)
{
return set(buffer.getLong(), buffer.getLong());
}
@Override
public default Vec2l store(LongBuffer buffer)
{
buffer.put(getX()).put(getY());
return this;
}
@Override
public default Vec2l load(LongBuffer buffer)
{
return set(buffer.get(), buffer.get());
}
@Override
public default Vec2b asByte(){return isMutable() ? Vec2b.newMutable((byte)getX(), (byte)getY()) : Vec2b.newVec((byte)getX(), (byte)getY());}
@Override
public default Vec2s asShort(){return isMutable() ? Vec2s.newMutable((short)getX(), (short)getY()) : Vec2s.newVec((short)getX(), (short)getY());}
@Override
public default Vec2i asInt(){return isMutable() ? Vec2i.newMutable((int)getX(), (int)getY()) : Vec2i.newVec((int)getX(), (int)getY());}
@Override
public default Vec2f asFloat() {return isMutable() ? Vec2f.newMutable(getX(), getY()) : Vec2f.newVec(getX(), getY());}
@Override
public default Vec2d asDouble(){return isMutable() ? Vec2d.newMutable(getX(), getY()) : Vec2d.newVec(getX(), getY());}
@Override
public default Vec2l asMutable(){return isMutable() ? this : newMutable(this);}
@Override
public default Vec2l asImmutable(){return isMutable() ? newVec(this) : this;}
@Override
public default Vec2l copyAsMutable(){return newMutable(this);}
@Override
public default Vec2l copyAsImmutable(){return newVec(this);}
}

View File

@ -0,0 +1,92 @@
package speiger.src.coreengine.math.vector.longs;
import java.util.Objects;
public class Vec2lImmutable implements Vec2l
{
final long x;
final long y;
public Vec2lImmutable()
{
x = 0;
y = 0;
}
public Vec2lImmutable(long value)
{
x = value;
y = value;
}
public Vec2lImmutable(long x, long y)
{
this.x = x;
this.y = y;
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public long getX()
{
return x;
}
@Override
public long getY()
{
return y;
}
@Override
public Vec2l setX(long x)
{
return this.x == x ? this : Vec2l.newVec(x, y);
}
@Override
public Vec2l setY(long y)
{
return this.y == y ? this : Vec2l.newVec(x, y);
}
@Override
public Vec2l copy()
{
return Vec2l.newVec(this);
}
@Override
public Vec2l set(long x, long y)
{
return this.x == x && this.y == y ? this : Vec2l.newVec(x, y);
}
@Override
public int hashCode()
{
return Objects.hash(x, y);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec2l)
{
Vec2l vec = (Vec2l)obj;
return vec.getX() == x && vec.getY() == y;
}
return false;
}
@Override
public String toString()
{
return "Vec2l[x="+x+", y="+y+"]";
}
}

View File

@ -0,0 +1,94 @@
package speiger.src.coreengine.math.vector.longs;
import java.util.Objects;
public class Vec2lMutable implements Vec2l
{
long x;
long y;
public Vec2lMutable()
{
}
public Vec2lMutable(long value)
{
x = value;
y = value;
}
public Vec2lMutable(long x, long y)
{
this.x = x;
this.y = y;
}
@Override
public boolean isMutable()
{
return true;
}
@Override
public long getX()
{
return x;
}
@Override
public long getY()
{
return y;
}
@Override
public Vec2l setX(long x)
{
this.x = x;
return this;
}
@Override
public Vec2l setY(long y)
{
this.y = y;
return this;
}
@Override
public Vec2l copy()
{
return Vec2l.newMutable(this);
}
@Override
public Vec2l set(long x, long y)
{
this.x = x;
this.y = y;
return this;
}
@Override
public int hashCode()
{
return Objects.hash(x, y);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec2l)
{
Vec2l vec = (Vec2l)obj;
return vec.getX() == x && vec.getY() == y;
}
return false;
}
@Override
public String toString()
{
return "Vec2l[x="+x+", y="+y+"]";
}
}

View File

@ -0,0 +1,156 @@
package speiger.src.coreengine.math.vector.longs;
import java.nio.ByteBuffer;
import java.nio.LongBuffer;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.bytes.Vec3b;
import speiger.src.coreengine.math.vector.doubles.Vec3d;
import speiger.src.coreengine.math.vector.floats.Vec3f;
import speiger.src.coreengine.math.vector.ints.Vec3i;
import speiger.src.coreengine.math.vector.shorts.Vec3s;
public interface Vec3l extends Vecl
{
public static final Vec3l ZERO = newVec();
public static final Vec3l MINUS_ONE = newVec(-1L);
public static final Vec3l ONE = newVec(1L);
public static Vec3l newMutable(){return new Vec3lMutable();}
public static Vec3l newMutable(long value){return new Vec3lMutable(value);}
public static Vec3l newMutable(long x, long y, long z){return new Vec3lMutable(x, y, z);}
public static Vec3l newMutable(Vec3l vec){return newMutable(vec.getX(), vec.getY(), vec.getZ());}
public static Vec3l newVec(){return new Vec3lImmutable();}
public static Vec3l newVec(long value){return new Vec3lImmutable(value);}
public static Vec3l newVec(long x, long y, long z){return new Vec3lImmutable(x, y, z);}
public static Vec3l newVec(Vec3l vec){return newVec(vec.getX(), vec.getY(), vec.getZ());}
public long getX();
public long getY();
public long getZ();
public Vec3l setX(long x);
public Vec3l setY(long y);
public Vec3l setZ(long z);
@Override
public default long[] asArray(){return new long[]{getX(), getY(), getZ()};}
@Override
public Vec3l copy();
@Override
public default Vec3l abs(){return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()));}
@Override
public default Vec3l negate(){return set(0L, 0L, 0L);}
@Override
public default Vec3l invert(){return set(-getX(), -getY(), -getZ());}
@Override
public default Vec3l add(long value){return add(value, value, value);}
public default Vec3l add(Vec3l value){return add(value.getX(), value.getY(), value.getZ());}
public default Vec3l add(long x, long y, long z){return set(getX() + x, getY() + y, getZ() + z);}
@Override
public default Vec3l sub(long value){return sub(value, value, value);}
public default Vec3l sub(Vec3l value){return sub(value.getX(), value.getY(), value.getZ());}
public default Vec3l sub(long x, long y, long z){return set(getX() - x, getY() - y, getZ() - z);}
@Override
public default Vec3l multiply(long value){return multiply(value, value, value);}
public default Vec3l multiply(Vec3l value){return multiply(value.getX(), value.getY(), value.getZ());}
public default Vec3l multiply(long x, long y, long z){return set(getX() * x, getY() * y, getZ() * z);}
@Override
public default Vec3l devide(long value){return devide(value, value, value);}
public default Vec3l devide(Vec3l value){return devide(value.getX(), value.getY(), value.getZ());}
public default Vec3l devide(long x, long y, long z){return set(getX() / x, getY() / y, getZ() / z);}
@Override
public default Vec3l set(long value){return set(value, value, value);}
public default Vec3l set(Vec3l value){return set(value.getX(), value.getY(), value.getZ());}
public Vec3l set(long x, long y, long z);
public default double distanceTo(Vec3l value){return distanceTo(value.getX(), value.getY(), value.getZ());}
public default double distanceTo(long x, long y, long z){return Math.sqrt(distanceToSquared(x, y, z));}
public default long distanceToSquared(Vec3l value){return distanceToSquared(value.getX(), value.getY(), value.getZ());}
public default long distanceToSquared(long x, long y, long z)
{
long xPos = getX() - x;
long yPos = getY() - y;
long zPos = getZ() - z;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
}
@Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ());}
public default long dotProduct(Vec3l value){return dotProduct(value.getX(), value.getY(), value.getZ());}
public default long dotProduct(long x, long y, long z){return (getX() * x) + (getY() * y) + (getZ() * z);}
public default Vec3l min(Vec3l other) {return min(other, this);}
public default Vec3l min(Vec3l other, Vec3l result){return min(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3l min(long x, long y, long z) {return min(x, y, z, this);}
public default Vec3l min(long x, long y, long z, Vec3l result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z));}
public default Vec3l max(Vec3l other) {return max(other, this);}
public default Vec3l max(Vec3l other, Vec3l result){return max(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3l max(long x, long y, long z) {return max(x, y, z, this);}
public default Vec3l max(long x, long y, long z, Vec3l result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z));}
public default Vec3l difference(Vec3l other) {return difference(other, this);}
public default Vec3l difference(Vec3l other, Vec3l result){return difference(other.getX(), other.getY(), other.getZ(), result);}
public default Vec3l difference(long x, long y, long z) {return difference(x, y, z, this);}
public default Vec3l difference(long x, long y, long z, Vec3l result){return result.set(getX() - x, getY() - y, getZ() - z);}
@Override
public default Vec3l clamp(long min, long max){return clamp(min, max, ALL);}
public default Vec3l clamp(long min, long max, Vec3l result){return clamp(min, max, result, ALL);}
@Override
public default Vec3l clamp(long min, long max, int filter){return clamp(min, max, this, filter);}
public default Vec3l clamp(long min, long max, Vec3l result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()));}
@Override
public default Vec3l store(ByteBuffer buffer)
{
buffer.putLong(getX()).putLong(getY()).putLong(getZ());
return this;
}
@Override
public default Vec3l load(ByteBuffer buffer)
{
return set(buffer.getLong(), buffer.getLong(), buffer.getLong());
}
@Override
public default Vec3l store(LongBuffer buffer)
{
buffer.put(getX()).put(getY()).put(getZ());
return this;
}
@Override
public default Vec3l load(LongBuffer buffer)
{
return set(buffer.get(), buffer.get(), buffer.get());
}
@Override
public default Vec3b asByte(){return isMutable() ? Vec3b.newMutable((byte)getX(), (byte)getY(), (byte)getZ()) : Vec3b.newVec((byte)getX(), (byte)getY(), (byte)getZ());}
@Override
public default Vec3s asShort(){return isMutable() ? Vec3s.newMutable((short)getX(), (short)getY(), (short)getZ()) : Vec3s.newVec((short)getX(), (short)getY(), (short)getZ());}
@Override
public default Vec3i asInt(){return isMutable() ? Vec3i.newMutable((int)getX(), (int)getY(), (int)getZ()) : Vec3i.newVec((int)getX(), (int)getY(), (int)getZ());}
@Override
public default Vec3f asFloat() {return isMutable() ? Vec3f.newMutable(getX(), getY(), getZ()) : Vec3f.newVec(getX(), getY(), getZ());}
@Override
public default Vec3d asDouble(){return isMutable() ? Vec3d.newMutable(getX(), getY(), getZ()) : Vec3d.newVec(getX(), getY(), getZ());}
@Override
public default Vec3l asMutable(){return isMutable() ? this : newMutable(this);}
@Override
public default Vec3l asImmutable(){return isMutable() ? newVec(this) : this;}
@Override
public default Vec3l copyAsMutable(){return newMutable(this);}
@Override
public default Vec3l copyAsImmutable(){return newVec(this);}
}

View File

@ -0,0 +1,108 @@
package speiger.src.coreengine.math.vector.longs;
import java.util.Objects;
public class Vec3lImmutable implements Vec3l
{
final long x;
final long y;
final long z;
public Vec3lImmutable()
{
x = 0;
y = 0;
z = 0;
}
public Vec3lImmutable(long value)
{
x = value;
y = value;
z = value;
}
public Vec3lImmutable(long x, long y, long z)
{
this.x = x;
this.y = y;
this.z = z;
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public long getX()
{
return x;
}
@Override
public long getY()
{
return y;
}
@Override
public long getZ()
{
return z;
}
@Override
public Vec3l setX(long x)
{
return this.x == x ? this : Vec3l.newVec(x, y, z);
}
@Override
public Vec3l setY(long y)
{
return this.y == y ? this : Vec3l.newVec(x, y, z);
}
@Override
public Vec3l setZ(long z)
{
return this.z == z ? this : Vec3l.newVec(x, y, z);
}
@Override
public Vec3l copy()
{
return Vec3l.newVec(this);
}
@Override
public Vec3l set(long x, long y, long z)
{
return this.x == x && this.y == y && this.z == z ? this : Vec3l.newVec(x, y, z);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec3l)
{
Vec3l vec = (Vec3l)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
}
return false;
}
@Override
public String toString()
{
return "Vec3l[x="+x+", y="+y+", z="+z+"]";
}
}

View File

@ -0,0 +1,111 @@
package speiger.src.coreengine.math.vector.longs;
import java.util.Objects;
public class Vec3lMutable implements Vec3l
{
long x;
long y;
long z;
public Vec3lMutable()
{
}
public Vec3lMutable(long value)
{
x = value;
y = value;
z = value;
}
public Vec3lMutable(long x, long y, long z)
{
this.x = x;
this.y = y;
this.z = z;
}
@Override
public boolean isMutable()
{
return true;
}
@Override
public long getX()
{
return x;
}
@Override
public long getY()
{
return y;
}
@Override
public long getZ()
{
return z;
}
@Override
public Vec3l setX(long x)
{
this.x = x;
return this;
}
@Override
public Vec3l setY(long y)
{
this.y = y;
return this;
}
@Override
public Vec3l setZ(long z)
{
this.z = z;
return this;
}
@Override
public Vec3l copy()
{
return Vec3l.newMutable(this);
}
@Override
public Vec3l set(long x, long y, long z)
{
this.x = x;
this.y = y;
this.z = z;
return this;
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec3l)
{
Vec3l vec = (Vec3l)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
}
return false;
}
@Override
public String toString()
{
return "Vec3l[x="+x+", y="+y+", z="+z+"]";
}
}

View File

@ -0,0 +1,158 @@
package speiger.src.coreengine.math.vector.longs;
import java.nio.ByteBuffer;
import java.nio.LongBuffer;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.bytes.Vec4b;
import speiger.src.coreengine.math.vector.doubles.Vec4d;
import speiger.src.coreengine.math.vector.floats.Vec4f;
import speiger.src.coreengine.math.vector.ints.Vec4i;
import speiger.src.coreengine.math.vector.shorts.Vec4s;
public interface Vec4l extends Vecl
{
public static final Vec4l ZERO = newVec();
public static final Vec4l MINUS_ONE = newVec(-1L);
public static final Vec4l ONE = newVec(1L);
public static Vec4l newMutable(){return new Vec4lMutable();}
public static Vec4l newMutable(long value){return new Vec4lMutable(value);}
public static Vec4l newMutable(long x, long y, long z, long w){return new Vec4lMutable(x, y, z, w);}
public static Vec4l newMutable(Vec4l vec){return newMutable(vec.getX(), vec.getY(), vec.getZ(), vec.getW());}
public static Vec4l newVec(){return new Vec4lImmutable();}
public static Vec4l newVec(long value){return new Vec4lImmutable(value);}
public static Vec4l newVec(long x, long y, long z, long w){return new Vec4lImmutable(x, y, z, w);}
public static Vec4l newVec(Vec4l vec){return newVec(vec.getX(), vec.getY(), vec.getZ(), vec.getW());}
public long getX();
public long getY();
public long getZ();
public long getW();
public Vec4l setX(long x);
public Vec4l setY(long y);
public Vec4l setZ(long z);
public Vec4l setW(long w);
@Override
public default long[] asArray(){return new long[]{getX(), getY(), getZ(), getW()};}
@Override
public Vec4l copy();
@Override
public default Vec4l abs(){return set(Math.abs(getX()), Math.abs(getY()), Math.abs(getZ()), Math.abs(getW()));}
@Override
public default Vec4l negate(){return set(0L, 0L, 0L, 0L);}
@Override
public default Vec4l invert(){return set(-getX(), -getY(), -getZ(), -getW());}
@Override
public default Vec4l add(long value){return add(value, value, value, value);}
public default Vec4l add(Vec4l value){return add(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4l add(long x, long y, long z, long w){return set(getX() + x, getY() + y, getZ() + z, getW() + w);}
@Override
public default Vec4l sub(long value){return sub(value, value, value, value);}
public default Vec4l sub(Vec4l value){return sub(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4l sub(long x, long y, long z, long w){return set(getX() - x, getY() - y, getZ() - z, getW() - w);}
@Override
public default Vec4l multiply(long value){return multiply(value, value, value, value);}
public default Vec4l multiply(Vec4l value){return multiply(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4l multiply(long x, long y, long z, long w){return set(getX() * x, getY() * y, getZ() * z, getW() * w);}
@Override
public default Vec4l devide(long value){return devide(value, value, value, value);}
public default Vec4l devide(Vec4l value){return devide(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Vec4l devide(long x, long y, long z, long w){return set(getX() / x, getY() / y, getZ() / z, getW() / w);}
@Override
public default Vec4l set(long value){return set(value, value, value, value);}
public default Vec4l set(Vec4l value){return set(value.getX(), value.getY(), value.getZ(), value.getW());}
public Vec4l set(long x, long y, long z, long w);
public default double distanceTo(Vec4l value){return distanceTo(value.getX(), value.getY(), value.getZ(), value.getW());}
public default double distanceTo(long x, long y, long z, long w){return Math.sqrt(distanceTo(x, y, z, w));}
public default long distanceToSquared(Vec4l value){return distanceToSquared(value.getX(), value.getY(), value.getZ(), value.getW());}
public default long distanceToSquared(long x, long y, long z, long w)
{
long xPos = getX() - x;
long yPos = getY() - y;
long zPos = getZ() - z;
long wPos = getW() - w;
return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
}
@Override
public default long lengthSquared() {return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW());}
public default long dotProduct(Vec4l value){return dotProduct(value.getX(), value.getY(), value.getZ(), value.getW());}
public default long dotProduct(long x, long y, long z, long w){return (getX() * x) + (getY() * y) + (getZ() * z) + (getW() * w);};
public default Vec4l min(Vec4l other) {return min(other, this);}
public default Vec4l min(Vec4l other, Vec4l result){return min(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4l min(long x, long y, long z, long w) {return min(x, y, z, w, this);}
public default Vec4l min(long x, long y, long z, long w, Vec4l result){return result.set(Math.min(getX(), x), Math.min(getY(), y), Math.min(getZ(), z), Math.min(getW(), w));}
public default Vec4l max(Vec4l other) {return max(other, this);}
public default Vec4l max(Vec4l other, Vec4l result){return max(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4l max(long x, long y, long z, long w) {return max(x, y, z, w, this);}
public default Vec4l max(long x, long y, long z, long w, Vec4l result){return result.set(Math.max(getX(), x), Math.max(getY(), y), Math.max(getZ(), z), Math.max(getZ(), z));}
public default Vec4l difference(Vec4l other) {return difference(other, this);}
public default Vec4l difference(Vec4l other, Vec4l result){return difference(other.getX(), other.getY(), other.getZ(), other.getW(), result);}
public default Vec4l difference(long x, long y, long z, long w) {return difference(x, y, z, w, this);}
public default Vec4l difference(long x, long y, long z, long w, Vec4l result){return result.set(getX() - x, getY() - y, getZ() - z, getW() - w);}
@Override
public default Vec4l clamp(long min, long max){return clamp(min, max, ALL);}
public default Vec4l clamp(long min, long max, Vec4l result){return clamp(min, max, result, ALL);}
@Override
public default Vec4l clamp(long min, long max, int filter){return clamp(min, max, this, filter);}
public default Vec4l clamp(long min, long max, Vec4l result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()), (filter & Z) == 0 ? getZ() : MathUtils.clamp(min, max, getZ()), (filter & W) == 0 ? getW() : MathUtils.clamp(min, max, getW()));}
@Override
public default Vec4l store(ByteBuffer buffer)
{
buffer.putLong(getX()).putLong(getY()).putLong(getZ()).putLong(getW());
return this;
}
@Override
public default Vec4l load(ByteBuffer buffer)
{
return set(buffer.getLong(), buffer.getLong(), buffer.getLong(), buffer.getLong());
}
@Override
public default Vec4l store(LongBuffer buffer)
{
buffer.put(getX()).put(getY()).put(getZ()).put(getW());
return this;
}
@Override
public default Vec4l load(LongBuffer buffer)
{
return set(buffer.get(), buffer.get(), buffer.get(), buffer.get());
}
@Override
public default Vec4b asByte(){return isMutable() ? Vec4b.newMutable((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW()) : Vec4b.newVec((byte)getX(), (byte)getY(), (byte)getZ(), (byte)getW());}
@Override
public default Vec4s asShort(){return isMutable() ? Vec4s.newMutable((short)getX(), (short)getY(), (short)getZ(), (short)getW()) : Vec4s.newVec((short)getX(), (short)getY(), (short)getZ(), (short)getW());}
@Override
public default Vec4i asInt(){return isMutable() ? Vec4i.newMutable((int)getX(), (int)getY(), (int)getZ(), (int)getW()) : Vec4i.newVec((int)getX(), (int)getY(), (int)getZ(), (int)getW());}
@Override
public default Vec4f asFloat() {return isMutable() ? Vec4f.newMutable(getX(), getY(), getZ(), getW()) : Vec4f.newVec(getX(), getY(), getZ(), getW());}
@Override
public default Vec4d asDouble(){return isMutable() ? Vec4d.newMutable(getX(), getY(), getZ(), getW()) : Vec4d.newVec(getX(), getY(), getZ(), getW());}
@Override
public default Vec4l asMutable(){return isMutable() ? this : newMutable(this);}
@Override
public default Vec4l asImmutable(){return isMutable() ? newVec(this) : this;}
@Override
public default Vec4l copyAsMutable(){return newMutable(this);}
@Override
public default Vec4l copyAsImmutable(){return newVec(this);}
}

View File

@ -0,0 +1,124 @@
package speiger.src.coreengine.math.vector.longs;
import java.util.Objects;
public class Vec4lImmutable implements Vec4l
{
final long x;
final long y;
final long z;
final long w;
public Vec4lImmutable()
{
x = 0;
y = 0;
z = 0;
w = 0;
}
public Vec4lImmutable(long value)
{
x = value;
y = value;
z = value;
w = value;
}
public Vec4lImmutable(long x, long y, long z, long w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public long getX()
{
return x;
}
@Override
public long getY()
{
return y;
}
@Override
public long getZ()
{
return z;
}
@Override
public long getW()
{
return w;
}
@Override
public Vec4l setX(long x)
{
return this.x == x ? this : Vec4l.newVec(x, y, z, w);
}
@Override
public Vec4l setY(long y)
{
return this.y == y ? this : Vec4l.newVec(x, y, z, w);
}
@Override
public Vec4l setZ(long z)
{
return this.z == z ? this : Vec4l.newVec(x, y, z, w);
}
@Override
public Vec4l setW(long w)
{
return this.w == w ? this : Vec4l.newVec(x, y, z, w);
}
@Override
public Vec4l copy()
{
return Vec4l.newVec(this);
}
@Override
public Vec4l set(long x, long y, long z, long w)
{
return this.x == x && this.y == y && this.z == z && this.w == w ? this : Vec4l.newVec(x, y, z, w);
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z, w);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec4l)
{
Vec4l vec = (Vec4l)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
}
return false;
}
@Override
public String toString()
{
return "Vec4l[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
}

View File

@ -0,0 +1,128 @@
package speiger.src.coreengine.math.vector.longs;
import java.util.Objects;
public class Vec4lMutable implements Vec4l
{
long x;
long y;
long z;
long w;
public Vec4lMutable()
{
}
public Vec4lMutable(long value)
{
x = value;
y = value;
z = value;
w = value;
}
public Vec4lMutable(long x, long y, long z, long w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
@Override
public boolean isMutable()
{
return true;
}
@Override
public long getX()
{
return x;
}
@Override
public long getY()
{
return y;
}
@Override
public long getZ()
{
return z;
}
@Override
public long getW()
{
return w;
}
@Override
public Vec4l setX(long x)
{
this.x = x;
return this;
}
@Override
public Vec4l setY(long y)
{
this.y = y;
return this;
}
@Override
public Vec4l setZ(long z)
{
this.z = z;
return this;
}
@Override
public Vec4l setW(long w)
{
this.w = w;
return this;
}
@Override
public Vec4l copy()
{
return Vec4l.newMutable(this);
}
@Override
public Vec4l set(long x, long y, long z, long w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
return this;
}
@Override
public int hashCode()
{
return Objects.hash(x, y, z, w);
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Vec4l)
{
Vec4l vec = (Vec4l)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z && vec.getW() == w;
}
return false;
}
@Override
public String toString()
{
return "Vec4l[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
}

View File

@ -0,0 +1,34 @@
package speiger.src.coreengine.math.vector.longs;
import java.nio.LongBuffer;
import speiger.src.coreengine.math.vector.Vec;
import speiger.src.coreengine.math.vector.bytes.Vecb;
import speiger.src.coreengine.math.vector.doubles.Vecd;
import speiger.src.coreengine.math.vector.floats.Vecf;
import speiger.src.coreengine.math.vector.ints.Veci;
import speiger.src.coreengine.math.vector.shorts.Vecs;
public interface Vecl extends Vec
{
public Vecl set(long value);
public Vecl add(long value);
public Vecl sub(long value);
public Vecl multiply(long value);
public Vecl devide(long value);
public Vecl clamp(long min, long max);
public Vecl clamp(long min, long max, int filter);
public long lengthSquared();
public default double length(){return Math.sqrt(lengthSquared());}
public Vecl store(LongBuffer buffer);
public Vecl load(LongBuffer buffer);
public long[] asArray();
public Vecb asByte();
public Vecs asShort();
public Veci asInt();
public Vecf asFloat();
public Vecd asDouble();
}

View File

@ -0,0 +1,898 @@
package speiger.src.coreengine.math.vector.matrix;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.Arrays;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.VectorUtil;
import speiger.src.coreengine.math.vector.floats.Vec2f;
import speiger.src.coreengine.math.vector.floats.Vec3f;
import speiger.src.coreengine.math.vector.floats.Vec4f;
import speiger.src.coreengine.math.vector.quaternion.Quaternion;
public class Matrix4f
{
static final Vec3f X_ROTATION = Vec3f.newVec(1F, 0F, 0F);
static final Vec3f Y_ROTATION = Vec3f.newVec(0F, 1F, 0F);
static final Vec3f Z_ROTATION = Vec3f.newVec(0F, 0F, 1F);
float[] data = new float[16];
public Matrix4f()
{
setIdentity();
}
public Matrix4f(float[] data)
{
System.arraycopy(data, 0, this.data, 0, 16);
}
public Matrix4f(Matrix4f other)
{
this(other.data);
}
public Matrix4f store(FloatBuffer buffer)
{
buffer.put(data);
return this;
}
public Matrix4f store(ByteBuffer buffer)
{
for(int i = 0;i < 16;i++)
{
buffer.putFloat(data[i]);
}
return this;
}
public Matrix4f store(Matrix4f other)
{
System.arraycopy(data, 0, other.data, 0, 16);
return this;
}
public Matrix4f load(FloatBuffer buffer)
{
buffer.get(data);
return this;
}
public Matrix4f load(ByteBuffer buffer)
{
for(int i = 0;i < 16;i++)
{
data[i] = buffer.getFloat();
}
return this;
}
public Matrix4f load(Matrix4f other)
{
System.arraycopy(other.data, 0, data, 0, 16);
return this;
}
@Override
public String toString()
{
StringBuilder buf = new StringBuilder().append("\n");
buf.append("x0=").append(data[0]).append(' ').append("y0=").append(data[4]).append(' ').append("z0=").append(data[8]).append(' ').append("w0=").append(data[12]).append('\n');
buf.append("x1=").append(data[1]).append(' ').append("y1=").append(data[5]).append(' ').append("z1=").append(data[9]).append(' ').append("w1=").append(data[13]).append('\n');
buf.append("x2=").append(data[2]).append(' ').append("y2=").append(data[6]).append(' ').append("z2=").append(data[10]).append(' ').append("w2=").append(data[14]).append('\n');
buf.append("x3=").append(data[3]).append(' ').append("y3=").append(data[7]).append(' ').append("z3=").append(data[11]).append(' ').append("w3=").append(data[15]).append('\n');
return buf.toString();
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Matrix4f)
{
return Arrays.equals(data, ((Matrix4f)obj).data);
}
return false;
}
public float[] getData()
{
return data;
}
public float get(int index)
{
return data[index];
}
public float get(int column, int row)
{
return data[(column * 4) + row];
}
public Matrix4f set(int column, int row, float value)
{
data[(column * 4) + row] = value;
return this;
}
public Matrix4f set(int index, float value)
{
data[index] = value;
return this;
}
public Matrix4f setIdentity()
{
Arrays.fill(data, 0F);
data[0] = 1F;
data[5] = 1F;
data[10] = 1F;
data[15] = 1F;
return this;
}
public Matrix4f invert()
{
float determinant = determinant();
if(determinant != 0F)
{
float determinant_inv = 1F / determinant;
float t00 = determinant3x3(data[5], data[6], data[7], data[9], data[10], data[11], data[13], data[14], data[15]);
float t01 = -determinant3x3(data[4], data[6], data[7], data[8], data[10], data[11], data[12], data[14], data[15]);
float t02 = determinant3x3(data[4], data[5], data[7], data[8], data[9], data[11], data[12], data[13], data[15]);
float t03 = -determinant3x3(data[4], data[5], data[6], data[8], data[9], data[10], data[12], data[13], data[14]);
float t10 = -determinant3x3(data[1], data[2], data[3], data[9], data[10], data[11], data[13], data[14], data[15]);
float t11 = determinant3x3(data[0], data[2], data[3], data[8], data[10], data[11], data[12], data[14], data[15]);
float t12 = -determinant3x3(data[0], data[1], data[3], data[8], data[9], data[11], data[12], data[13], data[15]);
float t13 = determinant3x3(data[0], data[1], data[2], data[8], data[9], data[10], data[12], data[13], data[14]);
float t20 = determinant3x3(data[1], data[2], data[3], data[5], data[6], data[7], data[13], data[14], data[15]);
float t21 = -determinant3x3(data[0], data[2], data[3], data[4], data[6], data[7], data[12], data[14], data[15]);
float t22 = determinant3x3(data[0], data[1], data[3], data[4], data[5], data[7], data[12], data[13], data[15]);
float t23 = -determinant3x3(data[0], data[1], data[2], data[4], data[5], data[6], data[12], data[13], data[14]);
float t30 = -determinant3x3(data[1], data[2], data[3], data[5], data[6], data[7], data[9], data[10], data[11]);
float t31 = determinant3x3(data[0], data[2], data[3], data[4], data[6], data[7], data[8], data[10], data[11]);
float t32 = -determinant3x3(data[0], data[1], data[3], data[4], data[5], data[7], data[8], data[9], data[11]);
float t33 = determinant3x3(data[0], data[1], data[2], data[4], data[5], data[6], data[8], data[9], data[10]);
data[0] = t00 * determinant_inv;
data[5] = t11 * determinant_inv;
data[10] = t22 * determinant_inv;
data[15] = t33 * determinant_inv;
data[1] = t10 * determinant_inv;
data[4] = t01 * determinant_inv;
data[8] = t02 * determinant_inv;
data[2] = t20 * determinant_inv;
data[6] = t21 * determinant_inv;
data[9] = t12 * determinant_inv;
data[3] = t30 * determinant_inv;
data[12] = t03 * determinant_inv;
data[7] = t31 * determinant_inv;
data[13] = t13 * determinant_inv;
data[14] = t23 * determinant_inv;
data[11] = t32 * determinant_inv;
}
return this;
}
public Matrix4f flip()
{
data[0] = -data[0];
data[1] = -data[1];
data[2] = -data[2];
data[3] = -data[3];
data[4] = -data[4];
data[5] = -data[5];
data[6] = -data[6];
data[7] = -data[7];
data[8] = -data[8];
data[9] = -data[9];
data[10] = -data[10];
data[11] = -data[11];
data[12] = -data[12];
data[13] = -data[13];
data[14] = -data[14];
data[15] = -data[15];
return this;
}
public Matrix4f negate()
{
Arrays.fill(data, 0F);
return this;
}
public Matrix4f add(Matrix4f other)
{
data[0] += other.data[0];
data[1] += other.data[1];
data[2] += other.data[2];
data[3] += other.data[3];
data[4] += other.data[4];
data[5] += other.data[5];
data[6] += other.data[6];
data[7] += other.data[7];
data[8] += other.data[8];
data[9] += other.data[9];
data[10] += other.data[10];
data[11] += other.data[11];
data[12] += other.data[12];
data[13] += other.data[13];
data[14] += other.data[14];
data[15] += other.data[15];
return this;
}
public Matrix4f sub(Matrix4f other)
{
data[0] -= other.data[0];
data[1] -= other.data[1];
data[2] -= other.data[2];
data[3] -= other.data[3];
data[4] -= other.data[4];
data[5] -= other.data[5];
data[6] -= other.data[6];
data[7] -= other.data[7];
data[8] -= other.data[8];
data[9] -= other.data[9];
data[10] -= other.data[10];
data[11] -= other.data[11];
data[12] -= other.data[12];
data[13] -= other.data[13];
data[14] -= other.data[14];
data[15] -= other.data[15];
return this;
}
public Matrix4f multiply(Matrix4f other)
{
float data0 = data[0] * other.data[0] + data[4] * other.data[1] + data[8] * other.data[2] + data[12] * other.data[3];
float data1 = data[1] * other.data[0] + data[5] * other.data[1] + data[9] * other.data[2] + data[13] * other.data[3];
float data2 = data[2] * other.data[0] + data[6] * other.data[1] + data[10] * other.data[2] + data[14] * other.data[3];
float data3 = data[3] * other.data[0] + data[7] * other.data[1] + data[11] * other.data[2] + data[15] * other.data[3];
float data4 = data[0] * other.data[4] + data[4] * other.data[5] + data[8] * other.data[6] + data[12] * other.data[7];
float data5 = data[1] * other.data[4] + data[5] * other.data[5] + data[9] * other.data[6] + data[13] * other.data[7];
float data6 = data[2] * other.data[4] + data[6] * other.data[5] + data[10] * other.data[6] + data[14] * other.data[7];
float data7 = data[3] * other.data[4] + data[7] * other.data[5] + data[11] * other.data[6] + data[15] * other.data[7];
float data8 = data[0] * other.data[8] + data[4] * other.data[9] + data[8] * other.data[10] + data[12] * other.data[11];
float data9 = data[1] * other.data[8] + data[5] * other.data[9] + data[9] * other.data[10] + data[13] * other.data[11];
float data10 = data[2] * other.data[8] + data[6] * other.data[9] + data[10] * other.data[10] + data[14] * other.data[11];
float data11 = data[3] * other.data[8] + data[7] * other.data[9] + data[11] * other.data[10] + data[15] * other.data[11];
float data12 = data[0] * other.data[12] + data[4] * other.data[13] + data[8] * other.data[14] + data[12] * other.data[15];
float data13 = data[1] * other.data[12] + data[5] * other.data[13] + data[9] * other.data[14] + data[13] * other.data[15];
float data14 = data[2] * other.data[12] + data[6] * other.data[13] + data[10] * other.data[14] + data[14] * other.data[15];
float data15 = data[3] * other.data[12] + data[7] * other.data[13] + data[11] * other.data[14] + data[15] * other.data[15];
data[0] = data0;
data[1] = data1;
data[2] = data2;
data[3] = data3;
data[4] = data4;
data[5] = data5;
data[6] = data6;
data[7] = data7;
data[8] = data8;
data[9] = data9;
data[10] = data10;
data[11] = data11;
data[12] = data12;
data[13] = data13;
data[14] = data14;
data[15] = data15;
return this;
}
public Matrix4f transpose()
{
float data0 = data[0];
float data1 = data[4];
float data2 = data[8];
float data3 = data[12];
float data4 = data[1];
float data5 = data[5];
float data6 = data[9];
float data7 = data[13];
float data8 = data[2];
float data9 = data[6];
float data10 = data[10];
float data11 = data[14];
float data12 = data[3];
float data13 = data[7];
float data14 = data[11];
float data15 = data[15];
data[0] = data0;
data[1] = data1;
data[2] = data2;
data[3] = data3;
data[4] = data4;
data[5] = data5;
data[6] = data6;
data[7] = data7;
data[8] = data8;
data[9] = data9;
data[10] = data10;
data[11] = data11;
data[12] = data12;
data[13] = data13;
data[14] = data14;
data[15] = data15;
return this;
}
public Matrix4f transpose3x3()
{
float nm00 = data[0];
float nm01 = data[4];
float nm02 = data[8];
float nm10 = data[1];
float nm11 = data[5];
float nm12 = data[9];
float nm20 = data[2];
float nm21 = data[6];
float nm22 = data[10];
data[0] = nm00;
data[1] = nm01;
data[2] = nm02;
data[4] = nm10;
data[5] = nm11;
data[6] = nm12;
data[8] = nm20;
data[9] = nm21;
data[10] = nm22;
return this;
}
public Matrix4f decompose(Vec3f position, Quaternion rotation, Vec3f scale)
{
position.set(get(3, 0), get(3, 1), get(3, 2));
rotation.set(this);
scale.set(get(0, 0), get(1, 1), get(2, 2));
return this;
}
public Matrix4f setTranslation(Vec3f vec)
{
data[12] = vec.getX();
data[13] = vec.getY();
data[14] = vec.getZ();
return this;
}
public Matrix4f translate(Vec2f vec)
{
return translate(vec.getX(), vec.getY());
}
public Matrix4f translate(float x, float y)
{
data[12] += data[0] * x + data[4] * y;
data[13] += data[1] * x + data[5] * y;
data[14] += data[2] * x + data[6] * y;
data[15] += data[3] * x + data[7] * y;
return this;
}
public Matrix4f translate(Vec3f vec)
{
data[12] += data[0] * vec.getX() + data[4] * vec.getY() + data[8] * vec.getZ();
data[13] += data[1] * vec.getX() + data[5] * vec.getY() + data[9] * vec.getZ();
data[14] += data[2] * vec.getX() + data[6] * vec.getY() + data[10] * vec.getZ();
data[15] += data[3] * vec.getX() + data[7] * vec.getY() + data[11] * vec.getZ();
return this;
}
public Matrix4f translate(float x, float y, float z)
{
data[12] += data[0] * x + data[4] * y + data[8] * z;
data[13] += data[1] * x + data[5] * y + data[9] * z;
data[14] += data[2] * x + data[6] * y + data[10] * z;
data[15] += data[3] * x + data[7] * y + data[11] * z;
return this;
}
public Matrix4f rotateX(float angle)
{
return rotate((float)Math.toRadians(angle), X_ROTATION);
}
public Matrix4f rotateY(float angle)
{
return rotate((float)Math.toRadians(angle), Y_ROTATION);
}
public Matrix4f rotateZ(float angle)
{
return rotate((float)Math.toRadians(angle), Z_ROTATION);
}
public Matrix4f rotateRadX(float angle)
{
return rotate(angle, X_ROTATION);
}
public Matrix4f rotateRadY(float angle)
{
return rotate(angle, Y_ROTATION);
}
public Matrix4f rotateRadZ(float angle)
{
return rotate(angle, Z_ROTATION);
}
public Matrix4f rotate(float angle, Vec3f axis)
{
float c = MathUtils.cos(angle);
float s = MathUtils.sin(angle);
float oneminusc = 1.0f - c;
float xy = axis.getX() * axis.getY();
float yz = axis.getY() * axis.getZ();
float xz = axis.getX() * axis.getZ();
float xs = axis.getX() * s;
float ys = axis.getY() * s;
float zs = axis.getZ() * s;
float f00 = axis.getX() * axis.getX() * oneminusc + c;
float f01 = xy * oneminusc + zs;
float f02 = xz * oneminusc - ys;
float f10 = xy * oneminusc - zs;
float f11 = axis.getY() * axis.getY() * oneminusc + c;
float f12 = yz * oneminusc + xs;
float f20 = xz * oneminusc + ys;
float f21 = yz * oneminusc - xs;
float f22 = axis.getZ() * axis.getZ() * oneminusc + c;
float t00 = data[0] * f00 + data[4] * f01 + data[8] * f02;
float t01 = data[1] * f00 + data[5] * f01 + data[9] * f02;
float t02 = data[2] * f00 + data[6] * f01 + data[10] * f02;
float t03 = data[3] * f00 + data[7] * f01 + data[11] * f02;
float t10 = data[0] * f10 + data[4] * f11 + data[8] * f12;
float t11 = data[1] * f10 + data[5] * f11 + data[9] * f12;
float t12 = data[2] * f10 + data[6] * f11 + data[10] * f12;
float t13 = data[3] * f10 + data[7] * f11 + data[11] * f12;
data[8] = data[0] * f20 + data[4] * f21 + data[8] * f22;
data[9] = data[1] * f20 + data[5] * f21 + data[9] * f22;
data[10] = data[2] * f20 + data[6] * f21 + data[10] * f22;
data[11] = data[3] * f20 + data[7] * f21 + data[11] * f22;
data[0] = t00;
data[1] = t01;
data[2] = t02;
data[3] = t03;
data[4] = t10;
data[5] = t11;
data[6] = t12;
data[7] = t13;
return this;
}
public Matrix4f rotate(Quaternion rotation)
{
float w2 = rotation.getW() * rotation.getW();
float x2 = rotation.getX() * rotation.getX();
float y2 = rotation.getY() * rotation.getY();
float z2 = rotation.getZ() * rotation.getZ();
float zw = rotation.getZ() * rotation.getW();
float dzw = zw + zw;
float xy = rotation.getX() * rotation.getY();
float dxy = xy + xy;
float xz = rotation.getX() * rotation.getZ();
float dxz = xz + xz;
float yw = rotation.getY() * rotation.getW();
float dyw = yw + yw;
float yz = rotation.getY() * rotation.getZ();
float dyz = yz + yz;
float xw = rotation.getX() * rotation.getW();
float dxw = xw + xw;
float rm00 = w2 + x2 - z2 - y2;
float rm01 = dxy + dzw;
float rm02 = dxz - dyw;
float rm10 = -dzw + dxy;
float rm11 = y2 - z2 + w2 - x2;
float rm12 = dyz + dxw;
float rm20 = dyw + dxz;
float rm21 = dyz - dxw;
float rm22 = z2 - y2 - x2 + w2;
float nm00 = data[0] * rm00 + data[4] * rm01 + data[8] * rm02;
float nm01 = data[1] * rm00 + data[5] * rm01 + data[9] * rm02;
float nm02 = data[2] * rm00 + data[6] * rm01 + data[10] * rm02;
float nm03 = data[3] * rm00 + data[7] * rm01 + data[11] * rm02;
float nm10 = data[0] * rm10 + data[4] * rm11 + data[8] * rm12;
float nm11 = data[1] * rm10 + data[5] * rm11 + data[9] * rm12;
float nm12 = data[2] * rm10 + data[6] * rm11 + data[10] * rm12;
float nm13 = data[3] * rm10 + data[7] * rm11 + data[11] * rm12;
data[8] = data[0] * rm20 + data[4] * rm21 + data[8] * rm22;
data[9] = data[1] * rm20 + data[5] * rm21 + data[9] * rm22;
data[10] = data[2] * rm20 + data[6] * rm21 + data[10] * rm22;
data[11] = data[3] * rm20 + data[7] * rm21 + data[11] * rm22;
data[0] = nm00;
data[1] = nm01;
data[2] = nm02;
data[3] = nm03;
data[4] = nm10;
data[5] = nm11;
data[6] = nm12;
data[7] = nm13;
return this;
}
public Matrix4f setRotation(Matrix4f source)
{
data[0] = source.data[0];
data[1] = source.data[1];
data[2] = source.data[2];
data[4] = source.data[4];
data[5] = source.data[5];
data[6] = source.data[6];
data[8] = source.data[8];
data[9] = source.data[9];
data[10] = source.data[10];
return this;
}
public Matrix4f setBillboard(Matrix4f source)
{
data[0] = source.data[0];
data[1] = source.data[4];
data[2] = source.data[8];
data[4] = source.data[1];
data[5] = source.data[5];
data[6] = source.data[9];
data[8] = source.data[2];
data[9] = source.data[6];
data[10] = source.data[10];
return this;
}
public Matrix4f scale(Vec3f vec)
{
return scale(vec.getX(), vec.getY(), vec.getZ());
}
public Matrix4f scale(float value)
{
return scale(value, value, value);
}
public Matrix4f scale(float x, float y, float z)
{
data[0] *= x;
data[1] *= x;
data[2] *= x;
data[3] *= x;
data[4] *= y;
data[5] *= y;
data[6] *= y;
data[7] *= y;
data[8] *= z;
data[9] *= z;
data[10] *= z;
data[11] *= z;
return this;
}
public Matrix4f unscale(Vec3f vec)
{
return unscale(vec.getX(), vec.getY(), vec.getZ());
}
public Matrix4f unscale(float scale)
{
return unscale(scale, scale, scale);
}
public Matrix4f unscale(float x, float y, float z)
{
data[0] /= x;
data[1] /= x;
data[2] /= x;
data[3] /= x;
data[4] /= y;
data[5] /= y;
data[6] /= y;
data[7] /= y;
data[8] /= z;
data[9] /= z;
data[10] /= z;
data[11] /= z;
return this;
}
public Matrix4f setPerspective(float fovy, float aspect, float zNear, float zFar)
{
float h = (float)Math.tan(fovy * 0.5f);
set(0, 0, 1F / (h * aspect)).set(1, 1, 1F / h);
boolean farInf = zFar > 0 && Float.isInfinite(zFar);
boolean nearInf = zNear > 0 && Float.isInfinite(zNear);
if(farInf)
{
float e = 1E-6f;
set(2, 2, e - 1F).set(3, 2, (e - 2F) * zNear);
}
else if(nearInf)
{
float e = 1E-6f;
set(2, 2, 1F - e).set(3, 2, (2F - e) * zFar);
}
else
{
set(2, 2, (zFar + zNear) / (zNear - zFar)).set(3, 2, (zFar + zFar) * zNear / (zNear - zFar));
}
return set(2, 3, -1.0f);
}
public Matrix4f getTranslation(Vec3f vec)
{
vec.set(data[12], data[13], data[14]);
return this;
}
public Matrix4f getScale(Vec3f vec)
{
vec.setX((float)Math.sqrt(data[0] * data[0] + data[1] * data[1] + data[2] * data[2]));
vec.setY((float)Math.sqrt(data[4] * data[4] + data[5] * data[5] + data[6] * data[6]));
vec.setZ((float)Math.sqrt(data[8] * data[8] + data[9] * data[9] + data[10] * data[10]));
return this;
}
public Vec4f transform(Vec4f input)
{
return transform(input, input);
}
public Vec4f transform(Vec4f input, Vec4f output)
{
float x = data[0] * input.getX() + data[4] * input.getY() + data[8] * input.getZ() + data[12] * input.getW();
float y = data[1] * input.getX() + data[5] * input.getY() + data[9] * input.getZ() + data[13] * input.getW();
float z = data[2] * input.getX() + data[6] * input.getY() + data[10] * input.getZ() + data[14] * input.getW();
float w = data[3] * input.getX() + data[7] * input.getY() + data[11] * input.getZ() + data[15] * input.getW();
return output.set(x, y, z, w);
}
public void transform(Vec4f input, FloatBuffer buffer)
{
buffer.put(data[0] * input.getX() + data[4] * input.getY() + data[8] * input.getZ() + data[12] * input.getW());
buffer.put(data[1] * input.getX() + data[5] * input.getY() + data[9] * input.getZ() + data[13] * input.getW());
buffer.put(data[2] * input.getX() + data[6] * input.getY() + data[10] * input.getZ() + data[14] * input.getW());
buffer.put(data[3] * input.getX() + data[7] * input.getY() + data[11] * input.getZ() + data[15] * input.getW());
}
public Vec3f transform(Vec3f input, boolean position)
{
return transform(input, input, position);
}
public Vec3f transform(Vec3f input, Vec3f output, boolean position)
{
float pos = position ? 1F : 0F;
return output.set(data[0] * input.getX() + data[4] * input.getY() + data[8] * input.getZ() + data[12] * pos, data[1] * input.getX() + data[5] * input.getY() + data[9] * input.getZ() + data[13] * pos, data[2] * input.getX() + data[6] * input.getY() + data[10] * input.getZ() + data[14] * pos);
}
public void transform(Vec3f input, FloatBuffer buffer, boolean position)
{
float pos = position ? 1F : 0F;
buffer.put(data[0] * input.getX() + data[4] * input.getY() + data[8] * input.getZ() + data[12] * pos);
buffer.put(data[1] * input.getX() + data[5] * input.getY() + data[9] * input.getZ() + data[13] * pos);
buffer.put(data[2] * input.getX() + data[6] * input.getY() + data[10] * input.getZ() + data[14] * pos);
}
public float determinant()
{
float f = data[0] * ((data[5] * data[10] * data[15] + data[6] * data[11] * data[13] + data[7] * data[9] * data[14]) - data[7] * data[10] * data[13] - data[5] * data[11] * data[14] - data[6] * data[9] * data[15]);
f -= data[1] * ((data[4] * data[10] * data[15] + data[6] * data[11] * data[12] + data[7] * data[8] * data[14]) - data[7] * data[10] * data[12] - data[4] * data[11] * data[14] - data[6] * data[8] * data[15]);
f += data[2] * ((data[4] * data[9] * data[15] + data[5] * data[11] * data[12] + data[7] * data[8] * data[13]) - data[7] * data[9] * data[12] - data[4] * data[11] * data[13] - data[5] * data[8] * data[15]);
f -= data[3] * ((data[4] * data[9] * data[14] + data[5] * data[10] * data[12] + data[6] * data[8] * data[13]) - data[6] * data[9] * data[12] - data[4] * data[10] * data[13] - data[5] * data[8] * data[14]);
return f;
}
public float determinant3x3(float t00, float t01, float t02, float t10, float t11, float t12, float t20, float t21, float t22)
{
return t00 * (t11 * t22 - t12 * t21) + t01 * (t12 * t20 - t10 * t22) + t02 * (t10 * t21 - t11 * t20);
}
public Matrix4f setTransform(Vec3f position, Vec3f rotation, float scale)
{
setIdentity();
translate(position);
rotate((float)Math.toRadians(rotation.getX()), X_ROTATION);
rotate((float)Math.toRadians(rotation.getY()), Y_ROTATION);
rotate((float)Math.toRadians(rotation.getZ()), Z_ROTATION);
scale(scale, scale, scale);
return this;
}
public Matrix4f setTransform(Vec3f position, Vec3f rotation, Vec3f scale)
{
setIdentity();
translate(position);
rotate((float)Math.toRadians(rotation.getX()), X_ROTATION);
rotate((float)Math.toRadians(rotation.getY()), Y_ROTATION);
rotate((float)Math.toRadians(rotation.getZ()), Z_ROTATION);
scale(scale);
return this;
}
public Matrix4f setTransform(Vec3f position, Vec3f offset, Vec3f rotation, float scale)
{
setIdentity();
translate(position);
translate(offset);
rotate((float)Math.toRadians(rotation.getX()), X_ROTATION);
rotate((float)Math.toRadians(rotation.getY()), Y_ROTATION);
rotate((float)Math.toRadians(rotation.getZ()), Z_ROTATION);
scale(scale, scale, scale);
return this;
}
public Matrix4f setTransform(Vec3f position, Vec3f offset, Vec3f rotation, Vec3f scale)
{
setIdentity();
translate(position);
translate(offset);
rotate((float)Math.toRadians(rotation.getX()), X_ROTATION);
rotate((float)Math.toRadians(rotation.getY()), Y_ROTATION);
rotate((float)Math.toRadians(rotation.getZ()), Z_ROTATION);
scale(scale);
return this;
}
public Matrix4f setTransform(Vec3f position, Quaternion rotation, float scale)
{
setIdentity();
translate(position);
rotate(rotation);
scale(scale, scale, scale);
return this;
}
public Matrix4f setTransform(Vec3f position, Quaternion rotation, Vec3f scale)
{
setIdentity();
translate(position);
rotate(rotation);
scale(scale);
return this;
}
public Matrix4f setTransform(Vec3f position, Vec3f offset, Quaternion rotation, float scale)
{
setIdentity();
translate(position);
translate(offset);
rotate(rotation);
scale(scale, scale, scale);
return this;
}
public Matrix4f setTransform(Vec3f position, Vec3f offset, Quaternion rotation, Vec3f scale)
{
setIdentity();
translate(position);
translate(offset);
rotate(rotation);
scale(scale);
return this;
}
public Matrix4f setTransform(Vec3f position, Matrix4f billRotation, float scale)
{
setIdentity();
translate(position);
setBillboard(billRotation);
scale(scale, scale, scale);
return this;
}
public Matrix4f setTransform(Vec3f position, Matrix4f billRotation, Vec3f scale)
{
setIdentity();
translate(position);
setBillboard(billRotation);
transpose3x3();
scale(scale);
return this;
}
public Vec3f project(float x, float y, float z, int[] viewport, Vec3f winCoordsDest)
{
float invW = 1F / VectorUtil.fma(data[3], x, VectorUtil.fma(data[7], y, VectorUtil.fma(data[11], z, data[15])));
float nx = VectorUtil.fma(data[0], x, VectorUtil.fma(data[4], y, VectorUtil.fma(data[8], z, data[12]))) * invW;
float ny = VectorUtil.fma(data[1], x, VectorUtil.fma(data[5], y, VectorUtil.fma(data[9], z, data[13]))) * invW;
float nz = VectorUtil.fma(data[2], x, VectorUtil.fma(data[6], y, VectorUtil.fma(data[10], z, data[14]))) * invW;
return winCoordsDest.set(VectorUtil.fma(VectorUtil.fma(nx, 0.5F, 0.5F), viewport[2], viewport[0]), VectorUtil.fma(VectorUtil.fma(ny, 0.5F, 0.5F), viewport[3], viewport[1]), VectorUtil.fma(0.5F, nz, 0.5F));
}
public Vec3f unproject(float winX, float winY, float winZ, int[] viewport, Vec3f dest) {
float a = data[0] * data[5] - data[1] * data[4];
float b = data[0] * data[6] - data[2] * data[4];
float c = data[0] * data[7] - data[3] * data[4];
float d = data[1] * data[6] - data[2] * data[5];
float e = data[1] * data[7] - data[3] * data[5];
float f = data[2] * data[7] - data[3] * data[6];
float g = data[8] * data[13] - data[9] * data[12];
float h = data[8] * data[14] - data[10] * data[12];
float i = data[8] * data[15] - data[11] * data[12];
float j = data[9] * data[14] - data[10] * data[13];
float k = data[9] * data[15] - data[11] * data[13];
float l = data[10] * data[15] - data[11] * data[14];
float det = a * l - b * k + c * j + d * i - e * h + f * g;
det = 1.0f / det;
float im00 = ( data[5] * l - data[6] * k + data[7] * j) * det;
float im01 = (-data[1] * l + data[2] * k - data[3] * j) * det;
float im02 = ( data[13] * f - data[14] * e + data[15] * d) * det;
float im03 = (-data[9] * f + data[10] * e - data[11] * d) * det;
float im10 = (-data[4] * l + data[6] * i - data[7] * h) * det;
float im11 = ( data[0] * l - data[2] * i + data[3] * h) * det;
float im12 = (-data[12] * f + data[14] * c - data[15] * b) * det;
float im13 = ( data[8] * f - data[10] * c + data[11] * b) * det;
float im20 = ( data[4] * k - data[5] * i + data[7] * g) * det;
float im21 = (-data[0] * k + data[1] * i - data[3] * g) * det;
float im22 = ( data[12] * e - data[13] * c + data[15] * a) * det;
float im23 = (-data[8] * e + data[9] * c - data[11] * a) * det;
float im30 = (-data[4] * j + data[5] * h - data[6] * g) * det;
float im31 = ( data[0] * j - data[1] * h + data[2] * g) * det;
float im32 = (-data[12] * d + data[13] * b - data[14] * a) * det;
float im33 = ( data[8] * d - data[9] * b + data[10] * a) * det;
float ndcX = (winX-viewport[0])/viewport[2]*2.0f-1.0f;
float ndcY = (winY-viewport[1])/viewport[3]*2.0f-1.0f;
float ndcZ = winZ+winZ-1.0f;
float invW = 1.0f / (im03 * ndcX + im13 * ndcY + im23 * ndcZ + im33);
return dest.set((im00 * ndcX + im10 * ndcY + im20 * ndcZ + im30) * invW, (im01 * ndcX + im11 * ndcY + im21 * ndcZ + im31) * invW, (im02 * ndcX + im12 * ndcY + im22 * ndcZ + im32) * invW);
}
public Matrix4f ortho(float x, float y, float width, float height, float zNear, float zFar)
{
return ortho(x, x+width, y+height, y, zNear, zFar, false);
}
public Matrix4f ortho(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne)
{
float rm00 = 2F / (right - left);
float rm11 = 2F / (top - bottom);
float rm22 = (zZeroToOne ? 1F : 2F) / (zFar - zNear);
float rm30 = (left + right) / (left - right);
float rm31 = (top + bottom) / (bottom - top);
float rm32 = (zZeroToOne ? zNear : (zFar + zNear)) / (zNear - zFar);
data[12] = data[0] * rm30 + data[4] * rm31 + data[8] * rm32 + data[12];
data[13] = data[1] * rm30 + data[5] * rm31 + data[9] * rm32 + data[13];
data[14] = data[2] * rm30 + data[6] * rm31 + data[10] * rm32 + data[14];
data[15] = data[3] * rm30 + data[7] * rm31 + data[11] * rm32 + data[15];
data[0] = data[0] * rm00;
data[1] = data[1] * rm00;
data[2] = data[2] * rm00;
data[3] = data[3] * rm00;
data[4] = data[4] * rm11;
data[5] = data[5] * rm11;
data[6] = data[6] * rm11;
data[7] = data[7] * rm11;
data[8] = data[8] * rm22;
data[9] = data[9] * rm22;
data[10] = data[10] * rm22;
data[11] = data[11] * rm22;
return this;
}
public Vec4f storeFrustrumPlane(int plane, Vec4f toStore)
{
switch(plane)
{
case 0:
return toStore.set(data[3] + data[0], data[7] + data[4], data[11] + data[8], data[15] + data[12]).normalize3D();
case 1:
return toStore.set(data[3] - data[0], data[7] - data[4], data[11] - data[8], data[15] - data[12]).normalize3D();
case 2:
return toStore.set(data[3] + data[1], data[7] + data[5], data[11] + data[9], data[15] + data[13]).normalize3D();
case 3:
return toStore.set(data[3] - data[1], data[7] - data[5], data[11] - data[9], data[15] - data[13]).normalize3D();
case 4:
return toStore.set(data[3] + data[2], data[7] + data[6], data[11] + data[10], data[15] + data[14]).normalize3D();
case 5:
return toStore.set(data[3] - data[2], data[7] - data[6], data[11] - data[10], data[15] - data[14]).normalize3D();
}
return toStore;
}
}

View File

@ -0,0 +1,215 @@
package speiger.src.coreengine.math.vector.quaternion;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.floats.Vec4f;
import speiger.src.coreengine.math.vector.matrix.Matrix4f;
public interface Quaternion
{
public static final Quaternion ZERO = newQuat(0F, 0F, 0F, 0F);
public static final Quaternion IDENTITY = newQuat();
public static Quaternion newQuat(){return new QuaternionImmutable();}
public static Quaternion newQuat(Quaternion source){return newQuat(source.getX(), source.getY(), source.getZ(), source.getW());}
public static Quaternion newQuat(float x, float y, float z, float w){return new QuaternionImmutable(x, y, z, w);}
public static Quaternion newAxisRadQuat(float x, float y, float z, float angle){return ZERO.setAxisRad(x, y, z, angle);}
public static Quaternion newAxisDegQuat(float x, float y, float z, float angle){return ZERO.setAxisDeg(x, y, z, angle);}
public static Quaternion newMutable(){return new QuaternionMutable();}
public static Quaternion newMutable(Quaternion source){return newMutable(source.getX(), source.getY(), source.getZ(), source.getW());}
public static Quaternion newMutable(float x, float y, float z, float w){return new QuaternionMutable(x, y, z, w);}
public static Quaternion newMutableRadAxis(float x, float y, float z, float angle){return newMutable().setAxisRad(x, y, z, angle);}
public static Quaternion newMutableDegAxis(float x, float y, float z, float angle){return newMutable().setAxisDeg(x, y, z, angle);}
public static double acos(double v){return v < -1D ? 3.141592653589793D : (v > 1D ? 0D : Math.acos(v));}
public Quaternion setX(float x);
public Quaternion setY(float y);
public Quaternion setZ(float z);
public Quaternion setW(float w);
public float getX();
public float getY();
public float getZ();
public float getW();
public default Quaternion negate(){return set(0F, 0F, 0F, 0F);}
public default Quaternion invert(){return set(-getX(), -getY(), -getZ(), -getW());}
public default Quaternion normalize(){return scale(1.0F / length());}
public default Quaternion conjugate(){return set(-getX(), -getY(), -getZ(), getW());}
public default Quaternion setIdentity(){return set(0F, 0F, 0F, 1F);}
public default Quaternion multiply(Quaternion other){return set(getX() * other.getW() + getW() * other.getX() + getY() * other.getZ() - getZ() * other.getY(), getY() * other.getW() + getW() * other.getY() + getZ() * other.getX() - getX() * other.getZ(), getZ() * other.getW() + getW() * other.getZ() + getX() * other.getY() - getY() * other.getX(), getW() * other.getW() - getX() * other.getX() - getY() * other.getY() - getZ() * other.getZ());}
public default Quaternion scale(float scale){return set(getX() * scale, getY() * scale, getZ() * scale, getW() * scale);}
public default Quaternion rotateX(float angle)
{
angle = (float)Math.toRadians(angle);
float sin = MathUtils.sin(angle * 0.5D);
float cos = MathUtils.cos(angle * 0.5D);
return set(getW() * sin + getX() * cos, getY() * cos + getZ() * sin, getZ() * cos - getY() * sin, getW() * cos - getX() * sin);
}
public default Quaternion rotateY(float angle)
{
angle = (float)Math.toRadians(angle);
float sin = MathUtils.sin(angle * 0.5D);
float cos = MathUtils.cos(angle * 0.5D);
return set(getX() * cos - getZ() * sin, getW() * sin + getY() * cos, getX() * sin + getZ() * cos, getW() * cos - getY() * sin);
}
public default Quaternion rotateZ(float angle)
{
angle = (float)Math.toRadians(angle);
float sin = MathUtils.sin(angle * 0.5D);
float cos = MathUtils.cos(angle * 0.5D);
return set(getX() * cos + getY() * sin, getY() * cos - getX() * sin, getW() * sin + getZ() * cos, getW() * cos - getZ() * sin);
}
public default Quaternion set(Vec4f value){return set(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Quaternion set(Quaternion value){return set(value.getX(), value.getY(), value.getZ(), value.getW());}
public default Quaternion set(Matrix4f matrix)
{
float tr = matrix.get(0, 0) + matrix.get(1, 1) + matrix.get(2, 2);
if(tr >= 0.0D)
{
float s = (float)Math.sqrt(tr + 1.0D);
float w = s * 0.5F;
s = 0.5F / s;
float x = (matrix.get(2, 1) - matrix.get(1, 2)) * s;
float y = (matrix.get(0, 2) - matrix.get(2, 0)) * s;
float z = (matrix.get(1, 0) - matrix.get(0, 1)) * s;
return set(x, y, z, w);
}
else
{
float max = Math.max(Math.max(matrix.get(0, 0), matrix.get(1, 1)), matrix.get(2, 2));
if(max == matrix.get(0, 0))
{
float s = (float)Math.sqrt(matrix.get(0, 0) - (matrix.get(1, 1) + matrix.get(2, 2)) + 1.0D);
float x = s * 0.5F;
s = 0.5F / s;
float y = (matrix.get(0, 1) + matrix.get(1, 0)) * s;
float z = (matrix.get(2, 0) + matrix.get(0, 2)) * s;
float w = (matrix.get(2, 1) - matrix.get(1, 2)) * s;
return set(x, y, z, w);
}
else if(max == matrix.get(1, 1))
{
float s = (float)Math.sqrt(matrix.get(1, 1) - (matrix.get(2, 2) + matrix.get(0, 0)) + 1.0D);
float y = s * 0.5F;
s = 0.5F / s;
float z = (matrix.get(1, 2) + matrix.get(2, 1)) * s;
float x = (matrix.get(0, 1) + matrix.get(1, 0)) * s;
float w = (matrix.get(0, 2) - matrix.get(2, 0)) * s;
return set(x, y, z, w);
}
else
{
float s = (float)Math.sqrt(matrix.get(2, 2) - (matrix.get(0, 0) + matrix.get(1, 1)) + 1.0D);
float z = s * 0.5F;
s = 0.5F / s;
float x = (matrix.get(2, 0) + matrix.get(0, 2)) * s;
float y = (matrix.get(1, 2) + matrix.get(2, 1)) * s;
float w = (matrix.get(1, 0) - matrix.get(0, 1)) * s;
return set(x, y, z, w);
}
}
}
public default Quaternion setAxisRad(float x, float y, float z, float angle)
{
float sin = MathUtils.sin(angle * 0.5D);
float cos = MathUtils.cos(angle * 0.5D);
return set(x * sin, y * sin, z * sin, cos);
}
public default Quaternion setAxisDeg(float x, float y, float z, float angle)
{
angle = (float)Math.toRadians(angle);
float sin = MathUtils.sin(angle * 0.5D);
float cos = MathUtils.cos(angle * 0.5D);
return set(x * sin, y * sin, z * sin, cos);
}
public Quaternion set(float x, float y, float z, float w);
public default float dot(Quaternion other){return getX() * other.getX() + getY() * other.getY() + getZ() * other.getZ() + getW() * other.getW();}
public default Quaternion difference(Quaternion other){return difference(other, this);}
public default Quaternion difference(Quaternion other, Quaternion result)
{
float invNorm = 1.0F / (getX() * getX() + getY() * getY() + getZ() * getZ() + getW() * getW());
float x = -getX() * invNorm;
float y = -getY() * invNorm;
float z = -getZ() * invNorm;
float w = getW() * invNorm;
return set(w * other.getX() + x * other.getW() + y * other.getZ() - z * other.getY(), w * other.getY() - x * other.getZ() + y * other.getW() + z * other.getX(), w * other.getZ() + x * other.getY() - y * other.getX() + z * other.getW(), w * other.getW() - x * other.getX() - y * other.getY() - z * other.getZ());
}
public default Quaternion lerp(Quaternion other, float progress){return lerp(other, progress, this);}
public default Quaternion lerp(Quaternion other, float progress, Quaternion result)
{
float cosom = getX() * other.getX() + getY() * other.getY() + getZ() * other.getZ() + getW() * other.getW();
float absCosom = Math.abs(cosom);
float scale1;
float scale0;
if(1.0F - absCosom > 1.0E-006F)
{
float sinSqr = 1.0F - absCosom * absCosom;
float sinom = (float)(1.0D / Math.sqrt(sinSqr));
float omega = (float)Math.atan2(sinSqr * sinom, absCosom);
scale0 = MathUtils.sin((1.0D - progress) * omega) * sinom;
scale1 = MathUtils.sin(progress * omega) * sinom;
}
else
{
scale0 = 1.0F - progress;
scale1 = progress;
}
scale1 = cosom >= 0.0F ? scale1 : -scale1;
return result.set(scale0 * getX() + scale1 * other.getX(), scale0 * getY() + scale1 * other.getY(), scale0 * getZ() + scale1 * other.getZ(), scale0 * getW() + scale1 * other.getW());
}
public default float length(){return (float)Math.sqrt(lengthSquared());}
public default double lengthSquared(){return (getX() * getX()) + (getY() * getY()) + (getZ() * getZ()) + (getW() * getW());}
public default Matrix4f asRotationMatrix(){return new Matrix4f().rotate(this);}
public default Vec4f toAxisDegreeRotation() {return toAxisDegreeRotation(Vec4f.newMutable());}
public default Vec4f toAxisDegreeRotation(Vec4f input)
{
double invSqrt = 1.0D / Math.sqrt(1.0D - getW() * getW());
return input.set((float)(getX() * invSqrt), (float)(getY() * invSqrt), (float)(getZ() * invSqrt), (float)Math.toDegrees(acos(getW()) * 2F));
}
public default Vec4f toAxisRotation() {return toAxisRotation(Vec4f.newMutable());}
public default Vec4f toAxisRotation(Vec4f input)
{
double invSqrt = 1.0D / Math.sqrt(1.0D - getW() * getW());
return input.set((float)(getX() * invSqrt), (float)(getY() * invSqrt), (float)(getZ() * invSqrt), (float)acos(getW()) * 2F);
}
public default Quaternion store(ByteBuffer buffer)
{
buffer.putFloat(getX()).putFloat(getY()).putFloat(getZ()).putFloat(getW());
return this;
}
public default Quaternion load(ByteBuffer buffer)
{
return set(buffer.getFloat(), buffer.getFloat(), buffer.getFloat(), buffer.getFloat());
}
public default Quaternion store(FloatBuffer buffer)
{
buffer.put(getX()).put(getY()).put(getZ()).put(getW());
return this;
}
public default Quaternion load(FloatBuffer buffer)
{
return set(buffer.get(), buffer.get(), buffer.get(), buffer.get());
}
public Quaternion copy();
public boolean isMutable();
public default Quaternion asMutable(){return isMutable() ? this : newQuat(this);}
public default Quaternion asImmutable(){return isMutable() ? newMutable(this) : this;}
public default Quaternion copyAsMutable(){return newMutable(this);}
public default Quaternion copyAsImmutable(){return newQuat(this);}
}

View File

@ -0,0 +1,116 @@
package speiger.src.coreengine.math.vector.quaternion;
import java.util.Arrays;
public class QuaternionImmutable implements Quaternion
{
final float x;
final float y;
final float z;
final float w;
public QuaternionImmutable()
{
x = 0F;
y = 0F;
z = 0F;
w = 1F;
}
public QuaternionImmutable(float x, float y, float z, float w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
@Override
public Quaternion setX(float x)
{
return this.x == x ? this : set(x, y, z, w);
}
@Override
public Quaternion setY(float y)
{
return this.y == y ? this : set(x, y, z, w);
}
@Override
public Quaternion setZ(float z)
{
return this.z == z ? this : set(x, y, z, w);
}
@Override
public Quaternion setW(float w)
{
return this.w == w ? this : set(x, y, z, w);
}
@Override
public float getX()
{
return x;
}
@Override
public float getY()
{
return y;
}
@Override
public float getZ()
{
return z;
}
@Override
public float getW()
{
return w;
}
@Override
public Quaternion set(float x, float y, float z, float w)
{
return this.x == x && this.y == y && this.z == z && this.w == w ? this : Quaternion.newQuat(x, y, z, w);
}
@Override
public Quaternion copy()
{
return Quaternion.newQuat(this);
}
@Override
public boolean isMutable()
{
return false;
}
@Override
public int hashCode()
{
return Arrays.hashCode(new float[]{x,y,z,w});
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof Quaternion)
{
Quaternion other = (Quaternion)obj;
return other.getX() == x && other.getY() == y && other.getZ() == z && other.getW() == w;
}
return false;
}
@Override
public String toString()
{
return "Quaternion[x="+x+", y="+y+", z="+z+", w="+w+"]";
}
}

Some files were not shown because too many files have changed in this diff Show More