src code
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<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.7">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ginger</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,14 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
|
@ -0,0 +1,4 @@
|
|||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
|
@ -0,0 +1,58 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>me.hydos</groupId>
|
||||
<artifactId>ginger</artifactId>
|
||||
<name>gingerEngine</name>
|
||||
<version>NIGHTLY</version>
|
||||
<description>an engine for 3d java game development</description>
|
||||
<url>http://maven.apache.org</url>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer>
|
||||
<mainClass>io.github.hydos.ginger.Starter</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>lwjgl-natives-linux</id>
|
||||
<properties>
|
||||
<lwjgl.natives>natives-linux</lwjgl.natives>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>lwjgl-natives-macos</id>
|
||||
<properties>
|
||||
<lwjgl.natives>natives-macos</lwjgl.natives>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>lwjgl-natives-windows</id>
|
||||
<properties>
|
||||
<lwjgl.natives>natives-windows</lwjgl.natives>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
<properties>
|
||||
<lwjgl.version>3.2.2</lwjgl.version>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
</project>
|
|
@ -0,0 +1,310 @@
|
|||
#
|
||||
# A fatal error has been detected by the Java Runtime Environment:
|
||||
#
|
||||
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffe6f8f7370, pid=27340, tid=0x000000000000d7b8
|
||||
#
|
||||
# JRE version: Java(TM) SE Runtime Environment (8.0_201-b09) (build 1.8.0_201-b09)
|
||||
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.201-b09 mixed mode windows-amd64 compressed oops)
|
||||
# Problematic frame:
|
||||
# C [ig9icd64.dll+0x157370]
|
||||
#
|
||||
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
|
||||
#
|
||||
# If you would like to submit a bug report, please visit:
|
||||
# http://bugreport.java.com/bugreport/crash.jsp
|
||||
# The crash happened outside the Java Virtual Machine in native code.
|
||||
# See problematic frame for where to report the bug.
|
||||
#
|
||||
|
||||
--------------- T H R E A D ---------------
|
||||
|
||||
Current thread (0x0000000003093800): JavaThread "main" [_thread_in_native, id=55224, stack(0x0000000002f90000,0x0000000003090000)]
|
||||
|
||||
siginfo: ExceptionCode=0xc0000005, reading address 0x000000002648a000
|
||||
|
||||
Registers:
|
||||
RAX=0x000000000000183e, RBX=0x000000000308e410, RCX=0x0000000000000000, RDX=0x0000000026489fa0
|
||||
RSP=0x000000000308e320, RBP=0x000000000308e480, RSI=0x0000000023540000, RDI=0x0000000023601f00
|
||||
R8 =0x0000000000100000, R9 =0x0000000000002000, R10=0x000000000000183f, R11=0x00000000242fdb64
|
||||
R12=0x0000000000000000, R13=0x000000000308e5a0, R14=0x0000000000000200, R15=0x00000000000001c1
|
||||
RIP=0x00007ffe6f8f7370, EFLAGS=0x0000000000010207
|
||||
|
||||
Top of Stack: (sp=0x000000000308e320)
|
||||
0x000000000308e320: cafebabecafebabe 0000000000000000
|
||||
0x000000000308e330: 0000000000000000 0000000000000000
|
||||
0x000000000308e340: 00000000263c80a0 00007ffe6fc9795c
|
||||
0x000000000308e350: 000000000308e500 00000000263c80a0
|
||||
0x000000000308e360: 00007ffe6fc97600 000000000308e5a0
|
||||
0x000000000308e370: 0000000000000000 00007ffe6fc9a2a3
|
||||
0x000000000308e380: 000000000308e480 000000000308e560
|
||||
0x000000000308e390: 0000000023540000 00007ffe6fc98910
|
||||
0x000000000308e3a0: 80000b0040000049 0000000000000001
|
||||
0x000000000308e3b0: 00000000263c80a0 0000000000000000
|
||||
0x000000000308e3c0: 0000000000000000 00007ffe6f7c436b
|
||||
0x000000000308e3d0: 00000000262da830 0000000000000001
|
||||
0x000000000308e3e0: 00000000012fadd0 0000000000000001
|
||||
0x000000000308e3f0: 0000000000000001 0000000000000000
|
||||
0x000000000308e400: 000000000308e400 00000000012adff0
|
||||
0x000000000308e410: 00007ffe70305ca0 00000000242e4e80
|
||||
|
||||
Instructions: (pc=0x00007ffe6f8f7370)
|
||||
0x00007ffe6f8f7350: f3 0f 6f 3a 41 ff c2 f3 0f 6f 72 10 f3 0f 6f 6a
|
||||
0x00007ffe6f8f7360: 20 f3 0f 6f 62 30 f3 0f 6f 5a 40 f3 0f 6f 52 50
|
||||
0x00007ffe6f8f7370: f3 0f 6f 4a 60 f3 0f 6f 42 70 48 83 ea 80 66 0f
|
||||
0x00007ffe6f8f7380: e7 3f 66 0f e7 77 10 66 0f e7 6f 20 66 0f e7 67
|
||||
|
||||
|
||||
Register to memory mapping:
|
||||
|
||||
RAX=0x000000000000183e is an unknown value
|
||||
RBX=0x000000000308e410 is pointing into the stack for thread: 0x0000000003093800
|
||||
RCX=0x0000000000000000 is an unknown value
|
||||
RDX=0x0000000026489fa0 is an unknown value
|
||||
RSP=0x000000000308e320 is pointing into the stack for thread: 0x0000000003093800
|
||||
RBP=0x000000000308e480 is pointing into the stack for thread: 0x0000000003093800
|
||||
RSI=0x0000000023540000 is an unknown value
|
||||
RDI=0x0000000023601f00 is an unknown value
|
||||
R8 =0x0000000000100000 is an unknown value
|
||||
R9 =0x0000000000002000 is an unknown value
|
||||
R10=0x000000000000183f is an unknown value
|
||||
R11=0x00000000242fdb64 is an unknown value
|
||||
R12=0x0000000000000000 is an unknown value
|
||||
R13=0x000000000308e5a0 is pointing into the stack for thread: 0x0000000003093800
|
||||
R14=0x0000000000000200 is an unknown value
|
||||
R15=0x00000000000001c1 is an unknown value
|
||||
|
||||
|
||||
Stack: [0x0000000002f90000,0x0000000003090000], sp=0x000000000308e320, free space=1016k
|
||||
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
|
||||
C [ig9icd64.dll+0x157370]
|
||||
C [ig9icd64.dll+0x4f795c]
|
||||
C [ig9icd64.dll+0x4fa2a3]
|
||||
C [ig9icd64.dll+0x4ff938]
|
||||
C [ig9icd64.dll+0x39f3af]
|
||||
C [ig9icd64.dll+0x35aa9a]
|
||||
C [ig9icd64.dll+0x1b4428]
|
||||
C [ig9icd64.dll+0x1aa4a3]
|
||||
C [ig9icd64.dll+0x1a741d]
|
||||
C [ig9icd64.dll+0xecd03]
|
||||
C [opengl32.dll+0x2e014]
|
||||
C [lwjgl_opengl.dll+0xcab5]
|
||||
C 0x00000000031a8c67
|
||||
|
||||
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
|
||||
j org.lwjgl.opengl.GL11C.nglTexImage2D(IIIIIIIIJ)V+0
|
||||
j org.lwjgl.opengl.GL11C.glTexImage2D(IIIIIIIILjava/nio/ByteBuffer;)V+17
|
||||
j org.lwjgl.opengl.GL11.glTexImage2D(IIIIIIIILjava/nio/ByteBuffer;)V+14
|
||||
j io.github.hydos.ginger.renderEngine.texture.ModelTexture.<init>(Ljava/lang/String;)V+124
|
||||
j io.github.hydos.ginger.utils.Loader.loadTexture(Ljava/lang/String;)I+5
|
||||
j io.github.hydos.ginger.renderEngine.renderers.WaterRenderer.<init>(Lio/github/hydos/ginger/renderEngine/shaders/WaterShader;Lio/github/hydos/ginger/mathEngine/matrixes/Matrix4f;Lio/github/hydos/ginger/water/WaterFrameBuffers;)V+22
|
||||
j io.github.hydos.ginger.renderEngine.renderers.MasterRenderer.<init>()V+159
|
||||
j io.github.hydos.ginger.Example.main([Ljava/lang/String;)V+27
|
||||
j io.github.hydos.ginger.Starter.main([Ljava/lang/String;)V+8
|
||||
v ~StubRoutines::call_stub
|
||||
|
||||
--------------- P R O C E S S ---------------
|
||||
|
||||
Java Threads: ( => current thread )
|
||||
0x000000001958f800 JavaThread "Service Thread" daemon [_thread_blocked, id=67772, stack(0x0000000019b70000,0x0000000019c70000)]
|
||||
0x000000001957a800 JavaThread "C1 CompilerThread2" daemon [_thread_blocked, id=70376, stack(0x0000000019a70000,0x0000000019b70000)]
|
||||
0x0000000017d6e000 JavaThread "C2 CompilerThread1" daemon [_thread_blocked, id=36704, stack(0x0000000019970000,0x0000000019a70000)]
|
||||
0x0000000017d1b000 JavaThread "C2 CompilerThread0" daemon [_thread_blocked, id=70296, stack(0x0000000019470000,0x0000000019570000)]
|
||||
0x0000000017d16800 JavaThread "Attach Listener" daemon [_thread_blocked, id=72360, stack(0x0000000019370000,0x0000000019470000)]
|
||||
0x0000000017d15000 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=38732, stack(0x0000000019270000,0x0000000019370000)]
|
||||
0x000000000318c800 JavaThread "Finalizer" daemon [_thread_blocked, id=73512, stack(0x0000000018f70000,0x0000000019070000)]
|
||||
0x0000000003184000 JavaThread "Reference Handler" daemon [_thread_blocked, id=70956, stack(0x0000000018e70000,0x0000000018f70000)]
|
||||
=>0x0000000003093800 JavaThread "main" [_thread_in_native, id=55224, stack(0x0000000002f90000,0x0000000003090000)]
|
||||
|
||||
Other Threads:
|
||||
0x0000000017cd7000 VMThread [stack: 0x0000000018d70000,0x0000000018e70000] [id=72484]
|
||||
0x0000000019592000 WatcherThread [stack: 0x0000000019c70000,0x0000000019d70000] [id=67712]
|
||||
|
||||
VM state:not at safepoint (normal execution)
|
||||
|
||||
VM Mutex/Monitor currently owned by a thread: None
|
||||
|
||||
heap address: 0x0000000081200000, size: 2030 MB, Compressed Oops mode: 32-bit
|
||||
Narrow klass base: 0x0000000000000000, Narrow klass shift: 3
|
||||
Compressed class space size: 1073741824 Address: 0x0000000100000000
|
||||
|
||||
Heap:
|
||||
PSYoungGen total 38400K, used 15792K [0x00000000d5b80000, 0x00000000d8600000, 0x0000000100000000)
|
||||
eden space 33280K, 47% used [0x00000000d5b80000,0x00000000d6aec198,0x00000000d7c00000)
|
||||
from space 5120K, 0% used [0x00000000d8100000,0x00000000d8100000,0x00000000d8600000)
|
||||
to space 5120K, 0% used [0x00000000d7c00000,0x00000000d7c00000,0x00000000d8100000)
|
||||
ParOldGen total 87552K, used 0K [0x0000000081200000, 0x0000000086780000, 0x00000000d5b80000)
|
||||
object space 87552K, 0% used [0x0000000081200000,0x0000000081200000,0x0000000086780000)
|
||||
Metaspace used 9052K, capacity 9267K, committed 9600K, reserved 1058816K
|
||||
class space used 769K, capacity 845K, committed 896K, reserved 1048576K
|
||||
|
||||
Card table byte_map: [0x0000000012550000,0x0000000012950000] byte_map_base: 0x0000000012147000
|
||||
|
||||
Marking Bits: (ParMarkBitMap*) 0x0000000054c84ce0
|
||||
Begin Bits: [0x0000000013000000, 0x0000000014fb8000)
|
||||
End Bits: [0x0000000014fb8000, 0x0000000016f70000)
|
||||
|
||||
Polling page: 0x0000000001220000
|
||||
|
||||
CodeCache: size=245760Kb used=2900Kb max_used=2914Kb free=242859Kb
|
||||
bounds [0x0000000003190000, 0x0000000003470000, 0x0000000012190000]
|
||||
total_blobs=1573 nmethods=688 adapters=798
|
||||
compilation: enabled
|
||||
|
||||
Compilation events (10 events):
|
||||
Event: 1.997 Thread 0x000000001957a800 683 3 java.nio.DirectByteBuffer::put (126 bytes)
|
||||
Event: 1.998 Thread 0x000000001957a800 nmethod 683 0x000000000345fe90 code [0x0000000003460060, 0x0000000003460808]
|
||||
Event: 1.998 Thread 0x000000001957a800 684 3 java.io.BufferedInputStream::fill (233 bytes)
|
||||
Event: 2.000 Thread 0x000000001957a800 nmethod 684 0x0000000003460b50 code [0x0000000003460dc0, 0x0000000003461cb8]
|
||||
Event: 2.018 Thread 0x000000001957a800 685 s 3 java.io.BufferedInputStream::available (35 bytes)
|
||||
Event: 2.019 Thread 0x000000001957a800 nmethod 685 0x00000000034621d0 code [0x0000000003462360, 0x0000000003462898]
|
||||
Event: 2.119 Thread 0x000000001957a800 686 3 java.util.WeakHashMap::put (162 bytes)
|
||||
Event: 2.121 Thread 0x000000001957a800 nmethod 686 0x0000000003462a50 code [0x0000000003462c80, 0x0000000003463b18]
|
||||
Event: 2.172 Thread 0x0000000017d6e000 688 ! 4 java.io.BufferedReader::readLine (304 bytes)
|
||||
Event: 2.194 Thread 0x0000000017d6e000 nmethod 688 0x0000000003468010 code [0x00000000034681c0, 0x0000000003469038]
|
||||
|
||||
GC Heap History (0 events):
|
||||
No events
|
||||
|
||||
Deoptimization events (1 events):
|
||||
Event: 0.615 Thread 0x0000000003093800 Uncommon trap: reason=unstable_if action=reinterpret pc=0x000000000333ffa0 method=java.lang.String.indexOf([CII[CIII)I @ 3
|
||||
|
||||
Classes redefined (0 events):
|
||||
No events
|
||||
|
||||
Internal exceptions (10 events):
|
||||
Event: 0.048 Thread 0x0000000003093800 Exception <a 'java/lang/NoSuchMethodError': Method sun.misc.Unsafe.prefetchRead(Ljava/lang/Object;J)V name or signature does not match> (0x00000000d5b87f98) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u201\12322\hotspot\src\share\vm\prim
|
||||
Event: 0.373 Thread 0x0000000003093800 Exception <a 'java/lang/NoSuchMethodError': java.lang.Object.lambda$static$0(Ljava/lang/String;)Ljava/lang/Boolean;> (0x00000000d5dba520) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u201\12322\hotspot\src\share\vm\interpreter\linkResolve
|
||||
Event: 0.414 Thread 0x0000000003093800 Exception <a 'java/lang/NoSuchFieldError': method resolution failed> (0x00000000d5e32340) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u201\12322\hotspot\src\share\vm\prims\methodHandles.cpp, line 1167]
|
||||
Event: 0.423 Thread 0x0000000003093800 Exception <a 'java/lang/NoSuchFieldError': method resolution failed> (0x00000000d5e3f740) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u201\12322\hotspot\src\share\vm\prims\methodHandles.cpp, line 1167]
|
||||
Event: 0.508 Thread 0x0000000003093800 Exception <a 'java/security/PrivilegedActionException'> (0x00000000d5f867e0) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u201\12322\hotspot\src\share\vm\prims\jvm.cpp, line 1502]
|
||||
Event: 0.508 Thread 0x0000000003093800 Exception <a 'java/security/PrivilegedActionException'> (0x00000000d5f869f0) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u201\12322\hotspot\src\share\vm\prims\jvm.cpp, line 1502]
|
||||
Event: 0.509 Thread 0x0000000003093800 Exception <a 'java/security/PrivilegedActionException'> (0x00000000d5f8a900) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u201\12322\hotspot\src\share\vm\prims\jvm.cpp, line 1502]
|
||||
Event: 0.510 Thread 0x0000000003093800 Exception <a 'java/security/PrivilegedActionException'> (0x00000000d5f8ab10) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u201\12322\hotspot\src\share\vm\prims\jvm.cpp, line 1502]
|
||||
Event: 1.315 Thread 0x0000000003093800 Exception <a 'sun/nio/fs/WindowsException'> (0x00000000d62417d0) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u201\12322\hotspot\src\share\vm\prims\jni.cpp, line 709]
|
||||
Event: 1.315 Thread 0x0000000003093800 Exception <a 'sun/nio/fs/WindowsException'> (0x00000000d6241fb8) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u201\12322\hotspot\src\share\vm\prims\jni.cpp, line 709]
|
||||
|
||||
Events (10 events):
|
||||
Event: 2.119 loading class org/lwjgl/opengl/GL32C
|
||||
Event: 2.119 loading class org/lwjgl/opengl/GL32C done
|
||||
Event: 2.120 loading class org/lwjgl/opengl/GL31C
|
||||
Event: 2.120 loading class org/lwjgl/opengl/GL31C done
|
||||
Event: 2.170 loading class io/github/hydos/ginger/renderEngine/shaders/WaterShader
|
||||
Event: 2.170 loading class io/github/hydos/ginger/renderEngine/shaders/WaterShader done
|
||||
Event: 2.201 loading class io/github/hydos/ginger/renderEngine/renderers/WaterRenderer
|
||||
Event: 2.201 loading class io/github/hydos/ginger/renderEngine/renderers/WaterRenderer done
|
||||
Event: 2.202 loading class io/github/hydos/ginger/renderEngine/texture/ModelTexture
|
||||
Event: 2.202 loading class io/github/hydos/ginger/renderEngine/texture/ModelTexture done
|
||||
|
||||
|
||||
Dynamic libraries:
|
||||
0x00007ff696ca0000 - 0x00007ff696cd7000 C:\Program Files\Java\jdk1.8.0_201\bin\javaw.exe
|
||||
0x00007ffedc730000 - 0x00007ffedc91d000 C:\WINDOWS\SYSTEM32\ntdll.dll
|
||||
0x00007ffedb680000 - 0x00007ffedb733000 C:\WINDOWS\System32\KERNEL32.DLL
|
||||
0x00007ffed95e0000 - 0x00007ffed9873000 C:\WINDOWS\System32\KERNELBASE.dll
|
||||
0x00007ffed9960000 - 0x00007ffed9a03000 C:\WINDOWS\System32\ADVAPI32.dll
|
||||
0x00007ffedb430000 - 0x00007ffedb4ce000 C:\WINDOWS\System32\msvcrt.dll
|
||||
0x00007ffedafd0000 - 0x00007ffedb06e000 C:\WINDOWS\System32\sechost.dll
|
||||
0x00007ffedbc90000 - 0x00007ffedbdb2000 C:\WINDOWS\System32\RPCRT4.dll
|
||||
0x00007ffedb7c0000 - 0x00007ffedb957000 C:\WINDOWS\System32\USER32.dll
|
||||
0x00007ffed8800000 - 0x00007ffed8820000 C:\WINDOWS\System32\win32u.dll
|
||||
0x00007ffedbdc0000 - 0x00007ffedbde9000 C:\WINDOWS\System32\GDI32.dll
|
||||
0x00007ffed8820000 - 0x00007ffed89ba000 C:\WINDOWS\System32\gdi32full.dll
|
||||
0x00007ffed89c0000 - 0x00007ffed8a60000 C:\WINDOWS\System32\msvcp_win.dll
|
||||
0x00007ffed9280000 - 0x00007ffed937a000 C:\WINDOWS\System32\ucrtbase.dll
|
||||
0x00007ffec64f0000 - 0x00007ffec6769000 C:\WINDOWS\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.17763.437_none_05b63dca071e5dd6\COMCTL32.dll
|
||||
0x00007ffedb960000 - 0x00007ffedbc8c000 C:\WINDOWS\System32\combase.dll
|
||||
0x00007ffed9560000 - 0x00007ffed95de000 C:\WINDOWS\System32\bcryptPrimitives.dll
|
||||
0x00007ffedb2b0000 - 0x00007ffedb2de000 C:\WINDOWS\System32\IMM32.DLL
|
||||
0x0000000054d10000 - 0x0000000054de1000 C:\Program Files\Java\jdk1.8.0_201\jre\bin\msvcr100.dll
|
||||
0x0000000054460000 - 0x0000000054d04000 C:\Program Files\Java\jdk1.8.0_201\jre\bin\server\jvm.dll
|
||||
0x00007ffedb3b0000 - 0x00007ffedb3b8000 C:\WINDOWS\System32\PSAPI.DLL
|
||||
0x00007ffec3050000 - 0x00007ffec3059000 C:\WINDOWS\SYSTEM32\WSOCK32.dll
|
||||
0x00007ffedb600000 - 0x00007ffedb66d000 C:\WINDOWS\System32\WS2_32.dll
|
||||
0x00007ffeca990000 - 0x00007ffeca99a000 C:\WINDOWS\SYSTEM32\VERSION.dll
|
||||
0x00007ffed68b0000 - 0x00007ffed68d4000 C:\WINDOWS\SYSTEM32\WINMM.dll
|
||||
0x00007ffed6850000 - 0x00007ffed687d000 C:\WINDOWS\SYSTEM32\WINMMBASE.dll
|
||||
0x00007ffed91b0000 - 0x00007ffed91fa000 C:\WINDOWS\System32\cfgmgr32.dll
|
||||
0x00007ffed68e0000 - 0x00007ffed68ef000 C:\Program Files\Java\jdk1.8.0_201\jre\bin\verify.dll
|
||||
0x00007ffed00e0000 - 0x00007ffed0109000 C:\Program Files\Java\jdk1.8.0_201\jre\bin\java.dll
|
||||
0x00007ffecf070000 - 0x00007ffecf086000 C:\Program Files\Java\jdk1.8.0_201\jre\bin\zip.dll
|
||||
0x00007ffed9a10000 - 0x00007ffedaf00000 C:\WINDOWS\System32\SHELL32.dll
|
||||
0x00007ffedb2e0000 - 0x00007ffedb388000 C:\WINDOWS\System32\shcore.dll
|
||||
0x00007ffed8a60000 - 0x00007ffed91aa000 C:\WINDOWS\System32\windows.storage.dll
|
||||
0x00007ffed87d0000 - 0x00007ffed87f4000 C:\WINDOWS\System32\profapi.dll
|
||||
0x00007ffed8770000 - 0x00007ffed87cd000 C:\WINDOWS\System32\powrprof.dll
|
||||
0x00007ffedc640000 - 0x00007ffedc692000 C:\WINDOWS\System32\shlwapi.dll
|
||||
0x00007ffed8730000 - 0x00007ffed8741000 C:\WINDOWS\System32\kernel.appcore.dll
|
||||
0x00007ffed9200000 - 0x00007ffed9217000 C:\WINDOWS\System32\cryptsp.dll
|
||||
0x00007ffecef70000 - 0x00007ffecef8a000 C:\Program Files\Java\jdk1.8.0_201\jre\bin\net.dll
|
||||
0x00007ffec8480000 - 0x00007ffec8656000 C:\WINDOWS\SYSTEM32\urlmon.dll
|
||||
0x00007ffec8870000 - 0x00007ffec8b18000 C:\WINDOWS\SYSTEM32\iertutil.dll
|
||||
0x00007ffed8180000 - 0x00007ffed818c000 C:\WINDOWS\SYSTEM32\CRYPTBASE.DLL
|
||||
0x00007ffed7fb0000 - 0x00007ffed8017000 C:\WINDOWS\system32\mswsock.dll
|
||||
0x00007ffeced60000 - 0x00007ffeced71000 C:\Program Files\Java\jdk1.8.0_201\jre\bin\nio.dll
|
||||
0x00007ffeb6660000 - 0x00007ffeb66d2000 C:\Users\hayde\AppData\Local\Temp\lwjglhayde\3.2.2-build-10\lwjgl.dll
|
||||
0x00007ffeb6a20000 - 0x00007ffeb6a7e000 C:\Users\hayde\AppData\Local\Temp\lwjglhayde\3.2.2-build-10\glfw.dll
|
||||
0x00007ffed6cf0000 - 0x00007ffed6d8c000 C:\WINDOWS\system32\uxtheme.dll
|
||||
0x00007ffeca460000 - 0x00007ffeca4a4000 C:\WINDOWS\SYSTEM32\dinput8.dll
|
||||
0x00007ffeced40000 - 0x00007ffeced51000 C:\WINDOWS\SYSTEM32\xinput1_4.dll
|
||||
0x00007ffed8540000 - 0x00007ffed8569000 C:\WINDOWS\SYSTEM32\DEVOBJ.dll
|
||||
0x00007ffed6de0000 - 0x00007ffed6e0e000 C:\WINDOWS\SYSTEM32\dwmapi.dll
|
||||
0x00007ffed9380000 - 0x00007ffed955b000 C:\WINDOWS\System32\CRYPT32.dll
|
||||
0x00007ffed8750000 - 0x00007ffed8762000 C:\WINDOWS\System32\MSASN1.dll
|
||||
0x00007ffec9c90000 - 0x00007ffec9d5c000 C:\WINDOWS\SYSTEM32\inputhost.dll
|
||||
0x00007ffed63f0000 - 0x00007ffed64d2000 C:\WINDOWS\SYSTEM32\CoreMessaging.dll
|
||||
0x00007ffed3eb0000 - 0x00007ffed41d2000 C:\WINDOWS\SYSTEM32\CoreUIComponents.dll
|
||||
0x00007ffed5a20000 - 0x00007ffed5fde000 C:\WINDOWS\SYSTEM32\d2d1.dll
|
||||
0x00007ffed6ec0000 - 0x00007ffed70cd000 C:\WINDOWS\SYSTEM32\twinapi.appcore.dll
|
||||
0x00007ffed57a0000 - 0x00007ffed5a1e000 C:\WINDOWS\SYSTEM32\d3d11.dll
|
||||
0x00007ffed5110000 - 0x00007ffed52b8000 C:\WINDOWS\SYSTEM32\PROPSYS.dll
|
||||
0x00007ffed4440000 - 0x00007ffed4593000 C:\WINDOWS\SYSTEM32\wintypes.dll
|
||||
0x00007ffedaf00000 - 0x00007ffedafc4000 C:\WINDOWS\System32\OLEAUT32.dll
|
||||
0x00007ffed77d0000 - 0x00007ffed7801000 C:\WINDOWS\SYSTEM32\ntmarta.dll
|
||||
0x00007ffed7440000 - 0x00007ffed7502000 C:\WINDOWS\SYSTEM32\dxgi.dll
|
||||
0x00007ffed70d0000 - 0x00007ffed70f8000 C:\WINDOWS\SYSTEM32\RMCLIENT.dll
|
||||
0x00007ffedc420000 - 0x00007ffedc58a000 C:\WINDOWS\System32\MSCTF.dll
|
||||
0x00007ffed73e0000 - 0x00007ffed73ee000 C:\WINDOWS\SYSTEM32\HID.DLL
|
||||
0x00007ffedbfa0000 - 0x00007ffedc416000 C:\WINDOWS\System32\SETUPAPI.DLL
|
||||
0x00007ffed9930000 - 0x00007ffed9956000 C:\WINDOWS\System32\bcrypt.dll
|
||||
0x00007ffed9220000 - 0x00007ffed9279000 C:\WINDOWS\System32\WINTRUST.dll
|
||||
0x00007ffec8c90000 - 0x00007ffec8db7000 C:\WINDOWS\SYSTEM32\opengl32.dll
|
||||
0x00007ffed1f70000 - 0x00007ffed1f9c000 C:\WINDOWS\SYSTEM32\GLU32.dll
|
||||
0x00007ffe6f7a0000 - 0x00007ffe707af000 C:\WINDOWS\System32\DriverStore\FileRepository\iigd_dch.inf_amd64_27edf49b9e5b5b9c\ig9icd64.dll
|
||||
0x00007ffe89850000 - 0x00007ffe8bb3d000 C:\WINDOWS\System32\DriverStore\FileRepository\iigd_dch.inf_amd64_27edf49b9e5b5b9c\igc64.dll
|
||||
0x00007ffedb0f0000 - 0x00007ffedb245000 C:\WINDOWS\System32\ole32.dll
|
||||
0x00007ffecdb80000 - 0x00007ffecdc9d000 C:\WINDOWS\System32\DriverStore\FileRepository\iigd_dch.inf_amd64_27edf49b9e5b5b9c\igdgmm64.dll
|
||||
0x00007ffeb6530000 - 0x00007ffeb6588000 C:\Users\hayde\AppData\Local\Temp\lwjglhayde\3.2.2-build-10\lwjgl_opengl.dll
|
||||
0x00007ffec9d60000 - 0x00007ffec9df5000 C:\WINDOWS\System32\TextInputFramework.dll
|
||||
0x00007ffec4220000 - 0x00007ffec428c000 C:\WINDOWS\system32\Oleacc.dll
|
||||
0x00007ffeb6440000 - 0x00007ffeb64bf000 C:\Users\hayde\AppData\Local\Temp\lwjglhayde\3.2.2-build-10\lwjgl_stb.dll
|
||||
0x00007ffed4ea0000 - 0x00007ffed508d000 C:\WINDOWS\SYSTEM32\dbghelp.dll
|
||||
|
||||
VM Arguments:
|
||||
jvm_args: -Dfile.encoding=Cp1252
|
||||
java_command: io.github.hydos.ginger.Starter -Djava.security.auth.login.config==theconfig.config
|
||||
java_class_path (initial): C:\Users\hayde\Desktop\dev\eclipse\ginger\target\classes;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl\3.2.2\lwjgl-3.2.2.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-assimp\3.2.2\lwjgl-assimp-3.2.2.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-bgfx\3.2.2\lwjgl-bgfx-3.2.2.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-glfw\3.2.2\lwjgl-glfw-3.2.2.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-nanovg\3.2.2\lwjgl-nanovg-3.2.2.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-nuklear\3.2.2\lwjgl-nuklear-3.2.2.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-openal\3.2.2\lwjgl-openal-3.2.2.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-opengl\3.2.2\lwjgl-opengl-3.2.2.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-openvr\3.2.2\lwjgl-openvr-3.2.2.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-par\3.2.2\lwjgl-par-3.2.2.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-stb\3.2.2\lwjgl-stb-3.2.2.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl\3.2.2\lwjgl-3.2.2-natives-windows.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-assimp\3.2.2\lwjgl-assimp-3.2.2-natives-windows.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-bgfx\3.2.2\lwjgl-bgfx-3.2.2-natives-windows.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-glfw\3.2.2\lwjgl-glfw-3.2.2-natives-windows.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-nanovg\3.2.2\lwjgl-nanovg-3.2.2-natives-windows.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-nuklear\3.2.2\lwjgl-nuklear-3.2.2-natives-windows.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-openal\3.2.2\lwjgl-openal-3.2.2-natives-windows.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-opengl\3.2.2\lwjgl-opengl-3.2.2-natives-windows.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-openvr\3.2.2\lwjgl-openvr-3.2.2-natives-windows.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-par\3.2.2\lwjgl-par-3.2.2-natives-windows.jar;C:\Users\hayde\.m2\repository\org\lwjgl\lwjgl-stb\3.2.2\lwjgl-stb-3.2.2-natives-windows.ja
|
||||
Launcher Type: SUN_STANDARD
|
||||
|
||||
Environment Variables:
|
||||
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_191
|
||||
PATH=C:/Program Files/Java/jre1.8.0_191/bin/server;C:/Program Files/Java/jre1.8.0_191/bin;C:/Program Files/Java/jre1.8.0_191/lib/amd64;C:\gradle\bin;C:\Users\hayde\Desktop\diffutils\bin;C:\Nintendo3DS\Programs\Python\Lib\site-packages\PyQt4;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Nintendo3DS\Programs\devkitPro\msys2\usr\bin;C:\Nintendo3DS\Programs\devkitARM\bin;C:\Nintendo3DS\Programs\Git\cmd;C:\Nintendo3DS\Programs\Python;C:\Nintendo3DS\Programs\Python\Scripts;C:\Nintendo3DS\Programs\MinGW\msys\1.0\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Nintendo\Nintendo Dev Interface;C:\Program Files\Java\jdk1.8.0_171\bin;C:\Users\hayde\AppData\Local\Programs\Python\Python36;C:\Program Files\PuTTY\;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin;C:\Program Files\nodejs\;C:\Program Files (x86)\Brackets\command;C:\ant\bin;C:\Program Files\dotnet\;C:\ProgramData\chocolatey\bin;C:\Users\hayde\AppData\Local\Programs\Python\Python36\Scripts\;C:\Users\hayde\AppData\Local\Programs\Python\Python36\;C:\Users\hayde\AppData\Local\Programs\Python\Python36-32\Scripts\;C:\Users\hayde\AppData\Local\Programs\Python\Python36-32\;C:\Users\hayde\AppData\Local\Microsoft\WindowsApps;C:\Users\hayde\AppData\Local\GitHubDesktop\bin;C:\maven\bin;C:\Program Files\Java\jdk1.8.0_171\bin;C:\Users\hayde\AppData\Local\Programs\Python\Python37\Scripts;C:\Users\hayde\AppData\Roaming\npm;C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.1\bin;;C:\Program Files\JetBrains\PhpStorm 2019.1.1\bin;;C:\Users\hayde\AppData\Local\Microsoft\WindowsApps;C:\devkitPro\devkitARM\bin;;C:\Users\hayde\AppData\Local\Programs\Microsoft VS Code\bin;C:\WINDOWS\System32;
|
||||
USERNAME=hayde
|
||||
OS=Windows_NT
|
||||
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
|
||||
|
||||
|
||||
|
||||
--------------- S Y S T E M ---------------
|
||||
|
||||
OS: Windows 10.0 , 64 bit Build 17763 (10.0.17763.437)
|
||||
|
||||
CPU:total 4 (initial active 4) (2 cores per cpu, 2 threads per core) family 6 model 78 stepping 3, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, avx, avx2, aes, clmul, erms, rtm, 3dnowpref, lzcnt, ht, tsc, tscinvbit, bmi1, bmi2, adx
|
||||
|
||||
Memory: 4k page, physical 8312096k(733164k free), swap 15650340k(3780748k free)
|
||||
|
||||
vm_info: Java HotSpot(TM) 64-Bit Server VM (25.201-b09) for windows-amd64 JRE (1.8.0_201-b09), built on Dec 15 2018 18:36:39 by "java_re" with MS VC++ 10.0 (VS2010)
|
||||
|
||||
time: Sun May 26 08:37:19 2019
|
||||
timezone: E. Australia Standard Time
|
||||
elapsed time: 2 seconds (0d 0h 0m 2s)
|
||||
|
|
@ -0,0 +1,264 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>me.hydos</groupId>
|
||||
<artifactId>ginger</artifactId>
|
||||
<version>NIGHTLY</version>
|
||||
<name>gingerEngine</name>
|
||||
<description>an engine for 3d java game development</description>
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<lwjgl.version>3.2.2</lwjgl.version>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>lwjgl-natives-linux</id>
|
||||
<activation>
|
||||
<os><family>unix</family></os>
|
||||
</activation>
|
||||
<properties>
|
||||
<lwjgl.natives>natives-linux</lwjgl.natives>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>lwjgl-natives-macos</id>
|
||||
<activation>
|
||||
<os><family>mac</family></os>
|
||||
</activation>
|
||||
<properties>
|
||||
<lwjgl.natives>natives-macos</lwjgl.natives>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>lwjgl-natives-windows</id>
|
||||
<activation>
|
||||
<os><family>windows</family></os>
|
||||
</activation>
|
||||
<properties>
|
||||
<lwjgl.natives>natives-windows</lwjgl.natives>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>io.github.hydos.ginger.Starter</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-assimp</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-bgfx</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-glfw</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-nanovg</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-nuklear</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-openal</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-opengl</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-openvr</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-par</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-stb</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-windows</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-assimp</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-windows</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-bgfx</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-windows</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-glfw</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-windows</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-nanovg</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-windows</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-nuklear</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-windows</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-openal</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-windows</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-opengl</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-windows</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-openvr</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-windows</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-par</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-windows</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-stb</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-windows</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-macos</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-assimp</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-macos</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-bgfx</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-macos</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-glfw</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-macos</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-nanovg</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-macos</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-nuklear</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-macos</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-openal</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-macos</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-opengl</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-macos</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-openvr</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-macos</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-par</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-macos</classifier>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl-stb</artifactId>
|
||||
<version>${lwjgl.version}</version>
|
||||
<classifier>natives-macos</classifier>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,118 @@
|
|||
package io.github.hydos.ginger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.github.hydos.ginger.elements.Entity;
|
||||
import io.github.hydos.ginger.elements.Light;
|
||||
import io.github.hydos.ginger.elements.Player;
|
||||
import io.github.hydos.ginger.elements.ThirdPersonCamera;
|
||||
import io.github.hydos.ginger.guis.GuiTexture;
|
||||
import io.github.hydos.ginger.io.Window;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector2f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
import io.github.hydos.ginger.obj.ModelLoader;
|
||||
import io.github.hydos.ginger.renderEngine.models.TexturedModel;
|
||||
import io.github.hydos.ginger.renderEngine.renderers.MasterRenderer;
|
||||
import io.github.hydos.ginger.renderEngine.texture.ModelTexture;
|
||||
import io.github.hydos.ginger.renderEngine.tools.MousePicker;
|
||||
import io.github.hydos.ginger.terrain.Terrain;
|
||||
import io.github.hydos.ginger.terrain.TerrainTexture;
|
||||
import io.github.hydos.ginger.terrain.TerrainTexturePack;
|
||||
import io.github.hydos.ginger.utils.Loader;
|
||||
|
||||
public class Example {
|
||||
|
||||
private MasterRenderer masterRenderer;
|
||||
|
||||
private List<Terrain> terrains = new ArrayList<Terrain>();
|
||||
|
||||
private List<GuiTexture> guis = new ArrayList<GuiTexture>();
|
||||
|
||||
private List<Light> lights = new ArrayList<Light>();
|
||||
|
||||
private List<Entity> entities = new ArrayList<Entity>();
|
||||
|
||||
|
||||
public void main(String[] args) {
|
||||
|
||||
|
||||
Window.create(1200, 800, "Ginger Example", 60);
|
||||
|
||||
Window.setBackgroundColour(0.2f, 0.2f, 0.8f);
|
||||
|
||||
masterRenderer = new MasterRenderer();
|
||||
|
||||
TexturedModel tModel = ModelLoader.loadModel("stall.obj", "stallTexture.png");
|
||||
tModel.getTexture().setReflectivity(1f);
|
||||
tModel.getTexture().setShineDamper(7f);
|
||||
|
||||
TexturedModel dragonMdl = ModelLoader.loadModel("dragon.obj", "stallTexture.png");
|
||||
dragonMdl.getTexture().setReflectivity(4f);
|
||||
dragonMdl.getTexture().setShineDamper(2f);
|
||||
|
||||
|
||||
|
||||
Player entity = new Player(tModel, new Vector3f(0,0,-3),0,180f,0, new Vector3f(0.2f, 0.2f, 0.2f));
|
||||
Light sun = new Light(new Vector3f(0,-0.5f,0), new Vector3f(1, 1, 1), new Vector3f(0.1f, 0.1f, 0.1f));
|
||||
lights.add(sun);
|
||||
|
||||
TexturedModel tgrass = ModelLoader.loadModel("grass.obj", "grass.png");
|
||||
tgrass.getTexture().setTransparency(true);
|
||||
tgrass.getTexture().useFakeLighting(true);
|
||||
|
||||
TerrainTexture backgroundTexture = Loader.loadTerrainTexture("grass.png");
|
||||
TerrainTexture rTexture = Loader.loadTerrainTexture("mud.png");
|
||||
TerrainTexture gTexture = Loader.loadTerrainTexture("grassFlowers.png");
|
||||
TerrainTexture bTexture = Loader.loadTerrainTexture("path.png");
|
||||
TerrainTexturePack texturePack = new TerrainTexturePack(backgroundTexture, rTexture, gTexture, bTexture);
|
||||
|
||||
TerrainTexture blendMap = Loader.loadTerrainTexture("blendMap.png");
|
||||
|
||||
Terrain terrain = new Terrain(-0.5f, -0.5f, texturePack, blendMap, "heightmap.png");
|
||||
|
||||
Entity dragon = new Entity(dragonMdl, new Vector3f(3,terrain.getHeightOfTerrain(3, -3),-3),0,180f,0, new Vector3f(0.2f, 0.2f, 0.2f));
|
||||
|
||||
Entity grassEntity = new Entity(tgrass, new Vector3f(-3,terrain.getHeightOfTerrain(-3, -3),-3),0,180f,0, new Vector3f(0.2f, 0.2f, 0.2f));
|
||||
entities.add(grassEntity);
|
||||
|
||||
ThirdPersonCamera camera = new ThirdPersonCamera(new Vector3f(0,1,0), entity);
|
||||
|
||||
GuiTexture guiTexture = new GuiTexture(new ModelTexture("guis/ginger.png").getTextureID(), new Vector2f(0.5f,0.5f), new Vector2f(0.25f,0.25f));
|
||||
guis.add(guiTexture);
|
||||
|
||||
MousePicker picker = new MousePicker(camera, masterRenderer.getProjectionMatrix(), terrain);
|
||||
|
||||
entities.add(entity);
|
||||
entities.add(dragon);
|
||||
|
||||
|
||||
terrains.add(terrain);
|
||||
|
||||
while(!Window.closed()) {
|
||||
|
||||
if(Window.isUpdating()) {
|
||||
Window.update();
|
||||
picker.update();
|
||||
camera.move();
|
||||
entity.move(terrain);
|
||||
Vector3f terrainPoint = picker.getCurrentTerrainPoint();
|
||||
if(terrainPoint!=null) {
|
||||
dragon.setPosition(terrainPoint);
|
||||
}
|
||||
|
||||
dragon.increaseRotation(0,1,0);
|
||||
masterRenderer.renderScene(entities, terrains, lights, camera);
|
||||
masterRenderer.renderGuis(guis);
|
||||
|
||||
Window.swapBuffers();
|
||||
}
|
||||
|
||||
}
|
||||
masterRenderer.cleanUp();
|
||||
Loader.cleanUp();
|
||||
System.exit(0);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package io.github.hydos.ginger;
|
||||
|
||||
public class Starter {
|
||||
|
||||
// private static final boolean usingEclipse = false;
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Example().main(args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package io.github.hydos.ginger.elements;
|
||||
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
import io.github.hydos.ginger.renderEngine.models.TexturedModel;
|
||||
|
||||
public class Entity {
|
||||
|
||||
private TexturedModel model;
|
||||
private Vector3f position;
|
||||
private float rotX = 0,rotY = 0,rotZ = 0;
|
||||
private Vector3f scale;
|
||||
public Entity(TexturedModel model, Vector3f position, float rotX, float rotY, float rotZ, Vector3f scale) {
|
||||
this.model = model;
|
||||
this.position = position;
|
||||
this.rotX = rotX;
|
||||
this.rotY = rotY;
|
||||
this.rotZ = rotZ;
|
||||
this.scale = scale;
|
||||
}
|
||||
public void increasePosition(float dx, float dy, float dz) {
|
||||
this.position.x += dx;
|
||||
this.position.y += dy;
|
||||
this.position.z += dz;
|
||||
}
|
||||
|
||||
public void increaseRotation(float dx, float dy, float dz) {
|
||||
this.rotX += dx;
|
||||
this.rotY += dy;
|
||||
this.rotZ += dz;
|
||||
}
|
||||
|
||||
public TexturedModel getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public void setModel(TexturedModel model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public Vector3f getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(Vector3f position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public float getRotX() {
|
||||
return rotX;
|
||||
}
|
||||
|
||||
public void setRotX(float rotX) {
|
||||
this.rotX = rotX;
|
||||
}
|
||||
|
||||
public float getRotY() {
|
||||
return rotY;
|
||||
}
|
||||
|
||||
public void setRotY(float rotY) {
|
||||
this.rotY = rotY;
|
||||
}
|
||||
|
||||
public float getRotZ() {
|
||||
return rotZ;
|
||||
}
|
||||
|
||||
public void setRotZ(float rotZ) {
|
||||
this.rotZ = rotZ;
|
||||
}
|
||||
|
||||
public Vector3f getScale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
public void setScale(Vector3f scale) {
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package io.github.hydos.ginger.elements;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import io.github.hydos.ginger.io.Window;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
|
||||
public class FirstPersonCamera {
|
||||
|
||||
private Vector3f position = new Vector3f(0,0,0);
|
||||
private float pitch, yaw;
|
||||
private float roll;
|
||||
|
||||
|
||||
public FirstPersonCamera() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public FirstPersonCamera(Vector3f vector3f) {
|
||||
this.position = vector3f;
|
||||
}
|
||||
|
||||
public void move() {
|
||||
if(Window.isKeyDown(GLFW.GLFW_KEY_W)){
|
||||
position.z-=0.05f;
|
||||
}
|
||||
if(Window.isKeyDown(GLFW.GLFW_KEY_A)){
|
||||
position.x-=0.05f;
|
||||
}
|
||||
if(Window.isKeyDown(GLFW.GLFW_KEY_S)){
|
||||
position.z-=-0.05f;
|
||||
}
|
||||
if(Window.isKeyDown(GLFW.GLFW_KEY_D)){
|
||||
position.x+=0.05f;
|
||||
}
|
||||
if(Window.isKeyDown(GLFW.GLFW_KEY_SPACE)){
|
||||
position.y+=0.05f;
|
||||
}
|
||||
if(Window.isKeyDown(GLFW.GLFW_KEY_LEFT_SHIFT)){
|
||||
position.y-=0.05f;
|
||||
}
|
||||
|
||||
if(Window.isKeyDown(GLFW.GLFW_KEY_LEFT)){
|
||||
yaw-=0.5f;
|
||||
}
|
||||
if(Window.isKeyDown(GLFW.GLFW_KEY_RIGHT)){
|
||||
yaw+=0.5f;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public Vector3f getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
|
||||
public float getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
|
||||
public float getRoll() {
|
||||
return roll;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package io.github.hydos.ginger.elements;
|
||||
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
|
||||
public class Light {
|
||||
|
||||
private Vector3f position, colour, attenuation;
|
||||
|
||||
public Light(Vector3f position, Vector3f colour) {
|
||||
this.position = position;
|
||||
this.colour = colour;
|
||||
}
|
||||
|
||||
public Light(Vector3f position, Vector3f colour, Vector3f attenuation) {
|
||||
this.position = position;
|
||||
this.colour = colour;
|
||||
this.attenuation = attenuation;
|
||||
}
|
||||
|
||||
public void setAttenuation(Vector3f a) {
|
||||
this.attenuation = a;
|
||||
}
|
||||
|
||||
public Vector3f getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public Vector3f getColour() {
|
||||
return colour;
|
||||
}
|
||||
|
||||
public void setPosition(Vector3f position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public void setColour(Vector3f colour) {
|
||||
this.colour = colour;
|
||||
}
|
||||
|
||||
public Vector3f getAttenuation() {
|
||||
return attenuation;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package io.github.hydos.ginger.elements;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import io.github.hydos.ginger.io.Window;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
import io.github.hydos.ginger.renderEngine.models.TexturedModel;
|
||||
import io.github.hydos.ginger.terrain.Terrain;
|
||||
|
||||
public class Player extends Entity{
|
||||
|
||||
private static final float RUN_SPEED = 0.3f;
|
||||
private static final float TURN_SPEED = 3f;
|
||||
private static final float GRAVITY = -0.04f;
|
||||
private static final float JUMP_POWER = 0.3f;
|
||||
|
||||
private static float terrainHeight = 0;
|
||||
|
||||
|
||||
private float currentSpeed = 0;
|
||||
private float currentTurn = 0;
|
||||
private float upwardsSpeed = 0;
|
||||
|
||||
private boolean isInAir = false;
|
||||
|
||||
public Player(TexturedModel model, Vector3f position, float rotX, float rotY, float rotZ, Vector3f scale) {
|
||||
super(model, position, rotX, rotY, rotZ, scale);
|
||||
}
|
||||
|
||||
public void move(Terrain t) {
|
||||
|
||||
checkInputs();
|
||||
super.increaseRotation(0, (float) ((currentTurn / 1000000) * Window.getTime()), 0);
|
||||
float distance = (currentSpeed / 1000000) * Window.getFloatTime();
|
||||
float dx = (float) (distance * Math.sin(Math.toRadians(super.getRotY())));
|
||||
float dz = (float) (distance * Math.cos(Math.toRadians(super.getRotY())));
|
||||
super.increasePosition(dx, 0, dz);
|
||||
super.increasePosition(0, (float) (upwardsSpeed * (Window.getTime() / 1000000)), 0);
|
||||
terrainHeight = t.getHeightOfTerrain(super.getPosition().x, super.getPosition().z);
|
||||
upwardsSpeed += GRAVITY * Window.getTime() / 1000000;
|
||||
if(super.getPosition().y < terrainHeight) {
|
||||
isInAir = false;
|
||||
upwardsSpeed = 0;
|
||||
super.getPosition().y = terrainHeight;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void jump() {
|
||||
if(!isInAir) {
|
||||
isInAir = true;
|
||||
this.upwardsSpeed = JUMP_POWER;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkInputs() {
|
||||
if(Window.isKeyDown(GLFW.GLFW_KEY_W)) {
|
||||
this.currentSpeed = RUN_SPEED;
|
||||
}
|
||||
else if(Window.isKeyDown(GLFW.GLFW_KEY_S)) {
|
||||
this.currentSpeed = -RUN_SPEED;
|
||||
}else {
|
||||
this.currentSpeed = 0;
|
||||
}
|
||||
|
||||
if(Window.isKeyDown(GLFW.GLFW_KEY_A)) {
|
||||
this.currentTurn = TURN_SPEED;
|
||||
|
||||
}
|
||||
else if(Window.isKeyDown(GLFW.GLFW_KEY_D)) {
|
||||
this.currentTurn = -TURN_SPEED;
|
||||
}
|
||||
if(Window.isKeyReleased(68) || Window.isKeyReleased(65)){
|
||||
this.currentTurn = 0;
|
||||
}
|
||||
|
||||
if(Window.isKeyDown(GLFW.GLFW_KEY_SPACE)) {
|
||||
jump();
|
||||
}else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
package io.github.hydos.ginger.elements;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.glfw.GLFWScrollCallback;
|
||||
|
||||
import io.github.hydos.ginger.io.Window;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
|
||||
public class ThirdPersonCamera {
|
||||
|
||||
private float distanceFromPlayer = 5;
|
||||
private float angleAroundPlayer = 0;
|
||||
|
||||
|
||||
private Vector3f position = new Vector3f(0,0,0);
|
||||
private float pitch, yaw;
|
||||
private float roll;
|
||||
|
||||
|
||||
private Player player;
|
||||
|
||||
|
||||
public ThirdPersonCamera(Player player) {
|
||||
this.player = player;
|
||||
|
||||
}
|
||||
|
||||
public ThirdPersonCamera(Vector3f vector3f, Player player) {
|
||||
this.position = vector3f;
|
||||
this.player = player;
|
||||
|
||||
}
|
||||
|
||||
public void move() {
|
||||
calculateZoom();
|
||||
calculatePitch();
|
||||
calculateAngleAroundPlayer();
|
||||
float hori = calculateHorizontalDistance();
|
||||
float vert = calculateVerticalDistance();
|
||||
calculateCameraPosition(hori, vert);
|
||||
this.yaw = 180 - (player.getRotY() + angleAroundPlayer);
|
||||
}
|
||||
|
||||
public Vector3f getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
|
||||
public float getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
|
||||
public float getRoll() {
|
||||
return roll;
|
||||
}
|
||||
|
||||
private void calculateZoom() {
|
||||
|
||||
GLFW.glfwSetScrollCallback(Window.window, new GLFWScrollCallback() {
|
||||
@Override public void invoke (long win, double dx, double dy) {
|
||||
float zoomLevel = (float) dy * 0.1f;
|
||||
distanceFromPlayer -= zoomLevel;
|
||||
}
|
||||
}); }
|
||||
|
||||
private void calculatePitch() {
|
||||
if(Window.isMouseDown(1)) {
|
||||
float pitchChange = (float) (Window.getDY() * 0.1f);
|
||||
pitch += pitchChange;
|
||||
if(pitch < 0)
|
||||
pitch = 0;
|
||||
else if(pitch > 90)
|
||||
pitch = 90;
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateAngleAroundPlayer() {
|
||||
if(Window.isMouseDown(1)) {
|
||||
float angleChange = (float) (Window.getDX() * 0.3f);
|
||||
angleAroundPlayer =- angleChange;
|
||||
}
|
||||
}
|
||||
|
||||
private float calculateHorizontalDistance() {
|
||||
return (float) (distanceFromPlayer * Math.cos(Math.toRadians(pitch)));
|
||||
}
|
||||
|
||||
private float calculateVerticalDistance(){
|
||||
float vD = (float) (distanceFromPlayer * Math.sin(Math.toRadians(pitch)));
|
||||
if(vD < 0.1f)
|
||||
vD = 0.1f;
|
||||
return vD;
|
||||
}
|
||||
|
||||
|
||||
public void calculateCameraPosition(float horizDistance, float verticDistance) {
|
||||
float theta = player.getRotY() + angleAroundPlayer;
|
||||
float offsetX = (float) (horizDistance * Math.sin(Math.toRadians(theta)));
|
||||
float offsetZ = (float) (horizDistance * Math.cos(Math.toRadians(theta)));
|
||||
position.y = player.getPosition().y + verticDistance;
|
||||
position.x = player.getPosition().x - offsetX;
|
||||
position.z = player.getPosition().z - offsetZ;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package io.github.hydos.ginger.guis;
|
||||
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector2f;
|
||||
|
||||
public class GuiTexture {
|
||||
|
||||
private int texture;
|
||||
private Vector2f position, scale;
|
||||
|
||||
public GuiTexture(int texture, Vector2f position, Vector2f scale) {
|
||||
this.texture = texture;
|
||||
this.position = position;
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
public int getTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
||||
public Vector2f getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public Vector2f getScale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
public void setTexture(int texture) {
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
public void setPosition(Vector2f position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public void setScale(Vector2f scale) {
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,284 @@
|
|||
package io.github.hydos.ginger.io;
|
||||
|
||||
|
||||
import java.nio.DoubleBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.glfw.GLFWImage;
|
||||
import org.lwjgl.glfw.GLFWVidMode;
|
||||
import org.lwjgl.opengl.GL;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
import io.github.hydos.ginger.renderEngine.texture.Image;
|
||||
|
||||
public class Window {
|
||||
|
||||
public static int width;
|
||||
public static int height;
|
||||
private static String title;
|
||||
public static long window;
|
||||
private static Vector3f backgroundColour = new Vector3f(0.2f,0.2f,0.4f);
|
||||
private static boolean[] keys = new boolean[GLFW.GLFW_KEY_LAST];
|
||||
private static boolean[] mouseButtons = new boolean[GLFW.GLFW_MOUSE_BUTTON_LAST];
|
||||
private static GLFWImage.Buffer iconBuffer = null;
|
||||
private static GLFWImage cursorBuffer = null;
|
||||
private static double fpsCap, time, processedTime = 0;
|
||||
private static boolean isFullscreen = false;
|
||||
private static double dy = 0;
|
||||
private static double dx = 0;
|
||||
static double oldX = 0;
|
||||
static double oldY = 0;
|
||||
static double newX = 0;
|
||||
static double newY = 0;
|
||||
// // Mouse positions
|
||||
// private static int mouseX, mouseY;
|
||||
// private static int mouseDX, mouseDY;
|
||||
private static boolean mouseLocked = false;
|
||||
|
||||
public static void create(int width, int height, String title, int fps) {
|
||||
Window.width = width;
|
||||
Window.height = height;
|
||||
Window.title = title;
|
||||
fpsCap = fps;
|
||||
create();
|
||||
}
|
||||
|
||||
public static void create() {
|
||||
if(!GLFW.glfwInit()) {
|
||||
System.err.println("Error: Couldn't initialize GLFW");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);
|
||||
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE);
|
||||
|
||||
GLFWVidMode vidmode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
|
||||
|
||||
if(!isFullscreen) {
|
||||
window = GLFW.glfwCreateWindow(width, height, title, (isFullscreen) ? GLFW.glfwGetPrimaryMonitor() : 0, window);
|
||||
}else {
|
||||
window = GLFW.glfwCreateWindow(vidmode.width(), vidmode.height(), title, (isFullscreen) ? GLFW.glfwGetPrimaryMonitor() : 0, window);
|
||||
}
|
||||
if(window == 0) {
|
||||
System.err.println("Error: Couldnt initilize window");
|
||||
System.exit(-1);
|
||||
|
||||
}
|
||||
|
||||
GLFW.glfwMakeContextCurrent(window);
|
||||
GL.createCapabilities();
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
|
||||
GLFW.glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
|
||||
|
||||
|
||||
GLFW.glfwShowWindow(window);
|
||||
|
||||
time = getTime();
|
||||
getCurrentTime();
|
||||
|
||||
}
|
||||
|
||||
public static boolean closed() {
|
||||
return GLFW.glfwWindowShouldClose(window);
|
||||
}
|
||||
|
||||
public static void update() {
|
||||
for(int i = 0; i < GLFW.GLFW_KEY_LAST; i++) keys[i] = isKeyDown(i);
|
||||
for(int i = 0; i < GLFW.GLFW_MOUSE_BUTTON_LAST; i++) mouseButtons[i] = isMouseDown(i);
|
||||
IntBuffer widthBuffer = BufferUtils.createIntBuffer(1);
|
||||
IntBuffer heightBuffer = BufferUtils.createIntBuffer(1);
|
||||
GLFW.glfwGetWindowSize(window, widthBuffer, heightBuffer);
|
||||
width = widthBuffer.get(0);
|
||||
height = heightBuffer.get(0);
|
||||
GL11.glViewport(0, 0, width, height);
|
||||
GL11.glClearColor(backgroundColour.x, backgroundColour.y, backgroundColour.z, 1.0f);
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
|
||||
GLFW.glfwPollEvents();
|
||||
|
||||
newX = Window.getMouseX();
|
||||
newY = Window.getMouseY();
|
||||
|
||||
Window.dx = newX - oldX;
|
||||
Window.dy = newY - oldY;
|
||||
|
||||
oldX = newX;
|
||||
oldY = newY;
|
||||
// DoubleBuffer x = BufferUtils.createDoubleBuffer(1);
|
||||
// DoubleBuffer y = BufferUtils.createDoubleBuffer(1);
|
||||
//
|
||||
// GLFW.glfwGetCursorPos(window, x, y);
|
||||
// x.rewind();
|
||||
// y.rewind();
|
||||
//
|
||||
// newX = (float) x.get();
|
||||
// newY = (float) y.get();
|
||||
//
|
||||
// float deltaX = newX - oldX;
|
||||
// float deltaY = newY - oldY;
|
||||
// Window.dx = deltaX;
|
||||
// Window.dy = deltaY;
|
||||
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static float getFrameTimeSeconds() {
|
||||
return (float) Window.getTime();
|
||||
}
|
||||
|
||||
public static void swapBuffers() {
|
||||
GLFW.glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
public static boolean isKeyDown(int keycode) {
|
||||
return GLFW.glfwGetKey(window, keycode) == 1;
|
||||
}
|
||||
|
||||
public static boolean isMouseDown(int mouseButton) {
|
||||
return GLFW.glfwGetMouseButton(window, mouseButton) == 1;
|
||||
}
|
||||
|
||||
public static boolean isKeyPressed(int keyCode) {
|
||||
return isKeyDown(keyCode) && !keys[keyCode];
|
||||
}
|
||||
|
||||
public static boolean isKeyReleased(int keyCode) {
|
||||
return !isKeyDown(keyCode) && keys[keyCode];
|
||||
}
|
||||
|
||||
public static boolean isMousePressed(int keyCode) {
|
||||
return isMouseDown(keyCode) && !mouseButtons[keyCode];
|
||||
}
|
||||
|
||||
public static boolean isMouseReleased(int keyCode) {
|
||||
return !isMouseDown(keyCode) && mouseButtons[keyCode];
|
||||
}
|
||||
|
||||
public static double getMouseX() {
|
||||
DoubleBuffer buffer = BufferUtils.createDoubleBuffer(1);
|
||||
GLFW.glfwGetCursorPos(window, buffer, null);
|
||||
return buffer.get(0);
|
||||
}
|
||||
|
||||
public static double getMouseY() {
|
||||
DoubleBuffer buffer = BufferUtils.createDoubleBuffer(1);
|
||||
GLFW.glfwGetCursorPos(window, null, buffer);
|
||||
return buffer.get(0);
|
||||
}
|
||||
|
||||
public static double getTime() {
|
||||
double f = (double) System.nanoTime() / (double) 1000000000;
|
||||
return f;
|
||||
}
|
||||
|
||||
public static float getFloatTime() {
|
||||
float f = (System.nanoTime() / (float) 1000000000);
|
||||
return f;
|
||||
}
|
||||
|
||||
public static boolean isUpdating() {
|
||||
double nextTime = getTime();
|
||||
double passedTime = nextTime - time;
|
||||
processedTime += passedTime;
|
||||
time = nextTime;
|
||||
|
||||
while (processedTime > 1.0/fpsCap) {
|
||||
processedTime -= 1.0/fpsCap;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void stop() {
|
||||
GLFW.glfwTerminate();
|
||||
}
|
||||
|
||||
public static void setBackgroundColour(float r, float g, float b) {
|
||||
backgroundColour = new Vector3f(r,g,b);
|
||||
}
|
||||
|
||||
public static void setIcon(String path) {
|
||||
Image icon = Image.createImage("/res/textures/" + path);
|
||||
GLFWImage iconImage = GLFWImage.malloc();
|
||||
iconBuffer = GLFWImage.malloc(1);
|
||||
iconImage.set(icon.getWidth(), icon.getHeight(), icon.getImage());
|
||||
iconBuffer.put(0, iconImage);
|
||||
}
|
||||
|
||||
public void setCursor(String path) {
|
||||
Image cursor = Image.createImage("/res/textures/" + path);
|
||||
cursorBuffer = GLFWImage.malloc();
|
||||
cursorBuffer.set(cursor.getWidth(), cursor.getHeight(), cursor.getImage());
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void showCursor() {
|
||||
if(iconBuffer != null) {
|
||||
long cursor = GLFW.glfwCreateCursor(cursorBuffer, 0, 0);
|
||||
GLFW.glfwSetCursor(window, cursor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void showIcon() {
|
||||
if(iconBuffer != null) {
|
||||
GLFW.glfwSetWindowIcon(window, iconBuffer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setFullscreen(boolean t) {
|
||||
Window.isFullscreen = t;
|
||||
}
|
||||
|
||||
public boolean isFullscreen() {
|
||||
return Window.isFullscreen;
|
||||
}
|
||||
|
||||
public void lockMouse() {
|
||||
GLFW.glfwSetInputMode(window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_DISABLED);
|
||||
mouseLocked = true;
|
||||
}
|
||||
|
||||
public void unlockMouse() {
|
||||
GLFW.glfwSetInputMode(window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_NORMAL);
|
||||
mouseLocked = false;
|
||||
}
|
||||
|
||||
public void toggleMouseLock() {
|
||||
if(mouseLocked) {
|
||||
unlockMouse();
|
||||
}else {
|
||||
lockMouse();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMouseLocked() {
|
||||
return mouseLocked;
|
||||
}
|
||||
|
||||
public static Vector3f getColour() {
|
||||
return Window.backgroundColour;
|
||||
}
|
||||
|
||||
private static long getCurrentTime() {
|
||||
return (long) (GLFW.glfwGetTime()*1000/GLFW.glfwGetTimerFrequency());
|
||||
}
|
||||
|
||||
public static double getDY() {
|
||||
return Window.dy;
|
||||
}
|
||||
|
||||
public static double getDX() {
|
||||
return Window.dx;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package io.github.hydos.ginger.mathEngine;
|
||||
|
||||
import io.github.hydos.ginger.elements.ThirdPersonCamera;
|
||||
import io.github.hydos.ginger.mathEngine.matrixes.Matrix4f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector2f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
|
||||
public class Maths {
|
||||
|
||||
public static Matrix4f createTransformationMatrix(Vector3f translation, float rx, float ry, float rz, Vector3f scale) {
|
||||
Matrix4f matrix = new Matrix4f();
|
||||
matrix.setIdentity();
|
||||
Matrix4f.translate(translation, matrix, matrix);
|
||||
Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1,0,0), matrix, matrix);
|
||||
Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0,1,0), matrix, matrix);
|
||||
Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0,0,1), matrix, matrix);
|
||||
Matrix4f.scale(scale, matrix, matrix);
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public static Matrix4f createViewMatrix(ThirdPersonCamera camera) {
|
||||
Matrix4f viewMatrix = new Matrix4f();
|
||||
viewMatrix.setIdentity();
|
||||
Matrix4f.rotate((float) Math.toRadians(camera.getPitch()), new Vector3f(1, 0, 0), viewMatrix, viewMatrix);
|
||||
Matrix4f.rotate((float) Math.toRadians(camera.getYaw()), new Vector3f(0, 1, 0), viewMatrix, viewMatrix);
|
||||
Matrix4f.rotate((float) Math.toRadians(camera.getRoll()), new Vector3f(0, 0, 1), viewMatrix, viewMatrix);
|
||||
Vector3f cameraPos = camera.getPosition();
|
||||
Vector3f negativeCameraPos = new Vector3f(-cameraPos.x,-cameraPos.y,-cameraPos.z);
|
||||
Matrix4f.translate(negativeCameraPos, viewMatrix, viewMatrix);
|
||||
return viewMatrix;
|
||||
}
|
||||
|
||||
public static float barryCentric(Vector3f p1, Vector3f p2, Vector3f p3, Vector2f pos) {
|
||||
float det = (p2.z - p3.z) * (p1.x - p3.x) + (p3.x - p2.x) * (p1.z - p3.z);
|
||||
float l1 = ((p2.z - p3.z) * (pos.x - p3.x) + (p3.x - p2.x) * (pos.y - p3.z)) / det;
|
||||
float l2 = ((p3.z - p1.z) * (pos.x - p3.x) + (p1.x - p3.x) * (pos.y - p3.z)) / det;
|
||||
float l3 = 1.0f - l1 - l2;
|
||||
return l1 * p1.y + l2 * p2.y + l3 * p3.y;
|
||||
}
|
||||
|
||||
public static Matrix4f createTransformationMatrix(Vector2f translation, Vector2f scale) {
|
||||
Matrix4f matrix = new Matrix4f();
|
||||
matrix.setIdentity();
|
||||
Matrix4f.translate(translation, matrix, matrix);
|
||||
Matrix4f.scale(new Vector3f(scale.x, scale.y, 1f), matrix, matrix);
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public static Matrix4f createTransformationMatrix(Vector3f translation, float rx, float ry, float rz, float scale) {
|
||||
Matrix4f matrix = new Matrix4f();
|
||||
matrix.setIdentity();
|
||||
Matrix4f.translate(translation, matrix, matrix);
|
||||
Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1,0,0), matrix, matrix);
|
||||
Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0,1,0), matrix, matrix);
|
||||
Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0,0,1), matrix, matrix);
|
||||
Vector3f newScale = new Vector3f(scale,scale,scale);
|
||||
Matrix4f.scale(newScale, matrix, matrix);
|
||||
return matrix;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,546 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package io.github.hydos.ginger.mathEngine;
|
||||
|
||||
/**
|
||||
*
|
||||
* Quaternions for LWJGL!
|
||||
*
|
||||
* @author fbi
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import io.github.hydos.ginger.mathEngine.matrixes.Matrix3f;
|
||||
import io.github.hydos.ginger.mathEngine.matrixes.Matrix4f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.ReadableVector4f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector4f;
|
||||
|
||||
public class Quaternion extends Vector implements ReadableVector4f {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float x, y, z, w;
|
||||
|
||||
/**
|
||||
* C'tor. The quaternion will be initialized to the identity.
|
||||
*/
|
||||
public Quaternion() {
|
||||
super();
|
||||
setIdentity();
|
||||
}
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
*
|
||||
* @param src
|
||||
*/
|
||||
public Quaternion(ReadableVector4f src) {
|
||||
set(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* C'tor
|
||||
*
|
||||
*/
|
||||
public Quaternion(float x, float y, float z, float w) {
|
||||
set(x, y, z, w);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
|
||||
*/
|
||||
public void set(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float)
|
||||
*/
|
||||
public void set(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.util.vector.WritableVector4f#set(float, float, float,
|
||||
* float)
|
||||
*/
|
||||
public void set(float x, float y, float z, float w) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another Vector4f
|
||||
*
|
||||
* @param src
|
||||
* The source vector
|
||||
* @return this
|
||||
*/
|
||||
public Quaternion set(ReadableVector4f src) {
|
||||
x = src.getX();
|
||||
y = src.getY();
|
||||
z = src.getZ();
|
||||
w = src.getW();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this quaternion to the multiplication identity.
|
||||
* @return this
|
||||
*/
|
||||
public Quaternion setIdentity() {
|
||||
return setIdentity(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the given quaternion to the multiplication identity.
|
||||
* @param q The quaternion
|
||||
* @return q
|
||||
*/
|
||||
public static Quaternion setIdentity(Quaternion q) {
|
||||
q.x = 0;
|
||||
q.y = 0;
|
||||
q.z = 0;
|
||||
q.w = 1;
|
||||
return q;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length squared of the quaternion
|
||||
*/
|
||||
@Override
|
||||
public float lengthSquared() {
|
||||
return x * x + y * y + z * z + w * w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise the source quaternion and place the result in another quaternion.
|
||||
*
|
||||
* @param src
|
||||
* The source quaternion
|
||||
* @param dest
|
||||
* The destination quaternion, or null if a new quaternion is to be
|
||||
* created
|
||||
* @return The normalised quaternion
|
||||
*/
|
||||
public static Quaternion normalise(Quaternion src, Quaternion dest) {
|
||||
float inv_l = 1f/src.length();
|
||||
|
||||
if (dest == null)
|
||||
dest = new Quaternion();
|
||||
|
||||
dest.set(src.x * inv_l, src.y * inv_l, src.z * inv_l, src.w * inv_l);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise this quaternion and place the result in another quaternion.
|
||||
*
|
||||
* @param dest
|
||||
* The destination quaternion, or null if a new quaternion is to be
|
||||
* created
|
||||
* @return the normalised quaternion
|
||||
*/
|
||||
public Quaternion normalise(Quaternion dest) {
|
||||
return normalise(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* The dot product of two quaternions
|
||||
*
|
||||
* @param left
|
||||
* The LHS quat
|
||||
* @param right
|
||||
* The RHS quat
|
||||
* @return left dot right
|
||||
*/
|
||||
public static float dot(Quaternion left, Quaternion right) {
|
||||
return left.x * right.x + left.y * right.y + left.z * right.z + left.w
|
||||
* right.w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the conjugate of this quaternion and put it into the given one
|
||||
*
|
||||
* @param dest
|
||||
* The quaternion which should be set to the conjugate of this
|
||||
* quaternion
|
||||
*/
|
||||
public Quaternion negate(Quaternion dest) {
|
||||
return negate(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the conjugate of this quaternion and put it into the given one
|
||||
*
|
||||
* @param src
|
||||
* The source quaternion
|
||||
* @param dest
|
||||
* The quaternion which should be set to the conjugate of this
|
||||
* quaternion
|
||||
*/
|
||||
public static Quaternion negate(Quaternion src, Quaternion dest) {
|
||||
if (dest == null)
|
||||
dest = new Quaternion();
|
||||
|
||||
dest.x = -src.x;
|
||||
dest.y = -src.y;
|
||||
dest.z = -src.z;
|
||||
dest.w = src.w;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the conjugate of this quaternion
|
||||
*/
|
||||
@Override
|
||||
public Vector negate() {
|
||||
return negate(this, this);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.util.vector.Vector#load(java.nio.FloatBuffer)
|
||||
*/
|
||||
@Override
|
||||
public Vector load(FloatBuffer buf) {
|
||||
x = buf.get();
|
||||
y = buf.get();
|
||||
z = buf.get();
|
||||
w = buf.get();
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.lwjgl.vector.Vector#scale(float)
|
||||
*/
|
||||
@Override
|
||||
public Vector scale(float scale) {
|
||||
return scale(scale, this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scale the source quaternion by scale and put the result in the destination
|
||||
* @param scale The amount to scale by
|
||||
* @param src The source quaternion
|
||||
* @param dest The destination quaternion, or null if a new quaternion is to be created
|
||||
* @return The scaled quaternion
|
||||
*/
|
||||
public static Quaternion scale(float scale, Quaternion src, Quaternion dest) {
|
||||
if (dest == null)
|
||||
dest = new Quaternion();
|
||||
dest.x = src.x * scale;
|
||||
dest.y = src.y * scale;
|
||||
dest.z = src.z * scale;
|
||||
dest.w = src.w * scale;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.util.vector.ReadableVector#store(java.nio.FloatBuffer)
|
||||
*/
|
||||
@Override
|
||||
public Vector store(FloatBuffer buf) {
|
||||
buf.put(x);
|
||||
buf.put(y);
|
||||
buf.put(z);
|
||||
buf.put(w);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return x
|
||||
*/
|
||||
@Override
|
||||
public final float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return y
|
||||
*/
|
||||
@Override
|
||||
public final float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X
|
||||
*
|
||||
* @param x
|
||||
*/
|
||||
public final void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Y
|
||||
*
|
||||
* @param y
|
||||
*/
|
||||
public final void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Z
|
||||
*
|
||||
* @param z
|
||||
*/
|
||||
public void setZ(float z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/*
|
||||
* (Overrides)
|
||||
*
|
||||
* @see org.lwjgl.vector.ReadableVector3f#getZ()
|
||||
*/
|
||||
@Override
|
||||
public float getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set W
|
||||
*
|
||||
* @param w
|
||||
*/
|
||||
public void setW(float w) {
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/*
|
||||
* (Overrides)
|
||||
*
|
||||
* @see org.lwjgl.vector.ReadableVector3f#getW()
|
||||
*/
|
||||
@Override
|
||||
public float getW() {
|
||||
return w;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Quaternion: " + x + " " + y + " " + z + " " + w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of this quaternion to the quaternion product of
|
||||
* quaternions left and right (this = left * right). Note that this is safe
|
||||
* for aliasing (e.g. this can be left or right).
|
||||
*
|
||||
* @param left
|
||||
* the first quaternion
|
||||
* @param right
|
||||
* the second quaternion
|
||||
*/
|
||||
public static Quaternion mul(Quaternion left, Quaternion right,
|
||||
Quaternion dest) {
|
||||
if (dest == null)
|
||||
dest = new Quaternion();
|
||||
dest.set(left.x * right.w + left.w * right.x + left.y * right.z
|
||||
- left.z * right.y, left.y * right.w + left.w * right.y
|
||||
+ left.z * right.x - left.x * right.z, left.z * right.w
|
||||
+ left.w * right.z + left.x * right.y - left.y * right.x,
|
||||
left.w * right.w - left.x * right.x - left.y * right.y
|
||||
- left.z * right.z);
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Multiplies quaternion left by the inverse of quaternion right and places
|
||||
* the value into this quaternion. The value of both argument quaternions is
|
||||
* preservered (this = left * right^-1).
|
||||
*
|
||||
* @param left
|
||||
* the left quaternion
|
||||
* @param right
|
||||
* the right quaternion
|
||||
*/
|
||||
public static Quaternion mulInverse(Quaternion left, Quaternion right,
|
||||
Quaternion dest) {
|
||||
float n = right.lengthSquared();
|
||||
// zero-div may occur.
|
||||
n = (n == 0.0 ? n : 1 / n);
|
||||
// store on stack once for aliasing-safty
|
||||
if (dest == null)
|
||||
dest = new Quaternion();
|
||||
dest
|
||||
.set((left.x * right.w - left.w * right.x - left.y
|
||||
* right.z + left.z * right.y)
|
||||
* n, (left.y * right.w - left.w * right.y - left.z
|
||||
* right.x + left.x * right.z)
|
||||
* n, (left.z * right.w - left.w * right.z - left.x
|
||||
* right.y + left.y * right.x)
|
||||
* n, (left.w * right.w + left.x * right.x + left.y
|
||||
* right.y + left.z * right.z)
|
||||
* n);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of this quaternion to the equivalent rotation of the
|
||||
* Axis-Angle argument.
|
||||
*
|
||||
* @param a1
|
||||
* the axis-angle: (x,y,z) is the axis and w is the angle
|
||||
*/
|
||||
public final void setFromAxisAngle(Vector4f a1) {
|
||||
x = a1.x;
|
||||
y = a1.y;
|
||||
z = a1.z;
|
||||
float n = (float) Math.sqrt(x * x + y * y + z * z);
|
||||
// zero-div may occur.
|
||||
float s = (float) (Math.sin(0.5 * a1.w) / n);
|
||||
x *= s;
|
||||
y *= s;
|
||||
z *= s;
|
||||
w = (float) Math.cos(0.5 * a1.w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of this quaternion using the rotational component of the
|
||||
* passed matrix.
|
||||
*
|
||||
* @param m
|
||||
* The matrix
|
||||
* @return this
|
||||
*/
|
||||
public final Quaternion setFromMatrix(Matrix4f m) {
|
||||
return setFromMatrix(m, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the source quaternion using the rotational component of the
|
||||
* passed matrix.
|
||||
*
|
||||
* @param m
|
||||
* The source matrix
|
||||
* @param q
|
||||
* The destination quaternion, or null if a new quaternion is to be created
|
||||
* @return q
|
||||
*/
|
||||
public static Quaternion setFromMatrix(Matrix4f m, Quaternion q) {
|
||||
return q.setFromMat(m.m00, m.m01, m.m02, m.m10, m.m11, m.m12, m.m20,
|
||||
m.m21, m.m22);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of this quaternion using the rotational component of the
|
||||
* passed matrix.
|
||||
*
|
||||
* @param m
|
||||
* The source matrix
|
||||
*/
|
||||
public final Quaternion setFromMatrix(Matrix3f m) {
|
||||
return setFromMatrix(m, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the source quaternion using the rotational component of the
|
||||
* passed matrix.
|
||||
*
|
||||
* @param m
|
||||
* The source matrix
|
||||
* @param q
|
||||
* The destination quaternion, or null if a new quaternion is to be created
|
||||
* @return q
|
||||
*/
|
||||
public static Quaternion setFromMatrix(Matrix3f m, Quaternion q) {
|
||||
return q.setFromMat(m.m00, m.m01, m.m02, m.m10, m.m11, m.m12, m.m20,
|
||||
m.m21, m.m22);
|
||||
}
|
||||
|
||||
/**
|
||||
* Private method to perform the matrix-to-quaternion conversion
|
||||
*/
|
||||
private Quaternion setFromMat(float m00, float m01, float m02, float m10,
|
||||
float m11, float m12, float m20, float m21, float m22) {
|
||||
|
||||
float s;
|
||||
float tr = m00 + m11 + m22;
|
||||
if (tr >= 0.0) {
|
||||
s = (float) Math.sqrt(tr + 1.0);
|
||||
w = s * 0.5f;
|
||||
s = 0.5f / s;
|
||||
x = (m21 - m12) * s;
|
||||
y = (m02 - m20) * s;
|
||||
z = (m10 - m01) * s;
|
||||
} else {
|
||||
float max = Math.max(Math.max(m00, m11), m22);
|
||||
if (max == m00) {
|
||||
s = (float) Math.sqrt(m00 - (m11 + m22) + 1.0);
|
||||
x = s * 0.5f;
|
||||
s = 0.5f / s;
|
||||
y = (m01 + m10) * s;
|
||||
z = (m20 + m02) * s;
|
||||
w = (m21 - m12) * s;
|
||||
} else if (max == m11) {
|
||||
s = (float) Math.sqrt(m11 - (m22 + m00) + 1.0);
|
||||
y = s * 0.5f;
|
||||
s = 0.5f / s;
|
||||
z = (m12 + m21) * s;
|
||||
x = (m01 + m10) * s;
|
||||
w = (m02 - m20) * s;
|
||||
} else {
|
||||
s = (float) Math.sqrt(m22 - (m00 + m11) + 1.0);
|
||||
z = s * 0.5f;
|
||||
s = 0.5f / s;
|
||||
x = (m20 + m02) * s;
|
||||
y = (m12 + m21) * s;
|
||||
w = (m10 - m01) * s;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package io.github.hydos.ginger.mathEngine.matrixes;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Base class for matrices. When a matrix is constructed it will be the identity
|
||||
* matrix unless otherwise stated.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public abstract class Matrix implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for Matrix.
|
||||
*/
|
||||
protected Matrix() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this matrix to be the identity matrix.
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix setIdentity();
|
||||
|
||||
|
||||
/**
|
||||
* Invert this matrix
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix invert();
|
||||
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in column major
|
||||
* (OpenGL) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix load(FloatBuffer buf);
|
||||
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in row major
|
||||
* (mathematical) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix loadTranspose(FloatBuffer buf);
|
||||
|
||||
|
||||
/**
|
||||
* Negate this matrix
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix negate();
|
||||
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in column
|
||||
* major (openGL) order.
|
||||
* @param buf The buffer to store this matrix in
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix store(FloatBuffer buf);
|
||||
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in row
|
||||
* major (maths) order.
|
||||
* @param buf The buffer to store this matrix in
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix storeTranspose(FloatBuffer buf);
|
||||
|
||||
|
||||
/**
|
||||
* Transpose this matrix
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix transpose();
|
||||
|
||||
|
||||
/**
|
||||
* Set this matrix to 0.
|
||||
* @return this
|
||||
*/
|
||||
public abstract Matrix setZero();
|
||||
|
||||
|
||||
/**
|
||||
* @return the determinant of the matrix
|
||||
*/
|
||||
public abstract float determinant();
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,413 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package io.github.hydos.ginger.mathEngine.matrixes;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector2f;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds a 2x2 matrix
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
public class Matrix2f extends Matrix implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float m00, m01, m10, m11;
|
||||
|
||||
/**
|
||||
* Constructor for Matrix2f. The matrix is initialised to the identity.
|
||||
*/
|
||||
public Matrix2f() {
|
||||
setIdentity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Matrix2f(Matrix2f src) {
|
||||
load(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another matrix
|
||||
* @param src The source matrix
|
||||
* @return this
|
||||
*/
|
||||
public Matrix2f load(Matrix2f src) {
|
||||
return load(src, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the source matrix to the destination matrix.
|
||||
* @param src The source matrix
|
||||
* @param dest The destination matrix, or null if a new one should be created.
|
||||
* @return The copied matrix
|
||||
*/
|
||||
public static Matrix2f load(Matrix2f src, Matrix2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
|
||||
dest.m00 = src.m00;
|
||||
dest.m01 = src.m01;
|
||||
dest.m10 = src.m10;
|
||||
dest.m11 = src.m11;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in column major
|
||||
* (OpenGL) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Matrix load(FloatBuffer buf) {
|
||||
|
||||
m00 = buf.get();
|
||||
m01 = buf.get();
|
||||
m10 = buf.get();
|
||||
m11 = buf.get();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in row major
|
||||
* (mathematical) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Matrix loadTranspose(FloatBuffer buf) {
|
||||
|
||||
m00 = buf.get();
|
||||
m10 = buf.get();
|
||||
m01 = buf.get();
|
||||
m11 = buf.get();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in column
|
||||
* major (openGL) order.
|
||||
* @param buf The buffer to store this matrix in
|
||||
*/
|
||||
@Override
|
||||
public Matrix store(FloatBuffer buf) {
|
||||
buf.put(m00);
|
||||
buf.put(m01);
|
||||
buf.put(m10);
|
||||
buf.put(m11);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in row
|
||||
* major (maths) order.
|
||||
* @param buf The buffer to store this matrix in
|
||||
*/
|
||||
@Override
|
||||
public Matrix storeTranspose(FloatBuffer buf) {
|
||||
buf.put(m00);
|
||||
buf.put(m10);
|
||||
buf.put(m01);
|
||||
buf.put(m11);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Add two matrices together and place the result in a third matrix.
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix2f add(Matrix2f left, Matrix2f right, Matrix2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
|
||||
dest.m00 = left.m00 + right.m00;
|
||||
dest.m01 = left.m01 + right.m01;
|
||||
dest.m10 = left.m10 + right.m10;
|
||||
dest.m11 = left.m11 + right.m11;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract the right matrix from the left and place the result in a third matrix.
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix2f sub(Matrix2f left, Matrix2f right, Matrix2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
|
||||
dest.m00 = left.m00 - right.m00;
|
||||
dest.m01 = left.m01 - right.m01;
|
||||
dest.m10 = left.m10 - right.m10;
|
||||
dest.m11 = left.m11 - right.m11;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply the right matrix by the left and place the result in a third matrix.
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix2f mul(Matrix2f left, Matrix2f right, Matrix2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
|
||||
float m00 = left.m00 * right.m00 + left.m10 * right.m01;
|
||||
float m01 = left.m01 * right.m00 + left.m11 * right.m01;
|
||||
float m10 = left.m00 * right.m10 + left.m10 * right.m11;
|
||||
float m11 = left.m01 * right.m10 + left.m11 * right.m11;
|
||||
|
||||
dest.m00 = m00;
|
||||
dest.m01 = m01;
|
||||
dest.m10 = m10;
|
||||
dest.m11 = m11;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a Vector by a matrix and return the result in a destination
|
||||
* vector.
|
||||
* @param left The left matrix
|
||||
* @param right The right vector
|
||||
* @param dest The destination vector, or null if a new one is to be created
|
||||
* @return the destination vector
|
||||
*/
|
||||
public static Vector2f transform(Matrix2f left, Vector2f right, Vector2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Vector2f();
|
||||
|
||||
float x = left.m00 * right.x + left.m10 * right.y;
|
||||
float y = left.m01 * right.x + left.m11 * right.y;
|
||||
|
||||
dest.x = x;
|
||||
dest.y = y;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose this matrix
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Matrix transpose() {
|
||||
return transpose(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose this matrix and place the result in another matrix.
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return the transposed matrix
|
||||
*/
|
||||
public Matrix2f transpose(Matrix2f dest) {
|
||||
return transpose(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose the source matrix and place the result in the destination matrix.
|
||||
* @param src The source matrix or null if a new matrix is to be created
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return the transposed matrix
|
||||
*/
|
||||
public static Matrix2f transpose(Matrix2f src, Matrix2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
|
||||
float m01 = src.m10;
|
||||
float m10 = src.m01;
|
||||
|
||||
dest.m01 = m01;
|
||||
dest.m10 = m10;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert this matrix
|
||||
* @return this if successful, null otherwise
|
||||
*/
|
||||
@Override
|
||||
public Matrix invert() {
|
||||
return invert(this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert the source matrix and place the result in the destination matrix.
|
||||
* @param src The source matrix to be inverted
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return The inverted matrix, or null if source can't be reverted.
|
||||
*/
|
||||
public static Matrix2f invert(Matrix2f src, Matrix2f dest) {
|
||||
/*
|
||||
*inv(A) = 1/det(A) * adj(A);
|
||||
*/
|
||||
|
||||
float determinant = src.determinant();
|
||||
if (determinant != 0) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
float determinant_inv = 1f/determinant;
|
||||
float t00 = src.m11*determinant_inv;
|
||||
float t01 = -src.m01*determinant_inv;
|
||||
float t11 = src.m00*determinant_inv;
|
||||
float t10 = -src.m10*determinant_inv;
|
||||
|
||||
dest.m00 = t00;
|
||||
dest.m01 = t01;
|
||||
dest.m10 = t10;
|
||||
dest.m11 = t11;
|
||||
return dest;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this matrix
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(m00).append(' ').append(m10).append(' ').append('\n');
|
||||
buf.append(m01).append(' ').append(m11).append(' ').append('\n');
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate this matrix
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Matrix negate() {
|
||||
return negate(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate this matrix and stash the result in another matrix.
|
||||
* @param dest The destination matrix, or null if a new matrix is to be created
|
||||
* @return the negated matrix
|
||||
*/
|
||||
public Matrix2f negate(Matrix2f dest) {
|
||||
return negate(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate the source matrix and stash the result in the destination matrix.
|
||||
* @param src The source matrix to be negated
|
||||
* @param dest The destination matrix, or null if a new matrix is to be created
|
||||
* @return the negated matrix
|
||||
*/
|
||||
public static Matrix2f negate(Matrix2f src, Matrix2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix2f();
|
||||
|
||||
dest.m00 = -src.m00;
|
||||
dest.m01 = -src.m01;
|
||||
dest.m10 = -src.m10;
|
||||
dest.m11 = -src.m11;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this matrix to be the identity matrix.
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Matrix setIdentity() {
|
||||
return setIdentity(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the source matrix to be the identity matrix.
|
||||
* @param src The matrix to set to the identity.
|
||||
* @return The source matrix
|
||||
*/
|
||||
public static Matrix2f setIdentity(Matrix2f src) {
|
||||
src.m00 = 1.0f;
|
||||
src.m01 = 0.0f;
|
||||
src.m10 = 0.0f;
|
||||
src.m11 = 1.0f;
|
||||
return src;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this matrix to 0.
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Matrix setZero() {
|
||||
return setZero(this);
|
||||
}
|
||||
|
||||
public static Matrix2f setZero(Matrix2f src) {
|
||||
src.m00 = 0.0f;
|
||||
src.m01 = 0.0f;
|
||||
src.m10 = 0.0f;
|
||||
src.m11 = 0.0f;
|
||||
return src;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.vector.Matrix#determinant()
|
||||
*/
|
||||
@Override
|
||||
public float determinant() {
|
||||
return m00 * m11 - m01*m10;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,525 @@
|
|||
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package io.github.hydos.ginger.mathEngine.matrixes;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds a 3x3 matrix.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
public class Matrix3f extends Matrix implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float m00,
|
||||
m01,
|
||||
m02,
|
||||
m10,
|
||||
m11,
|
||||
m12,
|
||||
m20,
|
||||
m21,
|
||||
m22;
|
||||
|
||||
/**
|
||||
* Constructor for Matrix3f. Matrix is initialised to the identity.
|
||||
*/
|
||||
public Matrix3f() {
|
||||
super();
|
||||
setIdentity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another matrix
|
||||
* @param src The source matrix
|
||||
* @return this
|
||||
*/
|
||||
public Matrix3f load(Matrix3f src) {
|
||||
return load(src, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy source matrix to destination matrix
|
||||
* @param src The source matrix
|
||||
* @param dest The destination matrix, or null of a new matrix is to be created
|
||||
* @return The copied matrix
|
||||
*/
|
||||
public static Matrix3f load(Matrix3f src, Matrix3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
|
||||
dest.m00 = src.m00;
|
||||
dest.m10 = src.m10;
|
||||
dest.m20 = src.m20;
|
||||
dest.m01 = src.m01;
|
||||
dest.m11 = src.m11;
|
||||
dest.m21 = src.m21;
|
||||
dest.m02 = src.m02;
|
||||
dest.m12 = src.m12;
|
||||
dest.m22 = src.m22;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in column major
|
||||
* (OpenGL) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Matrix load(FloatBuffer buf) {
|
||||
|
||||
m00 = buf.get();
|
||||
m01 = buf.get();
|
||||
m02 = buf.get();
|
||||
m10 = buf.get();
|
||||
m11 = buf.get();
|
||||
m12 = buf.get();
|
||||
m20 = buf.get();
|
||||
m21 = buf.get();
|
||||
m22 = buf.get();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in row major
|
||||
* (maths) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Matrix loadTranspose(FloatBuffer buf) {
|
||||
|
||||
m00 = buf.get();
|
||||
m10 = buf.get();
|
||||
m20 = buf.get();
|
||||
m01 = buf.get();
|
||||
m11 = buf.get();
|
||||
m21 = buf.get();
|
||||
m02 = buf.get();
|
||||
m12 = buf.get();
|
||||
m22 = buf.get();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in column
|
||||
* major (openGL) order.
|
||||
* @param buf The buffer to store this matrix in
|
||||
*/
|
||||
@Override
|
||||
public Matrix store(FloatBuffer buf) {
|
||||
buf.put(m00);
|
||||
buf.put(m01);
|
||||
buf.put(m02);
|
||||
buf.put(m10);
|
||||
buf.put(m11);
|
||||
buf.put(m12);
|
||||
buf.put(m20);
|
||||
buf.put(m21);
|
||||
buf.put(m22);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in row
|
||||
* major (maths) order.
|
||||
* @param buf The buffer to store this matrix in
|
||||
*/
|
||||
@Override
|
||||
public Matrix storeTranspose(FloatBuffer buf) {
|
||||
buf.put(m00);
|
||||
buf.put(m10);
|
||||
buf.put(m20);
|
||||
buf.put(m01);
|
||||
buf.put(m11);
|
||||
buf.put(m21);
|
||||
buf.put(m02);
|
||||
buf.put(m12);
|
||||
buf.put(m22);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add two matrices together and place the result in a third matrix.
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix3f add(Matrix3f left, Matrix3f right, Matrix3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
|
||||
dest.m00 = left.m00 + right.m00;
|
||||
dest.m01 = left.m01 + right.m01;
|
||||
dest.m02 = left.m02 + right.m02;
|
||||
dest.m10 = left.m10 + right.m10;
|
||||
dest.m11 = left.m11 + right.m11;
|
||||
dest.m12 = left.m12 + right.m12;
|
||||
dest.m20 = left.m20 + right.m20;
|
||||
dest.m21 = left.m21 + right.m21;
|
||||
dest.m22 = left.m22 + right.m22;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract the right matrix from the left and place the result in a third matrix.
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix3f sub(Matrix3f left, Matrix3f right, Matrix3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
|
||||
dest.m00 = left.m00 - right.m00;
|
||||
dest.m01 = left.m01 - right.m01;
|
||||
dest.m02 = left.m02 - right.m02;
|
||||
dest.m10 = left.m10 - right.m10;
|
||||
dest.m11 = left.m11 - right.m11;
|
||||
dest.m12 = left.m12 - right.m12;
|
||||
dest.m20 = left.m20 - right.m20;
|
||||
dest.m21 = left.m21 - right.m21;
|
||||
dest.m22 = left.m22 - right.m22;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply the right matrix by the left and place the result in a third matrix.
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix3f mul(Matrix3f left, Matrix3f right, Matrix3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
|
||||
float m00 =
|
||||
left.m00 * right.m00 + left.m10 * right.m01 + left.m20 * right.m02;
|
||||
float m01 =
|
||||
left.m01 * right.m00 + left.m11 * right.m01 + left.m21 * right.m02;
|
||||
float m02 =
|
||||
left.m02 * right.m00 + left.m12 * right.m01 + left.m22 * right.m02;
|
||||
float m10 =
|
||||
left.m00 * right.m10 + left.m10 * right.m11 + left.m20 * right.m12;
|
||||
float m11 =
|
||||
left.m01 * right.m10 + left.m11 * right.m11 + left.m21 * right.m12;
|
||||
float m12 =
|
||||
left.m02 * right.m10 + left.m12 * right.m11 + left.m22 * right.m12;
|
||||
float m20 =
|
||||
left.m00 * right.m20 + left.m10 * right.m21 + left.m20 * right.m22;
|
||||
float m21 =
|
||||
left.m01 * right.m20 + left.m11 * right.m21 + left.m21 * right.m22;
|
||||
float m22 =
|
||||
left.m02 * right.m20 + left.m12 * right.m21 + left.m22 * right.m22;
|
||||
|
||||
dest.m00 = m00;
|
||||
dest.m01 = m01;
|
||||
dest.m02 = m02;
|
||||
dest.m10 = m10;
|
||||
dest.m11 = m11;
|
||||
dest.m12 = m12;
|
||||
dest.m20 = m20;
|
||||
dest.m21 = m21;
|
||||
dest.m22 = m22;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a Vector by a matrix and return the result in a destination
|
||||
* vector.
|
||||
* @param left The left matrix
|
||||
* @param right The right vector
|
||||
* @param dest The destination vector, or null if a new one is to be created
|
||||
* @return the destination vector
|
||||
*/
|
||||
public static Vector3f transform(Matrix3f left, Vector3f right, Vector3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Vector3f();
|
||||
|
||||
float x = left.m00 * right.x + left.m10 * right.y + left.m20 * right.z;
|
||||
float y = left.m01 * right.x + left.m11 * right.y + left.m21 * right.z;
|
||||
float z = left.m02 * right.x + left.m12 * right.y + left.m22 * right.z;
|
||||
|
||||
dest.x = x;
|
||||
dest.y = y;
|
||||
dest.z = z;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose this matrix
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Matrix transpose() {
|
||||
return transpose(this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose this matrix and place the result in another matrix
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return the transposed matrix
|
||||
*/
|
||||
public Matrix3f transpose(Matrix3f dest) {
|
||||
return transpose(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose the source matrix and place the result into the destination matrix
|
||||
* @param src The source matrix to be transposed
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return the transposed matrix
|
||||
*/
|
||||
public static Matrix3f transpose(Matrix3f src, Matrix3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
float m00 = src.m00;
|
||||
float m01 = src.m10;
|
||||
float m02 = src.m20;
|
||||
float m10 = src.m01;
|
||||
float m11 = src.m11;
|
||||
float m12 = src.m21;
|
||||
float m20 = src.m02;
|
||||
float m21 = src.m12;
|
||||
float m22 = src.m22;
|
||||
|
||||
dest.m00 = m00;
|
||||
dest.m01 = m01;
|
||||
dest.m02 = m02;
|
||||
dest.m10 = m10;
|
||||
dest.m11 = m11;
|
||||
dest.m12 = m12;
|
||||
dest.m20 = m20;
|
||||
dest.m21 = m21;
|
||||
dest.m22 = m22;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the determinant of the matrix
|
||||
*/
|
||||
@Override
|
||||
public float determinant() {
|
||||
float f =
|
||||
m00 * (m11 * m22 - m12 * m21)
|
||||
+ m01 * (m12 * m20 - m10 * m22)
|
||||
+ m02 * (m10 * m21 - m11 * m20);
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this matrix
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(m00).append(' ').append(m10).append(' ').append(m20).append(' ').append('\n');
|
||||
buf.append(m01).append(' ').append(m11).append(' ').append(m21).append(' ').append('\n');
|
||||
buf.append(m02).append(' ').append(m12).append(' ').append(m22).append(' ').append('\n');
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert this matrix
|
||||
* @return this if successful, null otherwise
|
||||
*/
|
||||
@Override
|
||||
public Matrix invert() {
|
||||
return invert(this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert the source matrix and put the result into the destination matrix
|
||||
* @param src The source matrix to be inverted
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return The inverted matrix if successful, null otherwise
|
||||
*/
|
||||
public static Matrix3f invert(Matrix3f src, Matrix3f dest) {
|
||||
float determinant = src.determinant();
|
||||
|
||||
if (determinant != 0) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
/* do it the ordinary way
|
||||
*
|
||||
* inv(A) = 1/det(A) * adj(T), where adj(T) = transpose(Conjugate Matrix)
|
||||
*
|
||||
* m00 m01 m02
|
||||
* m10 m11 m12
|
||||
* m20 m21 m22
|
||||
*/
|
||||
float determinant_inv = 1f/determinant;
|
||||
|
||||
// get the conjugate matrix
|
||||
float t00 = src.m11 * src.m22 - src.m12* src.m21;
|
||||
float t01 = - src.m10 * src.m22 + src.m12 * src.m20;
|
||||
float t02 = src.m10 * src.m21 - src.m11 * src.m20;
|
||||
float t10 = - src.m01 * src.m22 + src.m02 * src.m21;
|
||||
float t11 = src.m00 * src.m22 - src.m02 * src.m20;
|
||||
float t12 = - src.m00 * src.m21 + src.m01 * src.m20;
|
||||
float t20 = src.m01 * src.m12 - src.m02 * src.m11;
|
||||
float t21 = -src.m00 * src.m12 + src.m02 * src.m10;
|
||||
float t22 = src.m00 * src.m11 - src.m01 * src.m10;
|
||||
|
||||
dest.m00 = t00*determinant_inv;
|
||||
dest.m11 = t11*determinant_inv;
|
||||
dest.m22 = t22*determinant_inv;
|
||||
dest.m01 = t10*determinant_inv;
|
||||
dest.m10 = t01*determinant_inv;
|
||||
dest.m20 = t02*determinant_inv;
|
||||
dest.m02 = t20*determinant_inv;
|
||||
dest.m12 = t21*determinant_inv;
|
||||
dest.m21 = t12*determinant_inv;
|
||||
return dest;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Negate this matrix
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Matrix negate() {
|
||||
return negate(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate this matrix and place the result in a destination matrix.
|
||||
* @param dest The destination matrix, or null if a new matrix is to be created
|
||||
* @return the negated matrix
|
||||
*/
|
||||
public Matrix3f negate(Matrix3f dest) {
|
||||
return negate(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate the source matrix and place the result in the destination matrix.
|
||||
* @param src The source matrix
|
||||
* @param dest The destination matrix, or null if a new matrix is to be created
|
||||
* @return the negated matrix
|
||||
*/
|
||||
public static Matrix3f negate(Matrix3f src, Matrix3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix3f();
|
||||
|
||||
dest.m00 = -src.m00;
|
||||
dest.m01 = -src.m02;
|
||||
dest.m02 = -src.m01;
|
||||
dest.m10 = -src.m10;
|
||||
dest.m11 = -src.m12;
|
||||
dest.m12 = -src.m11;
|
||||
dest.m20 = -src.m20;
|
||||
dest.m21 = -src.m22;
|
||||
dest.m22 = -src.m21;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this matrix to be the identity matrix.
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Matrix setIdentity() {
|
||||
return setIdentity(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the matrix to be the identity matrix.
|
||||
* @param m The matrix to be set to the identity
|
||||
* @return m
|
||||
*/
|
||||
public static Matrix3f setIdentity(Matrix3f m) {
|
||||
m.m00 = 1.0f;
|
||||
m.m01 = 0.0f;
|
||||
m.m02 = 0.0f;
|
||||
m.m10 = 0.0f;
|
||||
m.m11 = 1.0f;
|
||||
m.m12 = 0.0f;
|
||||
m.m20 = 0.0f;
|
||||
m.m21 = 0.0f;
|
||||
m.m22 = 1.0f;
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this matrix to 0.
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Matrix setZero() {
|
||||
return setZero(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the matrix matrix to 0.
|
||||
* @param m The matrix to be set to 0
|
||||
* @return m
|
||||
*/
|
||||
public static Matrix3f setZero(Matrix3f m) {
|
||||
m.m00 = 0.0f;
|
||||
m.m01 = 0.0f;
|
||||
m.m02 = 0.0f;
|
||||
m.m10 = 0.0f;
|
||||
m.m11 = 0.0f;
|
||||
m.m12 = 0.0f;
|
||||
m.m20 = 0.0f;
|
||||
m.m21 = 0.0f;
|
||||
m.m22 = 0.0f;
|
||||
return m;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,871 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package io.github.hydos.ginger.mathEngine.matrixes;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector2f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector4f;
|
||||
|
||||
/**
|
||||
* Holds a 4x4 float matrix.
|
||||
*
|
||||
* @author foo
|
||||
*/
|
||||
public class Matrix4f extends Matrix implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33;
|
||||
|
||||
/**
|
||||
* Construct a new matrix, initialized to the identity.
|
||||
*/
|
||||
public Matrix4f() {
|
||||
super();
|
||||
setIdentity();
|
||||
}
|
||||
|
||||
public Matrix4f(final Matrix4f src) {
|
||||
super();
|
||||
load(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this matrix
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(m00).append(' ').append(m10).append(' ').append(m20).append(' ').append(m30).append('\n');
|
||||
buf.append(m01).append(' ').append(m11).append(' ').append(m21).append(' ').append(m31).append('\n');
|
||||
buf.append(m02).append(' ').append(m12).append(' ').append(m22).append(' ').append(m32).append('\n');
|
||||
buf.append(m03).append(' ').append(m13).append(' ').append(m23).append(' ').append(m33).append('\n');
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this matrix to be the identity matrix.
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Matrix setIdentity() {
|
||||
return setIdentity(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the given matrix to be the identity matrix.
|
||||
* @param m The matrix to set to the identity
|
||||
* @return m
|
||||
*/
|
||||
public static Matrix4f setIdentity(Matrix4f m) {
|
||||
m.m00 = 1.0f;
|
||||
m.m01 = 0.0f;
|
||||
m.m02 = 0.0f;
|
||||
m.m03 = 0.0f;
|
||||
m.m10 = 0.0f;
|
||||
m.m11 = 1.0f;
|
||||
m.m12 = 0.0f;
|
||||
m.m13 = 0.0f;
|
||||
m.m20 = 0.0f;
|
||||
m.m21 = 0.0f;
|
||||
m.m22 = 1.0f;
|
||||
m.m23 = 0.0f;
|
||||
m.m30 = 0.0f;
|
||||
m.m31 = 0.0f;
|
||||
m.m32 = 0.0f;
|
||||
m.m33 = 1.0f;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this matrix to 0.
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Matrix setZero() {
|
||||
return setZero(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the given matrix to 0.
|
||||
* @param m The matrix to set to 0
|
||||
* @return m
|
||||
*/
|
||||
public static Matrix4f setZero(Matrix4f m) {
|
||||
m.m00 = 0.0f;
|
||||
m.m01 = 0.0f;
|
||||
m.m02 = 0.0f;
|
||||
m.m03 = 0.0f;
|
||||
m.m10 = 0.0f;
|
||||
m.m11 = 0.0f;
|
||||
m.m12 = 0.0f;
|
||||
m.m13 = 0.0f;
|
||||
m.m20 = 0.0f;
|
||||
m.m21 = 0.0f;
|
||||
m.m22 = 0.0f;
|
||||
m.m23 = 0.0f;
|
||||
m.m30 = 0.0f;
|
||||
m.m31 = 0.0f;
|
||||
m.m32 = 0.0f;
|
||||
m.m33 = 0.0f;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another matrix4f
|
||||
* @param src The source matrix
|
||||
* @return this
|
||||
*/
|
||||
public Matrix4f load(Matrix4f src) {
|
||||
return load(src, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the source matrix to the destination matrix
|
||||
* @param src The source matrix
|
||||
* @param dest The destination matrix, or null of a new one is to be created
|
||||
* @return The copied matrix
|
||||
*/
|
||||
public static Matrix4f load(Matrix4f src, Matrix4f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix4f();
|
||||
dest.m00 = src.m00;
|
||||
dest.m01 = src.m01;
|
||||
dest.m02 = src.m02;
|
||||
dest.m03 = src.m03;
|
||||
dest.m10 = src.m10;
|
||||
dest.m11 = src.m11;
|
||||
dest.m12 = src.m12;
|
||||
dest.m13 = src.m13;
|
||||
dest.m20 = src.m20;
|
||||
dest.m21 = src.m21;
|
||||
dest.m22 = src.m22;
|
||||
dest.m23 = src.m23;
|
||||
dest.m30 = src.m30;
|
||||
dest.m31 = src.m31;
|
||||
dest.m32 = src.m32;
|
||||
dest.m33 = src.m33;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in column major
|
||||
* (OpenGL) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Matrix load(FloatBuffer buf) {
|
||||
|
||||
m00 = buf.get();
|
||||
m01 = buf.get();
|
||||
m02 = buf.get();
|
||||
m03 = buf.get();
|
||||
m10 = buf.get();
|
||||
m11 = buf.get();
|
||||
m12 = buf.get();
|
||||
m13 = buf.get();
|
||||
m20 = buf.get();
|
||||
m21 = buf.get();
|
||||
m22 = buf.get();
|
||||
m23 = buf.get();
|
||||
m30 = buf.get();
|
||||
m31 = buf.get();
|
||||
m32 = buf.get();
|
||||
m33 = buf.get();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from a float buffer. The buffer stores the matrix in row major
|
||||
* (maths) order.
|
||||
*
|
||||
* @param buf A float buffer to read from
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Matrix loadTranspose(FloatBuffer buf) {
|
||||
|
||||
m00 = buf.get();
|
||||
m10 = buf.get();
|
||||
m20 = buf.get();
|
||||
m30 = buf.get();
|
||||
m01 = buf.get();
|
||||
m11 = buf.get();
|
||||
m21 = buf.get();
|
||||
m31 = buf.get();
|
||||
m02 = buf.get();
|
||||
m12 = buf.get();
|
||||
m22 = buf.get();
|
||||
m32 = buf.get();
|
||||
m03 = buf.get();
|
||||
m13 = buf.get();
|
||||
m23 = buf.get();
|
||||
m33 = buf.get();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in column
|
||||
* major (openGL) order.
|
||||
* @param buf The buffer to store this matrix in
|
||||
*/
|
||||
@Override
|
||||
public Matrix store(FloatBuffer buf) {
|
||||
buf.put(m00);
|
||||
buf.put(m01);
|
||||
buf.put(m02);
|
||||
buf.put(m03);
|
||||
buf.put(m10);
|
||||
buf.put(m11);
|
||||
buf.put(m12);
|
||||
buf.put(m13);
|
||||
buf.put(m20);
|
||||
buf.put(m21);
|
||||
buf.put(m22);
|
||||
buf.put(m23);
|
||||
buf.put(m30);
|
||||
buf.put(m31);
|
||||
buf.put(m32);
|
||||
buf.put(m33);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this matrix in a float buffer. The matrix is stored in row
|
||||
* major (maths) order.
|
||||
* @param buf The buffer to store this matrix in
|
||||
*/
|
||||
@Override
|
||||
public Matrix storeTranspose(FloatBuffer buf) {
|
||||
buf.put(m00);
|
||||
buf.put(m10);
|
||||
buf.put(m20);
|
||||
buf.put(m30);
|
||||
buf.put(m01);
|
||||
buf.put(m11);
|
||||
buf.put(m21);
|
||||
buf.put(m31);
|
||||
buf.put(m02);
|
||||
buf.put(m12);
|
||||
buf.put(m22);
|
||||
buf.put(m32);
|
||||
buf.put(m03);
|
||||
buf.put(m13);
|
||||
buf.put(m23);
|
||||
buf.put(m33);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the rotation portion of this matrix in a float buffer. The matrix is stored in column
|
||||
* major (openGL) order.
|
||||
* @param buf The buffer to store this matrix in
|
||||
*/
|
||||
public Matrix store3f(FloatBuffer buf) {
|
||||
buf.put(m00);
|
||||
buf.put(m01);
|
||||
buf.put(m02);
|
||||
buf.put(m10);
|
||||
buf.put(m11);
|
||||
buf.put(m12);
|
||||
buf.put(m20);
|
||||
buf.put(m21);
|
||||
buf.put(m22);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add two matrices together and place the result in a third matrix.
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix4f add(Matrix4f left, Matrix4f right, Matrix4f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix4f();
|
||||
|
||||
dest.m00 = left.m00 + right.m00;
|
||||
dest.m01 = left.m01 + right.m01;
|
||||
dest.m02 = left.m02 + right.m02;
|
||||
dest.m03 = left.m03 + right.m03;
|
||||
dest.m10 = left.m10 + right.m10;
|
||||
dest.m11 = left.m11 + right.m11;
|
||||
dest.m12 = left.m12 + right.m12;
|
||||
dest.m13 = left.m13 + right.m13;
|
||||
dest.m20 = left.m20 + right.m20;
|
||||
dest.m21 = left.m21 + right.m21;
|
||||
dest.m22 = left.m22 + right.m22;
|
||||
dest.m23 = left.m23 + right.m23;
|
||||
dest.m30 = left.m30 + right.m30;
|
||||
dest.m31 = left.m31 + right.m31;
|
||||
dest.m32 = left.m32 + right.m32;
|
||||
dest.m33 = left.m33 + right.m33;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract the right matrix from the left and place the result in a third matrix.
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
public static Matrix4f sub(Matrix4f left, Matrix4f right, Matrix4f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix4f();
|
||||
|
||||
dest.m00 = left.m00 - right.m00;
|
||||
dest.m01 = left.m01 - right.m01;
|
||||
dest.m02 = left.m02 - right.m02;
|
||||
dest.m03 = left.m03 - right.m03;
|
||||
dest.m10 = left.m10 - right.m10;
|
||||
dest.m11 = left.m11 - right.m11;
|
||||
dest.m12 = left.m12 - right.m12;
|
||||
dest.m13 = left.m13 - right.m13;
|
||||
dest.m20 = left.m20 - right.m20;
|
||||
dest.m21 = left.m21 - right.m21;
|
||||
dest.m22 = left.m22 - right.m22;
|
||||
dest.m23 = left.m23 - right.m23;
|
||||
dest.m30 = left.m30 - right.m30;
|
||||
dest.m31 = left.m31 - right.m31;
|
||||
dest.m32 = left.m32 - right.m32;
|
||||
dest.m33 = left.m33 - right.m33;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply the right matrix by the left and place the result in a third matrix.
|
||||
* @param left The left source matrix
|
||||
* @param right The right source matrix
|
||||
* @param dest The destination matrix, or null if a new one is to be created
|
||||
* @return the destination matrix
|
||||
*/
|
||||
|
||||
public Matrix4f mul(Matrix4f left) {
|
||||
return Matrix4f.mul(left, left, this);
|
||||
|
||||
}
|
||||
|
||||
public static Matrix4f mul(Matrix4f left, Matrix4f right, Matrix4f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix4f();
|
||||
|
||||
float m00 = left.m00 * right.m00 + left.m10 * right.m01 + left.m20 * right.m02 + left.m30 * right.m03;
|
||||
float m01 = left.m01 * right.m00 + left.m11 * right.m01 + left.m21 * right.m02 + left.m31 * right.m03;
|
||||
float m02 = left.m02 * right.m00 + left.m12 * right.m01 + left.m22 * right.m02 + left.m32 * right.m03;
|
||||
float m03 = left.m03 * right.m00 + left.m13 * right.m01 + left.m23 * right.m02 + left.m33 * right.m03;
|
||||
float m10 = left.m00 * right.m10 + left.m10 * right.m11 + left.m20 * right.m12 + left.m30 * right.m13;
|
||||
float m11 = left.m01 * right.m10 + left.m11 * right.m11 + left.m21 * right.m12 + left.m31 * right.m13;
|
||||
float m12 = left.m02 * right.m10 + left.m12 * right.m11 + left.m22 * right.m12 + left.m32 * right.m13;
|
||||
float m13 = left.m03 * right.m10 + left.m13 * right.m11 + left.m23 * right.m12 + left.m33 * right.m13;
|
||||
float m20 = left.m00 * right.m20 + left.m10 * right.m21 + left.m20 * right.m22 + left.m30 * right.m23;
|
||||
float m21 = left.m01 * right.m20 + left.m11 * right.m21 + left.m21 * right.m22 + left.m31 * right.m23;
|
||||
float m22 = left.m02 * right.m20 + left.m12 * right.m21 + left.m22 * right.m22 + left.m32 * right.m23;
|
||||
float m23 = left.m03 * right.m20 + left.m13 * right.m21 + left.m23 * right.m22 + left.m33 * right.m23;
|
||||
float m30 = left.m00 * right.m30 + left.m10 * right.m31 + left.m20 * right.m32 + left.m30 * right.m33;
|
||||
float m31 = left.m01 * right.m30 + left.m11 * right.m31 + left.m21 * right.m32 + left.m31 * right.m33;
|
||||
float m32 = left.m02 * right.m30 + left.m12 * right.m31 + left.m22 * right.m32 + left.m32 * right.m33;
|
||||
float m33 = left.m03 * right.m30 + left.m13 * right.m31 + left.m23 * right.m32 + left.m33 * right.m33;
|
||||
|
||||
dest.m00 = m00;
|
||||
dest.m01 = m01;
|
||||
dest.m02 = m02;
|
||||
dest.m03 = m03;
|
||||
dest.m10 = m10;
|
||||
dest.m11 = m11;
|
||||
dest.m12 = m12;
|
||||
dest.m13 = m13;
|
||||
dest.m20 = m20;
|
||||
dest.m21 = m21;
|
||||
dest.m22 = m22;
|
||||
dest.m23 = m23;
|
||||
dest.m30 = m30;
|
||||
dest.m31 = m31;
|
||||
dest.m32 = m32;
|
||||
dest.m33 = m33;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a Vector by a matrix and return the result in a destination
|
||||
* vector.
|
||||
* @param left The left matrix
|
||||
* @param right The right vector
|
||||
* @param dest The destination vector, or null if a new one is to be created
|
||||
* @return the destination vector
|
||||
*/
|
||||
public static Vector4f transform(Matrix4f left, Vector4f right, Vector4f dest) {
|
||||
if (dest == null)
|
||||
dest = new Vector4f();
|
||||
|
||||
float x = left.m00 * right.x + left.m10 * right.y + left.m20 * right.z + left.m30 * right.w;
|
||||
float y = left.m01 * right.x + left.m11 * right.y + left.m21 * right.z + left.m31 * right.w;
|
||||
float z = left.m02 * right.x + left.m12 * right.y + left.m22 * right.z + left.m32 * right.w;
|
||||
float w = left.m03 * right.x + left.m13 * right.y + left.m23 * right.z + left.m33 * right.w;
|
||||
|
||||
dest.x = x;
|
||||
dest.y = y;
|
||||
dest.z = z;
|
||||
dest.w = w;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose this matrix
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Matrix transpose() {
|
||||
return transpose(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate this matrix
|
||||
* @param vec The vector to translate by
|
||||
* @return this
|
||||
*/
|
||||
public Matrix4f translate(Vector2f vec) {
|
||||
return translate(vec, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate this matrix
|
||||
* @param vec The vector to translate by
|
||||
* @return this
|
||||
*/
|
||||
public Matrix4f translate(Vector3f vec) {
|
||||
return translate(vec, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scales this matrix
|
||||
* @param vec The vector to scale by
|
||||
* @return this
|
||||
*/
|
||||
public Matrix4f scale(Vector3f vec) {
|
||||
return scale(vec, this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scales the source matrix and put the result in the destination matrix
|
||||
* @param vec The vector to scale by
|
||||
* @param src The source matrix
|
||||
* @param dest The destination matrix, or null if a new matrix is to be created
|
||||
* @return The scaled matrix
|
||||
*/
|
||||
public static Matrix4f scale(Vector3f vec, Matrix4f src, Matrix4f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix4f();
|
||||
dest.m00 = src.m00 * vec.x;
|
||||
dest.m01 = src.m01 * vec.x;
|
||||
dest.m02 = src.m02 * vec.x;
|
||||
dest.m03 = src.m03 * vec.x;
|
||||
dest.m10 = src.m10 * vec.y;
|
||||
dest.m11 = src.m11 * vec.y;
|
||||
dest.m12 = src.m12 * vec.y;
|
||||
dest.m13 = src.m13 * vec.y;
|
||||
dest.m20 = src.m20 * vec.z;
|
||||
dest.m21 = src.m21 * vec.z;
|
||||
dest.m22 = src.m22 * vec.z;
|
||||
dest.m23 = src.m23 * vec.z;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates the matrix around the given axis the specified angle
|
||||
* @param angle the angle, in radians.
|
||||
* @param axis The vector representing the rotation axis. Must be normalized.
|
||||
* @return this
|
||||
*/
|
||||
public Matrix4f rotate(float angle, Vector3f axis) {
|
||||
return rotate(angle, axis, this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Rotates the matrix around the given axis the specified angle
|
||||
* @param angle the angle, in radians.
|
||||
* @param axis The vector representing the rotation axis. Must be normalized.
|
||||
* @param dest The matrix to put the result, or null if a new matrix is to be created
|
||||
* @return The rotated matrix
|
||||
*/
|
||||
public Matrix4f rotate(float angle, Vector3f axis, Matrix4f dest) {
|
||||
return rotate(angle, axis, this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates the source matrix around the given axis the specified angle and
|
||||
* put the result in the destination matrix.
|
||||
* @param angle the angle, in radians.
|
||||
* @param axis The vector representing the rotation axis. Must be normalized.
|
||||
* @param src The matrix to rotate
|
||||
* @param dest The matrix to put the result, or null if a new matrix is to be created
|
||||
* @return The rotated matrix
|
||||
*/
|
||||
public static Matrix4f rotate(float angle, Vector3f axis, Matrix4f src, Matrix4f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix4f();
|
||||
float c = (float) Math.cos(angle);
|
||||
float s = (float) Math.sin(angle);
|
||||
float oneminusc = 1.0f - c;
|
||||
float xy = axis.x*axis.y;
|
||||
float yz = axis.y*axis.z;
|
||||
float xz = axis.x*axis.z;
|
||||
float xs = axis.x*s;
|
||||
float ys = axis.y*s;
|
||||
float zs = axis.z*s;
|
||||
|
||||
float f00 = axis.x*axis.x*oneminusc+c;
|
||||
float f01 = xy*oneminusc+zs;
|
||||
float f02 = xz*oneminusc-ys;
|
||||
// n[3] not used
|
||||
float f10 = xy*oneminusc-zs;
|
||||
float f11 = axis.y*axis.y*oneminusc+c;
|
||||
float f12 = yz*oneminusc+xs;
|
||||
// n[7] not used
|
||||
float f20 = xz*oneminusc+ys;
|
||||
float f21 = yz*oneminusc-xs;
|
||||
float f22 = axis.z*axis.z*oneminusc+c;
|
||||
|
||||
float t00 = src.m00 * f00 + src.m10 * f01 + src.m20 * f02;
|
||||
float t01 = src.m01 * f00 + src.m11 * f01 + src.m21 * f02;
|
||||
float t02 = src.m02 * f00 + src.m12 * f01 + src.m22 * f02;
|
||||
float t03 = src.m03 * f00 + src.m13 * f01 + src.m23 * f02;
|
||||
float t10 = src.m00 * f10 + src.m10 * f11 + src.m20 * f12;
|
||||
float t11 = src.m01 * f10 + src.m11 * f11 + src.m21 * f12;
|
||||
float t12 = src.m02 * f10 + src.m12 * f11 + src.m22 * f12;
|
||||
float t13 = src.m03 * f10 + src.m13 * f11 + src.m23 * f12;
|
||||
dest.m20 = src.m00 * f20 + src.m10 * f21 + src.m20 * f22;
|
||||
dest.m21 = src.m01 * f20 + src.m11 * f21 + src.m21 * f22;
|
||||
dest.m22 = src.m02 * f20 + src.m12 * f21 + src.m22 * f22;
|
||||
dest.m23 = src.m03 * f20 + src.m13 * f21 + src.m23 * f22;
|
||||
dest.m00 = t00;
|
||||
dest.m01 = t01;
|
||||
dest.m02 = t02;
|
||||
dest.m03 = t03;
|
||||
dest.m10 = t10;
|
||||
dest.m11 = t11;
|
||||
dest.m12 = t12;
|
||||
dest.m13 = t13;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate this matrix and stash the result in another matrix
|
||||
* @param vec The vector to translate by
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return the translated matrix
|
||||
*/
|
||||
public Matrix4f translate(Vector3f vec, Matrix4f dest) {
|
||||
return translate(vec, this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate the source matrix and stash the result in the destination matrix
|
||||
* @param vec The vector to translate by
|
||||
* @param src The source matrix
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return The translated matrix
|
||||
*/
|
||||
public static Matrix4f translate(Vector3f vec, Matrix4f src, Matrix4f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix4f();
|
||||
|
||||
dest.m30 += src.m00 * vec.x + src.m10 * vec.y + src.m20 * vec.z;
|
||||
dest.m31 += src.m01 * vec.x + src.m11 * vec.y + src.m21 * vec.z;
|
||||
dest.m32 += src.m02 * vec.x + src.m12 * vec.y + src.m22 * vec.z;
|
||||
dest.m33 += src.m03 * vec.x + src.m13 * vec.y + src.m23 * vec.z;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate this matrix and stash the result in another matrix
|
||||
* @param vec The vector to translate by
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return the translated matrix
|
||||
*/
|
||||
public Matrix4f translate(Vector2f vec, Matrix4f dest) {
|
||||
return translate(vec, this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate the source matrix and stash the result in the destination matrix
|
||||
* @param vec The vector to translate by
|
||||
* @param src The source matrix
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return The translated matrix
|
||||
*/
|
||||
public static Matrix4f translate(Vector2f vec, Matrix4f src, Matrix4f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix4f();
|
||||
|
||||
dest.m30 += src.m00 * vec.x + src.m10 * vec.y;
|
||||
dest.m31 += src.m01 * vec.x + src.m11 * vec.y;
|
||||
dest.m32 += src.m02 * vec.x + src.m12 * vec.y;
|
||||
dest.m33 += src.m03 * vec.x + src.m13 * vec.y;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose this matrix and place the result in another matrix
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return the transposed matrix
|
||||
*/
|
||||
public Matrix4f transpose(Matrix4f dest) {
|
||||
return transpose(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transpose the source matrix and place the result in the destination matrix
|
||||
* @param src The source matrix
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return the transposed matrix
|
||||
*/
|
||||
public static Matrix4f transpose(Matrix4f src, Matrix4f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix4f();
|
||||
float m00 = src.m00;
|
||||
float m01 = src.m10;
|
||||
float m02 = src.m20;
|
||||
float m03 = src.m30;
|
||||
float m10 = src.m01;
|
||||
float m11 = src.m11;
|
||||
float m12 = src.m21;
|
||||
float m13 = src.m31;
|
||||
float m20 = src.m02;
|
||||
float m21 = src.m12;
|
||||
float m22 = src.m22;
|
||||
float m23 = src.m32;
|
||||
float m30 = src.m03;
|
||||
float m31 = src.m13;
|
||||
float m32 = src.m23;
|
||||
float m33 = src.m33;
|
||||
|
||||
dest.m00 = m00;
|
||||
dest.m01 = m01;
|
||||
dest.m02 = m02;
|
||||
dest.m03 = m03;
|
||||
dest.m10 = m10;
|
||||
dest.m11 = m11;
|
||||
dest.m12 = m12;
|
||||
dest.m13 = m13;
|
||||
dest.m20 = m20;
|
||||
dest.m21 = m21;
|
||||
dest.m22 = m22;
|
||||
dest.m23 = m23;
|
||||
dest.m30 = m30;
|
||||
dest.m31 = m31;
|
||||
dest.m32 = m32;
|
||||
dest.m33 = m33;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the determinant of the matrix
|
||||
*/
|
||||
@Override
|
||||
public float determinant() {
|
||||
float f =
|
||||
m00
|
||||
* ((m11 * m22 * m33 + m12 * m23 * m31 + m13 * m21 * m32)
|
||||
- m13 * m22 * m31
|
||||
- m11 * m23 * m32
|
||||
- m12 * m21 * m33);
|
||||
f -= m01
|
||||
* ((m10 * m22 * m33 + m12 * m23 * m30 + m13 * m20 * m32)
|
||||
- m13 * m22 * m30
|
||||
- m10 * m23 * m32
|
||||
- m12 * m20 * m33);
|
||||
f += m02
|
||||
* ((m10 * m21 * m33 + m11 * m23 * m30 + m13 * m20 * m31)
|
||||
- m13 * m21 * m30
|
||||
- m10 * m23 * m31
|
||||
- m11 * m20 * m33);
|
||||
f -= m03
|
||||
* ((m10 * m21 * m32 + m11 * m22 * m30 + m12 * m20 * m31)
|
||||
- m12 * m21 * m30
|
||||
- m10 * m22 * m31
|
||||
- m11 * m20 * m32);
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the determinant of a 3x3 matrix
|
||||
* @return result
|
||||
*/
|
||||
|
||||
private static 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert this matrix
|
||||
* @return this if successful, null otherwise
|
||||
*/
|
||||
@Override
|
||||
public Matrix invert() {
|
||||
return invert(this, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invert the source matrix and put the result in the destination
|
||||
* @param src The source matrix
|
||||
* @param dest The destination matrix, or null if a new matrix is to be created
|
||||
* @return The inverted matrix if successful, null otherwise
|
||||
*/
|
||||
public static Matrix4f invert(Matrix4f src, Matrix4f dest) {
|
||||
float determinant = src.determinant();
|
||||
|
||||
if (determinant != 0) {
|
||||
/*
|
||||
* m00 m01 m02 m03
|
||||
* m10 m11 m12 m13
|
||||
* m20 m21 m22 m23
|
||||
* m30 m31 m32 m33
|
||||
*/
|
||||
if (dest == null)
|
||||
dest = new Matrix4f();
|
||||
float determinant_inv = 1f/determinant;
|
||||
|
||||
// first row
|
||||
float t00 = determinant3x3(src.m11, src.m12, src.m13, src.m21, src.m22, src.m23, src.m31, src.m32, src.m33);
|
||||
float t01 = -determinant3x3(src.m10, src.m12, src.m13, src.m20, src.m22, src.m23, src.m30, src.m32, src.m33);
|
||||
float t02 = determinant3x3(src.m10, src.m11, src.m13, src.m20, src.m21, src.m23, src.m30, src.m31, src.m33);
|
||||
float t03 = -determinant3x3(src.m10, src.m11, src.m12, src.m20, src.m21, src.m22, src.m30, src.m31, src.m32);
|
||||
// second row
|
||||
float t10 = -determinant3x3(src.m01, src.m02, src.m03, src.m21, src.m22, src.m23, src.m31, src.m32, src.m33);
|
||||
float t11 = determinant3x3(src.m00, src.m02, src.m03, src.m20, src.m22, src.m23, src.m30, src.m32, src.m33);
|
||||
float t12 = -determinant3x3(src.m00, src.m01, src.m03, src.m20, src.m21, src.m23, src.m30, src.m31, src.m33);
|
||||
float t13 = determinant3x3(src.m00, src.m01, src.m02, src.m20, src.m21, src.m22, src.m30, src.m31, src.m32);
|
||||
// third row
|
||||
float t20 = determinant3x3(src.m01, src.m02, src.m03, src.m11, src.m12, src.m13, src.m31, src.m32, src.m33);
|
||||
float t21 = -determinant3x3(src.m00, src.m02, src.m03, src.m10, src.m12, src.m13, src.m30, src.m32, src.m33);
|
||||
float t22 = determinant3x3(src.m00, src.m01, src.m03, src.m10, src.m11, src.m13, src.m30, src.m31, src.m33);
|
||||
float t23 = -determinant3x3(src.m00, src.m01, src.m02, src.m10, src.m11, src.m12, src.m30, src.m31, src.m32);
|
||||
// fourth row
|
||||
float t30 = -determinant3x3(src.m01, src.m02, src.m03, src.m11, src.m12, src.m13, src.m21, src.m22, src.m23);
|
||||
float t31 = determinant3x3(src.m00, src.m02, src.m03, src.m10, src.m12, src.m13, src.m20, src.m22, src.m23);
|
||||
float t32 = -determinant3x3(src.m00, src.m01, src.m03, src.m10, src.m11, src.m13, src.m20, src.m21, src.m23);
|
||||
float t33 = determinant3x3(src.m00, src.m01, src.m02, src.m10, src.m11, src.m12, src.m20, src.m21, src.m22);
|
||||
|
||||
// transpose and divide by the determinant
|
||||
dest.m00 = t00*determinant_inv;
|
||||
dest.m11 = t11*determinant_inv;
|
||||
dest.m22 = t22*determinant_inv;
|
||||
dest.m33 = t33*determinant_inv;
|
||||
dest.m01 = t10*determinant_inv;
|
||||
dest.m10 = t01*determinant_inv;
|
||||
dest.m20 = t02*determinant_inv;
|
||||
dest.m02 = t20*determinant_inv;
|
||||
dest.m12 = t21*determinant_inv;
|
||||
dest.m21 = t12*determinant_inv;
|
||||
dest.m03 = t30*determinant_inv;
|
||||
dest.m30 = t03*determinant_inv;
|
||||
dest.m13 = t31*determinant_inv;
|
||||
dest.m31 = t13*determinant_inv;
|
||||
dest.m32 = t23*determinant_inv;
|
||||
dest.m23 = t32*determinant_inv;
|
||||
return dest;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate this matrix
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Matrix negate() {
|
||||
return negate(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate this matrix and place the result in a destination matrix.
|
||||
* @param dest The destination matrix, or null if a new matrix is to be created
|
||||
* @return the negated matrix
|
||||
*/
|
||||
public Matrix4f negate(Matrix4f dest) {
|
||||
return negate(this, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate this matrix and place the result in a destination matrix.
|
||||
* @param src The source matrix
|
||||
* @param dest The destination matrix, or null if a new matrix is to be created
|
||||
* @return The negated matrix
|
||||
*/
|
||||
public static Matrix4f negate(Matrix4f src, Matrix4f dest) {
|
||||
if (dest == null)
|
||||
dest = new Matrix4f();
|
||||
|
||||
dest.m00 = -src.m00;
|
||||
dest.m01 = -src.m01;
|
||||
dest.m02 = -src.m02;
|
||||
dest.m03 = -src.m03;
|
||||
dest.m10 = -src.m10;
|
||||
dest.m11 = -src.m11;
|
||||
dest.m12 = -src.m12;
|
||||
dest.m13 = -src.m13;
|
||||
dest.m20 = -src.m20;
|
||||
dest.m21 = -src.m21;
|
||||
dest.m22 = -src.m22;
|
||||
dest.m23 = -src.m23;
|
||||
dest.m30 = -src.m30;
|
||||
dest.m31 = -src.m31;
|
||||
dest.m32 = -src.m32;
|
||||
dest.m33 = -src.m33;
|
||||
|
||||
return dest;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package io.github.hydos.ginger.mathEngine.vectors;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
* @author foo
|
||||
*/
|
||||
public interface ReadableVector {
|
||||
/**
|
||||
* @return the length of the vector
|
||||
*/
|
||||
float length();
|
||||
/**
|
||||
* @return the length squared of the vector
|
||||
*/
|
||||
float lengthSquared();
|
||||
/**
|
||||
* Store this vector in a FloatBuffer
|
||||
* @param buf The buffer to store it in, at the current position
|
||||
* @return this
|
||||
*/
|
||||
Vector store(FloatBuffer buf);
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package io.github.hydos.ginger.mathEngine.vectors;
|
||||
|
||||
/**
|
||||
* @author foo
|
||||
*/
|
||||
public interface ReadableVector2f extends ReadableVector {
|
||||
/**
|
||||
* @return x
|
||||
*/
|
||||
float getX();
|
||||
/**
|
||||
* @return y
|
||||
*/
|
||||
float getY();
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package io.github.hydos.ginger.mathEngine.vectors;
|
||||
|
||||
/**
|
||||
* @author foo
|
||||
*/
|
||||
public interface ReadableVector3f extends ReadableVector2f {
|
||||
/**
|
||||
* @return z
|
||||
*/
|
||||
float getZ();
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package io.github.hydos.ginger.mathEngine.vectors;
|
||||
|
||||
/**
|
||||
* @author foo
|
||||
*/
|
||||
public interface ReadableVector4f extends ReadableVector3f {
|
||||
|
||||
/**
|
||||
* @return w
|
||||
*/
|
||||
float getW();
|
||||
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package io.github.hydos.ginger.mathEngine.vectors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Base class for vectors.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public abstract class Vector implements Serializable, ReadableVector {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for Vector.
|
||||
*/
|
||||
protected Vector() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length of the vector
|
||||
*/
|
||||
@Override
|
||||
public final float length() {
|
||||
return (float) Math.sqrt(lengthSquared());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the length squared of the vector
|
||||
*/
|
||||
@Override
|
||||
public abstract float lengthSquared();
|
||||
|
||||
/**
|
||||
* Load this vector from a FloatBuffer
|
||||
* @param buf The buffer to load it from, at the current position
|
||||
* @return this
|
||||
*/
|
||||
public abstract Vector load(FloatBuffer buf);
|
||||
|
||||
/**
|
||||
* Negate a vector
|
||||
* @return this
|
||||
*/
|
||||
public abstract Vector negate();
|
||||
|
||||
|
||||
/**
|
||||
* Normalise this vector
|
||||
* @return this
|
||||
*/
|
||||
public final Vector normalise() {
|
||||
float len = length();
|
||||
if (len != 0.0f) {
|
||||
float l = 1.0f / len;
|
||||
return scale(l);
|
||||
} else
|
||||
throw new IllegalStateException("Zero length vector");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Store this vector in a FloatBuffer
|
||||
* @param buf The buffer to store it in, at the current position
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public abstract Vector store(FloatBuffer buf);
|
||||
|
||||
|
||||
/**
|
||||
* Scale this vector
|
||||
* @param scale The scale factor
|
||||
* @return this
|
||||
*/
|
||||
public abstract Vector scale(float scale);
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,313 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package io.github.hydos.ginger.mathEngine.vectors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds a 2-tuple vector.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
public class Vector2f extends Vector implements Serializable, ReadableVector2f, WritableVector2f {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float x, y;
|
||||
|
||||
/**
|
||||
* Constructor for Vector2f.
|
||||
*/
|
||||
public Vector2f() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Vector2f(ReadableVector2f src) {
|
||||
set(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Vector2f(float x, float y) {
|
||||
set(x, y);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
|
||||
*/
|
||||
@Override
|
||||
public void set(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another Vector2f
|
||||
* @param src The source vector
|
||||
* @return this
|
||||
*/
|
||||
public Vector2f set(ReadableVector2f src) {
|
||||
x = src.getX();
|
||||
y = src.getY();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length squared of the vector
|
||||
*/
|
||||
@Override
|
||||
public float lengthSquared() {
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a vector
|
||||
* @param x The translation in x
|
||||
* @param y the translation in y
|
||||
* @return this
|
||||
*/
|
||||
public Vector2f translate(float x, float y) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate a vector
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Vector negate() {
|
||||
x = -x;
|
||||
y = -y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate a vector and place the result in a destination vector.
|
||||
* @param dest The destination vector or null if a new vector is to be created
|
||||
* @return the negated vector
|
||||
*/
|
||||
public Vector2f negate(Vector2f dest) {
|
||||
if (dest == null)
|
||||
dest = new Vector2f();
|
||||
dest.x = -x;
|
||||
dest.y = -y;
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Normalise this vector and place the result in another vector.
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the normalised vector
|
||||
*/
|
||||
public Vector2f normalise(Vector2f dest) {
|
||||
float l = length();
|
||||
|
||||
if (dest == null)
|
||||
dest = new Vector2f(x / l, y / l);
|
||||
else
|
||||
dest.set(x / l, y / l);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* The dot product of two vectors is calculated as
|
||||
* v1.x * v2.x + v1.y * v2.y + v1.z * v2.z
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @return left dot right
|
||||
*/
|
||||
public static float dot(Vector2f left, Vector2f right) {
|
||||
return left.x * right.x + left.y * right.y;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the angle between two vectors, in radians
|
||||
* @param a A vector
|
||||
* @param b The other vector
|
||||
* @return the angle between the two vectors, in radians
|
||||
*/
|
||||
public static float angle(Vector2f a, Vector2f b) {
|
||||
float dls = dot(a, b) / (a.length() * b.length());
|
||||
if (dls < -1f)
|
||||
dls = -1f;
|
||||
else if (dls > 1.0f)
|
||||
dls = 1.0f;
|
||||
return (float)Math.acos(dls);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a vector to another vector and place the result in a destination
|
||||
* vector.
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the sum of left and right in dest
|
||||
*/
|
||||
public static Vector2f add(Vector2f left, Vector2f right, Vector2f dest) {
|
||||
if (dest == null)
|
||||
return new Vector2f(left.x + right.x, left.y + right.y);
|
||||
else {
|
||||
dest.set(left.x + right.x, left.y + right.y);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract a vector from another vector and place the result in a destination
|
||||
* vector.
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return left minus right in dest
|
||||
*/
|
||||
public static Vector2f sub(Vector2f left, Vector2f right, Vector2f dest) {
|
||||
if (dest == null)
|
||||
return new Vector2f(left.x - right.x, left.y - right.y);
|
||||
else {
|
||||
dest.set(left.x - right.x, left.y - right.y);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this vector in a FloatBuffer
|
||||
* @param buf The buffer to store it in, at the current position
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Vector store(FloatBuffer buf) {
|
||||
buf.put(x);
|
||||
buf.put(y);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load this vector from a FloatBuffer
|
||||
* @param buf The buffer to load it from, at the current position
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Vector load(FloatBuffer buf) {
|
||||
x = buf.get();
|
||||
y = buf.get();
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.vector.Vector#scale(float)
|
||||
*/
|
||||
@Override
|
||||
public Vector scale(float scale) {
|
||||
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(64);
|
||||
|
||||
sb.append("Vector2f[");
|
||||
sb.append(x);
|
||||
sb.append(", ");
|
||||
sb.append(y);
|
||||
sb.append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return x
|
||||
*/
|
||||
@Override
|
||||
public final float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return y
|
||||
*/
|
||||
@Override
|
||||
public final float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X
|
||||
* @param x
|
||||
*/
|
||||
@Override
|
||||
public final void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Y
|
||||
* @param y
|
||||
*/
|
||||
@Override
|
||||
public final void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
Vector2f other = (Vector2f)obj;
|
||||
|
||||
if (x == other.x && y == other.y) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,387 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package io.github.hydos.ginger.mathEngine.vectors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds a 3-tuple vector.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
public class Vector3f extends Vector implements Serializable, ReadableVector3f, WritableVector3f {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float x, y, z;
|
||||
|
||||
/**
|
||||
* Constructor for Vector3f.
|
||||
*/
|
||||
public Vector3f() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Vector3f(ReadableVector3f src) {
|
||||
set(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Vector3f(float x, float y, float z) {
|
||||
set(x, y, z);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
|
||||
*/
|
||||
@Override
|
||||
public void set(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float)
|
||||
*/
|
||||
@Override
|
||||
public void set(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another Vector3f
|
||||
* @param src The source vector
|
||||
* @return this
|
||||
*/
|
||||
public Vector3f set(ReadableVector3f src) {
|
||||
x = src.getX();
|
||||
y = src.getY();
|
||||
z = src.getZ();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length squared of the vector
|
||||
*/
|
||||
@Override
|
||||
public float lengthSquared() {
|
||||
return x * x + y * y + z * z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a vector
|
||||
* @param x The translation in x
|
||||
* @param y the translation in y
|
||||
* @return this
|
||||
*/
|
||||
public Vector3f translate(float x, float y, float z) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
this.z += z;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a vector to another vector and place the result in a destination
|
||||
* vector.
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the sum of left and right in dest
|
||||
*/
|
||||
public static Vector3f add(Vector3f left, Vector3f right, Vector3f dest) {
|
||||
if (dest == null)
|
||||
return new Vector3f(left.x + right.x, left.y + right.y, left.z + right.z);
|
||||
else {
|
||||
dest.set(left.x + right.x, left.y + right.y, left.z + right.z);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3f add(Vector3f vector)
|
||||
{
|
||||
return new Vector3f(x + vector.x, y + vector.y, z + vector.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract a vector from another vector and place the result in a destination
|
||||
* vector.
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return left minus right in dest
|
||||
*/
|
||||
public static Vector3f sub(Vector3f left, Vector3f right, Vector3f dest) {
|
||||
if (dest == null)
|
||||
return new Vector3f(left.x - right.x, left.y - right.y, left.z - right.z);
|
||||
else {
|
||||
dest.set(left.x - right.x, left.y - right.y, left.z - right.z);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The cross product of two vectors.
|
||||
*
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination result, or null if a new vector is to be created
|
||||
* @return left cross right
|
||||
*/
|
||||
public static Vector3f cross(
|
||||
Vector3f left,
|
||||
Vector3f right,
|
||||
Vector3f dest)
|
||||
{
|
||||
|
||||
if (dest == null)
|
||||
dest = new Vector3f();
|
||||
|
||||
dest.set(
|
||||
left.y * right.z - left.z * right.y,
|
||||
right.x * left.z - right.z * left.x,
|
||||
left.x * right.y - left.y * right.x
|
||||
);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Negate a vector
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Vector negate() {
|
||||
x = -x;
|
||||
y = -y;
|
||||
z = -z;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate a vector and place the result in a destination vector.
|
||||
* @param dest The destination vector or null if a new vector is to be created
|
||||
* @return the negated vector
|
||||
*/
|
||||
public Vector3f negate(Vector3f dest) {
|
||||
if (dest == null)
|
||||
dest = new Vector3f();
|
||||
dest.x = -x;
|
||||
dest.y = -y;
|
||||
dest.z = -z;
|
||||
return dest;
|
||||
}
|
||||
|
||||
public Vector3f mul(float value)
|
||||
{
|
||||
return new Vector3f(x * value, y * value, z * value);
|
||||
}
|
||||
|
||||
public Vector3f mul(Vector3f vector)
|
||||
{
|
||||
return new Vector3f(x * vector.x, y * vector.y, z * vector.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise this vector and place the result in another vector.
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the normalised vector
|
||||
*/
|
||||
public Vector3f normalise(Vector3f dest) {
|
||||
float l = length();
|
||||
|
||||
if (dest == null)
|
||||
dest = new Vector3f(x / l, y / l, z / l);
|
||||
else
|
||||
dest.set(x / l, y / l, z / l);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* The dot product of two vectors is calculated as
|
||||
* v1.x * v2.x + v1.y * v2.y + v1.z * v2.z
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @return left dot right
|
||||
*/
|
||||
public static float dot(Vector3f left, Vector3f right) {
|
||||
return left.x * right.x + left.y * right.y + left.z * right.z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the angle between two vectors, in radians
|
||||
* @param a A vector
|
||||
* @param b The other vector
|
||||
* @return the angle between the two vectors, in radians
|
||||
*/
|
||||
public static float angle(Vector3f a, Vector3f b) {
|
||||
float dls = dot(a, b) / (a.length() * b.length());
|
||||
if (dls < -1f)
|
||||
dls = -1f;
|
||||
else if (dls > 1.0f)
|
||||
dls = 1.0f;
|
||||
return (float)Math.acos(dls);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.vector.Vector#load(FloatBuffer)
|
||||
*/
|
||||
@Override
|
||||
public Vector load(FloatBuffer buf) {
|
||||
x = buf.get();
|
||||
y = buf.get();
|
||||
z = buf.get();
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.vector.Vector#scale(float)
|
||||
*/
|
||||
@Override
|
||||
public Vector scale(float scale) {
|
||||
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
z *= scale;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.vector.Vector#store(FloatBuffer)
|
||||
*/
|
||||
@Override
|
||||
public Vector store(FloatBuffer buf) {
|
||||
|
||||
buf.put(x);
|
||||
buf.put(y);
|
||||
buf.put(z);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(64);
|
||||
|
||||
sb.append("Vector3f[");
|
||||
sb.append(x);
|
||||
sb.append(", ");
|
||||
sb.append(y);
|
||||
sb.append(", ");
|
||||
sb.append(z);
|
||||
sb.append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return x
|
||||
*/
|
||||
@Override
|
||||
public final float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return y
|
||||
*/
|
||||
@Override
|
||||
public final float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X
|
||||
* @param x
|
||||
*/
|
||||
@Override
|
||||
public final void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Y
|
||||
* @param y
|
||||
*/
|
||||
@Override
|
||||
public final void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Z
|
||||
* @param z
|
||||
*/
|
||||
@Override
|
||||
public void setZ(float z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/* (Overrides)
|
||||
* @see org.lwjgl.vector.ReadableVector3f#getZ()
|
||||
*/
|
||||
@Override
|
||||
public float getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
Vector3f other = (Vector3f)obj;
|
||||
|
||||
if (x == other.x && y == other.y && z == other.z) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,367 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package io.github.hydos.ginger.mathEngine.vectors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds a 4-tuple vector.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
public class Vector4f extends Vector implements Serializable, ReadableVector4f, WritableVector4f {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public float x, y, z, w;
|
||||
|
||||
/**
|
||||
* Constructor for Vector4f.
|
||||
*/
|
||||
public Vector4f() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Vector4f(ReadableVector4f src) {
|
||||
set(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Vector4f(float x, float y, float z, float w) {
|
||||
set(x, y, z, w);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
|
||||
*/
|
||||
@Override
|
||||
public void set(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float)
|
||||
*/
|
||||
@Override
|
||||
public void set(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.util.vector.WritableVector4f#set(float, float, float, float)
|
||||
*/
|
||||
@Override
|
||||
public void set(float x, float y, float z, float w) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load from another Vector4f
|
||||
* @param src The source vector
|
||||
* @return this
|
||||
*/
|
||||
public Vector4f set(ReadableVector4f src) {
|
||||
x = src.getX();
|
||||
y = src.getY();
|
||||
z = src.getZ();
|
||||
w = src.getW();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length squared of the vector
|
||||
*/
|
||||
@Override
|
||||
public float lengthSquared() {
|
||||
return x * x + y * y + z * z + w * w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a vector
|
||||
* @param x The translation in x
|
||||
* @param y the translation in y
|
||||
* @return this
|
||||
*/
|
||||
public Vector4f translate(float x, float y, float z, float w) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
this.z += z;
|
||||
this.w += w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a vector to another vector and place the result in a destination
|
||||
* vector.
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the sum of left and right in dest
|
||||
*/
|
||||
public static Vector4f add(Vector4f left, Vector4f right, Vector4f dest) {
|
||||
if (dest == null)
|
||||
return new Vector4f(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
|
||||
else {
|
||||
dest.set(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract a vector from another vector and place the result in a destination
|
||||
* vector.
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return left minus right in dest
|
||||
*/
|
||||
public static Vector4f sub(Vector4f left, Vector4f right, Vector4f dest) {
|
||||
if (dest == null)
|
||||
return new Vector4f(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
|
||||
else {
|
||||
dest.set(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Negate a vector
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Vector negate() {
|
||||
x = -x;
|
||||
y = -y;
|
||||
z = -z;
|
||||
w = -w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negate a vector and place the result in a destination vector.
|
||||
* @param dest The destination vector or null if a new vector is to be created
|
||||
* @return the negated vector
|
||||
*/
|
||||
public Vector4f negate(Vector4f dest) {
|
||||
if (dest == null)
|
||||
dest = new Vector4f();
|
||||
dest.x = -x;
|
||||
dest.y = -y;
|
||||
dest.z = -z;
|
||||
dest.w = -w;
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Normalise this vector and place the result in another vector.
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the normalised vector
|
||||
*/
|
||||
public Vector4f normalise(Vector4f dest) {
|
||||
float l = length();
|
||||
|
||||
if (dest == null)
|
||||
dest = new Vector4f(x / l, y / l, z / l, w / l);
|
||||
else
|
||||
dest.set(x / l, y / l, z / l, w / l);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* The dot product of two vectors is calculated as
|
||||
* v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @return left dot right
|
||||
*/
|
||||
public static float dot(Vector4f left, Vector4f right) {
|
||||
return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the angle between two vectors, in radians
|
||||
* @param a A vector
|
||||
* @param b The other vector
|
||||
* @return the angle between the two vectors, in radians
|
||||
*/
|
||||
public static float angle(Vector4f a, Vector4f b) {
|
||||
float dls = dot(a, b) / (a.length() * b.length());
|
||||
if (dls < -1f)
|
||||
dls = -1f;
|
||||
else if (dls > 1.0f)
|
||||
dls = 1.0f;
|
||||
return (float)Math.acos(dls);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.vector.Vector#load(FloatBuffer)
|
||||
*/
|
||||
@Override
|
||||
public Vector load(FloatBuffer buf) {
|
||||
x = buf.get();
|
||||
y = buf.get();
|
||||
z = buf.get();
|
||||
w = buf.get();
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.vector.Vector#scale(float)
|
||||
*/
|
||||
@Override
|
||||
public Vector scale(float scale) {
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
z *= scale;
|
||||
w *= scale;
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.vector.Vector#store(FloatBuffer)
|
||||
*/
|
||||
@Override
|
||||
public Vector store(FloatBuffer buf) {
|
||||
|
||||
buf.put(x);
|
||||
buf.put(y);
|
||||
buf.put(z);
|
||||
buf.put(w);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Vector4f: " + x + " " + y + " " + z + " " + w;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return x
|
||||
*/
|
||||
@Override
|
||||
public final float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return y
|
||||
*/
|
||||
@Override
|
||||
public final float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set X
|
||||
* @param x
|
||||
*/
|
||||
@Override
|
||||
public final void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Y
|
||||
* @param y
|
||||
*/
|
||||
@Override
|
||||
public final void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Z
|
||||
* @param z
|
||||
*/
|
||||
@Override
|
||||
public void setZ(float z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
|
||||
/* (Overrides)
|
||||
* @see org.lwjgl.vector.ReadableVector3f#getZ()
|
||||
*/
|
||||
@Override
|
||||
public float getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set W
|
||||
* @param w
|
||||
*/
|
||||
@Override
|
||||
public void setW(float w) {
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/* (Overrides)
|
||||
* @see org.lwjgl.vector.ReadableVector3f#getZ()
|
||||
*/
|
||||
@Override
|
||||
public float getW() {
|
||||
return w;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
Vector4f other = (Vector4f)obj;
|
||||
|
||||
if (x == other.x && y == other.y && z == other.z && w == other.w) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package io.github.hydos.ginger.mathEngine.vectors;
|
||||
|
||||
/**
|
||||
* Writable interface to Vector2fs
|
||||
* @author $author$
|
||||
* @version $revision$
|
||||
* $Id$
|
||||
*/
|
||||
public interface WritableVector2f {
|
||||
|
||||
/**
|
||||
* Set the X value
|
||||
* @param x
|
||||
*/
|
||||
void setX(float x);
|
||||
|
||||
/**
|
||||
* Set the Y value
|
||||
* @param y
|
||||
*/
|
||||
void setY(float y);
|
||||
|
||||
/**
|
||||
* Set the X,Y values
|
||||
* @param x
|
||||
* @param y
|
||||
*/
|
||||
void set(float x, float y);
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package io.github.hydos.ginger.mathEngine.vectors;
|
||||
|
||||
/**
|
||||
* Writable interface to Vector3fs
|
||||
* @author $author$
|
||||
* @version $revision$
|
||||
* $Id$
|
||||
*/
|
||||
public interface WritableVector3f extends WritableVector2f {
|
||||
|
||||
/**
|
||||
* Set the Z value
|
||||
* @param z
|
||||
*/
|
||||
void setZ(float z);
|
||||
|
||||
/**
|
||||
* Set the X,Y,Z values
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
void set(float x, float y, float z);
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package io.github.hydos.ginger.mathEngine.vectors;
|
||||
|
||||
/**
|
||||
* Writable interface to Vector4fs
|
||||
* @author $author$
|
||||
* @version $revision$
|
||||
* $Id$
|
||||
*/
|
||||
public interface WritableVector4f extends WritableVector3f {
|
||||
|
||||
/**
|
||||
* Set the W value
|
||||
* @param w
|
||||
*/
|
||||
void setW(float w);
|
||||
|
||||
/**
|
||||
* Set the X,Y,Z,W values
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param w
|
||||
*/
|
||||
void set(float x, float y, float z, float w);
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package io.github.hydos.ginger.normals.obj;
|
||||
|
||||
public class ModelDataNM {
|
||||
|
||||
private float[] vertices;
|
||||
private float[] textureCoords;
|
||||
private float[] normals;
|
||||
private float[] tangents;
|
||||
private int[] indices;
|
||||
private float furthestPoint;
|
||||
|
||||
public ModelDataNM(float[] vertices, float[] textureCoords, float[] normals, float[] tangents, int[] indices,
|
||||
float furthestPoint) {
|
||||
this.vertices = vertices;
|
||||
this.textureCoords = textureCoords;
|
||||
this.normals = normals;
|
||||
this.indices = indices;
|
||||
this.furthestPoint = furthestPoint;
|
||||
this.tangents = tangents;
|
||||
}
|
||||
|
||||
public float[] getVertices() {
|
||||
return vertices;
|
||||
}
|
||||
|
||||
public float[] getTextureCoords() {
|
||||
return textureCoords;
|
||||
}
|
||||
|
||||
public float[] getTangents(){
|
||||
return tangents;
|
||||
}
|
||||
|
||||
public float[] getNormals() {
|
||||
return normals;
|
||||
}
|
||||
|
||||
public int[] getIndices() {
|
||||
return indices;
|
||||
}
|
||||
|
||||
public float getFurthestPoint() {
|
||||
return furthestPoint;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,194 @@
|
|||
package io.github.hydos.ginger.normals.obj;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector2f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
import io.github.hydos.ginger.renderEngine.models.RawModel;
|
||||
import io.github.hydos.ginger.utils.Loader;
|
||||
|
||||
public class NormalMappedObjLoader {
|
||||
|
||||
private static final String RES_LOC = "res/";
|
||||
|
||||
public static RawModel loadOBJ(String objFileName) {
|
||||
FileReader isr = null;
|
||||
File objFile = new File(RES_LOC + objFileName + ".obj");
|
||||
try {
|
||||
isr = new FileReader(objFile);
|
||||
} catch (FileNotFoundException e) {
|
||||
System.err.println("File not found in res; don't use any extention");
|
||||
}
|
||||
BufferedReader reader = new BufferedReader(isr);
|
||||
String line;
|
||||
List<VertexNM> vertices = new ArrayList<VertexNM>();
|
||||
List<Vector2f> textures = new ArrayList<Vector2f>();
|
||||
List<Vector3f> normals = new ArrayList<Vector3f>();
|
||||
List<Integer> indices = new ArrayList<Integer>();
|
||||
try {
|
||||
while (true) {
|
||||
line = reader.readLine();
|
||||
if (line.startsWith("v ")) {
|
||||
String[] currentLine = line.split(" ");
|
||||
Vector3f vertex = new Vector3f((float) Float.valueOf(currentLine[1]),
|
||||
(float) Float.valueOf(currentLine[2]),
|
||||
(float) Float.valueOf(currentLine[3]));
|
||||
VertexNM newVertex = new VertexNM(vertices.size(), vertex);
|
||||
vertices.add(newVertex);
|
||||
|
||||
} else if (line.startsWith("vt ")) {
|
||||
String[] currentLine = line.split(" ");
|
||||
Vector2f texture = new Vector2f((float) Float.valueOf(currentLine[1]),
|
||||
(float) Float.valueOf(currentLine[2]));
|
||||
textures.add(texture);
|
||||
} else if (line.startsWith("vn ")) {
|
||||
String[] currentLine = line.split(" ");
|
||||
Vector3f normal = new Vector3f((float) Float.valueOf(currentLine[1]),
|
||||
(float) Float.valueOf(currentLine[2]),
|
||||
(float) Float.valueOf(currentLine[3]));
|
||||
normals.add(normal);
|
||||
} else if (line.startsWith("f ")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (line != null && line.startsWith("f ")) {
|
||||
String[] currentLine = line.split(" ");
|
||||
String[] vertex1 = currentLine[1].split("/");
|
||||
String[] vertex2 = currentLine[2].split("/");
|
||||
String[] vertex3 = currentLine[3].split("/");
|
||||
VertexNM v0 = processVertex(vertex1, vertices, indices);
|
||||
VertexNM v1 = processVertex(vertex2, vertices, indices);
|
||||
VertexNM v2 = processVertex(vertex3, vertices, indices);
|
||||
calculateTangents(v0, v1, v2, textures);//NEW
|
||||
line = reader.readLine();
|
||||
}
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error reading the file");
|
||||
}
|
||||
removeUnusedVertices(vertices);
|
||||
float[] verticesArray = new float[vertices.size() * 3];
|
||||
float[] texturesArray = new float[vertices.size() * 2];
|
||||
float[] normalsArray = new float[vertices.size() * 3];
|
||||
float[] tangentsArray = new float[vertices.size() * 3];
|
||||
float furthest = convertDataToArrays(vertices, textures, normals, verticesArray,
|
||||
texturesArray, normalsArray, tangentsArray);
|
||||
int[] indicesArray = convertIndicesListToArray(indices);
|
||||
|
||||
return Loader.loadToVAO(verticesArray, indicesArray, normalsArray, texturesArray);
|
||||
}
|
||||
|
||||
//used to be NEW
|
||||
private static void calculateTangents(VertexNM v0, VertexNM v1, VertexNM v2,
|
||||
List<Vector2f> textures) {
|
||||
Vector3f delatPos1 = Vector3f.sub(v1.getPosition(), v0.getPosition(), null);
|
||||
Vector3f delatPos2 = Vector3f.sub(v2.getPosition(), v0.getPosition(), null);
|
||||
Vector2f uv0 = textures.get(v0.getTextureIndex());
|
||||
Vector2f uv1 = textures.get(v1.getTextureIndex());
|
||||
Vector2f uv2 = textures.get(v2.getTextureIndex());
|
||||
Vector2f deltaUv1 = Vector2f.sub(uv1, uv0, null);
|
||||
Vector2f deltaUv2 = Vector2f.sub(uv2, uv0, null);
|
||||
|
||||
float r = 1.0f / (deltaUv1.x * deltaUv2.y - deltaUv1.y * deltaUv2.x);
|
||||
delatPos1.scale(deltaUv2.y);
|
||||
delatPos2.scale(deltaUv1.y);
|
||||
Vector3f tangent = Vector3f.sub(delatPos1, delatPos2, null);
|
||||
tangent.scale(r);
|
||||
v0.addTangent(tangent);
|
||||
v1.addTangent(tangent);
|
||||
v2.addTangent(tangent);
|
||||
}
|
||||
|
||||
private static VertexNM processVertex(String[] vertex, List<VertexNM> vertices,
|
||||
List<Integer> indices) {
|
||||
int index = Integer.parseInt(vertex[0]) - 1;
|
||||
VertexNM currentVertex = vertices.get(index);
|
||||
int textureIndex = Integer.parseInt(vertex[1]) - 1;
|
||||
int normalIndex = Integer.parseInt(vertex[2]) - 1;
|
||||
if (!currentVertex.isSet()) {
|
||||
currentVertex.setTextureIndex(textureIndex);
|
||||
currentVertex.setNormalIndex(normalIndex);
|
||||
indices.add(index);
|
||||
return currentVertex;
|
||||
} else {
|
||||
return dealWithAlreadyProcessedVertex(currentVertex, textureIndex, normalIndex, indices,
|
||||
vertices);
|
||||
}
|
||||
}
|
||||
|
||||
private static int[] convertIndicesListToArray(List<Integer> indices) {
|
||||
int[] indicesArray = new int[indices.size()];
|
||||
for (int i = 0; i < indicesArray.length; i++) {
|
||||
indicesArray[i] = indices.get(i);
|
||||
}
|
||||
return indicesArray;
|
||||
}
|
||||
|
||||
private static float convertDataToArrays(List<VertexNM> vertices, List<Vector2f> textures,
|
||||
List<Vector3f> normals, float[] verticesArray, float[] texturesArray,
|
||||
float[] normalsArray, float[] tangentsArray) {
|
||||
float furthestPoint = 0;
|
||||
for (int i = 0; i < vertices.size(); i++) {
|
||||
VertexNM currentVertex = vertices.get(i);
|
||||
if (currentVertex.getLength() > furthestPoint) {
|
||||
furthestPoint = currentVertex.getLength();
|
||||
}
|
||||
Vector3f position = currentVertex.getPosition();
|
||||
Vector2f textureCoord = textures.get(currentVertex.getTextureIndex());
|
||||
Vector3f normalVector = normals.get(currentVertex.getNormalIndex());
|
||||
Vector3f tangent = currentVertex.getAverageTangent();
|
||||
verticesArray[i * 3] = position.x;
|
||||
verticesArray[i * 3 + 1] = position.y;
|
||||
verticesArray[i * 3 + 2] = position.z;
|
||||
texturesArray[i * 2] = textureCoord.x;
|
||||
texturesArray[i * 2 + 1] = 1 - textureCoord.y;
|
||||
normalsArray[i * 3] = normalVector.x;
|
||||
normalsArray[i * 3 + 1] = normalVector.y;
|
||||
normalsArray[i * 3 + 2] = normalVector.z;
|
||||
tangentsArray[i * 3] = tangent.x;
|
||||
tangentsArray[i * 3 + 1] = tangent.y;
|
||||
tangentsArray[i * 3 + 2] = tangent.z;
|
||||
|
||||
}
|
||||
return furthestPoint;
|
||||
}
|
||||
|
||||
private static VertexNM dealWithAlreadyProcessedVertex(VertexNM previousVertex, int newTextureIndex,
|
||||
int newNormalIndex, List<Integer> indices, List<VertexNM> vertices) {
|
||||
if (previousVertex.hasSameTextureAndNormal(newTextureIndex, newNormalIndex)) {
|
||||
indices.add(previousVertex.getIndex());
|
||||
return previousVertex;
|
||||
} else {
|
||||
VertexNM anotherVertex = previousVertex.getDuplicateVertex();
|
||||
if (anotherVertex != null) {
|
||||
return dealWithAlreadyProcessedVertex(anotherVertex, newTextureIndex,
|
||||
newNormalIndex, indices, vertices);
|
||||
} else {
|
||||
VertexNM duplicateVertex = previousVertex.duplicate(vertices.size());//NEW
|
||||
duplicateVertex.setTextureIndex(newTextureIndex);
|
||||
duplicateVertex.setNormalIndex(newNormalIndex);
|
||||
previousVertex.setDuplicateVertex(duplicateVertex);
|
||||
vertices.add(duplicateVertex);
|
||||
indices.add(duplicateVertex.getIndex());
|
||||
return duplicateVertex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void removeUnusedVertices(List<VertexNM> vertices) {
|
||||
for (VertexNM vertex : vertices) {
|
||||
vertex.averageTangents();
|
||||
if (!vertex.isSet()) {
|
||||
vertex.setTextureIndex(0);
|
||||
vertex.setNormalIndex(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package io.github.hydos.ginger.normals.obj;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
|
||||
public class VertexNM {
|
||||
|
||||
private static final int NO_INDEX = -1;
|
||||
|
||||
private Vector3f position;
|
||||
private int textureIndex = NO_INDEX;
|
||||
private int normalIndex = NO_INDEX;
|
||||
private VertexNM duplicateVertex = null;
|
||||
private int index;
|
||||
private float length;
|
||||
private List<Vector3f> tangents = new ArrayList<Vector3f>();
|
||||
private Vector3f averagedTangent = new Vector3f(0, 0, 0);
|
||||
|
||||
protected VertexNM(int index, Vector3f position){
|
||||
this.index = index;
|
||||
this.position = position;
|
||||
this.length = position.length();
|
||||
}
|
||||
|
||||
protected void addTangent(Vector3f tangent){
|
||||
tangents.add(tangent);
|
||||
}
|
||||
|
||||
//NEW
|
||||
protected VertexNM duplicate(int newIndex){
|
||||
VertexNM vertex = new VertexNM(newIndex, position);
|
||||
vertex.tangents = this.tangents;
|
||||
return vertex;
|
||||
}
|
||||
|
||||
protected void averageTangents(){
|
||||
if(tangents.isEmpty()){
|
||||
return;
|
||||
}
|
||||
for(Vector3f tangent : tangents){
|
||||
Vector3f.add(averagedTangent, tangent, averagedTangent);
|
||||
}
|
||||
averagedTangent.normalise();
|
||||
}
|
||||
|
||||
protected Vector3f getAverageTangent(){
|
||||
return averagedTangent;
|
||||
}
|
||||
|
||||
protected int getIndex(){
|
||||
return index;
|
||||
}
|
||||
|
||||
protected float getLength(){
|
||||
return length;
|
||||
}
|
||||
|
||||
protected boolean isSet(){
|
||||
return textureIndex!=NO_INDEX && normalIndex!=NO_INDEX;
|
||||
}
|
||||
|
||||
protected boolean hasSameTextureAndNormal(int textureIndexOther,int normalIndexOther){
|
||||
return textureIndexOther==textureIndex && normalIndexOther==normalIndex;
|
||||
}
|
||||
|
||||
protected void setTextureIndex(int textureIndex){
|
||||
this.textureIndex = textureIndex;
|
||||
}
|
||||
|
||||
protected void setNormalIndex(int normalIndex){
|
||||
this.normalIndex = normalIndex;
|
||||
}
|
||||
|
||||
protected Vector3f getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
protected int getTextureIndex() {
|
||||
return textureIndex;
|
||||
}
|
||||
|
||||
protected int getNormalIndex() {
|
||||
return normalIndex;
|
||||
}
|
||||
|
||||
protected VertexNM getDuplicateVertex() {
|
||||
return duplicateVertex;
|
||||
}
|
||||
|
||||
protected void setDuplicateVertex(VertexNM duplicateVertex) {
|
||||
this.duplicateVertex = duplicateVertex;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package io.github.hydos.ginger.obj;
|
||||
|
||||
public class ModelData {
|
||||
|
||||
private float[] vertices;
|
||||
private float[] textureCoords;
|
||||
private float[] normals;
|
||||
private int[] indices;
|
||||
private float furthestPoint;
|
||||
|
||||
public ModelData(float[] vertices, float[] textureCoords, float[] normals, int[] indices,
|
||||
float furthestPoint) {
|
||||
this.vertices = vertices;
|
||||
this.textureCoords = textureCoords;
|
||||
this.normals = normals;
|
||||
this.indices = indices;
|
||||
this.furthestPoint = furthestPoint;
|
||||
}
|
||||
|
||||
public float[] getVertices() {
|
||||
return vertices;
|
||||
}
|
||||
|
||||
public float[] getTextureCoords() {
|
||||
return textureCoords;
|
||||
}
|
||||
|
||||
public float[] getNormals() {
|
||||
return normals;
|
||||
}
|
||||
|
||||
public int[] getIndices() {
|
||||
return indices;
|
||||
}
|
||||
|
||||
public float getFurthestPoint() {
|
||||
return furthestPoint;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package io.github.hydos.ginger.obj;
|
||||
|
||||
import io.github.hydos.ginger.renderEngine.models.TexturedModel;
|
||||
import io.github.hydos.ginger.renderEngine.texture.ModelTexture;
|
||||
import io.github.hydos.ginger.utils.Loader;
|
||||
|
||||
public class ModelLoader {
|
||||
|
||||
public static TexturedModel loadModel(String objPath, String texturePath) {
|
||||
ModelData data = OBJFileLoader.loadOBJ(objPath);
|
||||
TexturedModel tm = new TexturedModel(Loader.loadToVAO(data.getVertices(), data.getIndices(), data.getNormals(), data.getTextureCoords()), new ModelTexture(texturePath));
|
||||
return tm;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
package io.github.hydos.ginger.obj;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector2f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
|
||||
public class OBJFileLoader {
|
||||
|
||||
private static final String RES_LOC = "/models/";
|
||||
|
||||
public static ModelData loadOBJ(String objFileName) {
|
||||
String objFile = RES_LOC + objFileName;
|
||||
InputStreamReader isr = new InputStreamReader(Class.class.getResourceAsStream(objFile));
|
||||
BufferedReader reader = new BufferedReader(isr);
|
||||
String line;
|
||||
List<Vertex> vertices = new ArrayList<Vertex>();
|
||||
List<Vector2f> textures = new ArrayList<Vector2f>();
|
||||
List<Vector3f> normals = new ArrayList<Vector3f>();
|
||||
List<Integer> indices = new ArrayList<Integer>();
|
||||
try {
|
||||
while (true) {
|
||||
line = reader.readLine();
|
||||
if (line.startsWith("v ")) {
|
||||
String[] currentLine = line.split(" ");
|
||||
Vector3f vertex = new Vector3f(Float.valueOf(currentLine[1]),
|
||||
Float.valueOf(currentLine[2]),
|
||||
Float.valueOf(currentLine[3]));
|
||||
Vertex newVertex = new Vertex(vertices.size(), vertex);
|
||||
vertices.add(newVertex);
|
||||
|
||||
} else if (line.startsWith("vt ")) {
|
||||
String[] currentLine = line.split(" ");
|
||||
Vector2f texture = new Vector2f(Float.valueOf(currentLine[1]),
|
||||
Float.valueOf(currentLine[2]));
|
||||
textures.add(texture);
|
||||
} else if (line.startsWith("vn ")) {
|
||||
String[] currentLine = line.split(" ");
|
||||
Vector3f normal = new Vector3f(Float.valueOf(currentLine[1]),
|
||||
Float.valueOf(currentLine[2]),
|
||||
Float.valueOf(currentLine[3]));
|
||||
normals.add(normal);
|
||||
} else if (line.startsWith("f ")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (line != null && line.startsWith("f ")) {
|
||||
String[] currentLine = line.split(" ");
|
||||
String[] vertex1 = currentLine[1].split("/");
|
||||
String[] vertex2 = currentLine[2].split("/");
|
||||
String[] vertex3 = currentLine[3].split("/");
|
||||
processVertex(vertex1, vertices, indices);
|
||||
processVertex(vertex2, vertices, indices);
|
||||
processVertex(vertex3, vertices, indices);
|
||||
line = reader.readLine();
|
||||
}
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error reading the file");
|
||||
}
|
||||
removeUnusedVertices(vertices);
|
||||
float[] verticesArray = new float[vertices.size() * 3];
|
||||
float[] texturesArray = new float[vertices.size() * 2];
|
||||
float[] normalsArray = new float[vertices.size() * 3];
|
||||
float furthest = convertDataToArrays(vertices, textures, normals, verticesArray,
|
||||
texturesArray, normalsArray);
|
||||
int[] indicesArray = convertIndicesListToArray(indices);
|
||||
ModelData data = new ModelData(verticesArray, texturesArray, normalsArray, indicesArray,
|
||||
furthest);
|
||||
return data;
|
||||
}
|
||||
|
||||
private static void processVertex(String[] vertex, List<Vertex> vertices, List<Integer> indices) {
|
||||
int index = Integer.parseInt(vertex[0]) - 1;
|
||||
Vertex currentVertex = vertices.get(index);
|
||||
int textureIndex = Integer.parseInt(vertex[1]) - 1;
|
||||
int normalIndex = Integer.parseInt(vertex[2]) - 1;
|
||||
if (!currentVertex.isSet()) {
|
||||
currentVertex.setTextureIndex(textureIndex);
|
||||
currentVertex.setNormalIndex(normalIndex);
|
||||
indices.add(index);
|
||||
} else {
|
||||
dealWithAlreadyProcessedVertex(currentVertex, textureIndex, normalIndex, indices,
|
||||
vertices);
|
||||
}
|
||||
}
|
||||
|
||||
private static int[] convertIndicesListToArray(List<Integer> indices) {
|
||||
int[] indicesArray = new int[indices.size()];
|
||||
for (int i = 0; i < indicesArray.length; i++) {
|
||||
indicesArray[i] = indices.get(i);
|
||||
}
|
||||
return indicesArray;
|
||||
}
|
||||
|
||||
private static float convertDataToArrays(List<Vertex> vertices, List<Vector2f> textures,
|
||||
List<Vector3f> normals, float[] verticesArray, float[] texturesArray,
|
||||
float[] normalsArray) {
|
||||
float furthestPoint = 0;
|
||||
for (int i = 0; i < vertices.size(); i++) {
|
||||
Vertex currentVertex = vertices.get(i);
|
||||
if (currentVertex.getLength() > furthestPoint) {
|
||||
furthestPoint = currentVertex.getLength();
|
||||
}
|
||||
Vector3f position = currentVertex.getPosition();
|
||||
Vector2f textureCoord = textures.get(currentVertex.getTextureIndex());
|
||||
Vector3f normalVector = normals.get(currentVertex.getNormalIndex());
|
||||
verticesArray[i * 3] = position.x;
|
||||
verticesArray[i * 3 + 1] = position.y;
|
||||
verticesArray[i * 3 + 2] = position.z;
|
||||
texturesArray[i * 2] = textureCoord.x;
|
||||
texturesArray[i * 2 + 1] = 1 - textureCoord.y;
|
||||
normalsArray[i * 3] = normalVector.x;
|
||||
normalsArray[i * 3 + 1] = normalVector.y;
|
||||
normalsArray[i * 3 + 2] = normalVector.z;
|
||||
}
|
||||
return furthestPoint;
|
||||
}
|
||||
|
||||
private static void dealWithAlreadyProcessedVertex(Vertex previousVertex, int newTextureIndex,
|
||||
int newNormalIndex, List<Integer> indices, List<Vertex> vertices) {
|
||||
if (previousVertex.hasSameTextureAndNormal(newTextureIndex, newNormalIndex)) {
|
||||
indices.add(previousVertex.getIndex());
|
||||
} else {
|
||||
Vertex anotherVertex = previousVertex.getDuplicateVertex();
|
||||
if (anotherVertex != null) {
|
||||
dealWithAlreadyProcessedVertex(anotherVertex, newTextureIndex, newNormalIndex,
|
||||
indices, vertices);
|
||||
} else {
|
||||
Vertex duplicateVertex = new Vertex(vertices.size(), previousVertex.getPosition());
|
||||
duplicateVertex.setTextureIndex(newTextureIndex);
|
||||
duplicateVertex.setNormalIndex(newNormalIndex);
|
||||
previousVertex.setDuplicateVertex(duplicateVertex);
|
||||
vertices.add(duplicateVertex);
|
||||
indices.add(duplicateVertex.getIndex());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void removeUnusedVertices(List<Vertex> vertices){
|
||||
for(Vertex vertex:vertices){
|
||||
if(!vertex.isSet()){
|
||||
vertex.setTextureIndex(0);
|
||||
vertex.setNormalIndex(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package io.github.hydos.ginger.obj;
|
||||
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
|
||||
public class Vertex {
|
||||
|
||||
private static final int NO_INDEX = -1;
|
||||
|
||||
private Vector3f position;
|
||||
private int textureIndex = NO_INDEX;
|
||||
private int normalIndex = NO_INDEX;
|
||||
private Vertex duplicateVertex = null;
|
||||
private int index;
|
||||
private float length;
|
||||
|
||||
public Vertex(int index,Vector3f position){
|
||||
this.index = index;
|
||||
this.position = position;
|
||||
this.length = position.length();
|
||||
}
|
||||
|
||||
public int getIndex(){
|
||||
return index;
|
||||
}
|
||||
|
||||
public float getLength(){
|
||||
return length;
|
||||
}
|
||||
|
||||
public boolean isSet(){
|
||||
return textureIndex!=NO_INDEX && normalIndex!=NO_INDEX;
|
||||
}
|
||||
|
||||
public boolean hasSameTextureAndNormal(int textureIndexOther,int normalIndexOther){
|
||||
return textureIndexOther==textureIndex && normalIndexOther==normalIndex;
|
||||
}
|
||||
|
||||
public void setTextureIndex(int textureIndex){
|
||||
this.textureIndex = textureIndex;
|
||||
}
|
||||
|
||||
public void setNormalIndex(int normalIndex){
|
||||
this.normalIndex = normalIndex;
|
||||
}
|
||||
|
||||
public Vector3f getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public int getTextureIndex() {
|
||||
return textureIndex;
|
||||
}
|
||||
|
||||
public int getNormalIndex() {
|
||||
return normalIndex;
|
||||
}
|
||||
|
||||
public Vertex getDuplicateVertex() {
|
||||
return duplicateVertex;
|
||||
}
|
||||
|
||||
public void setDuplicateVertex(Vertex duplicateVertex) {
|
||||
this.duplicateVertex = duplicateVertex;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package io.github.hydos.ginger.renderEngine.models;
|
||||
|
||||
public class RawModel {
|
||||
|
||||
private int vaoID;
|
||||
private int vertexCount;
|
||||
|
||||
public RawModel(int vaoID, int vertexCount) {
|
||||
this.vaoID = vaoID;
|
||||
this.vertexCount = vertexCount;
|
||||
}
|
||||
|
||||
public int getVaoID() {
|
||||
return vaoID;
|
||||
}
|
||||
|
||||
public int getVertexCount() {
|
||||
return vertexCount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package io.github.hydos.ginger.renderEngine.models;
|
||||
|
||||
import io.github.hydos.ginger.renderEngine.texture.ModelTexture;
|
||||
|
||||
public class TexturedModel {
|
||||
|
||||
private RawModel rawModel;
|
||||
private ModelTexture texture;
|
||||
|
||||
public TexturedModel(RawModel model, ModelTexture texture) {
|
||||
this.rawModel = model;
|
||||
this.texture = texture;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public RawModel getRawModel() {
|
||||
return rawModel;
|
||||
}
|
||||
|
||||
public ModelTexture getTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package io.github.hydos.ginger.renderEngine.renderers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
import io.github.hydos.ginger.elements.Entity;
|
||||
import io.github.hydos.ginger.mathEngine.Maths;
|
||||
import io.github.hydos.ginger.mathEngine.matrixes.Matrix4f;
|
||||
import io.github.hydos.ginger.renderEngine.models.RawModel;
|
||||
import io.github.hydos.ginger.renderEngine.models.TexturedModel;
|
||||
import io.github.hydos.ginger.renderEngine.shaders.StaticShader;
|
||||
import io.github.hydos.ginger.renderEngine.texture.ModelTexture;
|
||||
|
||||
public class EntityRenderer {
|
||||
|
||||
private StaticShader shader;
|
||||
|
||||
public EntityRenderer(StaticShader shader, Matrix4f projectionMatrix) {
|
||||
this.shader = shader;
|
||||
shader.start();
|
||||
shader.loadProjectionMatrix(projectionMatrix);
|
||||
shader.stop();
|
||||
}
|
||||
|
||||
public void render(Map<TexturedModel,List<Entity>> entities) {
|
||||
for(TexturedModel model: entities.keySet()) {
|
||||
prepareTexturedModel(model);
|
||||
List<Entity> batch = entities.get(model);
|
||||
for(Entity entity:batch) {
|
||||
prepareInstance(entity);
|
||||
GL11.glDrawElements(GL11.GL_TRIANGLES, model.getRawModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
unbindTexturedModel();
|
||||
}
|
||||
}
|
||||
|
||||
private void prepareTexturedModel(TexturedModel model) {
|
||||
RawModel rawModel = model.getRawModel();
|
||||
GL30.glBindVertexArray(rawModel.getVaoID());
|
||||
GL20.glEnableVertexAttribArray(0);
|
||||
GL20.glEnableVertexAttribArray(1);
|
||||
GL20.glEnableVertexAttribArray(2);
|
||||
ModelTexture texture = model.getTexture();
|
||||
if(texture.isTransparent()) {
|
||||
MasterRenderer.disableCulling();
|
||||
}else {
|
||||
MasterRenderer.enableCulling();
|
||||
}
|
||||
shader.loadFakeLightingVariable(texture.isUseFakeLighting());
|
||||
shader.loadShine(texture.getShineDamper(), texture.getReflectivity());
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, model.getTexture().getTextureID());
|
||||
}
|
||||
|
||||
private void unbindTexturedModel() {
|
||||
GL20.glDisableVertexAttribArray(0);
|
||||
GL20.glDisableVertexAttribArray(1);
|
||||
GL20.glDisableVertexAttribArray(2);
|
||||
GL30.glBindVertexArray(0);
|
||||
}
|
||||
|
||||
private void prepareInstance(Entity entity) {
|
||||
Matrix4f transformationMatrix = Maths.createTransformationMatrix(entity.getPosition(), entity.getRotX(), entity.getRotY(), entity.getRotZ(), entity.getScale());
|
||||
shader.loadTransformationMatrix(transformationMatrix);
|
||||
|
||||
}
|
||||
|
||||
public void prepare() {
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package io.github.hydos.ginger.renderEngine.renderers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
import io.github.hydos.ginger.guis.GuiTexture;
|
||||
import io.github.hydos.ginger.mathEngine.Maths;
|
||||
import io.github.hydos.ginger.mathEngine.matrixes.Matrix4f;
|
||||
import io.github.hydos.ginger.renderEngine.models.RawModel;
|
||||
import io.github.hydos.ginger.renderEngine.shaders.GuiShader;
|
||||
import io.github.hydos.ginger.utils.Loader;
|
||||
|
||||
public class GuiRenderer {
|
||||
|
||||
private final RawModel quad;
|
||||
|
||||
private GuiShader shader;
|
||||
|
||||
public GuiRenderer(GuiShader shader) {
|
||||
this.shader = shader;
|
||||
float[] positions = {-1, 1, -1, -1, 1, 1, 1, -1};
|
||||
quad = Loader.loadToVAO(positions, 2);
|
||||
|
||||
}
|
||||
|
||||
public void render(List<GuiTexture> guis) {
|
||||
shader.start();
|
||||
GL30.glBindVertexArray(quad.getVaoID());
|
||||
GL20.glEnableVertexAttribArray(0);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
for(GuiTexture gui: guis) {
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, gui.getTexture());
|
||||
Matrix4f matrix = Maths.createTransformationMatrix(gui.getPosition(), gui.getScale());
|
||||
shader.loadTransformation(matrix);
|
||||
GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, quad.getVertexCount());
|
||||
}
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
GL20.glDisableVertexAttribArray(0);
|
||||
GL30.glBindVertexArray(0);
|
||||
shader.stop();
|
||||
}
|
||||
|
||||
public void cleanUp() {
|
||||
shader.cleanUp();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,142 @@
|
|||
package io.github.hydos.ginger.renderEngine.renderers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import io.github.hydos.ginger.elements.Entity;
|
||||
import io.github.hydos.ginger.elements.Light;
|
||||
import io.github.hydos.ginger.elements.ThirdPersonCamera;
|
||||
import io.github.hydos.ginger.guis.GuiTexture;
|
||||
import io.github.hydos.ginger.io.Window;
|
||||
import io.github.hydos.ginger.mathEngine.matrixes.Matrix4f;
|
||||
import io.github.hydos.ginger.renderEngine.models.TexturedModel;
|
||||
import io.github.hydos.ginger.renderEngine.shaders.GuiShader;
|
||||
import io.github.hydos.ginger.renderEngine.shaders.StaticShader;
|
||||
import io.github.hydos.ginger.renderEngine.shaders.TerrainShader;
|
||||
import io.github.hydos.ginger.terrain.Terrain;
|
||||
|
||||
public class MasterRenderer {
|
||||
|
||||
private StaticShader entityShader;
|
||||
private EntityRenderer entityRenderer;
|
||||
|
||||
private TerrainShader terrainShader;
|
||||
private TerrainRenderer terrainRenderer;
|
||||
|
||||
private GuiShader guiShader;
|
||||
private GuiRenderer guiRenderer;
|
||||
|
||||
private SkyboxRenderer skyboxRenderer;
|
||||
|
||||
private Matrix4f projectionMatrix;
|
||||
|
||||
private Map<TexturedModel, List<Entity>> entities = new HashMap<TexturedModel, List<Entity>>();
|
||||
|
||||
private static final float FOV = 70f;
|
||||
private static final float NEAR_PLANE = 0.1f;
|
||||
private static final float FAR_PLANE = 1000f;
|
||||
|
||||
public MasterRenderer() {
|
||||
createProjectionMatrix();
|
||||
entityShader = new StaticShader();
|
||||
entityRenderer = new EntityRenderer(entityShader, projectionMatrix);
|
||||
|
||||
skyboxRenderer = new SkyboxRenderer(projectionMatrix);
|
||||
|
||||
guiShader = new GuiShader();
|
||||
guiRenderer = new GuiRenderer(guiShader);
|
||||
|
||||
terrainShader = new TerrainShader();
|
||||
terrainRenderer = new TerrainRenderer(terrainShader, projectionMatrix);
|
||||
|
||||
}
|
||||
|
||||
public static void enableCulling() {
|
||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
GL11.glCullFace(GL11.GL_BACK);
|
||||
}
|
||||
|
||||
public static void disableCulling() {
|
||||
GL11.glDisable(GL11.GL_CULL_FACE);
|
||||
}
|
||||
|
||||
public void renderScene(List<Entity> entities, List<Terrain> terrains, List<Light> lights, ThirdPersonCamera camera) {
|
||||
renderEntities(entities, camera, lights);
|
||||
renderTerrains(terrains, lights, camera);
|
||||
renderEntities(entities, camera, lights);
|
||||
renderTerrains(terrains, lights, camera);
|
||||
skyboxRenderer.render(camera);
|
||||
|
||||
}
|
||||
|
||||
public void renderGuis(List<GuiTexture> guis) {
|
||||
guiRenderer.render(guis);
|
||||
}
|
||||
|
||||
private void renderTerrains(List<Terrain> terrains, List<Light> lights, ThirdPersonCamera camera) {
|
||||
terrainShader.start();
|
||||
terrainShader.loadSkyColour(Window.getColour());
|
||||
terrainShader.loadLights(lights);
|
||||
terrainShader.loadViewMatrix(camera);
|
||||
terrainRenderer.render(terrains);
|
||||
terrainShader.stop();
|
||||
}
|
||||
|
||||
private void renderEntities(List<Entity> entities, ThirdPersonCamera camera, List<Light> lights) {
|
||||
for(Entity entity: entities) {
|
||||
processEntity(entity);
|
||||
}
|
||||
entityRenderer.prepare();
|
||||
entityShader.start();
|
||||
entityShader.loadSkyColour(Window.getColour());
|
||||
entityShader.loadLights(lights);
|
||||
entityShader.loadViewMatrix(camera);
|
||||
entityRenderer.render(this.entities);
|
||||
entityShader.stop();
|
||||
this.entities.clear();
|
||||
}
|
||||
|
||||
private void processEntity(Entity entity) {
|
||||
TexturedModel entityModel = entity.getModel();
|
||||
List<Entity> batch = entities.get(entityModel);
|
||||
if(batch!=null) {
|
||||
batch.add(entity);
|
||||
}else {
|
||||
List<Entity> newBatch = new ArrayList<Entity>();
|
||||
newBatch.add(entity);
|
||||
entities.put(entityModel, newBatch);
|
||||
}
|
||||
}
|
||||
|
||||
public void cleanUp() {
|
||||
entityShader.cleanUp();
|
||||
terrainShader.cleanUp();
|
||||
guiRenderer.cleanUp();
|
||||
|
||||
}
|
||||
|
||||
public Matrix4f getProjectionMatrix() {
|
||||
return this.projectionMatrix;
|
||||
}
|
||||
|
||||
private void createProjectionMatrix() {
|
||||
float aspectRatio = (float) Window.width / Window.height;
|
||||
float y_scale = (float) ((1f / Math.tan(Math.toRadians(FOV / 2f))) * aspectRatio);
|
||||
float x_Scale = y_scale / aspectRatio;
|
||||
float frustum_length = FAR_PLANE - NEAR_PLANE;
|
||||
|
||||
projectionMatrix = new Matrix4f();
|
||||
projectionMatrix.m00 = x_Scale;
|
||||
projectionMatrix.m11 = y_scale;
|
||||
projectionMatrix.m22 = -((FAR_PLANE + NEAR_PLANE) / frustum_length);
|
||||
projectionMatrix.m23 = -1;
|
||||
projectionMatrix.m32 = -((2* NEAR_PLANE * FAR_PLANE) / frustum_length);
|
||||
projectionMatrix.m33 = 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package io.github.hydos.ginger.renderEngine.renderers;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
import io.github.hydos.ginger.elements.ThirdPersonCamera;
|
||||
import io.github.hydos.ginger.mathEngine.matrixes.Matrix4f;
|
||||
import io.github.hydos.ginger.renderEngine.models.RawModel;
|
||||
import io.github.hydos.ginger.renderEngine.shaders.SkyboxShader;
|
||||
import io.github.hydos.ginger.utils.Loader;
|
||||
|
||||
public class SkyboxRenderer {
|
||||
|
||||
private static final float SIZE = 50f;
|
||||
|
||||
private static final float[] VERTICES = {
|
||||
-SIZE, SIZE, -SIZE,
|
||||
-SIZE, -SIZE, -SIZE,
|
||||
SIZE, -SIZE, -SIZE,
|
||||
SIZE, -SIZE, -SIZE,
|
||||
SIZE, SIZE, -SIZE,
|
||||
-SIZE, SIZE, -SIZE,
|
||||
|
||||
-SIZE, -SIZE, SIZE,
|
||||
-SIZE, -SIZE, -SIZE,
|
||||
-SIZE, SIZE, -SIZE,
|
||||
-SIZE, SIZE, -SIZE,
|
||||
-SIZE, SIZE, SIZE,
|
||||
-SIZE, -SIZE, SIZE,
|
||||
|
||||
SIZE, -SIZE, -SIZE,
|
||||
SIZE, -SIZE, SIZE,
|
||||
SIZE, SIZE, SIZE,
|
||||
SIZE, SIZE, SIZE,
|
||||
SIZE, SIZE, -SIZE,
|
||||
SIZE, -SIZE, -SIZE,
|
||||
|
||||
-SIZE, -SIZE, SIZE,
|
||||
-SIZE, SIZE, SIZE,
|
||||
SIZE, SIZE, SIZE,
|
||||
SIZE, SIZE, SIZE,
|
||||
SIZE, -SIZE, SIZE,
|
||||
-SIZE, -SIZE, SIZE,
|
||||
|
||||
-SIZE, SIZE, -SIZE,
|
||||
SIZE, SIZE, -SIZE,
|
||||
SIZE, SIZE, SIZE,
|
||||
SIZE, SIZE, SIZE,
|
||||
-SIZE, SIZE, SIZE,
|
||||
-SIZE, SIZE, -SIZE,
|
||||
|
||||
-SIZE, -SIZE, -SIZE,
|
||||
-SIZE, -SIZE, SIZE,
|
||||
SIZE, -SIZE, -SIZE,
|
||||
SIZE, -SIZE, -SIZE,
|
||||
-SIZE, -SIZE, SIZE,
|
||||
SIZE, -SIZE, SIZE
|
||||
};
|
||||
|
||||
private static String[] TEXTURE_FILES = {"right.png", "left.png", "up.png", "down.png", "back.png", "front.png"};
|
||||
|
||||
|
||||
private RawModel cube;
|
||||
private int texture;
|
||||
private SkyboxShader shader;
|
||||
|
||||
public SkyboxRenderer(Matrix4f projectionMatrix) {
|
||||
cube = Loader.loadToVAO(VERTICES, 3);
|
||||
texture = Loader.loadCubeMap(TEXTURE_FILES);
|
||||
shader = new SkyboxShader();
|
||||
shader.start();
|
||||
shader.loadProjectionMatrix(projectionMatrix);
|
||||
shader.stop();
|
||||
}
|
||||
|
||||
public void render(ThirdPersonCamera camera) {
|
||||
shader.start();
|
||||
shader.loadViewMatrix(camera);
|
||||
GL30.glBindVertexArray(cube.getVaoID());
|
||||
GL20.glEnableVertexAttribArray(0);
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texture);
|
||||
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, cube.getVertexCount());
|
||||
GL20.glDisableVertexAttribArray(0);
|
||||
GL30.glBindVertexArray(0);
|
||||
shader.stop();
|
||||
}
|
||||
|
||||
public void cleanUp() {
|
||||
shader.cleanUp();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package io.github.hydos.ginger.renderEngine.renderers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
import io.github.hydos.ginger.mathEngine.Maths;
|
||||
import io.github.hydos.ginger.mathEngine.matrixes.Matrix4f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
import io.github.hydos.ginger.renderEngine.models.RawModel;
|
||||
import io.github.hydos.ginger.renderEngine.shaders.TerrainShader;
|
||||
import io.github.hydos.ginger.terrain.Terrain;
|
||||
import io.github.hydos.ginger.terrain.TerrainTexture;
|
||||
import io.github.hydos.ginger.terrain.TerrainTexturePack;
|
||||
|
||||
public class TerrainRenderer {
|
||||
|
||||
private TerrainShader shader;
|
||||
|
||||
public TerrainRenderer(TerrainShader shader, Matrix4f projectionMatrix) {
|
||||
this.shader = shader;
|
||||
shader.start();
|
||||
shader.loadProjectionMatrix(projectionMatrix);
|
||||
shader.connectTextureUnits();
|
||||
shader.stop();
|
||||
}
|
||||
|
||||
public void render(List<Terrain> terrains) {
|
||||
for(Terrain t : terrains) {
|
||||
prepareTerrain(t);
|
||||
loadModelMatrix(t);
|
||||
GL11.glDrawElements(GL11.GL_TRIANGLES, t.getModel().getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
|
||||
unbindTerrain();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void prepareTerrain(Terrain terrain) {
|
||||
RawModel rawModel = terrain.getModel();
|
||||
GL30.glBindVertexArray(rawModel.getVaoID());
|
||||
GL20.glEnableVertexAttribArray(0);
|
||||
GL20.glEnableVertexAttribArray(1);
|
||||
GL20.glEnableVertexAttribArray(2);
|
||||
bindTextures(terrain);
|
||||
shader.loadShine(1, 0);
|
||||
|
||||
}
|
||||
|
||||
private void bindTextures(Terrain terrain) {
|
||||
TerrainTexturePack texturePack = terrain.getTexturePack();
|
||||
TerrainTexture blendMap = terrain.getBlendMap();
|
||||
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texturePack.getBackgroundTexture().getTextureID());
|
||||
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE1);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texturePack.getrTexture().getTextureID());
|
||||
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE2);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texturePack.getgTexture().getTextureID());
|
||||
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE3);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texturePack.getbTexture().getTextureID());
|
||||
|
||||
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE4);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, blendMap.getTextureID());
|
||||
}
|
||||
|
||||
private void unbindTerrain() {
|
||||
GL20.glDisableVertexAttribArray(0);
|
||||
GL20.glDisableVertexAttribArray(1);
|
||||
GL20.glDisableVertexAttribArray(2);
|
||||
GL30.glBindVertexArray(0);
|
||||
}
|
||||
|
||||
private void loadModelMatrix(Terrain terrain) {
|
||||
Matrix4f transformationMatrix = Maths.createTransformationMatrix(new Vector3f(terrain.getX(), 0, terrain.getZ()), 0, 0, 0, new Vector3f(1,1,1));
|
||||
shader.loadTransformationMatrix(transformationMatrix);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package io.github.hydos.ginger.renderEngine.shaders;
|
||||
|
||||
import io.github.hydos.ginger.mathEngine.matrixes.Matrix4f;
|
||||
|
||||
public class GuiShader extends ShaderProgram{
|
||||
|
||||
private static final String VERTEX_FILE = "guiVertexShader.glsl";
|
||||
private static final String FRAGMENT_FILE = "guiFragmentShader.glsl";
|
||||
|
||||
private int location_transformationMatrix;
|
||||
|
||||
public GuiShader() {
|
||||
super(VERTEX_FILE, FRAGMENT_FILE);
|
||||
}
|
||||
|
||||
public void loadTransformation(Matrix4f matrix){
|
||||
super.loadMatrix(location_transformationMatrix, matrix);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getAllUniformLocations() {
|
||||
location_transformationMatrix = super.getUniformLocation("transformationMatrix");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindAttributes() {
|
||||
super.bindAttribute(0, "position");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package io.github.hydos.ginger.renderEngine.shaders;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
|
||||
import io.github.hydos.ginger.mathEngine.matrixes.Matrix4f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector2f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector4f;
|
||||
|
||||
public abstract class ShaderProgram {
|
||||
|
||||
private int programID;
|
||||
private int vertexShaderID;
|
||||
private int fragmentShaderID;
|
||||
|
||||
private static FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(16);
|
||||
|
||||
public ShaderProgram(String vertexFile,String fragmentFile){
|
||||
vertexShaderID = loadShader(vertexFile,GL20.GL_VERTEX_SHADER);
|
||||
fragmentShaderID = loadShader(fragmentFile,GL20.GL_FRAGMENT_SHADER);
|
||||
programID = GL20.glCreateProgram();
|
||||
GL20.glAttachShader(programID, vertexShaderID);
|
||||
GL20.glAttachShader(programID, fragmentShaderID);
|
||||
bindAttributes();
|
||||
GL20.glLinkProgram(programID);
|
||||
GL20.glValidateProgram(programID);
|
||||
getAllUniformLocations();
|
||||
}
|
||||
|
||||
protected abstract void getAllUniformLocations();
|
||||
|
||||
protected int getUniformLocation(String uniformName){
|
||||
return GL20.glGetUniformLocation(programID,uniformName);
|
||||
}
|
||||
|
||||
public void start(){
|
||||
GL20.glUseProgram(programID);
|
||||
}
|
||||
|
||||
public void stop(){
|
||||
GL20.glUseProgram(0);
|
||||
}
|
||||
|
||||
public void cleanUp(){
|
||||
stop();
|
||||
GL20.glDetachShader(programID, vertexShaderID);
|
||||
GL20.glDetachShader(programID, fragmentShaderID);
|
||||
GL20.glDeleteShader(vertexShaderID);
|
||||
GL20.glDeleteShader(fragmentShaderID);
|
||||
GL20.glDeleteProgram(programID);
|
||||
}
|
||||
|
||||
protected abstract void bindAttributes();
|
||||
|
||||
protected void bindAttribute(int attribute, String variableName){
|
||||
GL20.glBindAttribLocation(programID, attribute, variableName);
|
||||
}
|
||||
|
||||
protected void loadFloat(int location, float value){
|
||||
GL20.glUniform1f(location, value);
|
||||
}
|
||||
|
||||
protected void loadInt(int location, int value){
|
||||
GL20.glUniform1i(location, value);
|
||||
}
|
||||
|
||||
protected void loadVector(int location, Vector3f vector){
|
||||
GL20.glUniform3f(location,vector.x,vector.y,vector.z);
|
||||
}
|
||||
|
||||
protected void loadVector(int location, Vector4f vector){
|
||||
GL20.glUniform4f(location,vector.x,vector.y,vector.z, vector.w);
|
||||
}
|
||||
|
||||
protected void load2DVector(int location, Vector2f vector){
|
||||
GL20.glUniform2f(location,vector.x,vector.y);
|
||||
}
|
||||
|
||||
protected void loadBoolean(int location, boolean value){
|
||||
float toLoad = 0;
|
||||
if(value){
|
||||
toLoad = 1;
|
||||
}
|
||||
GL20.glUniform1f(location, toLoad);
|
||||
}
|
||||
|
||||
protected void loadMatrix(int location, Matrix4f matrix){
|
||||
matrix.store(matrixBuffer);
|
||||
matrixBuffer.flip();
|
||||
GL20.glUniformMatrix4fv(location, false, matrixBuffer);
|
||||
}
|
||||
|
||||
private static int loadShader(String file, int type){
|
||||
StringBuilder shaderSource = new StringBuilder();
|
||||
try{
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(Class.class.getResourceAsStream("/shaders/" + file)));
|
||||
String line;
|
||||
while((line = reader.readLine())!=null){
|
||||
shaderSource.append(line).append("\n");
|
||||
}
|
||||
reader.close();
|
||||
}catch(IOException e){
|
||||
e.printStackTrace();
|
||||
System.exit(-1);
|
||||
}
|
||||
int shaderID = GL20.glCreateShader(type);
|
||||
GL20.glShaderSource(shaderID, shaderSource);
|
||||
GL20.glCompileShader(shaderID);
|
||||
if(GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS )== GL11.GL_FALSE){
|
||||
System.out.println(GL20.glGetShaderInfoLog(shaderID, 500));
|
||||
System.err.println("Could not compile shader!");
|
||||
System.exit(-1);
|
||||
}
|
||||
return shaderID;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package io.github.hydos.ginger.renderEngine.shaders;
|
||||
|
||||
import io.github.hydos.ginger.elements.ThirdPersonCamera;
|
||||
import io.github.hydos.ginger.mathEngine.Maths;
|
||||
import io.github.hydos.ginger.mathEngine.matrixes.Matrix4f;
|
||||
|
||||
public class SkyboxShader extends ShaderProgram{
|
||||
|
||||
private int location_projectionMatrix;
|
||||
private int location_viewMatrix;
|
||||
|
||||
public SkyboxShader() {
|
||||
super("skyboxVertexShader.glsl", "skyboxFragmentShader.glsl");
|
||||
}
|
||||
|
||||
public void loadProjectionMatrix(Matrix4f matrix){
|
||||
super.loadMatrix(location_projectionMatrix, matrix);
|
||||
}
|
||||
|
||||
public void loadViewMatrix(ThirdPersonCamera camera){
|
||||
Matrix4f matrix = Maths.createViewMatrix(camera);
|
||||
matrix.m30 = 0;
|
||||
matrix.m31 = 0;
|
||||
matrix.m32 = 0;
|
||||
super.loadMatrix(location_viewMatrix, matrix);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getAllUniformLocations() {
|
||||
location_projectionMatrix = super.getUniformLocation("projectionMatrix");
|
||||
location_viewMatrix = super.getUniformLocation("viewMatrix");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindAttributes() {
|
||||
super.bindAttribute(0, "position");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
package io.github.hydos.ginger.renderEngine.shaders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.github.hydos.ginger.elements.Light;
|
||||
import io.github.hydos.ginger.elements.ThirdPersonCamera;
|
||||
import io.github.hydos.ginger.mathEngine.Maths;
|
||||
import io.github.hydos.ginger.mathEngine.matrixes.Matrix4f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
|
||||
public class StaticShader extends ShaderProgram{
|
||||
|
||||
private static final int MAX_LIGHTS = 5;
|
||||
|
||||
private int location_transformationMatrix;
|
||||
private int location_projectionMatrix;
|
||||
private int location_viewMatrix;
|
||||
private int location_lightColour[];
|
||||
private int location_lightPosition[];
|
||||
private int location_attenuation[];
|
||||
private int location_shineDamper;
|
||||
private int location_reflectivity;
|
||||
private int location_useFakeLighting;
|
||||
private int location_skyColour;
|
||||
|
||||
|
||||
|
||||
public StaticShader() {
|
||||
super("entityVertexShader.glsl", "entityFragmentShader.glsl");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getAllUniformLocations() {
|
||||
location_transformationMatrix = super.getUniformLocation("transformationMatrix");
|
||||
location_projectionMatrix = super.getUniformLocation("projectionMatrix");
|
||||
location_viewMatrix = super.getUniformLocation("viewMatrix");
|
||||
location_shineDamper = super.getUniformLocation("shineDamper");
|
||||
location_reflectivity = super.getUniformLocation("reflectivity");
|
||||
location_useFakeLighting = super.getUniformLocation("useFakeLighting");
|
||||
location_skyColour = super.getUniformLocation("skyColour");
|
||||
|
||||
location_lightPosition = new int[MAX_LIGHTS];
|
||||
location_lightColour = new int[MAX_LIGHTS];
|
||||
location_attenuation = new int[MAX_LIGHTS];
|
||||
for(int i=0; i<MAX_LIGHTS;i++) {
|
||||
location_lightPosition[i] = super.getUniformLocation("lightPosition[" + i + "]");
|
||||
location_lightColour[i] = super.getUniformLocation("lightColour[" + i + "]");
|
||||
location_attenuation[i] = super.getUniformLocation("attenuation[" + i + "]");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindAttributes() {
|
||||
super.bindAttribute(0, "position");
|
||||
super.bindAttribute(1, "textureCoords");
|
||||
super.bindAttribute(2, "normal");
|
||||
}
|
||||
|
||||
public void loadTransformationMatrix(Matrix4f matrix) {
|
||||
super.loadMatrix(location_transformationMatrix, matrix);
|
||||
}
|
||||
|
||||
public void loadProjectionMatrix(Matrix4f matrix) {
|
||||
super.loadMatrix(location_projectionMatrix, matrix);
|
||||
}
|
||||
|
||||
public void loadViewMatrix(ThirdPersonCamera camera) {
|
||||
Matrix4f matrix = Maths.createViewMatrix(camera);
|
||||
super.loadMatrix(location_viewMatrix, matrix);
|
||||
}
|
||||
|
||||
public void loadLights(List<Light> lights) {
|
||||
for(int i=0; i<MAX_LIGHTS;i++) {
|
||||
if(i<lights.size()) {
|
||||
super.loadVector(location_lightPosition[i], lights.get(i).getPosition());
|
||||
super.loadVector(location_lightColour[i], lights.get(i).getColour());
|
||||
super.loadVector(location_attenuation[i], lights.get(i).getAttenuation());
|
||||
}else {
|
||||
super.loadVector(location_lightPosition[i], new Vector3f(0, 0, 0));
|
||||
super.loadVector(location_lightColour[i], new Vector3f(0, 0, 0));
|
||||
super.loadVector(location_attenuation[i], new Vector3f(1, 0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadShine(float damper, float reflectivity) {
|
||||
super.loadFloat(location_shineDamper, damper);
|
||||
super.loadFloat(location_reflectivity, reflectivity);
|
||||
}
|
||||
|
||||
public void loadFakeLightingVariable(boolean useFake) {
|
||||
super.loadBoolean(location_useFakeLighting, useFake);
|
||||
}
|
||||
|
||||
public void loadSkyColour(Vector3f colour) {
|
||||
super.loadVector(location_skyColour, colour);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
package io.github.hydos.ginger.renderEngine.shaders;
|
||||
|
||||
import io.github.hydos.ginger.elements.ThirdPersonCamera;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.github.hydos.ginger.elements.Light;
|
||||
import io.github.hydos.ginger.mathEngine.Maths;
|
||||
import io.github.hydos.ginger.mathEngine.matrixes.Matrix4f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
|
||||
public class TerrainShader extends ShaderProgram{
|
||||
|
||||
private static final int MAX_LIGHTS = 5;
|
||||
|
||||
private int location_transformationMatrix;
|
||||
private int location_projectionMatrix;
|
||||
private int location_viewMatrix;
|
||||
|
||||
private int location_lightColour[];
|
||||
private int location_lightPosition[];
|
||||
private int location_attenuation[];
|
||||
|
||||
private int location_shineDamper;
|
||||
private int location_reflectivity;
|
||||
|
||||
private int location_skyColour;
|
||||
|
||||
private int location_backgroundTexture;
|
||||
|
||||
private int location_rTexture;
|
||||
|
||||
private int location_gTexture;
|
||||
|
||||
private int location_bTexture;
|
||||
|
||||
private int location_blendMap;
|
||||
|
||||
|
||||
public TerrainShader() {
|
||||
super("terrainVertexShader.glsl", "terrainFragmentShader.glsl");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getAllUniformLocations() {
|
||||
location_transformationMatrix = super.getUniformLocation("transformationMatrix");
|
||||
location_projectionMatrix = super.getUniformLocation("projectionMatrix");
|
||||
location_viewMatrix = super.getUniformLocation("viewMatrix");
|
||||
location_lightPosition = new int[MAX_LIGHTS];
|
||||
location_lightColour = new int[MAX_LIGHTS];
|
||||
location_attenuation = new int[MAX_LIGHTS];
|
||||
for(int i=0; i<MAX_LIGHTS;i++) {
|
||||
location_lightPosition[i] = super.getUniformLocation("lightPosition[" + i + "]");
|
||||
location_lightColour[i] = super.getUniformLocation("lightColour[" + i + "]");
|
||||
location_attenuation[i] = super.getUniformLocation("attenuation[" + i + "]");
|
||||
}
|
||||
location_shineDamper = super.getUniformLocation("shineDamper");
|
||||
location_reflectivity = super.getUniformLocation("reflectivity");
|
||||
location_skyColour = super.getUniformLocation("skyColour");
|
||||
location_backgroundTexture = super.getUniformLocation("backgroundTexture");
|
||||
location_rTexture = super.getUniformLocation("rTexture");
|
||||
location_gTexture = super.getUniformLocation("gTexture");
|
||||
location_bTexture = super.getUniformLocation("bTexture");
|
||||
location_blendMap = super.getUniformLocation("blendMap");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindAttributes() {
|
||||
super.bindAttribute(0, "position");
|
||||
super.bindAttribute(1, "textureCoords");
|
||||
super.bindAttribute(2, "normal");
|
||||
}
|
||||
|
||||
public void loadTransformationMatrix(Matrix4f matrix) {
|
||||
super.loadMatrix(location_transformationMatrix, matrix);
|
||||
}
|
||||
|
||||
public void loadProjectionMatrix(Matrix4f matrix) {
|
||||
super.loadMatrix(location_projectionMatrix, matrix);
|
||||
}
|
||||
|
||||
public void loadViewMatrix(ThirdPersonCamera camera) {
|
||||
Matrix4f matrix = Maths.createViewMatrix(camera);
|
||||
super.loadMatrix(location_viewMatrix, matrix);
|
||||
}
|
||||
|
||||
public void loadLights(List<Light> lights) {
|
||||
for(int i=0; i<MAX_LIGHTS;i++) {
|
||||
if(i<lights.size()) {
|
||||
super.loadVector(location_lightPosition[i], lights.get(i).getPosition());
|
||||
super.loadVector(location_lightColour[i], lights.get(i).getColour());
|
||||
super.loadVector(location_attenuation[i], lights.get(i).getAttenuation());
|
||||
}else {
|
||||
super.loadVector(location_lightPosition[i], new Vector3f(0, 0, 0));
|
||||
super.loadVector(location_lightColour[i], new Vector3f(0, 0, 0));
|
||||
super.loadVector(location_attenuation[i], new Vector3f(1, 0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadShine(float damper, float reflectivity) {
|
||||
super.loadFloat(location_shineDamper, damper);
|
||||
super.loadFloat(location_reflectivity, reflectivity);
|
||||
}
|
||||
|
||||
public void loadSkyColour(Vector3f colour) {
|
||||
super.loadVector(location_skyColour, colour);
|
||||
}
|
||||
|
||||
public void connectTextureUnits() {
|
||||
super.loadInt(location_backgroundTexture, 0);
|
||||
super.loadInt(location_rTexture, 1);
|
||||
super.loadInt(location_gTexture, 2);
|
||||
super.loadInt(location_bTexture, 3);
|
||||
super.loadInt(location_blendMap, 4);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
package io.github.hydos.ginger.renderEngine.texture;
|
||||
|
||||
import static org.lwjgl.stb.STBImage.stbi_failure_reason;
|
||||
import static org.lwjgl.stb.STBImage.stbi_info_from_memory;
|
||||
import static org.lwjgl.stb.STBImage.stbi_load_from_memory;
|
||||
import static org.lwjgl.system.MemoryStack.stackPush;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
|
||||
import io.github.hydos.ginger.renderEngine.tools.IOUtil;
|
||||
|
||||
public class Image {
|
||||
|
||||
public Image(String imagePath) {
|
||||
ByteBuffer img;
|
||||
ByteBuffer imageBuffer;
|
||||
try {
|
||||
imageBuffer = IOUtil.ioResourceToByteBuffer(imagePath, 8 * 1024);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try (MemoryStack stack = stackPush()) {
|
||||
IntBuffer w = stack.mallocInt(1);
|
||||
IntBuffer h = stack.mallocInt(1);
|
||||
IntBuffer comp = stack.mallocInt(1);
|
||||
|
||||
// Use info to read image metadata without decoding the entire image.
|
||||
// We don't need this for this demo, just testing the API.
|
||||
if (!stbi_info_from_memory(imageBuffer, w, h, comp)) {
|
||||
throw new RuntimeException("Failed to read image information: " + stbi_failure_reason());
|
||||
}
|
||||
|
||||
// System.out.println("Image width: " + w.get(0));
|
||||
// System.out.println("Image height: " + h.get(0));
|
||||
// System.out.println("Image components: " + comp.get(0));
|
||||
// System.out.println("Image HDR: " + stbi_is_hdr_from_memory(imageBuffer));
|
||||
|
||||
// Decode the image
|
||||
img = stbi_load_from_memory(imageBuffer, w, h, comp, 0);
|
||||
if (img == null) {
|
||||
throw new RuntimeException("Failed to load image: " + stbi_failure_reason());
|
||||
}
|
||||
|
||||
this.image = img;
|
||||
this.width = w.get(0);
|
||||
this.height = h.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
public static Image createImage(String imagePath) {
|
||||
ByteBuffer img;
|
||||
ByteBuffer imageBuffer;
|
||||
try {
|
||||
imageBuffer = IOUtil.ioResourceToByteBuffer(imagePath, 8 * 1024);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try (MemoryStack stack = stackPush()) {
|
||||
IntBuffer w = stack.mallocInt(1);
|
||||
IntBuffer h = stack.mallocInt(1);
|
||||
IntBuffer comp = stack.mallocInt(1);
|
||||
|
||||
// Use info to read image metadata without decoding the entire image.
|
||||
// We don't need this for this demo, just testing the API.
|
||||
if (!stbi_info_from_memory(imageBuffer, w, h, comp)) {
|
||||
throw new RuntimeException("Failed to read image information: " + stbi_failure_reason());
|
||||
}
|
||||
|
||||
img = stbi_load_from_memory(imageBuffer, w, h, comp, 0);
|
||||
if (img == null) {
|
||||
throw new RuntimeException("Failed to load image: " + stbi_failure_reason());
|
||||
}
|
||||
|
||||
return new Image(w.get(0), h.get(0), img);
|
||||
}
|
||||
}
|
||||
|
||||
public ByteBuffer getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
private ByteBuffer image;
|
||||
private int width, height;
|
||||
|
||||
Image(int width, int heigh, ByteBuffer image) {
|
||||
this.image = image;
|
||||
this.height = heigh;
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package io.github.hydos.ginger.renderEngine.texture;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL14;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
public class ModelTexture {
|
||||
private int textureID = GL11.glGenTextures();
|
||||
|
||||
private boolean transparency = false;
|
||||
private boolean useFakeLighting = false;
|
||||
|
||||
private float shineDamper = 1;
|
||||
private float reflectivity = 1;
|
||||
|
||||
private Image texture;
|
||||
|
||||
public ModelTexture(String file) {
|
||||
texture = Image.createImage("/textures/" + file);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.textureID);
|
||||
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, 10241, 9729.0f);
|
||||
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, 10240, 9729.0f);
|
||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, texture.getWidth(), texture.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, texture.getImage());
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
|
||||
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
|
||||
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, -0.4f);
|
||||
}
|
||||
|
||||
public ModelTexture(Image texture) {
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.textureID);
|
||||
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, 10241, 9729.0f);
|
||||
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, 10240, 9729.0f);
|
||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, 6408, texture.getWidth(), texture.getHeight(), 0, 6408, 5121, texture.getImage());
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
GL11.glDeleteTextures(this.textureID);
|
||||
}
|
||||
|
||||
public int getTextureID() {
|
||||
return this.textureID;
|
||||
}
|
||||
|
||||
public Image getTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
||||
public float getShineDamper() {
|
||||
return shineDamper;
|
||||
}
|
||||
|
||||
public float getReflectivity() {
|
||||
return reflectivity;
|
||||
}
|
||||
|
||||
public void setShineDamper(float shineDamper) {
|
||||
this.shineDamper = shineDamper;
|
||||
}
|
||||
|
||||
public void setReflectivity(float reflectivity) {
|
||||
this.reflectivity = reflectivity;
|
||||
}
|
||||
|
||||
public boolean isTransparent() {
|
||||
return transparency;
|
||||
}
|
||||
|
||||
public void setTransparency(boolean b) {
|
||||
this.transparency = b;
|
||||
}
|
||||
|
||||
public boolean isUseFakeLighting() {
|
||||
return useFakeLighting;
|
||||
}
|
||||
|
||||
public void useFakeLighting(boolean useFakeLighting) {
|
||||
this.useFakeLighting = useFakeLighting;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package io.github.hydos.ginger.renderEngine.tools;
|
||||
|
||||
import static org.lwjgl.BufferUtils.createByteBuffer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
|
||||
public class IOUtil {
|
||||
|
||||
private IOUtil() {
|
||||
}
|
||||
|
||||
private static ByteBuffer resizeBuffer(ByteBuffer buffer, int newCapacity) {
|
||||
ByteBuffer newBuffer = BufferUtils.createByteBuffer(newCapacity);
|
||||
buffer.flip();
|
||||
newBuffer.put(buffer);
|
||||
return newBuffer;
|
||||
}
|
||||
|
||||
public static ByteBuffer ioResourceToByteBuffer(String resource, int bufferSize) throws IOException {
|
||||
ByteBuffer buffer;
|
||||
try (
|
||||
|
||||
InputStream source = Class.class.getResourceAsStream(resource);
|
||||
|
||||
ReadableByteChannel rbc = Channels.newChannel(source)
|
||||
) {
|
||||
buffer = createByteBuffer(bufferSize);
|
||||
|
||||
while (true) {
|
||||
int bytes = rbc.read(buffer);
|
||||
if (bytes == -1) {
|
||||
break;
|
||||
}
|
||||
if (buffer.remaining() == 0) {
|
||||
buffer = resizeBuffer(buffer, buffer.capacity() * 3 / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buffer.flip();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
package io.github.hydos.ginger.renderEngine.tools;
|
||||
|
||||
import io.github.hydos.ginger.elements.ThirdPersonCamera;
|
||||
import io.github.hydos.ginger.io.Window;
|
||||
import io.github.hydos.ginger.mathEngine.Maths;
|
||||
import io.github.hydos.ginger.mathEngine.matrixes.Matrix4f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector2f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector4f;
|
||||
import io.github.hydos.ginger.terrain.Terrain;
|
||||
|
||||
public class MousePicker {
|
||||
|
||||
private static final int RECURSION_COUNT = 200;
|
||||
private static final float RAY_RANGE = 600;
|
||||
|
||||
private Vector3f currentRay = new Vector3f();
|
||||
|
||||
private Matrix4f projectionMatrix;
|
||||
private Matrix4f viewMatrix;
|
||||
private ThirdPersonCamera camera;
|
||||
|
||||
private Terrain terrain;
|
||||
private Vector3f currentTerrainPoint;
|
||||
|
||||
public MousePicker(ThirdPersonCamera cam, Matrix4f projection, Terrain terrain) {
|
||||
camera = cam;
|
||||
projectionMatrix = projection;
|
||||
viewMatrix = Maths.createViewMatrix(camera);
|
||||
this.terrain = terrain;
|
||||
}
|
||||
|
||||
public Vector3f getCurrentTerrainPoint() {
|
||||
return currentTerrainPoint;
|
||||
}
|
||||
|
||||
public Vector3f getCurrentRay() {
|
||||
return currentRay;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
viewMatrix = Maths.createViewMatrix(camera);
|
||||
currentRay = calculateMouseRay();
|
||||
if (intersectionInRange(0, RAY_RANGE, currentRay)) {
|
||||
currentTerrainPoint = binarySearch(0, 0, RAY_RANGE, currentRay);
|
||||
} else {
|
||||
currentTerrainPoint = null;
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3f calculateMouseRay() {
|
||||
float mouseX = (float) Window.getMouseX();
|
||||
float mouseY = (float) ((float) Window.height - Window.getMouseY());
|
||||
Vector2f normalizedCoords = getNormalisedDeviceCoordinates(mouseX, mouseY);
|
||||
Vector4f clipCoords = new Vector4f(normalizedCoords.x, normalizedCoords.y, -1.0f, 1.0f);
|
||||
Vector4f eyeCoords = toEyeCoords(clipCoords);
|
||||
Vector3f worldRay = toWorldCoords(eyeCoords);
|
||||
return worldRay;
|
||||
}
|
||||
|
||||
private Vector3f toWorldCoords(Vector4f eyeCoords) {
|
||||
Matrix4f invertedView = Matrix4f.invert(viewMatrix, null);
|
||||
Vector4f rayWorld = Matrix4f.transform(invertedView, eyeCoords, null);
|
||||
Vector3f mouseRay = new Vector3f(rayWorld.x, rayWorld.y, rayWorld.z);
|
||||
mouseRay.normalise();
|
||||
return mouseRay;
|
||||
}
|
||||
|
||||
private Vector4f toEyeCoords(Vector4f clipCoords) {
|
||||
Matrix4f invertedProjection = Matrix4f.invert(projectionMatrix, null);
|
||||
Vector4f eyeCoords = Matrix4f.transform(invertedProjection, clipCoords, null);
|
||||
return new Vector4f(eyeCoords.x, eyeCoords.y, -1f, 0f);
|
||||
}
|
||||
|
||||
private Vector2f getNormalisedDeviceCoordinates(float mouseX, float mouseY) {
|
||||
float x = (2.0f * mouseX) / Window.width - 1f;
|
||||
float y = (2.0f * mouseY) / Window.height - 1f;
|
||||
return new Vector2f(x, y);
|
||||
}
|
||||
|
||||
//**********************************************************
|
||||
|
||||
private Vector3f getPointOnRay(Vector3f ray, float distance) {
|
||||
Vector3f camPos = camera.getPosition();
|
||||
Vector3f start = new Vector3f(camPos.x, camPos.y, camPos.z);
|
||||
Vector3f scaledRay = new Vector3f(ray.x * distance, ray.y * distance, ray.z * distance);
|
||||
return Vector3f.add(start, scaledRay, null);
|
||||
}
|
||||
|
||||
private Vector3f binarySearch(int count, float start, float finish, Vector3f ray) {
|
||||
float half = start + ((finish - start) / 2f);
|
||||
if (count >= RECURSION_COUNT) {
|
||||
Vector3f endPoint = getPointOnRay(ray, half);
|
||||
Terrain terrain = getTerrain(endPoint.getX(), endPoint.getZ());
|
||||
if (terrain != null) {
|
||||
return endPoint;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (intersectionInRange(start, half, ray)) {
|
||||
return binarySearch(count + 1, start, half, ray);
|
||||
} else {
|
||||
return binarySearch(count + 1, half, finish, ray);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean intersectionInRange(float start, float finish, Vector3f ray) {
|
||||
Vector3f startPoint = getPointOnRay(ray, start);
|
||||
Vector3f endPoint = getPointOnRay(ray, finish);
|
||||
if (!isUnderGround(startPoint) && isUnderGround(endPoint)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isUnderGround(Vector3f testPoint) {
|
||||
Terrain terrain = getTerrain(testPoint.getX(), testPoint.getZ());
|
||||
float height = 0;
|
||||
if (terrain != null) {
|
||||
height = terrain.getHeightOfTerrain(testPoint.getX(), testPoint.getZ());
|
||||
}
|
||||
if (testPoint.y < height) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private Terrain getTerrain(float worldX, float worldZ) {
|
||||
return terrain;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,157 @@
|
|||
package io.github.hydos.ginger.terrain;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import io.github.hydos.ginger.mathEngine.Maths;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector2f;
|
||||
import io.github.hydos.ginger.mathEngine.vectors.Vector3f;
|
||||
import io.github.hydos.ginger.renderEngine.models.RawModel;
|
||||
import io.github.hydos.ginger.utils.Loader;
|
||||
|
||||
public class Terrain {
|
||||
|
||||
private static final float SIZE = 100;
|
||||
private static final float MAX_HEIGHT = 20;
|
||||
private static final float MAX_PIXEL_COLOUR = 256 * 256 * 256;
|
||||
|
||||
private float[][] heights;
|
||||
|
||||
private float x, z;
|
||||
private RawModel model;
|
||||
private TerrainTexturePack texturePack;
|
||||
private TerrainTexture blendMap;
|
||||
|
||||
public Terrain(float gridX, float gridZ, TerrainTexturePack texturePack, TerrainTexture blendMap, String heightMapLocation) {
|
||||
this.texturePack = texturePack;
|
||||
this.blendMap = blendMap;
|
||||
this.x = gridX * SIZE;
|
||||
this.z = gridZ * SIZE;
|
||||
|
||||
this.model = generateTerrain(heightMapLocation);
|
||||
|
||||
}
|
||||
|
||||
public float getHeightOfTerrain(float worldX, float worldZ) {
|
||||
float terrainX = worldX - this.x;
|
||||
float terrainZ = worldZ - this.z;
|
||||
float gridSquareSize = SIZE / ((float) heights.length - 1);
|
||||
int gridX = (int) Math.floor(terrainX / gridSquareSize);
|
||||
int gridZ = (int) Math.floor(terrainZ / gridSquareSize);
|
||||
if(gridX >= heights.length - 1 || gridZ >= heights.length - 1 || gridX <0 || gridZ < 0) {
|
||||
return 0;
|
||||
}
|
||||
float xCoord = (terrainX % gridSquareSize) / gridSquareSize;
|
||||
float zCoord = (terrainZ % gridSquareSize) / gridSquareSize;
|
||||
float answer;
|
||||
if (xCoord <= (1-zCoord)) {
|
||||
answer = Maths
|
||||
.barryCentric(new Vector3f(0, heights[gridX][gridZ], 0), new Vector3f(1,
|
||||
heights[gridX + 1][gridZ], 0), new Vector3f(0,
|
||||
heights[gridX][gridZ + 1], 1), new Vector2f(xCoord, zCoord));
|
||||
} else {
|
||||
answer = Maths
|
||||
.barryCentric(new Vector3f(1, heights[gridX + 1][gridZ], 0), new Vector3f(1,
|
||||
heights[gridX + 1][gridZ + 1], 1), new Vector3f(0,
|
||||
heights[gridX][gridZ + 1], 1), new Vector2f(xCoord, zCoord));
|
||||
}
|
||||
return answer;
|
||||
|
||||
}
|
||||
|
||||
public float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public float getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public RawModel getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public TerrainTexturePack getTexturePack() {
|
||||
return texturePack;
|
||||
}
|
||||
|
||||
public TerrainTexture getBlendMap() {
|
||||
return blendMap;
|
||||
}
|
||||
|
||||
private RawModel generateTerrain(String heightMap){
|
||||
BufferedImage image = null;
|
||||
try {
|
||||
image = ImageIO.read(Class.class.getResourceAsStream("/textures/terrain/" + heightMap));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
int VERTEX_COUNT = image.getHeight();
|
||||
heights = new float[VERTEX_COUNT][VERTEX_COUNT];
|
||||
int count = VERTEX_COUNT * VERTEX_COUNT;
|
||||
float[] vertices = new float[count * 3];
|
||||
float[] normals = new float[count * 3];
|
||||
float[] textureCoords = new float[count*2];
|
||||
int[] indices = new int[6*(VERTEX_COUNT-1)*(VERTEX_COUNT-1)];
|
||||
int vertexPointer = 0;
|
||||
|
||||
for(int i=0;i<VERTEX_COUNT;i++){
|
||||
for(int j=0;j<VERTEX_COUNT;j++){
|
||||
vertices[vertexPointer*3] = j/((float)VERTEX_COUNT - 1) * SIZE;
|
||||
float height = getHeight(j, i, image);
|
||||
heights[j][i] = height;
|
||||
vertices[vertexPointer*3+1] = height;
|
||||
vertices[vertexPointer*3+2] = i/((float)VERTEX_COUNT - 1) * SIZE;
|
||||
Vector3f normal = calculateNormal(j, i, image);
|
||||
normals[vertexPointer*3] = normal.x;
|
||||
normals[vertexPointer*3+1] = normal.y;
|
||||
normals[vertexPointer*3+2] = normal.z;
|
||||
textureCoords[vertexPointer*2] = j/((float)VERTEX_COUNT - 1);
|
||||
textureCoords[vertexPointer*2+1] = i/((float)VERTEX_COUNT - 1);
|
||||
vertexPointer++;
|
||||
}
|
||||
}
|
||||
int pointer = 0;
|
||||
for(int gz=0;gz<VERTEX_COUNT-1;gz++){
|
||||
for(int gx=0;gx<VERTEX_COUNT-1;gx++){
|
||||
int topLeft = (gz*VERTEX_COUNT)+gx;
|
||||
int topRight = topLeft + 1;
|
||||
int bottomLeft = ((gz+1)*VERTEX_COUNT)+gx;
|
||||
int bottomRight = bottomLeft + 1;
|
||||
indices[pointer++] = topLeft;
|
||||
indices[pointer++] = bottomLeft;
|
||||
indices[pointer++] = topRight;
|
||||
indices[pointer++] = topRight;
|
||||
indices[pointer++] = bottomLeft;
|
||||
indices[pointer++] = bottomRight;
|
||||
}
|
||||
}
|
||||
return Loader.loadToVAO(vertices, indices, normals, textureCoords);
|
||||
}
|
||||
|
||||
private float getHeight(int x, int z, BufferedImage image) {
|
||||
if(x<0 || x>=image.getHeight() || z<0 || z>=image.getHeight()) {
|
||||
return 0;
|
||||
}
|
||||
float height = image.getRGB(x, z);
|
||||
height += MAX_PIXEL_COLOUR / 2f;
|
||||
height /= MAX_PIXEL_COLOUR / 2f;
|
||||
height *= MAX_HEIGHT;
|
||||
return height;
|
||||
}
|
||||
|
||||
private Vector3f calculateNormal(int x, int z, BufferedImage image) {
|
||||
float heightL = getHeight(x-1, z, image);
|
||||
float heightR = getHeight(x+1, z, image);
|
||||
float heightD = getHeight(x, z-1, image);
|
||||
float heightU = getHeight(x, z+1, image);
|
||||
Vector3f normal = new Vector3f(heightL-heightR, 2f, heightD - heightU);
|
||||
normal.normalise();
|
||||
return normal;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package io.github.hydos.ginger.terrain;
|
||||
|
||||
public class TerrainTexture {
|
||||
|
||||
private int textureID;
|
||||
|
||||
public int getTextureID() {
|
||||
return textureID;
|
||||
}
|
||||
|
||||
public TerrainTexture(int textureID) {
|
||||
super();
|
||||
this.textureID = textureID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package io.github.hydos.ginger.terrain;
|
||||
|
||||
public class TerrainTexturePack {
|
||||
|
||||
private TerrainTexture backgroundTexture;
|
||||
private TerrainTexture rTexture;
|
||||
private TerrainTexture gTexture;
|
||||
private TerrainTexture bTexture;
|
||||
public TerrainTexturePack(TerrainTexture backgroundTexture, TerrainTexture rTexture, TerrainTexture gTexture,
|
||||
TerrainTexture bTexture) {
|
||||
this.backgroundTexture = backgroundTexture;
|
||||
this.rTexture = rTexture;
|
||||
this.gTexture = gTexture;
|
||||
this.bTexture = bTexture;
|
||||
}
|
||||
public TerrainTexture getBackgroundTexture() {
|
||||
return backgroundTexture;
|
||||
}
|
||||
public TerrainTexture getrTexture() {
|
||||
return rTexture;
|
||||
}
|
||||
public TerrainTexture getgTexture() {
|
||||
return gTexture;
|
||||
}
|
||||
public TerrainTexture getbTexture() {
|
||||
return bTexture;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
package io.github.hydos.ginger.utils;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
import io.github.hydos.ginger.renderEngine.models.RawModel;
|
||||
import io.github.hydos.ginger.renderEngine.texture.Image;
|
||||
import io.github.hydos.ginger.renderEngine.texture.ModelTexture;
|
||||
import io.github.hydos.ginger.terrain.TerrainTexture;
|
||||
|
||||
public class Loader {
|
||||
|
||||
private static List<Integer> vaos = new ArrayList<Integer>();
|
||||
private static List<Integer> vbos = new ArrayList<Integer>();
|
||||
|
||||
public static int loadCubeMap(String[] textureFiles) {
|
||||
int texID = GL11.glGenTextures();
|
||||
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
||||
GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texID);
|
||||
|
||||
for(int i=0;i<textureFiles.length;i++) {
|
||||
// System.out.println("/textures/skybox/" + textureFiles[i]);
|
||||
Image data = Image.createImage("/textures/skybox/" + textureFiles[i]);
|
||||
GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL11.GL_RGBA, data.getWidth(), data.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data.getImage());
|
||||
}
|
||||
|
||||
GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
|
||||
GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
||||
vaos.add(texID);
|
||||
return texID;
|
||||
}
|
||||
|
||||
private static void bindIndicesBuffer(int[] indices) {
|
||||
int vboID = GL15.glGenBuffers();
|
||||
vbos.add(vboID);
|
||||
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboID);
|
||||
IntBuffer buffer = storeDataInIntBuffer(indices);
|
||||
GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
public static RawModel loadToVAO(float[] positions, int dimensions) {
|
||||
int vaoID = createVAO();
|
||||
storeDataInAttributeList(0, dimensions, positions);
|
||||
unbindVAO();
|
||||
return new RawModel(vaoID, positions.length / dimensions);
|
||||
}
|
||||
|
||||
private static IntBuffer storeDataInIntBuffer(int[] data) {
|
||||
IntBuffer buffer = BufferUtils.createIntBuffer(data.length);
|
||||
buffer.put(data);
|
||||
buffer.flip();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private static int createVAO() {
|
||||
int vaoID = GL30.glGenVertexArrays();
|
||||
vaos.add(vaoID);
|
||||
GL30.glBindVertexArray(vaoID);
|
||||
return vaoID;
|
||||
}
|
||||
|
||||
private static void storeDataInAttributeList(int attributeNumber, int coordinateSize, float[] data) {
|
||||
int vboID = GL15.glGenBuffers();
|
||||
vbos.add(vboID);
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
|
||||
FloatBuffer buffer = storeDataInFloatBuffer(data);
|
||||
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
|
||||
GL20.glVertexAttribPointer(attributeNumber, coordinateSize, GL11.GL_FLOAT, false, 0, 0);
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
private static void unbindVAO() {
|
||||
GL30.glBindVertexArray(0);
|
||||
}
|
||||
|
||||
private static FloatBuffer storeDataInFloatBuffer(float[] data) {
|
||||
FloatBuffer buffer = BufferUtils.createFloatBuffer(data.length);
|
||||
buffer.put(data);
|
||||
buffer.flip();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static void cleanUp() {
|
||||
for(int vao:vaos) {
|
||||
GL30.glDeleteVertexArrays(vao);
|
||||
}
|
||||
for(int vbo:vbos) {
|
||||
GL15.glDeleteBuffers(vbo);
|
||||
}
|
||||
}
|
||||
|
||||
public static RawModel loadToVAO(float[] positions, int[] indices, float[] textureCoords) {
|
||||
int vaoID = createVAO();
|
||||
bindIndicesBuffer(indices);
|
||||
storeDataInAttributeList(0, 3, positions);
|
||||
storeDataInAttributeList(1, 2, textureCoords);
|
||||
unbindVAO();
|
||||
return new RawModel(vaoID, indices.length);
|
||||
}
|
||||
|
||||
public static RawModel loadToVAO(float[] positions, int[] indices, float[] normals, float[] textureCoords) {
|
||||
int vaoID = createVAO();
|
||||
bindIndicesBuffer(indices);
|
||||
storeDataInAttributeList(0, 3, positions);
|
||||
storeDataInAttributeList(1, 2, textureCoords);
|
||||
storeDataInAttributeList(2, 3, normals);
|
||||
unbindVAO();
|
||||
return new RawModel(vaoID, indices.length);
|
||||
}
|
||||
|
||||
public static TerrainTexture loadTerrainTexture(String string) {
|
||||
return new TerrainTexture(new ModelTexture("terrain/" + string).getTextureID());
|
||||
}
|
||||
|
||||
public static int loadTexture(String path) {
|
||||
return new ModelTexture(path).getTextureID();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,396 @@
|
|||
# Blender v2.67 (sub 0) OBJ File: ''
|
||||
# www.blender.org
|
||||
o Wood_container1
|
||||
v -83.000000 -83.000015 95.999985
|
||||
v 83.000000 -83.000015 95.999985
|
||||
v 83.000000 82.999985 96.000015
|
||||
v -83.000000 82.999985 96.000015
|
||||
v -83.000000 -82.999985 -96.000015
|
||||
v -83.000000 83.000015 -95.999985
|
||||
v 83.000000 83.000015 -95.999985
|
||||
v 83.000000 -82.999985 -96.000015
|
||||
v -83.000000 -96.000015 82.999985
|
||||
v -83.000000 -95.999985 -83.000015
|
||||
v 83.000000 -95.999985 -83.000015
|
||||
v 83.000000 -96.000015 82.999985
|
||||
v 96.000000 -83.000015 82.999985
|
||||
v 96.000000 -82.999985 -83.000015
|
||||
v 96.000000 83.000015 -82.999985
|
||||
v 96.000000 82.999985 83.000015
|
||||
v 83.000000 95.999985 83.000015
|
||||
v 83.000000 96.000015 -82.999985
|
||||
v -83.000000 96.000015 -82.999985
|
||||
v -83.000000 95.999985 83.000015
|
||||
v -96.000000 82.999985 83.000015
|
||||
v -96.000000 83.000015 -82.999985
|
||||
v -96.000000 -82.999985 -83.000015
|
||||
v -96.000000 -83.000015 82.999985
|
||||
v -100.000000 -100.000015 99.999985
|
||||
v 100.000000 -100.000015 99.999985
|
||||
v 83.000000 -83.000015 99.999985
|
||||
v -83.000000 -83.000015 99.999985
|
||||
v 100.000000 99.999985 100.000015
|
||||
v 83.000000 82.999985 100.000015
|
||||
v -100.000000 99.999985 100.000015
|
||||
v -83.000000 82.999985 100.000015
|
||||
v -100.000000 -99.999985 -100.000015
|
||||
v -100.000000 100.000015 -99.999985
|
||||
v -83.000000 83.000015 -99.999985
|
||||
v -83.000000 -82.999985 -100.000015
|
||||
v 100.000000 100.000015 -99.999985
|
||||
v 83.000000 83.000015 -99.999985
|
||||
v 100.000000 -99.999985 -100.000015
|
||||
v 83.000000 -82.999985 -100.000015
|
||||
v -83.000000 -99.999985 -83.000015
|
||||
v -83.000000 -100.000015 82.999985
|
||||
v 83.000000 -99.999985 -83.000015
|
||||
v 83.000000 -100.000015 82.999985
|
||||
v 100.000000 -82.999985 -83.000015
|
||||
v 100.000000 -83.000015 82.999985
|
||||
v 100.000000 83.000015 -82.999985
|
||||
v 100.000000 82.999985 83.000015
|
||||
v 83.000000 100.000015 -82.999985
|
||||
v 83.000000 99.999985 83.000015
|
||||
v -83.000000 100.000015 -82.999985
|
||||
v -83.000000 99.999985 83.000015
|
||||
v -100.000000 83.000015 -82.999985
|
||||
v -100.000000 82.999985 83.000015
|
||||
v -100.000000 -82.999985 -83.000015
|
||||
v -100.000000 -83.000015 82.999985
|
||||
v -100.000000 99.999985 100.000015
|
||||
v -100.000000 99.999985 100.000015
|
||||
v -100.000000 99.999985 100.000015
|
||||
v -100.000000 99.999985 100.000015
|
||||
v -100.000000 99.999985 100.000015
|
||||
v -83.000000 99.999985 83.000015
|
||||
v -83.000000 99.999985 83.000015
|
||||
v -83.000000 99.999985 83.000015
|
||||
v -100.000000 100.000015 -99.999985
|
||||
v -100.000000 100.000015 -99.999985
|
||||
v -100.000000 100.000015 -99.999985
|
||||
v -100.000000 100.000015 -99.999985
|
||||
v -100.000000 100.000015 -99.999985
|
||||
v -83.000000 100.000015 -82.999985
|
||||
v -83.000000 100.000015 -82.999985
|
||||
v -83.000000 100.000015 -82.999985
|
||||
v 83.000000 100.000015 -82.999985
|
||||
v 83.000000 100.000015 -82.999985
|
||||
v 83.000000 100.000015 -82.999985
|
||||
v 83.000000 99.999985 83.000015
|
||||
v 83.000000 99.999985 83.000015
|
||||
v 83.000000 99.999985 83.000015
|
||||
v 83.000000 -99.999985 -83.000015
|
||||
v 83.000000 -99.999985 -83.000015
|
||||
v 83.000000 -99.999985 -83.000015
|
||||
v 83.000000 -100.000015 82.999985
|
||||
v 83.000000 -100.000015 82.999985
|
||||
v 83.000000 -100.000015 82.999985
|
||||
v 83.000000 96.000015 -82.999985
|
||||
v 83.000000 96.000015 -82.999985
|
||||
v -83.000000 96.000015 -82.999985
|
||||
v -83.000000 96.000015 -82.999985
|
||||
v -100.000000 -100.000015 99.999985
|
||||
v -100.000000 -100.000015 99.999985
|
||||
v -100.000000 -100.000015 99.999985
|
||||
v -100.000000 -100.000015 99.999985
|
||||
v -100.000000 -100.000015 99.999985
|
||||
v -83.000000 -100.000015 82.999985
|
||||
v -83.000000 -100.000015 82.999985
|
||||
v -83.000000 -100.000015 82.999985
|
||||
v -96.000000 83.000015 -82.999985
|
||||
v -96.000000 83.000015 -82.999985
|
||||
v -100.000000 83.000015 -82.999985
|
||||
v -100.000000 83.000015 -82.999985
|
||||
v -100.000000 83.000015 -82.999985
|
||||
v -83.000000 -82.999985 -96.000015
|
||||
v -83.000000 -82.999985 -96.000015
|
||||
v -83.000000 -82.999985 -100.000015
|
||||
v -83.000000 -82.999985 -100.000015
|
||||
v -83.000000 -82.999985 -100.000015
|
||||
v 100.000000 -99.999985 -100.000015
|
||||
v 100.000000 -99.999985 -100.000015
|
||||
v 100.000000 -99.999985 -100.000015
|
||||
v 100.000000 -99.999985 -100.000015
|
||||
v 100.000000 -99.999985 -100.000015
|
||||
v 83.000000 -82.999985 -100.000015
|
||||
v 83.000000 -82.999985 -100.000015
|
||||
v 83.000000 -82.999985 -100.000015
|
||||
v 83.000000 82.999985 100.000015
|
||||
v 83.000000 82.999985 100.000015
|
||||
v 83.000000 82.999985 100.000015
|
||||
v -83.000000 82.999985 100.000015
|
||||
v -83.000000 82.999985 100.000015
|
||||
v -83.000000 82.999985 100.000015
|
||||
v -96.000000 -82.999985 -83.000015
|
||||
v -96.000000 -82.999985 -83.000015
|
||||
v -83.000000 95.999985 83.000015
|
||||
v -83.000000 95.999985 83.000015
|
||||
v 100.000000 100.000015 -99.999985
|
||||
v 100.000000 100.000015 -99.999985
|
||||
v 100.000000 100.000015 -99.999985
|
||||
v 100.000000 100.000015 -99.999985
|
||||
v 100.000000 100.000015 -99.999985
|
||||
v 83.000000 83.000015 -99.999985
|
||||
v 83.000000 83.000015 -99.999985
|
||||
v 83.000000 83.000015 -99.999985
|
||||
v 96.000000 82.999985 83.000015
|
||||
v 96.000000 82.999985 83.000015
|
||||
v 100.000000 82.999985 83.000015
|
||||
v 100.000000 82.999985 83.000015
|
||||
v 100.000000 82.999985 83.000015
|
||||
v 83.000000 -82.999985 -96.000015
|
||||
v 83.000000 -82.999985 -96.000015
|
||||
v 100.000000 -82.999985 -83.000015
|
||||
v 100.000000 -82.999985 -83.000015
|
||||
v 100.000000 -82.999985 -83.000015
|
||||
v 100.000000 -83.000015 82.999985
|
||||
v 100.000000 -83.000015 82.999985
|
||||
v 100.000000 -83.000015 82.999985
|
||||
v -83.000000 -99.999985 -83.000015
|
||||
v -83.000000 -99.999985 -83.000015
|
||||
v -83.000000 -99.999985 -83.000015
|
||||
v 96.000000 -83.000015 82.999985
|
||||
v 96.000000 -83.000015 82.999985
|
||||
v 83.000000 -83.000015 99.999985
|
||||
v 83.000000 -83.000015 99.999985
|
||||
v 83.000000 -83.000015 99.999985
|
||||
v 96.000000 83.000015 -82.999985
|
||||
v 96.000000 83.000015 -82.999985
|
||||
v 100.000000 83.000015 -82.999985
|
||||
v 100.000000 83.000015 -82.999985
|
||||
v 100.000000 83.000015 -82.999985
|
||||
v -83.000000 -96.000015 82.999985
|
||||
v -83.000000 -96.000015 82.999985
|
||||
v -83.000000 83.000015 -95.999985
|
||||
v -83.000000 83.000015 -95.999985
|
||||
v -100.000000 -82.999985 -83.000015
|
||||
v -100.000000 -82.999985 -83.000015
|
||||
v -100.000000 -82.999985 -83.000015
|
||||
v -83.000000 83.000015 -99.999985
|
||||
v -83.000000 83.000015 -99.999985
|
||||
v -83.000000 83.000015 -99.999985
|
||||
v -83.000000 -95.999985 -83.000015
|
||||
v -83.000000 -95.999985 -83.000015
|
||||
v -96.000000 82.999985 83.000015
|
||||
v -96.000000 82.999985 83.000015
|
||||
v -96.000000 -83.000015 82.999985
|
||||
v -96.000000 -83.000015 82.999985
|
||||
v 100.000000 -100.000015 99.999985
|
||||
v 100.000000 -100.000015 99.999985
|
||||
v 100.000000 -100.000015 99.999985
|
||||
v 100.000000 -100.000015 99.999985
|
||||
v 100.000000 -100.000015 99.999985
|
||||
v -100.000000 -99.999985 -100.000015
|
||||
v -100.000000 -99.999985 -100.000015
|
||||
v -100.000000 -99.999985 -100.000015
|
||||
v -100.000000 -99.999985 -100.000015
|
||||
v -100.000000 -99.999985 -100.000015
|
||||
v 83.000000 83.000015 -95.999985
|
||||
v 83.000000 83.000015 -95.999985
|
||||
v 83.000000 82.999985 96.000015
|
||||
v 83.000000 82.999985 96.000015
|
||||
v -100.000000 82.999985 83.000015
|
||||
v -100.000000 82.999985 83.000015
|
||||
v -100.000000 82.999985 83.000015
|
||||
v -83.000000 -83.000015 99.999985
|
||||
v -83.000000 -83.000015 99.999985
|
||||
v -83.000000 -83.000015 99.999985
|
||||
v 96.000000 -82.999985 -83.000015
|
||||
v 96.000000 -82.999985 -83.000015
|
||||
v 83.000000 95.999985 83.000015
|
||||
v 83.000000 95.999985 83.000015
|
||||
v -83.000000 -83.000015 95.999985
|
||||
v -83.000000 -83.000015 95.999985
|
||||
v -83.000000 82.999985 96.000015
|
||||
v -83.000000 82.999985 96.000015
|
||||
v 100.000000 99.999985 100.000015
|
||||
v 100.000000 99.999985 100.000015
|
||||
v 100.000000 99.999985 100.000015
|
||||
v 100.000000 99.999985 100.000015
|
||||
v 100.000000 99.999985 100.000015
|
||||
v 83.000000 -95.999985 -83.000015
|
||||
v 83.000000 -95.999985 -83.000015
|
||||
v -100.000000 -83.000015 82.999985
|
||||
v -100.000000 -83.000015 82.999985
|
||||
v -100.000000 -83.000015 82.999985
|
||||
v 83.000000 -83.000015 95.999985
|
||||
v 83.000000 -83.000015 95.999985
|
||||
v 83.000000 -96.000015 82.999985
|
||||
v 83.000000 -96.000015 82.999985
|
||||
vt 0.056200 0.549000
|
||||
vt 0.454300 0.549000
|
||||
vt 0.454300 0.947100
|
||||
vt 0.056200 0.947100
|
||||
vt 0.947600 0.452400
|
||||
vt 0.947600 0.058200
|
||||
vt 0.553400 0.058200
|
||||
vt 0.553400 0.550900
|
||||
vt 0.947700 0.550900
|
||||
vt 0.947700 0.945200
|
||||
vt 0.058100 0.452400
|
||||
vt 0.058100 0.058200
|
||||
vt 0.452300 0.058200
|
||||
vt 0.553400 0.945200
|
||||
vt 0.013000 0.505800
|
||||
vt 0.497500 0.505800
|
||||
vt 0.456300 0.547000
|
||||
vt 0.497500 0.990300
|
||||
vt 0.456300 0.949100
|
||||
vt 0.013000 0.990300
|
||||
vt 0.054200 0.949100
|
||||
vt 0.054200 0.547000
|
||||
vt 0.992800 0.497600
|
||||
vt 0.992800 0.013100
|
||||
vt 0.951600 0.456400
|
||||
vt 0.508300 0.013100
|
||||
vt 0.549400 0.054200
|
||||
vt 0.508300 0.497600
|
||||
vt 0.508300 0.505800
|
||||
vt 0.992800 0.505800
|
||||
vt 0.951600 0.547000
|
||||
vt 0.992800 0.990300
|
||||
vt 0.951600 0.949100
|
||||
vt 0.508300 0.990300
|
||||
vt 0.549500 0.949100
|
||||
vt 0.549500 0.547000
|
||||
vt 0.012900 0.497600
|
||||
vt 0.012900 0.013100
|
||||
vt 0.054100 0.456400
|
||||
vt 0.497400 0.013100
|
||||
vt 0.456300 0.054200
|
||||
vt 0.497400 0.497600
|
||||
vt 0.489900 0.528500
|
||||
vt 0.014400 0.528500
|
||||
vt 0.014400 0.510300
|
||||
vt 0.489900 0.510300
|
||||
vt 0.489900 0.528600
|
||||
vt 0.014400 0.528600
|
||||
vt 0.014400 0.510400
|
||||
vt 0.489900 0.510400
|
||||
vt 0.553400 0.452400
|
||||
vt 0.452300 0.452400
|
||||
vt 0.951600 0.054200
|
||||
vt 0.549400 0.456400
|
||||
vt 0.054100 0.054200
|
||||
vt 0.456300 0.456400
|
||||
vn 0.000000 0.000000 0.999969
|
||||
vn 0.000000 0.000000 1.000000
|
||||
vn 0.000000 0.000000 -0.999969
|
||||
vn 0.000000 0.000000 -1.000000
|
||||
vn 0.000000 -0.999969 0.000000
|
||||
vn 0.000000 -1.000000 0.000000
|
||||
vn 0.999969 0.000000 0.000000
|
||||
vn 1.000000 0.000000 0.000000
|
||||
vn 0.000000 0.999969 0.000000
|
||||
vn 0.000000 1.000000 0.000000
|
||||
vn -1.000000 0.000000 0.000000
|
||||
vn -0.999969 0.000000 0.000000
|
||||
s 1
|
||||
f 1/1/1 2/2/2 187/3/1
|
||||
f 102/2/3 6/3/4 7/4/3
|
||||
f 159/5/5 169/6/6 208/7/5
|
||||
f 13/8/7 195/9/8 154/10/7
|
||||
f 17/11/9 18/12/10 19/13/9
|
||||
f 21/14/11 97/10/12 24/8/12
|
||||
f 90/15/2 175/16/2 151/17/2
|
||||
f 177/16/2 204/18/2 115/19/2
|
||||
f 205/18/2 59/20/2 32/21/2
|
||||
f 57/20/2 89/15/2 28/22/2
|
||||
f 33/16/4 65/18/4 105/17/4
|
||||
f 67/18/4 37/20/4 38/21/4
|
||||
f 125/20/4 39/15/4 131/21/4
|
||||
f 108/15/4 180/16/4 104/17/4
|
||||
f 25/23/6 181/24/6 42/25/6
|
||||
f 183/24/6 110/26/6 79/27/6
|
||||
f 109/26/6 26/28/6 43/27/6
|
||||
f 178/28/6 92/23/6 94/25/6
|
||||
f 176/29/8 107/30/8 45/31/8
|
||||
f 111/30/8 126/32/8 156/33/8
|
||||
f 128/32/8 203/34/8 135/35/8
|
||||
f 207/34/8 179/29/8 144/36/8
|
||||
f 29/37/10 127/38/10 50/39/10
|
||||
f 129/38/10 34/40/10 51/41/10
|
||||
f 66/40/10 31/42/10 71/41/10
|
||||
f 60/42/10 206/37/10 76/39/10
|
||||
f 58/34/11 68/32/11 189/35/11
|
||||
f 69/32/11 182/30/11 100/33/11
|
||||
f 184/30/11 91/29/11 164/31/11
|
||||
f 93/29/11 61/34/11 211/36/11
|
||||
f 213/43/9 199/44/10 193/45/9
|
||||
f 153/45/11 116/46/11 214/44/11
|
||||
f 117/45/5 119/46/6 201/43/5
|
||||
f 200/43/8 202/44/8 120/45/8
|
||||
f 36/47/8 167/48/8 161/49/8
|
||||
f 168/43/5 130/44/6 185/49/5
|
||||
f 132/47/11 112/48/11 186/50/11
|
||||
f 114/47/9 106/48/10 103/49/9
|
||||
f 95/47/8 146/48/8 10/49/8
|
||||
f 148/43/1 80/44/2 11/45/1
|
||||
f 81/49/11 83/50/11 209/48/11
|
||||
f 84/49/3 96/50/4 160/47/3
|
||||
f 143/43/9 140/44/10 14/45/9
|
||||
f 142/49/1 47/50/2 15/47/1
|
||||
f 158/49/5 48/50/6 16/47/5
|
||||
f 137/49/3 145/50/4 150/47/3
|
||||
f 77/43/11 73/44/11 197/46/11
|
||||
f 75/49/1 70/50/2 87/47/1
|
||||
f 72/49/8 62/50/8 20/47/8
|
||||
f 64/47/3 78/48/4 198/49/3
|
||||
f 54/47/5 53/48/6 22/49/5
|
||||
f 101/47/1 55/48/2 121/49/1
|
||||
f 165/49/9 210/50/10 173/47/9
|
||||
f 212/43/3 191/44/4 172/49/3
|
||||
f 4/4/2 1/1/1 187/3/1
|
||||
f 138/1/4 102/2/3 7/4/3
|
||||
f 12/51/6 159/5/5 208/7/5
|
||||
f 133/14/8 13/8/7 154/10/7
|
||||
f 123/52/10 17/11/9 19/13/9
|
||||
f 97/10/12 23/9/11 24/8/12
|
||||
f 192/22/2 90/15/2 151/17/2
|
||||
f 27/17/2 177/16/2 115/19/2
|
||||
f 30/19/2 205/18/2 32/21/2
|
||||
f 118/21/2 57/20/2 28/22/2
|
||||
f 65/18/4 166/19/4 105/17/4
|
||||
f 35/19/4 67/18/4 38/21/4
|
||||
f 39/15/4 40/22/4 131/21/4
|
||||
f 113/22/4 108/15/4 104/17/4
|
||||
f 181/24/6 147/53/6 42/25/6
|
||||
f 41/53/6 183/24/6 79/27/6
|
||||
f 26/28/6 44/54/6 43/27/6
|
||||
f 82/54/6 178/28/6 94/25/6
|
||||
f 46/36/8 176/29/8 45/31/8
|
||||
f 141/31/8 111/30/8 156/33/8
|
||||
f 157/33/8 128/32/8 135/35/8
|
||||
f 136/35/8 207/34/8 144/36/8
|
||||
f 127/38/10 49/55/10 50/39/10
|
||||
f 74/55/10 129/38/10 51/41/10
|
||||
f 31/42/10 52/56/10 71/41/10
|
||||
f 63/56/10 60/42/10 76/39/10
|
||||
f 68/32/11 99/33/11 189/35/11
|
||||
f 182/30/11 163/31/11 100/33/11
|
||||
f 91/29/11 56/36/11 164/31/11
|
||||
f 61/34/11 190/35/11 211/36/11
|
||||
f 152/46/10 213/43/9 193/45/9
|
||||
f 116/46/11 3/43/11 214/44/11
|
||||
f 188/44/6 117/45/5 201/43/5
|
||||
f 194/46/8 200/43/8 120/45/8
|
||||
f 5/50/8 36/47/8 161/49/8
|
||||
f 162/50/6 168/43/5 185/49/5
|
||||
f 112/48/11 8/49/11 186/50/11
|
||||
f 139/50/10 114/47/9 103/49/9
|
||||
f 9/50/8 95/47/8 10/49/8
|
||||
f 170/46/2 148/43/1 11/45/1
|
||||
f 83/50/11 215/47/11 209/48/11
|
||||
f 216/48/4 84/49/3 160/47/3
|
||||
f 149/46/10 143/43/9 14/45/9
|
||||
f 196/48/2 142/49/1 15/47/1
|
||||
f 155/48/6 158/49/5 16/47/5
|
||||
f 134/48/4 137/49/3 150/47/3
|
||||
f 73/44/11 85/45/11 197/46/11
|
||||
f 86/48/2 75/49/1 87/47/1
|
||||
f 88/48/8 72/49/8 20/47/8
|
||||
f 124/50/4 64/47/3 198/49/3
|
||||
f 171/50/6 54/47/5 22/49/5
|
||||
f 98/50/2 101/47/1 121/49/1
|
||||
f 122/48/10 165/49/9 173/47/9
|
||||
f 174/50/4 212/43/3 172/49/3
|
|
@ -0,0 +1,26 @@
|
|||
# Blender v2.79 (sub 0) OBJ File: 'very good grass.blend'
|
||||
# www.blender.org
|
||||
o Plane
|
||||
v 0.000000 1.963634 1.000000
|
||||
v -0.000000 -0.036366 1.000000
|
||||
v 0.000000 1.963634 -1.000000
|
||||
v -0.000000 -0.036366 -1.000000
|
||||
v -0.978509 1.963634 0.206204
|
||||
v -0.978509 -0.036366 0.206204
|
||||
v 0.978509 1.963634 -0.206204
|
||||
v 0.978509 -0.036366 -0.206204
|
||||
vt 0.000977 -0.001953
|
||||
vt 1.000000 1.000000
|
||||
vt 0.000000 1.000000
|
||||
vt 0.997070 0.001953
|
||||
vt -0.001953 0.998047
|
||||
vt 0.998047 0.000000
|
||||
vt 0.998047 0.997070
|
||||
vt 0.003907 -0.002930
|
||||
vn 1.0000 -0.0000 0.0000
|
||||
vn 0.2062 -0.0000 0.9785
|
||||
s off
|
||||
f 2/1/1 3/2/1 1/3/1
|
||||
f 2/1/1 4/4/1 3/2/1
|
||||
f 5/5/2 8/6/2 7/7/2
|
||||
f 5/5/2 6/8/2 8/6/2
|
|
@ -0,0 +1,50 @@
|
|||
#version 140
|
||||
|
||||
in vec2 pass_textureCoords;
|
||||
in vec3 surfaceNormal;
|
||||
in vec3 toLightVector[5];
|
||||
in vec3 toCameraVector;
|
||||
in float visibility;
|
||||
|
||||
out vec4 out_Color;
|
||||
|
||||
uniform sampler2D textureSampler;
|
||||
uniform vec3 lightColour[5];
|
||||
uniform vec3 attenuation[5];
|
||||
uniform float shineDamper;
|
||||
uniform float reflectivity;
|
||||
uniform vec3 skyColour;
|
||||
|
||||
void main(void){
|
||||
|
||||
vec3 unitNormal = normalize(surfaceNormal);
|
||||
vec3 unitVectorToCamera = normalize(toCameraVector);
|
||||
|
||||
vec3 totalDiffuse = vec3(0.0);
|
||||
vec3 totalSpecular = vec3(0.0);
|
||||
|
||||
for(int i=0;i<5;i++){
|
||||
float distance = length(toLightVector[i]);
|
||||
float attFactor = attenuation[i].x + (attenuation[i].y * distance) + (attenuation[i].z * distance * distance);
|
||||
vec3 unitLightVector = normalize(toLightVector[i]);
|
||||
float nDotl = dot(unitNormal, unitLightVector);
|
||||
float brightness = max(nDotl, 0.0);
|
||||
vec3 lightDirection = -unitLightVector;
|
||||
vec3 reflectedLightDirection = reflect(lightDirection, unitNormal);
|
||||
float specularFactor = dot(reflectedLightDirection, unitVectorToCamera);
|
||||
specularFactor = max(specularFactor, 0.0);
|
||||
float dampedFactor = pow(specularFactor, shineDamper);
|
||||
totalDiffuse = totalDiffuse + (brightness * lightColour[i])/attFactor;
|
||||
totalSpecular = totalSpecular + (dampedFactor * reflectivity * lightColour[i])/attFactor;
|
||||
}
|
||||
totalDiffuse = max(totalDiffuse, 0.2);
|
||||
|
||||
vec4 textureColour = texture(textureSampler, pass_textureCoords);
|
||||
if(textureColour.a<0.5){
|
||||
discard;
|
||||
}
|
||||
|
||||
out_Color = vec4(totalDiffuse, 1.0) * textureColour + vec4(totalSpecular, 1.0);
|
||||
out_Color = mix(vec4(skyColour, 1.0), out_Color, visibility);
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
#version 150
|
||||
|
||||
|
||||
in vec3 position;
|
||||
in vec2 textureCoords;
|
||||
in vec3 normal;
|
||||
|
||||
out vec2 pass_textureCoords;
|
||||
out vec3 surfaceNormal;
|
||||
out vec3 toLightVector[5];
|
||||
out vec3 toCameraVector;
|
||||
out float visibility;
|
||||
|
||||
uniform mat4 transformationMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
uniform mat4 viewMatrix;
|
||||
uniform vec3 lightPosition[5];
|
||||
|
||||
const vec4 plane = vec4(0, -1, 0, 15);
|
||||
|
||||
uniform float useFakeLighting;
|
||||
|
||||
const float density = 0.01;
|
||||
const float gradient = 5.0;
|
||||
|
||||
void main(void){
|
||||
|
||||
vec4 worldPosition = transformationMatrix * vec4(position.xyz,1.0);
|
||||
|
||||
gl_ClipDistance[0] = dot(worldPosition, plane);
|
||||
|
||||
vec4 positionRelativeToCam = viewMatrix * worldPosition;
|
||||
|
||||
gl_Position = projectionMatrix * positionRelativeToCam;
|
||||
pass_textureCoords = textureCoords;
|
||||
|
||||
vec3 actualNormal = normal;
|
||||
if(useFakeLighting > 0.5){
|
||||
actualNormal = vec3(0.0, 1.0, 0.0);
|
||||
}
|
||||
|
||||
surfaceNormal = (transformationMatrix * vec4(actualNormal, 0.0)).xyz;
|
||||
for(int i=0;i<5;i++){
|
||||
toLightVector[i] = lightPosition[i] - worldPosition.xyz;
|
||||
}
|
||||
toCameraVector = (inverse(viewMatrix) * vec4(0.0, 0.0, 0.0, 1.0)).xyz - worldPosition.xyz;
|
||||
|
||||
float distance = length(positionRelativeToCam.xyz);
|
||||
visibility = exp(-pow((distance*density), gradient));
|
||||
visibility = clamp(visibility, 0.0, 1.0);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#version 140 core
|
||||
|
||||
in vec2 textureCoords;
|
||||
|
||||
out vec4 out_Color;
|
||||
|
||||
uniform sampler2D guiTexture;
|
||||
|
||||
void main(void){
|
||||
|
||||
out_Color = texture(guiTexture,textureCoords);
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#version 140 core
|
||||
|
||||
in vec2 position;
|
||||
|
||||
out vec2 textureCoords;
|
||||
|
||||
uniform mat4 transformationMatrix;
|
||||
|
||||
void main(void){
|
||||
|
||||
gl_Position = transformationMatrix * vec4(position, 0.0, 1.0);
|
||||
textureCoords = vec2((position.x+1.0)/2.0, 1 - (position.y+1.0)/2.0);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
#version 400
|
||||
|
||||
in vec3 textureCoords;
|
||||
out vec4 out_Color;
|
||||
|
||||
uniform samplerCube cubeMap;
|
||||
|
||||
void main(void){
|
||||
out_Color = texture(cubeMap, textureCoords);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#version 400
|
||||
|
||||
in vec3 position;
|
||||
out vec3 textureCoords;
|
||||
|
||||
uniform mat4 projectionMatrix;
|
||||
uniform mat4 viewMatrix;
|
||||
|
||||
void main(void){
|
||||
|
||||
gl_Position = projectionMatrix * viewMatrix * vec4(position, 1.0);
|
||||
textureCoords = position;
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
#version 400 core
|
||||
|
||||
in vec2 pass_textureCoords;
|
||||
in vec3 surfaceNormal;
|
||||
in vec3 toLightVector[5];
|
||||
in vec3 toCameraVector;
|
||||
in float visibility;
|
||||
|
||||
out vec4 out_Color;
|
||||
|
||||
uniform sampler2D backgroundTexture;
|
||||
uniform sampler2D rTexture;
|
||||
uniform sampler2D gTexture;
|
||||
uniform sampler2D bTexture;
|
||||
uniform sampler2D blendMap;
|
||||
uniform vec3 attenuation[5];
|
||||
uniform vec3 lightColour[5];
|
||||
const float shineDamper = 0;
|
||||
const float reflectivity = 0;
|
||||
uniform vec3 skyColour;
|
||||
|
||||
void main(void){
|
||||
|
||||
vec4 blendMapColour = texture(blendMap, pass_textureCoords);
|
||||
|
||||
vec3 unitVectorToCamera = normalize(toCameraVector);
|
||||
|
||||
float backTextureAmount = 1 - (blendMapColour.r + blendMapColour.g + blendMapColour.b);
|
||||
vec2 tiledCoords = pass_textureCoords * 40.0;
|
||||
vec4 backgroundTextureColour = texture(backgroundTexture, tiledCoords) * backTextureAmount;
|
||||
vec4 rTextureColour = texture(rTexture, tiledCoords) * blendMapColour.r;
|
||||
vec4 gTextureColour = texture(gTexture, tiledCoords) * blendMapColour.g;
|
||||
vec4 bTextureColour = texture(bTexture, tiledCoords) * blendMapColour.b;
|
||||
|
||||
vec4 totalColour = backgroundTextureColour + rTextureColour + gTextureColour + bTextureColour;
|
||||
|
||||
|
||||
vec3 totalDiffuse = vec3(0.0);
|
||||
vec3 totalSpecular = vec3(0.0);
|
||||
|
||||
for(int i=0;i<5;i++){
|
||||
float distance = length(toLightVector[i]);
|
||||
float attFactor = attenuation[i].x + (attenuation[i].y * distance) + (attenuation[i].z * distance * distance);
|
||||
vec3 unitNormal = normalize(surfaceNormal);
|
||||
vec3 unitLightVector = normalize(toLightVector[i]);
|
||||
float nDotl = dot(unitNormal, unitLightVector);
|
||||
float brightness = max(nDotl, 0.2);
|
||||
vec3 lightDirection = -unitLightVector;
|
||||
vec3 reflectedLightDirection = reflect(lightDirection, unitNormal);
|
||||
float specularFactor = dot(reflectedLightDirection, unitVectorToCamera);
|
||||
specularFactor = max(specularFactor, 0.0);
|
||||
float dampedFactor = pow(specularFactor, shineDamper);
|
||||
|
||||
totalDiffuse = totalDiffuse + brightness * lightColour[i] / attFactor;
|
||||
totalSpecular = totalSpecular + dampedFactor * reflectivity * lightColour[i] / attFactor;
|
||||
|
||||
}
|
||||
totalDiffuse = max(totalDiffuse, 0.2);
|
||||
|
||||
out_Color = vec4(totalDiffuse, 1.0) * totalColour + vec4(totalSpecular, 1.0);
|
||||
out_Color = mix(vec4(skyColour, 1.0), out_Color, visibility);
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
#version 400 core
|
||||
|
||||
in vec3 position;
|
||||
in vec2 textureCoords;
|
||||
in vec3 normal;
|
||||
|
||||
out vec2 pass_textureCoords;
|
||||
out vec3 surfaceNormal;
|
||||
out vec3 toLightVector[5];
|
||||
out vec3 toCameraVector;
|
||||
out float visibility;
|
||||
|
||||
uniform mat4 transformationMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
uniform mat4 viewMatrix;
|
||||
uniform vec3 lightPosition[5];
|
||||
|
||||
const float density = 0.01;
|
||||
const float gradient = 1;
|
||||
|
||||
void main(void){
|
||||
|
||||
vec4 worldPosition = transformationMatrix * vec4(position.xyz,1.0);
|
||||
vec4 positionRelativeToCam = viewMatrix * worldPosition;
|
||||
|
||||
gl_Position = projectionMatrix * positionRelativeToCam;
|
||||
pass_textureCoords = textureCoords;
|
||||
|
||||
surfaceNormal = (transformationMatrix * vec4(normal, 0.0)).xyz;
|
||||
for(int i=0;i<5;i++){
|
||||
toLightVector[i] = lightPosition[i] - worldPosition.xyz;
|
||||
}
|
||||
toCameraVector = (inverse(viewMatrix) * vec4(0.0, 0.0, 0.0, 1.0)).xyz - worldPosition.xyz;
|
||||
|
||||
float distance = length(positionRelativeToCam.xyz);
|
||||
visibility = exp(-pow((distance * density), gradient));
|
||||
visibility = clamp(visibility, 0.0, 1.0);
|
||||
}
|
After Width: | Height: | Size: 1.7 MiB |
After Width: | Height: | Size: 1.4 MiB |
After Width: | Height: | Size: 1.0 MiB |
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 301 KiB |
After Width: | Height: | Size: 2.2 MiB |
After Width: | Height: | Size: 1.4 MiB |
After Width: | Height: | Size: 440 KiB |
After Width: | Height: | Size: 591 KiB |
After Width: | Height: | Size: 450 KiB |
After Width: | Height: | Size: 430 KiB |
After Width: | Height: | Size: 509 KiB |
After Width: | Height: | Size: 166 KiB |
After Width: | Height: | Size: 49 KiB |
After Width: | Height: | Size: 517 KiB |
After Width: | Height: | Size: 238 KiB |
After Width: | Height: | Size: 198 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 60 KiB |
After Width: | Height: | Size: 426 KiB |
After Width: | Height: | Size: 618 KiB |
After Width: | Height: | Size: 618 KiB |