├── libs
└── jinput-2.0.5.jar
├── gradle
├── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
└── libs.versions.toml
├── .gitignore
├── src
└── main
│ └── java
│ └── org
│ └── lwjgl
│ ├── opengl
│ ├── ARBBufferObject.java
│ ├── EXTAbgr.java
│ ├── InputImplementation.java
│ ├── EXTTextureRectangle.java
│ ├── DisplayMode.java
│ ├── PixelFormatLWJGL.java
│ ├── GLContext.java
│ ├── OpenGLException.java
│ ├── Util.java
│ ├── EventQueue.java
│ └── Sync.java
│ ├── fusion
│ ├── input
│ │ ├── KeyboardImplementation.java
│ │ ├── MouseImplementation.java
│ │ └── CombinedInputImplementation.java
│ ├── LWJGLImplementationUtils.java
│ └── glfw
│ │ ├── GLFWMouseImplementation.java
│ │ └── GLFWKeyboardImplementation.java
│ ├── util
│ ├── vector
│ │ ├── ReadableVector3f.java
│ │ ├── ReadableVector4f.java
│ │ ├── ReadableVector2f.java
│ │ ├── WritableVector3f.java
│ │ ├── WritableVector4f.java
│ │ ├── ReadableVector.java
│ │ ├── WritableVector2f.java
│ │ ├── Vector.java
│ │ ├── Matrix.java
│ │ ├── Vector2f.java
│ │ ├── Vector4f.java
│ │ ├── Vector3f.java
│ │ └── Matrix2f.java
│ └── glu
│ │ ├── Registry.java
│ │ ├── PixelStoreState.java
│ │ ├── Util.java
│ │ ├── MipMap.java
│ │ └── Project.java
│ ├── input
│ ├── Cursor.java
│ ├── ControllerEvent.java
│ ├── Controller.java
│ └── Controllers.java
│ ├── LWJGLException.java
│ ├── Sys.java
│ └── openal
│ └── AL.java
├── .gitattributes
├── settings.gradle
├── README.md
├── .project
├── gradlew.bat
├── .classpath
└── gradlew
/libs/jinput-2.0.5.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EldoDebug/Lwjgl-Fusion/HEAD/libs/jinput-2.0.5.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EldoDebug/Lwjgl-Fusion/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore Gradle project-specific cache directory
2 | .gradle
3 |
4 | # Ignore Gradle build output directory
5 | build
6 | *.settings
7 | *bin
8 | *build
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/opengl/ARBBufferObject.java:
--------------------------------------------------------------------------------
1 | package org.lwjgl.opengl;
2 |
3 | public class ARBBufferObject extends ARBVertexBufferObject
4 | {
5 | }
6 |
--------------------------------------------------------------------------------
/gradle/libs.versions.toml:
--------------------------------------------------------------------------------
1 | # This file was generated by the Gradle 'init' task.
2 | # https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format
3 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/opengl/EXTAbgr.java:
--------------------------------------------------------------------------------
1 | package org.lwjgl.opengl;
2 |
3 | public class EXTAbgr {
4 | public final static int GL_ABGR_EXT = EXTABGR.GL_ABGR_EXT;
5 | }
6 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | #
2 | # https://help.github.com/articles/dealing-with-line-endings/
3 | #
4 | # Linux start script should use lf
5 | /gradlew text eol=lf
6 |
7 | # These are Windows script files and should use crlf
8 | *.bat text eol=crlf
9 |
10 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * This file was generated by the Gradle 'init' task.
3 | *
4 | * The settings file is used to specify which projects to include in your build.
5 | * For more detailed information on multi-project builds, please refer to https://docs.gradle.org/8.6/userguide/multi_project_builds.html in the Gradle documentation.
6 | */
7 |
8 | rootProject.name = 'Lwjgl-Fusion'
9 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/opengl/InputImplementation.java:
--------------------------------------------------------------------------------
1 | package org.lwjgl.opengl;
2 |
3 | import org.lwjgl.fusion.input.KeyboardImplementation;
4 | import org.lwjgl.fusion.input.MouseImplementation;
5 |
6 | /**
7 | * @author Zarzelcow
8 | * @created 28/09/2022 - 2:14 PM
9 | */
10 | public interface InputImplementation extends KeyboardImplementation, MouseImplementation {
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/opengl/EXTTextureRectangle.java:
--------------------------------------------------------------------------------
1 | package org.lwjgl.opengl;
2 |
3 | public class EXTTextureRectangle {
4 | public final static int GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT = 34040;
5 | public final static int GL_PROXY_TEXTURE_RECTANGLE_EXT = 34039;
6 | public final static int GL_TEXTURE_BINDING_RECTANGLE_EXT = 34038;
7 | public final static int GL_TEXTURE_RECTANGLE_EXT = 34037;
8 | }
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Lwjgl Fusion
2 | Compatibility layer between lwjgl2 and lwjgl3
3 |
4 | ## Differences from Legacy-Lwjgl3
5 | * Latest Lwjgl3
6 | * Delete Fabric Mod
7 | * Wayland support (not complete)
8 |
9 | ## Why should use this?
10 | * Improved performance is expected
11 | * Can use the latest lwjgl3 features (NanoVG, nfd etc...)
12 |
13 | ## Credits
14 | Legacy-Lwjgl3
15 | https://github.com/Zarzelcow/legacy-lwjgl3
16 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/fusion/input/KeyboardImplementation.java:
--------------------------------------------------------------------------------
1 | package org.lwjgl.fusion.input;
2 |
3 | import java.nio.ByteBuffer;
4 |
5 | /**
6 | * @author Zarzelcow
7 | * @created 28/09/2022 - 3:24 PM
8 | */
9 | public interface KeyboardImplementation {
10 | void createKeyboard();
11 |
12 | void destroyKeyboard();
13 |
14 | void pollKeyboard(ByteBuffer keyDownBuffer);
15 |
16 | void readKeyboard(ByteBuffer readBuffer);
17 | }
18 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Lwjgl-Fusion
4 |
5 |
6 |
7 | org.eclipse.jdt.core.javanature
8 |
9 |
10 |
11 | org.eclipse.jdt.core.javabuilder
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/fusion/input/MouseImplementation.java:
--------------------------------------------------------------------------------
1 | package org.lwjgl.fusion.input;
2 |
3 | import java.nio.ByteBuffer;
4 | import java.nio.IntBuffer;
5 |
6 | /**
7 | * @author Zarzelcow
8 | * @created 28/09/2022 - 8:58 PM
9 | */
10 | public interface MouseImplementation {
11 | int getNativeCursorCapabilities();
12 |
13 | void createMouse();
14 |
15 | void destroyMouse();
16 |
17 | void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons_buffer);
18 |
19 | void readMouse(ByteBuffer readBuffer);
20 |
21 | void setCursorPosition(int x, int y);
22 |
23 | void grabMouse(boolean grab);
24 |
25 | boolean hasWheel();
26 |
27 | int getButtonCount();
28 |
29 | boolean isInsideWindow();
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/fusion/LWJGLImplementationUtils.java:
--------------------------------------------------------------------------------
1 | package org.lwjgl.fusion;
2 |
3 | import org.lwjgl.fusion.glfw.GLFWKeyboardImplementation;
4 | import org.lwjgl.fusion.glfw.GLFWMouseImplementation;
5 | import org.lwjgl.fusion.input.CombinedInputImplementation;
6 | import org.lwjgl.opengl.InputImplementation;
7 |
8 | /**
9 | * @author Zarzelcow
10 | * @created 28/09/2022 - 3:12 PM
11 | */
12 | public class LWJGLImplementationUtils {
13 | private static InputImplementation _inputImplementation;
14 |
15 | public static InputImplementation getOrCreateInputImplementation() {
16 | if (_inputImplementation == null) {
17 | _inputImplementation = createImplementation();
18 | }
19 | return _inputImplementation;
20 | }
21 |
22 | private static InputImplementation createImplementation() {
23 | return new CombinedInputImplementation(new GLFWKeyboardImplementation(), new GLFWMouseImplementation());
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/opengl/DisplayMode.java:
--------------------------------------------------------------------------------
1 | package org.lwjgl.opengl;
2 |
3 | /**
4 | * Created by gudenau on 5/30/2017.
5 | *
6 | * LWJGL3
7 | */
8 | public final class DisplayMode {
9 | private final int width, height, bpp, freq;
10 | private final boolean fullscreen;
11 |
12 | public DisplayMode(int width, int height) {
13 | this(width, height, 0, 0, false);
14 | }
15 |
16 | DisplayMode(int width, int height, int bpp, int freq) {
17 | this(width, height, bpp, freq, false);
18 | }
19 |
20 | private DisplayMode(int width, int height, int bpp, int freq, boolean fullscreen) {
21 | this.width = width;
22 | this.height = height;
23 | this.bpp = bpp;
24 | this.freq = freq;
25 | this.fullscreen = fullscreen;
26 | }
27 |
28 | public boolean isFullscreenCapable() {
29 | return fullscreen;
30 | }
31 |
32 | public int getWidth() {
33 | return width;
34 | }
35 |
36 | public int getHeight() {
37 | return height;
38 | }
39 |
40 | public int getBitsPerPixel() {
41 | return bpp;
42 | }
43 |
44 | public int getFrequency() {
45 | return freq;
46 | }
47 |
48 | public boolean equals(Object obj) {
49 | if (obj == null || !(obj instanceof DisplayMode)) {
50 | return false;
51 | }
52 |
53 | DisplayMode dm = (DisplayMode) obj;
54 | return dm.width == width && dm.height == height && dm.bpp == bpp && dm.freq == freq;
55 | }
56 | public int hashCode() {
57 | return width ^ height ^ freq ^ bpp;
58 | }
59 |
60 | public String toString() {
61 | return width + " x " + height + " x " + bpp + " @" + freq + "Hz";
62 | }
63 | }
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/opengl/PixelFormatLWJGL.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2011 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.opengl;
33 |
34 | /**
35 | * [INTERNAL USE ONLY]
36 | *
37 | * @author Spasi
38 | */
39 | public interface PixelFormatLWJGL {
40 | // Marker interface
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/util/vector/ReadableVector3f.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.util.vector;
33 |
34 | /**
35 | * @author foo
36 | */
37 | public interface ReadableVector3f extends ReadableVector2f {
38 | /**
39 | * @return z
40 | */
41 | float getZ();
42 | }
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/util/vector/ReadableVector4f.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.util.vector;
33 |
34 | /**
35 | * @author foo
36 | */
37 | public interface ReadableVector4f extends ReadableVector3f {
38 |
39 | /**
40 | * @return w
41 | */
42 | float getW();
43 |
44 | }
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/util/vector/ReadableVector2f.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.util.vector;
33 |
34 | /**
35 | * @author foo
36 | */
37 | public interface ReadableVector2f extends ReadableVector {
38 | /**
39 | * @return x
40 | */
41 | float getX();
42 | /**
43 | * @return y
44 | */
45 | float getY();
46 | }
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/input/Cursor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.input;
33 |
34 | import java.nio.IntBuffer;
35 |
36 | import org.lwjgl.LWJGLException;
37 |
38 | /**
39 | * This class is a just a stub to resolve missing classes from lwjgl3
40 | */
41 |
42 | public class Cursor {
43 |
44 | public Cursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException {
45 | }
46 |
47 | public void destroy() {
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/util/vector/WritableVector3f.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.util.vector;
33 |
34 | /**
35 | * Writable interface to Vector3fs
36 | * @author $author$
37 | * @version $revision$
38 | * $Id$
39 | */
40 | public interface WritableVector3f extends WritableVector2f {
41 |
42 | /**
43 | * Set the Z value
44 | * @param z
45 | */
46 | void setZ(float z);
47 |
48 | /**
49 | * Set the X,Y,Z values
50 | * @param x
51 | * @param y
52 | * @param z
53 | */
54 | void set(float x, float y, float z);
55 |
56 | }
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/util/vector/WritableVector4f.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.util.vector;
33 |
34 | /**
35 | * Writable interface to Vector4fs
36 | * @author $author$
37 | * @version $revision$
38 | * $Id$
39 | */
40 | public interface WritableVector4f extends WritableVector3f {
41 |
42 | /**
43 | * Set the W value
44 | * @param w
45 | */
46 | void setW(float w);
47 |
48 | /**
49 | * Set the X,Y,Z,W values
50 | * @param x
51 | * @param y
52 | * @param z
53 | * @param w
54 | */
55 | void set(float x, float y, float z, float w);
56 |
57 | }
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/util/vector/ReadableVector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.util.vector;
33 |
34 | import java.nio.FloatBuffer;
35 |
36 | /**
37 | * @author foo
38 | */
39 | public interface ReadableVector {
40 | /**
41 | * @return the length of the vector
42 | */
43 | float length();
44 | /**
45 | * @return the length squared of the vector
46 | */
47 | float lengthSquared();
48 | /**
49 | * Store this vector in a FloatBuffer
50 | * @param buf The buffer to store it in, at the current position
51 | * @return this
52 | */
53 | Vector store(FloatBuffer buf);
54 | }
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/util/vector/WritableVector2f.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.util.vector;
33 |
34 | /**
35 | * Writable interface to Vector2fs
36 | * @author $author$
37 | * @version $revision$
38 | * $Id$
39 | */
40 | public interface WritableVector2f {
41 |
42 | /**
43 | * Set the X value
44 | * @param x
45 | */
46 | void setX(float x);
47 |
48 | /**
49 | * Set the Y value
50 | * @param y
51 | */
52 | void setY(float y);
53 |
54 | /**
55 | * Set the X,Y values
56 | * @param x
57 | * @param y
58 | */
59 | void set(float x, float y);
60 |
61 | }
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/fusion/input/CombinedInputImplementation.java:
--------------------------------------------------------------------------------
1 | package org.lwjgl.fusion.input;
2 |
3 | import java.nio.ByteBuffer;
4 | import java.nio.IntBuffer;
5 |
6 | import org.lwjgl.opengl.InputImplementation;
7 |
8 | /**
9 | * @author Zarzelcow
10 | * @created 28/09/2022 - 3:23 PM
11 | */
12 | public class CombinedInputImplementation implements InputImplementation {
13 | private KeyboardImplementation keyboardImpl;
14 | private MouseImplementation mouseImpl;
15 |
16 | public CombinedInputImplementation(KeyboardImplementation keyboard, MouseImplementation mouse) {
17 | this.keyboardImpl = keyboard;
18 | this.mouseImpl = mouse;
19 | }
20 |
21 | // ~~~~~ KEYBOARD ~~~~~
22 | @Override
23 | public void createKeyboard() {
24 | keyboardImpl.createKeyboard();
25 | }
26 |
27 | @Override
28 | public void destroyKeyboard() {
29 | keyboardImpl.destroyKeyboard();
30 | }
31 |
32 | @Override
33 | public void pollKeyboard(ByteBuffer keyDownBuffer) {
34 | keyboardImpl.pollKeyboard(keyDownBuffer);
35 | }
36 |
37 | @Override
38 | public void readKeyboard(ByteBuffer readBuffer) {
39 | keyboardImpl.readKeyboard(readBuffer);
40 | }
41 |
42 | // ~~~~~ MOUSE ~~~~~
43 |
44 | @Override
45 | public int getNativeCursorCapabilities() {
46 | return 0;
47 | }
48 |
49 | @Override
50 | public void createMouse() {
51 | mouseImpl.createMouse();
52 | }
53 |
54 | @Override
55 | public void destroyMouse() {
56 | mouseImpl.destroyMouse();
57 | }
58 |
59 | @Override
60 | public void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons_buffer) {
61 | mouseImpl.pollMouse(coord_buffer, buttons_buffer);
62 | }
63 |
64 | @Override
65 | public void readMouse(ByteBuffer readBuffer) {
66 | mouseImpl.readMouse(readBuffer);
67 | }
68 |
69 | @Override
70 | public void setCursorPosition(int x, int y) {
71 | mouseImpl.setCursorPosition(x, y);
72 | }
73 |
74 | @Override
75 | public void grabMouse(boolean grab) {
76 | mouseImpl.grabMouse(grab);
77 | }
78 |
79 | @Override
80 | public boolean hasWheel() {
81 | return mouseImpl.hasWheel();
82 | }
83 |
84 | @Override
85 | public int getButtonCount() {
86 | return mouseImpl.getButtonCount();
87 | }
88 |
89 | @Override
90 | public boolean isInsideWindow() {
91 | return mouseImpl.isInsideWindow();
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/LWJGLException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl;
33 |
34 | /**
35 | *
36 | * This exception is supplied to make exception handling more generic for LWJGL
37 | * specific exceptions
38 | *
39 | *
40 | * @author Brian Matzon
41 | */
42 | public class LWJGLException extends Exception {
43 |
44 | private static final long serialVersionUID = 1L;
45 |
46 | /**
47 | * Plain c'tor
48 | */
49 | public LWJGLException() {
50 | super();
51 | }
52 |
53 | /**
54 | * Creates a new LWJGLException
55 | *
56 | * @param msg String identifier for exception
57 | */
58 | public LWJGLException(String msg) {
59 | super(msg);
60 | }
61 |
62 | /**
63 | * @param message
64 | * @param cause
65 | */
66 | public LWJGLException(String message, Throwable cause) {
67 | super(message, cause);
68 | }
69 |
70 | /**
71 | * @param cause
72 | */
73 | public LWJGLException(Throwable cause) {
74 | super(cause);
75 | }
76 | }
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/opengl/GLContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.opengl;
33 |
34 | import javax.annotation.Nullable;
35 |
36 | import org.lwjgl.LWJGLException;
37 |
38 | /**
39 | * Created by gudenau on 5/31/2017.
40 | *
41 | * LWJGL3
42 | */
43 | public class GLContext {
44 | private static final ThreadLocal current_capabilities = new ThreadLocal<>();
45 |
46 | public static ContextCapabilities getCapabilities() {
47 | ContextCapabilities caps = getCapabilitiesImpl();
48 | if (caps == null) {
49 | //throw new RuntimeException("No OpenGL context found in the current thread.");
50 | try {
51 | ContextCapabilities created = new ContextCapabilities(false);
52 | setCapabilities(created);
53 | return created;
54 | } catch (LWJGLException e) {
55 | //e.printStackTrace();
56 | throw new RuntimeException("No OpenGL context found in the current thread and could not create!", e);
57 | }
58 | }
59 |
60 | return caps;
61 | }
62 |
63 | private static @Nullable ContextCapabilities getCapabilitiesImpl() {
64 | return getThreadLocalCapabilities();
65 | }
66 |
67 | private static @Nullable ContextCapabilities getThreadLocalCapabilities() {
68 | return current_capabilities.get();
69 | }
70 |
71 | static void setCapabilities(ContextCapabilities capabilities) {
72 | current_capabilities.set(capabilities);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/util/glu/Registry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.util.glu;
33 |
34 | import static org.lwjgl.util.glu.GLU.GLU_EXTENSIONS;
35 | import static org.lwjgl.util.glu.GLU.GLU_VERSION;
36 |
37 | /**
38 | * Registry.java
39 | *
40 | *
41 | * Created 11-jan-2004
42 | * @author Erik Duijs
43 | */
44 | public class Registry extends Util {
45 |
46 | private static final String versionString = "1.3";
47 | private static final String extensionString =
48 | "GLU_EXT_nurbs_tessellator " + "GLU_EXT_object_space_tess ";
49 |
50 | /**
51 | * Method gluGetString
52 | * @param name
53 | * @return String
54 | */
55 | public static String gluGetString(int name) {
56 |
57 | if (name == GLU_VERSION) {
58 | return versionString;
59 | } else if (name == GLU_EXTENSIONS) {
60 | return extensionString;
61 | }
62 | return null;
63 | }
64 |
65 | /**
66 | * Method gluCheckExtension
67 | *
68 | * @param extName is an extension name.
69 | * @param extString is a string of extensions separated by blank(s). There may or
70 | * may not be leading or trailing blank(s) in extString.
71 | * This works in cases of extensions being prefixes of another like
72 | * GL_EXT_texture and GL_EXT_texture3D.
73 | * @return boolean true if extName is found otherwise it returns false.
74 | */
75 | public static boolean gluCheckExtension(String extName, String extString){
76 | return extString != null && extName != null && extString.contains(extName);
77 | }
78 | }
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/opengl/OpenGLException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.opengl;
33 |
34 | /**
35 | *
36 | * Thrown by the debug build library of the LWJGL if any OpenGL operation causes an error.
37 | *
38 | * @author cix_foo
39 | * @version $Revision$
40 | * $Id$
41 | */
42 | public class OpenGLException extends RuntimeException {
43 |
44 | private static final long serialVersionUID = 1L;
45 |
46 | /** Constructor for OpenGLException. */
47 | public OpenGLException(int gl_error_code) {
48 | this(createErrorMessage(gl_error_code));
49 | }
50 |
51 | private static String createErrorMessage(int gl_error_code) {
52 | String error_string = Util.translateGLErrorString(gl_error_code);
53 | return error_string + " (" + gl_error_code + ")";
54 | }
55 |
56 | /** Constructor for OpenGLException. */
57 | public OpenGLException() {
58 | super();
59 | }
60 |
61 | /**
62 | * Constructor for OpenGLException.
63 | *
64 | * @param message
65 | */
66 | public OpenGLException(String message) {
67 | super(message);
68 | }
69 |
70 | /**
71 | * Constructor for OpenGLException.
72 | *
73 | * @param message
74 | * @param cause
75 | */
76 | public OpenGLException(String message, Throwable cause) {
77 | super(message, cause);
78 | }
79 |
80 | /**
81 | * Constructor for OpenGLException.
82 | *
83 | * @param cause
84 | */
85 | public OpenGLException(Throwable cause) {
86 | super(cause);
87 | }
88 |
89 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%"=="" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%"=="" set DIRNAME=.
29 | @rem This is normally unused
30 | set APP_BASE_NAME=%~n0
31 | set APP_HOME=%DIRNAME%
32 |
33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
35 |
36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
38 |
39 | @rem Find java.exe
40 | if defined JAVA_HOME goto findJavaFromJavaHome
41 |
42 | set JAVA_EXE=java.exe
43 | %JAVA_EXE% -version >NUL 2>&1
44 | if %ERRORLEVEL% equ 0 goto execute
45 |
46 | echo. 1>&2
47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
48 | echo. 1>&2
49 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
50 | echo location of your Java installation. 1>&2
51 |
52 | goto fail
53 |
54 | :findJavaFromJavaHome
55 | set JAVA_HOME=%JAVA_HOME:"=%
56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57 |
58 | if exist "%JAVA_EXE%" goto execute
59 |
60 | echo. 1>&2
61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
62 | echo. 1>&2
63 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
64 | echo location of your Java installation. 1>&2
65 |
66 | goto fail
67 |
68 | :execute
69 | @rem Setup the command line
70 |
71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
72 |
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if %ERRORLEVEL% equ 0 goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | set EXIT_CODE=%ERRORLEVEL%
85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87 | exit /b %EXIT_CODE%
88 |
89 | :mainEnd
90 | if "%OS%"=="Windows_NT" endlocal
91 |
92 | :omega
93 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/util/glu/PixelStoreState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.util.glu;
33 |
34 | import static org.lwjgl.opengl.GL11.*;
35 |
36 | /**
37 | * PixelStoreState.java
38 | *
39 | *
40 | * Created 11-jan-2004
41 | * @author Erik Duijs
42 | */
43 | class PixelStoreState extends Util {
44 |
45 | public int unpackRowLength;
46 | public int unpackAlignment;
47 | public int unpackSkipRows;
48 | public int unpackSkipPixels;
49 | public int packRowLength;
50 | public int packAlignment;
51 | public int packSkipRows;
52 | public int packSkipPixels;
53 |
54 | /**
55 | * Constructor for PixelStoreState.
56 | */
57 | PixelStoreState() {
58 | super();
59 | load();
60 | }
61 |
62 | public void load() {
63 | unpackRowLength = glGetInteger(GL_UNPACK_ROW_LENGTH);
64 | unpackAlignment = glGetInteger(GL_UNPACK_ALIGNMENT);
65 | unpackSkipRows = glGetInteger(GL_UNPACK_SKIP_ROWS);
66 | unpackSkipPixels = glGetInteger(GL_UNPACK_SKIP_PIXELS);
67 | packRowLength = glGetInteger(GL_PACK_ROW_LENGTH);
68 | packAlignment = glGetInteger(GL_PACK_ALIGNMENT);
69 | packSkipRows = glGetInteger(GL_PACK_SKIP_ROWS);
70 | packSkipPixels = glGetInteger(GL_PACK_SKIP_PIXELS);
71 | }
72 |
73 | public void save() {
74 | glPixelStorei(GL_UNPACK_ROW_LENGTH, unpackRowLength);
75 | glPixelStorei(GL_UNPACK_ALIGNMENT, unpackAlignment);
76 | glPixelStorei(GL_UNPACK_SKIP_ROWS, unpackSkipRows);
77 | glPixelStorei(GL_UNPACK_SKIP_PIXELS, unpackSkipPixels);
78 | glPixelStorei(GL_PACK_ROW_LENGTH, packRowLength);
79 | glPixelStorei(GL_PACK_ALIGNMENT, packAlignment);
80 | glPixelStorei(GL_PACK_SKIP_ROWS, packSkipRows);
81 | glPixelStorei(GL_PACK_SKIP_PIXELS, packSkipPixels);
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/Sys.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl;
33 |
34 | import java.awt.*;
35 | import java.io.IOException;
36 | import java.net.URI;
37 | import java.net.URISyntaxException;
38 |
39 | /**
40 | * Created by gudenau on 5/30/2017.
41 | *
42 | * LWJGL3
43 | */
44 | public class Sys {
45 | private static final long timerOffset;
46 | public static final String VERSION = Version.getVersion();
47 |
48 | private Sys() {
49 | }
50 |
51 | static {
52 | timerOffset = System.nanoTime();
53 | }
54 |
55 | /**
56 | * Obtains the number of ticks that the hires timer does in a second.
57 | *
58 | * @return timer resolution in ticks per second.
59 | */
60 | public static long getTimerResolution() {
61 | return 1000000000;
62 | }
63 |
64 | /**
65 | * Gets the current value of the hires timer, in ticks. When the Sys class is
66 | * first loaded the hires timer is reset to 0. If no hires timer is present then
67 | * this method will always return 0.
68 | *
69 | * NOTEZ BIEN that the hires timer WILL wrap around.
70 | *
71 | * @return the current hires time, in ticks (always >= 0)
72 | */
73 | public static long getTime() {
74 | return (System.nanoTime() - timerOffset) & 0x7FFFFFFFFFFFFFFFL;
75 | }
76 |
77 | /**
78 | * Return the version of the core LWJGL libraries as a String.
79 | */
80 | public static String getVersion() {
81 | return VERSION;
82 | }
83 |
84 | /**
85 | * Initialization. This is just a dummy method to trigger the static
86 | * constructor.
87 | */
88 | public static void initialize() {
89 | }
90 |
91 | public static boolean openURL(String url) {
92 | try {
93 | Desktop.getDesktop().browse(new URI(url));
94 | return true;
95 | } catch (IOException | URISyntaxException | UnsupportedOperationException e) {
96 | return false;
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/opengl/Util.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.opengl;
33 |
34 | import static org.lwjgl.opengl.ARBImaging.*;
35 | import static org.lwjgl.opengl.GL11.*;
36 | import static org.lwjgl.opengl.GL30.*;
37 |
38 | /**
39 | * Simple utility class.
40 | *
41 | * @author cix_foo
42 | * @version $Revision$
43 | */
44 |
45 | public final class Util {
46 | /** No c'tor */
47 | private Util() {
48 | }
49 |
50 | /**
51 | * Throws OpenGLException if glGetError() returns anything else than GL_NO_ERROR
52 | *
53 | */
54 | public static void checkGLError() throws OpenGLException {
55 | if ( ContextCapabilities.DEBUG) // Do not call GetError inside a Begin/End pair.
56 | return;
57 | int err = glGetError();
58 | if ( err != GL_NO_ERROR ) {
59 | throw new OpenGLException(err);
60 | }
61 | }
62 |
63 | /**
64 | * Translate a GL error code to a String describing the error
65 | */
66 | public static String translateGLErrorString(int error_code) {
67 | switch (error_code) {
68 | case GL_NO_ERROR:
69 | return "No error";
70 | case GL_INVALID_ENUM:
71 | return "Invalid enum";
72 | case GL_INVALID_VALUE:
73 | return "Invalid value";
74 | case GL_INVALID_OPERATION:
75 | return "Invalid operation";
76 | case GL_STACK_OVERFLOW:
77 | return "Stack overflow";
78 | case GL_STACK_UNDERFLOW:
79 | return "Stack underflow";
80 | case GL_OUT_OF_MEMORY:
81 | return "Out of memory";
82 | case GL_TABLE_TOO_LARGE:
83 | return "Table too large";
84 | case GL_INVALID_FRAMEBUFFER_OPERATION:
85 | return "Invalid framebuffer operation";
86 | default:
87 | return null;
88 | }
89 | }
90 | }
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/opengl/EventQueue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.opengl;
33 |
34 | /**
35 | * A java implementation of a LWJGL compatible event queue.
36 | * @author elias_naur
37 | */
38 |
39 | import java.nio.ByteBuffer;
40 |
41 | public class EventQueue {
42 | private static final int QUEUE_SIZE = 200;
43 |
44 | private final int event_size;
45 |
46 | private final ByteBuffer queue;
47 |
48 | public EventQueue(int event_size) {
49 | this.event_size = event_size;
50 | this.queue = ByteBuffer.allocate(QUEUE_SIZE*event_size);
51 | }
52 |
53 | public synchronized void clearEvents() {
54 | queue.clear();
55 | }
56 |
57 | /**
58 | * Copy available events into the specified buffer.
59 | */
60 | public synchronized void copyEvents(ByteBuffer dest) {
61 | queue.flip();
62 | int old_limit = queue.limit();
63 | if (dest.remaining() < queue.remaining())
64 | queue.limit(dest.remaining() + queue.position());
65 | dest.put(queue);
66 | queue.limit(old_limit);
67 | queue.compact();
68 | }
69 |
70 | /**
71 | * Put an event into the queue.
72 | * @return true if the event fitted into the queue, false otherwise
73 | */
74 | public synchronized boolean putEvent(ByteBuffer event) {
75 | if (event.remaining() != event_size)
76 | throw new IllegalArgumentException("Internal error: event size " + event_size + " does not equal the given event size " + event.remaining());
77 | if (queue.remaining() >= event.remaining()) {
78 | queue.put(event);
79 | return true;
80 | } else
81 | return false;
82 | }
83 |
84 | public synchronized ByteBuffer getLastEvent(){
85 | int position = queue.position();
86 | queue.position(Math.max(position-event_size, 0));
87 | ByteBuffer slice = queue.slice();
88 | slice.clear();
89 | queue.position(position);
90 | return slice;
91 | }
92 | }
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/util/vector/Vector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.util.vector;
33 |
34 | import java.io.Serializable;
35 | import java.nio.FloatBuffer;
36 |
37 | /**
38 | *
39 | * Base class for vectors.
40 | *
41 | * @author cix_foo
42 | * @version $Revision$
43 | * $Id$
44 | */
45 | public abstract class Vector implements Serializable, ReadableVector {
46 |
47 | private static final long serialVersionUID = 1L;
48 |
49 |
50 | /**
51 | * Constructor for Vector.
52 | */
53 | protected Vector() {
54 | super();
55 | }
56 |
57 | /**
58 | * @return the length of the vector
59 | */
60 | public final float length() {
61 | return (float) Math.sqrt(lengthSquared());
62 | }
63 |
64 |
65 | /**
66 | * @return the length squared of the vector
67 | */
68 | public abstract float lengthSquared();
69 |
70 | /**
71 | * Load this vector from a FloatBuffer
72 | * @param buf The buffer to load it from, at the current position
73 | * @return this
74 | */
75 | public abstract Vector load(FloatBuffer buf);
76 |
77 | /**
78 | * Negate a vector
79 | * @return this
80 | */
81 | public abstract Vector negate();
82 |
83 |
84 | /**
85 | * Normalise this vector
86 | * @return this
87 | */
88 | public final Vector normalise() {
89 | float len = length();
90 | if (len != 0.0f) {
91 | float l = 1.0f / len;
92 | return scale(l);
93 | } else
94 | throw new IllegalStateException("Zero length vector");
95 | }
96 |
97 |
98 | /**
99 | * Store this vector in a FloatBuffer
100 | * @param buf The buffer to store it in, at the current position
101 | * @return this
102 | */
103 | public abstract Vector store(FloatBuffer buf);
104 |
105 |
106 | /**
107 | * Scale this vector
108 | * @param scale The scale factor
109 | * @return this
110 | */
111 | public abstract Vector scale(float scale);
112 |
113 |
114 |
115 | }
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/util/vector/Matrix.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.util.vector;
33 |
34 | import java.io.Serializable;
35 | import java.nio.FloatBuffer;
36 |
37 | /**
38 | *
39 | * Base class for matrices. When a matrix is constructed it will be the identity
40 | * matrix unless otherwise stated.
41 | *
42 | * @author cix_foo
43 | * @version $Revision$
44 | * $Id$
45 | */
46 | public abstract class Matrix implements Serializable {
47 |
48 | private static final long serialVersionUID = 1L;
49 |
50 |
51 | /**
52 | * Constructor for Matrix.
53 | */
54 | protected Matrix() {
55 | super();
56 | }
57 |
58 | /**
59 | * Set this matrix to be the identity matrix.
60 | * @return this
61 | */
62 | public abstract Matrix setIdentity();
63 |
64 |
65 | /**
66 | * Invert this matrix
67 | * @return this
68 | */
69 | public abstract Matrix invert();
70 |
71 |
72 | /**
73 | * Load from a float buffer. The buffer stores the matrix in column major
74 | * (OpenGL) order.
75 | *
76 | * @param buf A float buffer to read from
77 | * @return this
78 | */
79 | public abstract Matrix load(FloatBuffer buf);
80 |
81 |
82 | /**
83 | * Load from a float buffer. The buffer stores the matrix in row major
84 | * (mathematical) order.
85 | *
86 | * @param buf A float buffer to read from
87 | * @return this
88 | */
89 | public abstract Matrix loadTranspose(FloatBuffer buf);
90 |
91 |
92 | /**
93 | * Negate this matrix
94 | * @return this
95 | */
96 | public abstract Matrix negate();
97 |
98 |
99 | /**
100 | * Store this matrix in a float buffer. The matrix is stored in column
101 | * major (openGL) order.
102 | * @param buf The buffer to store this matrix in
103 | * @return this
104 | */
105 | public abstract Matrix store(FloatBuffer buf);
106 |
107 |
108 | /**
109 | * Store this matrix in a float buffer. The matrix is stored in row
110 | * major (maths) order.
111 | * @param buf The buffer to store this matrix in
112 | * @return this
113 | */
114 | public abstract Matrix storeTranspose(FloatBuffer buf);
115 |
116 |
117 | /**
118 | * Transpose this matrix
119 | * @return this
120 | */
121 | public abstract Matrix transpose();
122 |
123 |
124 | /**
125 | * Set this matrix to 0.
126 | * @return this
127 | */
128 | public abstract Matrix setZero();
129 |
130 |
131 | /**
132 | * @return the determinant of the matrix
133 | */
134 | public abstract float determinant();
135 |
136 |
137 | }
--------------------------------------------------------------------------------
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/fusion/glfw/GLFWMouseImplementation.java:
--------------------------------------------------------------------------------
1 | package org.lwjgl.fusion.glfw;
2 |
3 | import org.lwjgl.fusion.input.MouseImplementation;
4 | import org.lwjgl.glfw.*;
5 | import org.lwjgl.input.Mouse;
6 | import org.lwjgl.opengl.Display;
7 | import org.lwjgl.opengl.EventQueue;
8 |
9 | import java.nio.ByteBuffer;
10 | import java.nio.IntBuffer;
11 |
12 | /**
13 | * @author Zarzelcow
14 | * @created 28/09/2022 - 8:58 PM
15 | */
16 | public class GLFWMouseImplementation implements MouseImplementation {
17 | private GLFWMouseButtonCallback buttonCallback;
18 | private GLFWCursorPosCallback posCallback;
19 | private GLFWScrollCallback scrollCallback;
20 | private GLFWCursorEnterCallback cursorEnterCallback;
21 | private long windowHandle;
22 | private boolean grabbed;
23 | private boolean isInsideWindow;
24 |
25 | private final EventQueue event_queue = new EventQueue(Mouse.EVENT_SIZE);
26 |
27 | private final ByteBuffer tmp_event = ByteBuffer.allocate(Mouse.EVENT_SIZE);
28 |
29 | private int last_x;
30 | private int last_y;
31 | private int accum_dx;
32 | private int accum_dy;
33 | private int accum_dz;
34 | private byte[] button_states = new byte[this.getButtonCount()];
35 | private boolean firstMove = true;
36 |
37 | @Override
38 | public void createMouse() {
39 |
40 | this.windowHandle = Display.getHandle();
41 |
42 | this.buttonCallback = GLFWMouseButtonCallback.create((window, button, action, mods) -> {
43 | byte state = action == GLFW.GLFW_PRESS ? (byte)1 : (byte)0;
44 | putMouseEvent((byte) button, state, 0, System.nanoTime());
45 | if (button < button_states.length)
46 | button_states[button] = state;
47 | });
48 | this.posCallback = GLFWCursorPosCallback.create((window, xpos, ypos) -> {
49 | int x = (int) xpos;
50 | int y = Display.getHeight() - 1 - (int) ypos; // I don't know why but this un-inverts the y motion of mouse inputs
51 | int dx = x - last_x;
52 | int dy = y - last_y;
53 | //TODO mouse input is faster in lwjgl2?
54 | //Needed to fix initial mouse delta
55 | if(firstMove) {
56 | firstMove = false;
57 | dx = dy = 0;
58 | last_x = x;
59 | last_y = y;
60 | }
61 | if (dx != 0 || dy != 0) {
62 | accum_dx += dx;
63 | accum_dy += dy;
64 | last_x = x;
65 | last_y = y;
66 | long nanos = System.nanoTime();
67 | if (grabbed) {
68 | putMouseEventWithCoords((byte)-1, (byte)0, dx, dy, 0, nanos);
69 | } else {
70 | putMouseEventWithCoords((byte)-1, (byte)0, x, y, 0, nanos);
71 | }
72 | }
73 | });
74 | this.scrollCallback = GLFWScrollCallback.create((window, xoffset, yoffset) -> {
75 | accum_dz += yoffset;
76 | putMouseEvent((byte)-1, (byte)0, (int) yoffset, System.nanoTime());
77 | });
78 | this.cursorEnterCallback = GLFWCursorEnterCallback.create((window, entered) -> this.isInsideWindow = entered);
79 |
80 | GLFW.glfwSetMouseButtonCallback(this.windowHandle, this.buttonCallback);
81 | GLFW.glfwSetCursorPosCallback(this.windowHandle, this.posCallback);
82 | GLFW.glfwSetScrollCallback(this.windowHandle, this.scrollCallback);
83 | GLFW.glfwSetCursorEnterCallback(this.windowHandle, this.cursorEnterCallback);
84 | }
85 |
86 | private void putMouseEvent(byte button, byte state, int dz, long nanos) {
87 | if (grabbed)
88 | putMouseEventWithCoords(button, state, 0, 0, dz, nanos);
89 | else
90 | putMouseEventWithCoords(button, state, last_x, last_y, dz, nanos);
91 | }
92 |
93 | private void putMouseEventWithCoords(byte button, byte state, int coord1, int coord2, int dz, long nanos) {
94 | tmp_event.clear();
95 | tmp_event.put(button).put(state).putInt(coord1).putInt(coord2).putInt(dz).putLong(nanos);
96 | tmp_event.flip();
97 | event_queue.putEvent(tmp_event);
98 | }
99 |
100 | @Override
101 | public void destroyMouse() {
102 | this.buttonCallback.free();
103 | this.posCallback.free();
104 | this.scrollCallback.free();
105 | this.cursorEnterCallback.free();
106 | }
107 |
108 | private void reset() {
109 | this.event_queue.clearEvents();
110 | accum_dx = accum_dy = 0;
111 | }
112 |
113 | @Override
114 | public void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons_buffer) {
115 | if (grabbed) {
116 | coord_buffer.put(0, accum_dx);
117 | coord_buffer.put(1, accum_dy);
118 | } else {
119 | coord_buffer.put(0, last_x);
120 | coord_buffer.put(1, last_y);
121 | }
122 | coord_buffer.put(2, accum_dz);
123 | accum_dx = accum_dy = accum_dz = 0;
124 | for (int i = 0; i < button_states.length; i++)
125 | buttons_buffer.put(i, button_states[i]);
126 | }
127 |
128 | @Override
129 | public void readMouse(ByteBuffer readBuffer) {
130 | event_queue.copyEvents(readBuffer);
131 | }
132 |
133 | @Override
134 | public void setCursorPosition(int x, int y) {
135 | this.last_x = x;
136 | this.last_y = y;
137 | int mode = GLFW.glfwGetInputMode(this.windowHandle, GLFW.GLFW_CURSOR);
138 | // Has to be GLFW_CURSOR_NORMAL because GLFW_CURSOR_DISABLED ignores this call
139 | GLFW.glfwSetInputMode(this.windowHandle, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_NORMAL);
140 | GLFW.glfwSetCursorPos(this.windowHandle, x, y);
141 | GLFW.glfwSetInputMode(this.windowHandle, GLFW.GLFW_CURSOR, mode);
142 | }
143 |
144 | @Override
145 | public void grabMouse(boolean grab) {
146 | GLFW.glfwSetInputMode(this.windowHandle, GLFW.GLFW_CURSOR, grab ? GLFW.GLFW_CURSOR_DISABLED : GLFW.GLFW_CURSOR_NORMAL);
147 | this.grabbed = grab;
148 | this.reset();
149 | }
150 |
151 | @Override
152 | public boolean hasWheel() {
153 | return true;
154 | }
155 |
156 | @Override
157 | public int getButtonCount() {
158 | return GLFW.GLFW_MOUSE_BUTTON_LAST + 1;
159 | }
160 |
161 | @Override
162 | public boolean isInsideWindow() {
163 | return this.isInsideWindow;
164 | }
165 |
166 | @Override
167 | public int getNativeCursorCapabilities() {
168 | return 0;
169 | }
170 | }
171 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/opengl/Sync.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.opengl;
33 |
34 | public class Sync{
35 | /** number of nano seconds in a second */
36 | private static final long NANOS_IN_SECOND = 1000L * 1000L * 1000L;
37 |
38 | /** The time to sleep/yield until the next frame */
39 | private static long nextFrame = 0;
40 |
41 | /** whether the initialisation code has run */
42 | private static boolean initialised = false;
43 |
44 | /** for calculating the averages the previous sleep/yield times are stored */
45 | private static RunningAvg sleepDurations = new RunningAvg(10);
46 | private static RunningAvg yieldDurations = new RunningAvg(10);
47 |
48 |
49 | /**
50 | * An accurate sync method that will attempt to run at a constant frame rate.
51 | * It should be called once every frame.
52 | *
53 | * @param fps - the desired frame rate, in frames per second
54 | */
55 | public static void sync(int fps) {
56 | if (fps <= 0) return;
57 | if (!initialised) initialise();
58 |
59 | try {
60 | // sleep until the average sleep time is greater than the time remaining till nextFrame
61 | for (long t0 = getTime(), t1; (nextFrame - t0) > sleepDurations.avg(); t0 = t1) {
62 | Thread.sleep(1);
63 | sleepDurations.add((t1 = getTime()) - t0); // update average sleep time
64 | }
65 |
66 | // slowly dampen sleep average if too high to avoid yielding too much
67 | sleepDurations.dampenForLowResTicker();
68 |
69 | // yield until the average yield time is greater than the time remaining till nextFrame
70 | for (long t0 = getTime(), t1; (nextFrame - t0) > yieldDurations.avg(); t0 = t1) {
71 | Thread.yield();
72 | yieldDurations.add((t1 = getTime()) - t0); // update average yield time
73 | }
74 | } catch (InterruptedException ignored) {}
75 |
76 | // schedule next frame, drop frame(s) if already too late for next frame
77 | nextFrame = Math.max(nextFrame + NANOS_IN_SECOND / fps, getTime());
78 | }
79 |
80 | /**
81 | * This method will initialise the sync method by setting initial
82 | * values for sleepDurations/yieldDurations and nextFrame.
83 | *
84 | * If running on windows it will start the sleep timer fix.
85 | */
86 | private static void initialise() {
87 | initialised = true;
88 |
89 | sleepDurations.init(1000 * 1000);
90 | yieldDurations.init((int) (-(getTime() - getTime()) * 1.333));
91 |
92 | nextFrame = getTime();
93 |
94 | String osName = System.getProperty("os.name");
95 |
96 | if (osName.startsWith("Win")) {
97 | // On windows the sleep functions can be highly inaccurate by
98 | // over 10ms making in unusable. However it can be forced to
99 | // be a bit more accurate by running a separate sleeping daemon
100 | // thread.
101 | Thread timerAccuracyThread = new Thread(()->{
102 | try {
103 | Thread.sleep(Long.MAX_VALUE);
104 | } catch (Exception ignored) {}
105 | });
106 |
107 | timerAccuracyThread.setName("LWJGL Timer");
108 | timerAccuracyThread.setDaemon(true);
109 | timerAccuracyThread.start();
110 | }
111 | }
112 |
113 | /**
114 | * Get the system time in nano seconds
115 | *
116 | * @return will return the current time in nano's
117 | */
118 | private static long getTime() {
119 | return System.nanoTime();
120 | }
121 |
122 | private static class RunningAvg {
123 | private final long[] slots;
124 | private int offset;
125 |
126 | private static final long DAMPEN_THRESHOLD = 10 * 1000L * 1000L; // 10ms
127 | private static final float DAMPEN_FACTOR = 0.9f; // don't change: 0.9f is exactly right!
128 |
129 | public RunningAvg(int slotCount) {
130 | this.slots = new long[slotCount];
131 | this.offset = 0;
132 | }
133 |
134 | public void init(long value) {
135 | while (this.offset < this.slots.length) {
136 | this.slots[this.offset++] = value;
137 | }
138 | }
139 |
140 | public void add(long value) {
141 | this.slots[this.offset++ % this.slots.length] = value;
142 | this.offset %= this.slots.length;
143 | }
144 |
145 | public long avg() {
146 | long sum = 0;
147 | for(long slot : this.slots){
148 | sum += slot;
149 | }
150 | return sum / this.slots.length;
151 | }
152 |
153 | public void dampenForLowResTicker() {
154 | if (this.avg() > DAMPEN_THRESHOLD) {
155 | for (int i = 0; i < this.slots.length; i++) {
156 | this.slots[i] *= DAMPEN_FACTOR;
157 | }
158 | }
159 | }
160 | }
161 |
162 | }
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/input/ControllerEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.input;
33 |
34 | /**
35 | * An event occuring on a controller.
36 | *
37 | * @author Kevin Glass
38 | */
39 | class ControllerEvent {
40 | /** Indicates the event was caused by a button */
41 | public static final int BUTTON = 1;
42 | /** Indicates the event was caused by a axis */
43 | public static final int AXIS = 2;
44 | /** Indicates the event was caused by a pov X */
45 | public static final int POVX = 3;
46 | /** Indicates the event was caused by a pov Y */
47 | public static final int POVY = 4;
48 |
49 | /** The controller generating the event */
50 | private Controller source;
51 | /** The index of the input (axis or button) that generated the event */
52 | private int index;
53 | /** Type of control that generated the event */
54 | private int type;
55 | /** True when a button is pressed, if this event was caused by the button */
56 | private boolean buttonState;
57 | /** True if this event was caused by the x axis */
58 | private boolean xaxis;
59 | /** True if this event was caused by the y axis */
60 | private boolean yaxis;
61 | /** The time stamp of this event */
62 | private long timeStamp;
63 | /** The value on a specified axis, if this event was caused by the x-axis */
64 | private float xaxisValue;
65 | /** The value on a specified axis, if this event was caused by the y-axis */
66 | private float yaxisValue;
67 |
68 | /**
69 | * Create a new event
70 | *
71 | * @param source The source of the event
72 | * @param timeStamp The time stamp given for this event
73 | * @param type The type of control generating this event
74 | * @param index The index of the input that generated the event
75 | * @param xaxis True if this event was caused by the x-axis
76 | * @param yaxis True if this event was caused by the y-axis
77 | */
78 | ControllerEvent(Controller source,long timeStamp, int type,int index,boolean xaxis,boolean yaxis) {
79 | this(source, timeStamp, type, index, false, xaxis, yaxis, 0, 0);
80 | }
81 |
82 | /**
83 | * Create a new event
84 | *
85 | * @param source The source of the event
86 | * @param timeStamp The time stamp given for this event
87 | * @param type The type of control generating this event
88 | * @param index The index of the input that generated the event
89 | * @param buttonState True when a button is pressed, if this event was caused by the button
90 | * @param xaxis True if this event was caused by the x-axis
91 | * @param yaxis True if this event was caused by the y-axis
92 | * @param xaxisValue The value on a specified axis, if this event was caused by the x-axis
93 | * @param yaxisValue The value on a specified axis, if this event was caused by the y-axis
94 | */
95 | ControllerEvent(Controller source,long timeStamp, int type,int index,boolean buttonState,boolean xaxis,boolean yaxis,float xaxisValue,float yaxisValue) {
96 | this.source = source;
97 | this.timeStamp = timeStamp;
98 | this.type = type;
99 | this.index = index;
100 | this.buttonState = buttonState;
101 | this.xaxis = xaxis;
102 | this.yaxis = yaxis;
103 | this.xaxisValue = xaxisValue;
104 | this.yaxisValue = yaxisValue;
105 | }
106 |
107 | /**
108 | * Get the time stamp given for this event. As with nanoTime()
109 | * this value means nothing other than giving ordering
110 | *
111 | * @return The time stamp given for this event
112 | */
113 | public long getTimeStamp() {
114 | return timeStamp;
115 | }
116 |
117 | /**
118 | * Get the controller that generated this event
119 | *
120 | * @return The controller that generated this event
121 | */
122 | public Controller getSource() {
123 | return source;
124 | }
125 |
126 | /**
127 | * Get the index of the control generating this event
128 | *
129 | * @return The index of the control generating this event
130 | */
131 | public int getControlIndex() {
132 | return index;
133 | }
134 |
135 | /**
136 | * Check if this event was generated by a button
137 | *
138 | * @return True if this event was generated by a button
139 | */
140 | public boolean isButton() {
141 | return type == BUTTON;
142 | }
143 |
144 | /**
145 | * Check the button is pressed or not, when this event was caused
146 | *
147 | * @return True when a button is pressed, if this event was caused by the button
148 | */
149 | public boolean getButtonState() {
150 | return buttonState;
151 | }
152 |
153 | /**
154 | * Check if this event was generated by a axis
155 | *
156 | * @return True if this event was generated by a axis
157 | */
158 | public boolean isAxis() {
159 | return type == AXIS;
160 | }
161 |
162 | /**
163 | * Check if this event was generated by a pov
164 | *
165 | * @return True if this event was generated by a pov
166 | */
167 | public boolean isPovY() {
168 | return type == POVY;
169 | }
170 | /**
171 | *
172 | * Check if this event was generated by a pov
173 | *
174 | * @return True if this event was generated by a pov
175 | */
176 | public boolean isPovX() {
177 | return type == POVX;
178 | }
179 |
180 | /**
181 | * Check if this event was caused by the X axis
182 | *
183 | * @return True if this event was caused by the X axis
184 | */
185 | public boolean isXAxis() {
186 | return xaxis;
187 | }
188 |
189 | /**
190 | * Check if this event was caused by the Y axis
191 | *
192 | * @return True if this event was caused by the Y axis
193 | */
194 | public boolean isYAxis() {
195 | return yaxis;
196 | }
197 |
198 | /**
199 | * Get the value on an X axis when this event was caused
200 | *
201 | * @return The value on a specified axis, if this event was caused by the x-axis
202 | */
203 | public float getXAxisValue() {
204 | return xaxisValue;
205 | }
206 |
207 | /**
208 | * Get the value on an Y axis when this event was caused
209 | *
210 | * @return The value on a specified axis, if this event was caused by the y-axis
211 | */
212 | public float getYAxisValue() {
213 | return yaxisValue;
214 | }
215 |
216 | /*
217 | * @see java.lang.Object#toString()
218 | */
219 | public String toString() {
220 | return "["+source+" type="+type+" xaxis="+xaxis+" yaxis="+yaxis+"]";
221 | }
222 | }
223 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/input/Controller.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.input;
33 |
34 | /**
35 | * A game controller of some sort that will provide input. The controller
36 | * presents buttons and axes. Buttons are either pressed or not pressed. Axis
37 | * provide analogue values.
38 | *
39 | * @author Kevin Glass
40 | */
41 | public interface Controller {
42 | /**
43 | * Get the name assigned to this controller.
44 | *
45 | * @return The name assigned to this controller
46 | */
47 | String getName();
48 |
49 | /**
50 | * Get the index of this controller in the collection
51 | *
52 | * @return The index of this controller in the collection
53 | */
54 | int getIndex();
55 |
56 | /**
57 | * Retrieve the number of buttons available on this controller
58 | *
59 | * @return The number of butotns available on this controller
60 | */
61 | int getButtonCount();
62 |
63 | /**
64 | * Get the name of the specified button. Be warned, often this is
65 | * as exciting as "Button X"
66 | *
67 | * @param index The index of the button whose name should be retrieved
68 | * @return The name of the button requested
69 | */
70 | String getButtonName(int index);
71 |
72 | /**
73 | * Check if a button is currently pressed
74 | *
75 | * @param index The button to check
76 | * @return True if the button is currently pressed
77 | */
78 | boolean isButtonPressed(int index);
79 |
80 | /**
81 | * Poll the controller for new data. This will also update
82 | * events
83 | */
84 | void poll();
85 |
86 | /**
87 | * Get the X-Axis value of the POV on this controller
88 | *
89 | * @return The X-Axis value of the POV on this controller
90 | */
91 | float getPovX();
92 |
93 | /**
94 | * Get the Y-Axis value of the POV on this controller
95 | *
96 | * @return The Y-Axis value of the POV on this controller
97 | */
98 | float getPovY();
99 |
100 | /**
101 | * Get the dead zone for a specified axis
102 | *
103 | * @param index The index of the axis for which to retrieve the dead zone
104 | * @return The dead zone for the specified axis
105 | */
106 | float getDeadZone(int index);
107 |
108 | /**
109 | * Set the dead zone for the specified axis
110 | *
111 | * @param index The index of hte axis for which to set the dead zone
112 | * @param zone The dead zone to use for the specified axis
113 | */
114 | void setDeadZone(int index,float zone);
115 |
116 | /**
117 | * Retrieve the number of axes available on this controller.
118 | *
119 | * @return The number of axes available on this controller.
120 | */
121 | int getAxisCount();
122 |
123 | /**
124 | * Get the name that's given to the specified axis
125 | *
126 | * @param index The index of the axis whose name should be retrieved
127 | * @return The name of the specified axis.
128 | */
129 | String getAxisName(int index);
130 |
131 | /**
132 | * Retrieve the value thats currently available on a specified axis. The
133 | * value will always be between 1.0 and -1.0 and will calibrate as values
134 | * are passed read. It may be useful to get the player to wiggle the joystick
135 | * from side to side to get the calibration right.
136 | *
137 | * @param index The index of axis to be read
138 | * @return The value from the specified axis.
139 | */
140 | float getAxisValue(int index);
141 |
142 | /**
143 | * Get the value from the X axis if there is one. If no X axis is
144 | * defined a zero value will be returned.
145 | *
146 | * @return The value from the X axis
147 | */
148 | float getXAxisValue();
149 |
150 | /**
151 | * Get the dead zone for the X axis.
152 | *
153 | * @return The dead zone for the X axis
154 | */
155 | float getXAxisDeadZone();
156 |
157 | /**
158 | * Set the dead zone for the X axis
159 | *
160 | * @param zone The dead zone to use for the X axis
161 | */
162 | void setXAxisDeadZone(float zone);
163 |
164 | /**
165 | * Get the value from the Y axis if there is one. If no Y axis is
166 | * defined a zero value will be returned.
167 | *
168 | * @return The value from the Y axis
169 | */
170 | float getYAxisValue();
171 |
172 | /**
173 | * Get the dead zone for the Y axis.
174 | *
175 | * @return The dead zone for the Y axis
176 | */
177 | float getYAxisDeadZone();
178 |
179 | /**
180 | * Set the dead zone for the Y axis
181 | *
182 | * @param zone The dead zone to use for the Y axis
183 | */
184 | void setYAxisDeadZone(float zone);
185 |
186 | /**
187 | * Get the value from the Z axis if there is one. If no Z axis is
188 | * defined a zero value will be returned.
189 | *
190 | * @return The value from the Z axis
191 | */
192 | float getZAxisValue();
193 |
194 | /**
195 | * Get the dead zone for the Z axis.
196 | *
197 | * @return The dead zone for the Z axis
198 | */
199 | float getZAxisDeadZone();
200 |
201 | /**
202 | * Set the dead zone for the Z axis
203 | *
204 | * @param zone The dead zone to use for the Z axis
205 | */
206 | void setZAxisDeadZone(float zone);
207 |
208 | /**
209 | * Get the value from the RX axis if there is one. If no RX axis is
210 | * defined a zero value will be returned.
211 | *
212 | * @return The value from the RX axis
213 | */
214 | float getRXAxisValue();
215 |
216 | /**
217 | * Get the dead zone for the RX axis.
218 | *
219 | * @return The dead zone for the RX axis
220 | */
221 | float getRXAxisDeadZone();
222 |
223 | /**
224 | * Set the dead zone for the RX axis
225 | *
226 | * @param zone The dead zone to use for the RX axis
227 | */
228 | void setRXAxisDeadZone(float zone);
229 |
230 | /**
231 | * Get the value from the RY axis if there is one. If no RY axis is
232 | * defined a zero value will be returned.
233 | *
234 | * @return The value from the RY axis
235 | */
236 | float getRYAxisValue();
237 |
238 | /**
239 | * Get the dead zone for the RY axis.
240 | *
241 | * @return The dead zone for the RY axis
242 | */
243 | float getRYAxisDeadZone();
244 |
245 | /**
246 | * Set the dead zone for the RY axis
247 | *
248 | * @param zone The dead zone to use for the RY axis
249 | */
250 | void setRYAxisDeadZone(float zone);
251 |
252 | /**
253 | * Get the value from the RZ axis if there is one. If no RZ axis is
254 | * defined a zero value will be returned.
255 | *
256 | * @return The value from the RZ axis
257 | */
258 | float getRZAxisValue();
259 |
260 | /**
261 | * Get the dead zone for the RZ axis.
262 | *
263 | * @return The dead zone for the RZ axis
264 | */
265 | float getRZAxisDeadZone();
266 |
267 | /**
268 | * Set the dead zone for the RZ axis
269 | *
270 | * @param zone The dead zone to use for the RZ axis
271 | */
272 | void setRZAxisDeadZone(float zone);
273 |
274 |
275 | /** Returns the number of rumblers this controller supports */
276 | int getRumblerCount();
277 |
278 | /** Returns the name of the specified rumbler
279 | *
280 | * @param index The rumbler index
281 | */
282 | String getRumblerName(int index);
283 |
284 | /** Sets the vibration strength of the specified rumbler
285 | *
286 | * @param index The index of the rumbler
287 | * @param strength The strength to vibrate at
288 | */
289 | void setRumblerStrength(int index, float strength);
290 | }
291 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/util/vector/Vector2f.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.util.vector;
33 |
34 | import java.io.Serializable;
35 | import java.nio.FloatBuffer;
36 |
37 | /**
38 | *
39 | * Holds a 2-tuple vector.
40 | *
41 | * @author cix_foo
42 | * @version $Revision$
43 | * $Id$
44 | */
45 |
46 | public class Vector2f extends Vector implements Serializable, ReadableVector2f, WritableVector2f {
47 |
48 | private static final long serialVersionUID = 1L;
49 |
50 | public float x, y;
51 |
52 | /**
53 | * Constructor for Vector2f.
54 | */
55 | public Vector2f() {
56 | super();
57 | }
58 |
59 | /**
60 | * Constructor.
61 | */
62 | public Vector2f(ReadableVector2f src) {
63 | set(src);
64 | }
65 |
66 | /**
67 | * Constructor.
68 | */
69 | public Vector2f(float x, float y) {
70 | set(x, y);
71 | }
72 |
73 | /* (non-Javadoc)
74 | * @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
75 | */
76 | public void set(float x, float y) {
77 | this.x = x;
78 | this.y = y;
79 | }
80 |
81 | /**
82 | * Load from another Vector2f
83 | * @param src The source vector
84 | * @return this
85 | */
86 | public Vector2f set(ReadableVector2f src) {
87 | x = src.getX();
88 | y = src.getY();
89 | return this;
90 | }
91 |
92 | /**
93 | * @return the length squared of the vector
94 | */
95 | public float lengthSquared() {
96 | return x * x + y * y;
97 | }
98 |
99 | /**
100 | * Translate a vector
101 | * @param x The translation in x
102 | * @param y the translation in y
103 | * @return this
104 | */
105 | public Vector2f translate(float x, float y) {
106 | this.x += x;
107 | this.y += y;
108 | return this;
109 | }
110 |
111 | /**
112 | * Negate a vector
113 | * @return this
114 | */
115 | public Vector negate() {
116 | x = -x;
117 | y = -y;
118 | return this;
119 | }
120 |
121 | /**
122 | * Negate a vector and place the result in a destination vector.
123 | * @param dest The destination vector or null if a new vector is to be created
124 | * @return the negated vector
125 | */
126 | public Vector2f negate(Vector2f dest) {
127 | if (dest == null)
128 | dest = new Vector2f();
129 | dest.x = -x;
130 | dest.y = -y;
131 | return dest;
132 | }
133 |
134 |
135 | /**
136 | * Normalise this vector and place the result in another vector.
137 | * @param dest The destination vector, or null if a new vector is to be created
138 | * @return the normalised vector
139 | */
140 | public Vector2f normalise(Vector2f dest) {
141 | float l = length();
142 |
143 | if (dest == null)
144 | dest = new Vector2f(x / l, y / l);
145 | else
146 | dest.set(x / l, y / l);
147 |
148 | return dest;
149 | }
150 |
151 | /**
152 | * The dot product of two vectors is calculated as
153 | * v1.x * v2.x + v1.y * v2.y + v1.z * v2.z
154 | * @param left The LHS vector
155 | * @param right The RHS vector
156 | * @return left dot right
157 | */
158 | public static float dot(Vector2f left, Vector2f right) {
159 | return left.x * right.x + left.y * right.y;
160 | }
161 |
162 |
163 |
164 | /**
165 | * Calculate the angle between two vectors, in radians
166 | * @param a A vector
167 | * @param b The other vector
168 | * @return the angle between the two vectors, in radians
169 | */
170 | public static float angle(Vector2f a, Vector2f b) {
171 | float dls = dot(a, b) / (a.length() * b.length());
172 | if (dls < -1f)
173 | dls = -1f;
174 | else if (dls > 1.0f)
175 | dls = 1.0f;
176 | return (float)Math.acos(dls);
177 | }
178 |
179 | /**
180 | * Add a vector to another vector and place the result in a destination
181 | * vector.
182 | * @param left The LHS vector
183 | * @param right The RHS vector
184 | * @param dest The destination vector, or null if a new vector is to be created
185 | * @return the sum of left and right in dest
186 | */
187 | public static Vector2f add(Vector2f left, Vector2f right, Vector2f dest) {
188 | if (dest == null)
189 | return new Vector2f(left.x + right.x, left.y + right.y);
190 | else {
191 | dest.set(left.x + right.x, left.y + right.y);
192 | return dest;
193 | }
194 | }
195 |
196 | /**
197 | * Subtract a vector from another vector and place the result in a destination
198 | * vector.
199 | * @param left The LHS vector
200 | * @param right The RHS vector
201 | * @param dest The destination vector, or null if a new vector is to be created
202 | * @return left minus right in dest
203 | */
204 | public static Vector2f sub(Vector2f left, Vector2f right, Vector2f dest) {
205 | if (dest == null)
206 | return new Vector2f(left.x - right.x, left.y - right.y);
207 | else {
208 | dest.set(left.x - right.x, left.y - right.y);
209 | return dest;
210 | }
211 | }
212 |
213 | /**
214 | * Store this vector in a FloatBuffer
215 | * @param buf The buffer to store it in, at the current position
216 | * @return this
217 | */
218 | public Vector store(FloatBuffer buf) {
219 | buf.put(x);
220 | buf.put(y);
221 | return this;
222 | }
223 |
224 | /**
225 | * Load this vector from a FloatBuffer
226 | * @param buf The buffer to load it from, at the current position
227 | * @return this
228 | */
229 | public Vector load(FloatBuffer buf) {
230 | x = buf.get();
231 | y = buf.get();
232 | return this;
233 | }
234 |
235 | /* (non-Javadoc)
236 | * @see org.lwjgl.vector.Vector#scale(float)
237 | */
238 | public Vector scale(float scale) {
239 |
240 | x *= scale;
241 | y *= scale;
242 |
243 | return this;
244 | }
245 |
246 | /* (non-Javadoc)
247 | * @see java.lang.Object#toString()
248 | */
249 | public String toString() {
250 | StringBuilder sb = new StringBuilder(64);
251 |
252 | sb.append("Vector2f[");
253 | sb.append(x);
254 | sb.append(", ");
255 | sb.append(y);
256 | sb.append(']');
257 | return sb.toString();
258 | }
259 |
260 | /**
261 | * @return x
262 | */
263 | public final float getX() {
264 | return x;
265 | }
266 |
267 | /**
268 | * @return y
269 | */
270 | public final float getY() {
271 | return y;
272 | }
273 |
274 | /**
275 | * Set X
276 | * @param x
277 | */
278 | public final void setX(float x) {
279 | this.x = x;
280 | }
281 |
282 | /**
283 | * Set Y
284 | * @param y
285 | */
286 | public final void setY(float y) {
287 | this.y = y;
288 | }
289 |
290 | public boolean equals(Object obj) {
291 | if (this == obj) return true;
292 | if (obj == null) return false;
293 | if (getClass() != obj.getClass()) return false;
294 | Vector2f other = (Vector2f)obj;
295 |
296 | if (x == other.x && y == other.y) return true;
297 |
298 | return false;
299 | }
300 |
301 | }
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/util/glu/Util.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.util.glu;
33 |
34 | import static org.lwjgl.opengl.ARBImaging.GL_TABLE_TOO_LARGE;
35 | import static org.lwjgl.opengl.GL11.GL_ALPHA;
36 | import static org.lwjgl.opengl.GL11.GL_BITMAP;
37 | import static org.lwjgl.opengl.GL11.GL_BLUE;
38 | import static org.lwjgl.opengl.GL11.GL_BYTE;
39 | import static org.lwjgl.opengl.GL11.GL_COLOR_INDEX;
40 | import static org.lwjgl.opengl.GL11.GL_DEPTH_COMPONENT;
41 | import static org.lwjgl.opengl.GL11.GL_FLOAT;
42 | import static org.lwjgl.opengl.GL11.GL_GREEN;
43 | import static org.lwjgl.opengl.GL11.GL_INT;
44 | import static org.lwjgl.opengl.GL11.GL_INVALID_ENUM;
45 | import static org.lwjgl.opengl.GL11.GL_INVALID_OPERATION;
46 | import static org.lwjgl.opengl.GL11.GL_INVALID_VALUE;
47 | import static org.lwjgl.opengl.GL11.GL_LUMINANCE;
48 | import static org.lwjgl.opengl.GL11.GL_LUMINANCE_ALPHA;
49 | import static org.lwjgl.opengl.GL11.GL_NO_ERROR;
50 | import static org.lwjgl.opengl.GL11.GL_OUT_OF_MEMORY;
51 | import static org.lwjgl.opengl.GL11.GL_RED;
52 | import static org.lwjgl.opengl.GL11.GL_RGB;
53 | import static org.lwjgl.opengl.GL11.GL_RGBA;
54 | import static org.lwjgl.opengl.GL11.GL_SHORT;
55 | import static org.lwjgl.opengl.GL11.GL_STACK_OVERFLOW;
56 | import static org.lwjgl.opengl.GL11.GL_STACK_UNDERFLOW;
57 | import static org.lwjgl.opengl.GL11.GL_STENCIL_INDEX;
58 | import static org.lwjgl.opengl.GL11.GL_UNSIGNED_BYTE;
59 | import static org.lwjgl.opengl.GL11.GL_UNSIGNED_INT;
60 | import static org.lwjgl.opengl.GL11.GL_UNSIGNED_SHORT;
61 | import static org.lwjgl.opengl.GL12.GL_BGR;
62 | import static org.lwjgl.opengl.GL12.GL_BGRA;
63 | import static org.lwjgl.opengl.GL30.GL_INVALID_FRAMEBUFFER_OPERATION;
64 |
65 | /**
66 | * Util.java
67 | *
68 | *
69 | * Created 7-jan-2004
70 | *
71 | * @author Erik Duijs
72 | */
73 | public class Util {
74 |
75 | /**
76 | * Return ceiling of integer division
77 | *
78 | * @param a
79 | * @param b
80 | *
81 | * @return int
82 | */
83 | protected static int ceil(int a, int b) {
84 | return (a % b == 0 ? a / b : a / b + 1);
85 | }
86 |
87 | /**
88 | * Normalize vector
89 | *
90 | * @param v
91 | *
92 | * @return float[]
93 | */
94 | protected static float[] normalize(float[] v) {
95 | float r;
96 |
97 | r = (float)Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
98 | if ( r == 0.0 )
99 | return v;
100 |
101 | r = 1.0f / r;
102 |
103 | v[0] *= r;
104 | v[1] *= r;
105 | v[2] *= r;
106 |
107 | return v;
108 | }
109 |
110 | /**
111 | * Calculate cross-product
112 | *
113 | * @param v1
114 | * @param v2
115 | * @param result
116 | */
117 | protected static void cross(float[] v1, float[] v2, float[] result) {
118 | result[0] = v1[1] * v2[2] - v1[2] * v2[1];
119 | result[1] = v1[2] * v2[0] - v1[0] * v2[2];
120 | result[2] = v1[0] * v2[1] - v1[1] * v2[0];
121 | }
122 |
123 | /**
124 | * Method compPerPix.
125 | *
126 | * @param format
127 | *
128 | * @return int
129 | */
130 | protected static int compPerPix(int format) {
131 | /* Determine number of components per pixel */
132 | switch ( format ) {
133 | case GL_COLOR_INDEX:
134 | case GL_STENCIL_INDEX:
135 | case GL_DEPTH_COMPONENT:
136 | case GL_RED:
137 | case GL_GREEN:
138 | case GL_BLUE:
139 | case GL_ALPHA:
140 | case GL_LUMINANCE:
141 | return 1;
142 | case GL_LUMINANCE_ALPHA:
143 | return 2;
144 | case GL_RGB:
145 | case GL_BGR:
146 | return 3;
147 | case GL_RGBA:
148 | case GL_BGRA:
149 | return 4;
150 | default :
151 | return -1;
152 | }
153 | }
154 |
155 | /**
156 | * Method nearestPower.
157 | *
158 | * Compute the nearest power of 2 number. This algorithm is a little strange, but it works quite well.
159 | *
160 | * @param value
161 | *
162 | * @return int
163 | */
164 | protected static int nearestPower(int value) {
165 | int i;
166 |
167 | i = 1;
168 |
169 | /* Error! */
170 | if ( value == 0 )
171 | return -1;
172 |
173 | for ( ; ; ) {
174 | if ( value == 1 ) {
175 | return i;
176 | } else if ( value == 3 ) {
177 | return i << 2;
178 | }
179 | value >>= 1;
180 | i <<= 1;
181 | }
182 | }
183 |
184 | /**
185 | * Method bytesPerPixel.
186 | *
187 | * @param format
188 | * @param type
189 | *
190 | * @return int
191 | */
192 | protected static int bytesPerPixel(int format, int type) {
193 | int n, m;
194 |
195 | switch ( format ) {
196 | case GL_COLOR_INDEX:
197 | case GL_STENCIL_INDEX:
198 | case GL_DEPTH_COMPONENT:
199 | case GL_RED:
200 | case GL_GREEN:
201 | case GL_BLUE:
202 | case GL_ALPHA:
203 | case GL_LUMINANCE:
204 | n = 1;
205 | break;
206 | case GL_LUMINANCE_ALPHA:
207 | n = 2;
208 | break;
209 | case GL_RGB:
210 | case GL_BGR:
211 | n = 3;
212 | break;
213 | case GL_RGBA:
214 | case GL_BGRA:
215 | n = 4;
216 | break;
217 | default :
218 | n = 0;
219 | }
220 |
221 | switch ( type ) {
222 | case GL_UNSIGNED_BYTE:
223 | m = 1;
224 | break;
225 | case GL_BYTE:
226 | m = 1;
227 | break;
228 | case GL_BITMAP:
229 | m = 1;
230 | break;
231 | case GL_UNSIGNED_SHORT:
232 | m = 2;
233 | break;
234 | case GL_SHORT:
235 | m = 2;
236 | break;
237 | case GL_UNSIGNED_INT:
238 | m = 4;
239 | break;
240 | case GL_INT:
241 | m = 4;
242 | break;
243 | case GL_FLOAT:
244 | m = 4;
245 | break;
246 | default :
247 | m = 0;
248 | }
249 |
250 | return n * m;
251 | }
252 | public static String translateGLErrorString(int error_code) {
253 | switch (error_code) {
254 | case GL_NO_ERROR:
255 | return "No error";
256 | case GL_INVALID_ENUM:
257 | return "Invalid enum";
258 | case GL_INVALID_VALUE:
259 | return "Invalid value";
260 | case GL_INVALID_OPERATION:
261 | return "Invalid operation";
262 | case GL_STACK_OVERFLOW:
263 | return "Stack overflow";
264 | case GL_STACK_UNDERFLOW:
265 | return "Stack underflow";
266 | case GL_OUT_OF_MEMORY:
267 | return "Out of memory";
268 | case GL_TABLE_TOO_LARGE:
269 | return "Table too large";
270 | case GL_INVALID_FRAMEBUFFER_OPERATION:
271 | return "Invalid framebuffer operation";
272 | default:
273 | return null;
274 | }
275 | }
276 | }
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/input/Controllers.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.input;
33 |
34 | import java.util.ArrayList;
35 |
36 | import net.java.games.input.ControllerEnvironment;
37 |
38 | import org.lwjgl.LWJGLException;
39 |
40 | /**
41 | * The collection of controllers currently connected.
42 | *
43 | * @author Kevin Glass
44 | */
45 | public class Controllers {
46 | /** The controllers available */
47 | private static ArrayList controllers = new ArrayList();
48 | /** The number of controllers */
49 | private static int controllerCount;
50 |
51 | /** The current list of events */
52 | private static ArrayList events = new ArrayList();
53 | /** The current event */
54 | private static ControllerEvent event;
55 |
56 | /** Whether controllers were created */
57 | private static boolean created;
58 |
59 | /**
60 | * Initialise the controllers collection
61 | *
62 | * @throws LWJGLException Indicates a failure to initialise the controller library.
63 | */
64 | public static void create() throws LWJGLException {
65 | if (created)
66 | return;
67 |
68 | try {
69 | ControllerEnvironment env = ControllerEnvironment.getDefaultEnvironment();
70 |
71 | net.java.games.input.Controller[] found = env.getControllers();
72 | ArrayList lollers = new ArrayList();
73 | for ( net.java.games.input.Controller c : found ) {
74 | if ( (!c.getType().equals(net.java.games.input.Controller.Type.KEYBOARD)) &&
75 | (!c.getType().equals(net.java.games.input.Controller.Type.MOUSE)) ) {
76 | lollers.add(c);
77 | }
78 | }
79 |
80 | for ( net.java.games.input.Controller c : lollers ) {
81 | createController(c);
82 | }
83 |
84 | created = true;
85 | } catch (Throwable e) {
86 | throw new LWJGLException("Failed to initialise controllers",e);
87 | }
88 | }
89 |
90 | /**
91 | * Utility to create a controller based on its potential sub-controllers
92 | *
93 | * @param c The controller to add
94 | */
95 | private static void createController(net.java.games.input.Controller c) {
96 | net.java.games.input.Controller[] subControllers = c.getControllers();
97 | if (subControllers.length == 0) {
98 | JInputController controller = new JInputController(controllerCount,c);
99 |
100 | controllers.add(controller);
101 | controllerCount++;
102 | } else {
103 | for ( net.java.games.input.Controller sub : subControllers ) {
104 | createController(sub);
105 | }
106 | }
107 | }
108 |
109 | /**
110 | * Get a controller from the collection
111 | *
112 | * @param index The index of the controller to retrieve
113 | * @return The controller requested
114 | */
115 | public static Controller getController(int index) {
116 | return controllers.get(index);
117 | }
118 |
119 | /**
120 | * Retrieve a count of the number of controllers
121 | *
122 | * @return The number of controllers available
123 | */
124 | public static int getControllerCount() {
125 | return controllers.size();
126 | }
127 |
128 | /**
129 | * Poll the controllers available. This will both update their state
130 | * and generate events that must be cleared.
131 | */
132 | public static void poll() {
133 | for (int i=0;i '}
77 | case $link in #(
78 | /*) app_path=$link ;; #(
79 | *) app_path=$APP_HOME$link ;;
80 | esac
81 | done
82 |
83 | # This is normally unused
84 | # shellcheck disable=SC2034
85 | APP_BASE_NAME=${0##*/}
86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
88 |
89 | # Use the maximum available, or set MAX_FD != -1 to use that value.
90 | MAX_FD=maximum
91 |
92 | warn () {
93 | echo "$*"
94 | } >&2
95 |
96 | die () {
97 | echo
98 | echo "$*"
99 | echo
100 | exit 1
101 | } >&2
102 |
103 | # OS specific support (must be 'true' or 'false').
104 | cygwin=false
105 | msys=false
106 | darwin=false
107 | nonstop=false
108 | case "$( uname )" in #(
109 | CYGWIN* ) cygwin=true ;; #(
110 | Darwin* ) darwin=true ;; #(
111 | MSYS* | MINGW* ) msys=true ;; #(
112 | NONSTOP* ) nonstop=true ;;
113 | esac
114 |
115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
116 |
117 |
118 | # Determine the Java command to use to start the JVM.
119 | if [ -n "$JAVA_HOME" ] ; then
120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
121 | # IBM's JDK on AIX uses strange locations for the executables
122 | JAVACMD=$JAVA_HOME/jre/sh/java
123 | else
124 | JAVACMD=$JAVA_HOME/bin/java
125 | fi
126 | if [ ! -x "$JAVACMD" ] ; then
127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
128 |
129 | Please set the JAVA_HOME variable in your environment to match the
130 | location of your Java installation."
131 | fi
132 | else
133 | JAVACMD=java
134 | if ! command -v java >/dev/null 2>&1
135 | then
136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137 |
138 | Please set the JAVA_HOME variable in your environment to match the
139 | location of your Java installation."
140 | fi
141 | fi
142 |
143 | # Increase the maximum file descriptors if we can.
144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
145 | case $MAX_FD in #(
146 | max*)
147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
148 | # shellcheck disable=SC2039,SC3045
149 | MAX_FD=$( ulimit -H -n ) ||
150 | warn "Could not query maximum file descriptor limit"
151 | esac
152 | case $MAX_FD in #(
153 | '' | soft) :;; #(
154 | *)
155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
156 | # shellcheck disable=SC2039,SC3045
157 | ulimit -n "$MAX_FD" ||
158 | warn "Could not set maximum file descriptor limit to $MAX_FD"
159 | esac
160 | fi
161 |
162 | # Collect all arguments for the java command, stacking in reverse order:
163 | # * args from the command line
164 | # * the main class name
165 | # * -classpath
166 | # * -D...appname settings
167 | # * --module-path (only if needed)
168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
169 |
170 | # For Cygwin or MSYS, switch paths to Windows format before running java
171 | if "$cygwin" || "$msys" ; then
172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
174 |
175 | JAVACMD=$( cygpath --unix "$JAVACMD" )
176 |
177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
178 | for arg do
179 | if
180 | case $arg in #(
181 | -*) false ;; # don't mess with options #(
182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
183 | [ -e "$t" ] ;; #(
184 | *) false ;;
185 | esac
186 | then
187 | arg=$( cygpath --path --ignore --mixed "$arg" )
188 | fi
189 | # Roll the args list around exactly as many times as the number of
190 | # args, so each arg winds up back in the position where it started, but
191 | # possibly modified.
192 | #
193 | # NB: a `for` loop captures its iteration list before it begins, so
194 | # changing the positional parameters here affects neither the number of
195 | # iterations, nor the values presented in `arg`.
196 | shift # remove old arg
197 | set -- "$@" "$arg" # push replacement arg
198 | done
199 | fi
200 |
201 |
202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
204 |
205 | # Collect all arguments for the java command:
206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
207 | # and any embedded shellness will be escaped.
208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
209 | # treated as '${Hostname}' itself on the command line.
210 |
211 | set -- \
212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
213 | -classpath "$CLASSPATH" \
214 | org.gradle.wrapper.GradleWrapperMain \
215 | "$@"
216 |
217 | # Stop when "xargs" is not available.
218 | if ! command -v xargs >/dev/null 2>&1
219 | then
220 | die "xargs is not available"
221 | fi
222 |
223 | # Use "xargs" to parse quoted args.
224 | #
225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
226 | #
227 | # In Bash we could simply go:
228 | #
229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
230 | # set -- "${ARGS[@]}" "$@"
231 | #
232 | # but POSIX shell has neither arrays nor command substitution, so instead we
233 | # post-process each arg (as a line of input to sed) to backslash-escape any
234 | # character that might be a shell metacharacter, then use eval to reverse
235 | # that process (while maintaining the separation between arguments), and wrap
236 | # the whole thing up as a single "set" statement.
237 | #
238 | # This will of course break if any of these variables contains a newline or
239 | # an unmatched quote.
240 | #
241 |
242 | eval "set -- $(
243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
244 | xargs -n1 |
245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
246 | tr '\n' ' '
247 | )" '"$@"'
248 |
249 | exec "$JAVACMD" "$@"
250 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/util/vector/Vector4f.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.util.vector;
33 |
34 | import java.nio.FloatBuffer;
35 |
36 |
37 | /**
38 | *
39 | * Holds a 4-tuple vector.
40 | *
41 | * @author cix_foo
42 | * @version $Revision$
43 | * $Id$
44 | */
45 |
46 | public class Vector4f extends Vector implements ReadableVector4f, WritableVector4f {
47 |
48 | private static final long serialVersionUID = 1L;
49 |
50 | public float x, y, z, w;
51 |
52 | /**
53 | * Constructor for Vector4f.
54 | */
55 | public Vector4f() {
56 | super();
57 | }
58 |
59 | /**
60 | * Constructor
61 | */
62 | public Vector4f(ReadableVector4f src) {
63 | set(src);
64 | }
65 |
66 | /**
67 | * Constructor
68 | */
69 | public Vector4f(float x, float y, float z, float w) {
70 | set(x, y, z, w);
71 | }
72 |
73 | /* (non-Javadoc)
74 | * @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
75 | */
76 | public void set(float x, float y) {
77 | this.x = x;
78 | this.y = y;
79 | }
80 |
81 | /* (non-Javadoc)
82 | * @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float)
83 | */
84 | public void set(float x, float y, float z) {
85 | this.x = x;
86 | this.y = y;
87 | this.z = z;
88 | }
89 |
90 | /* (non-Javadoc)
91 | * @see org.lwjgl.util.vector.WritableVector4f#set(float, float, float, float)
92 | */
93 | public void set(float x, float y, float z, float w) {
94 | this.x = x;
95 | this.y = y;
96 | this.z = z;
97 | this.w = w;
98 | }
99 |
100 | /**
101 | * Load from another Vector4f
102 | * @param src The source vector
103 | * @return this
104 | */
105 | public Vector4f set(ReadableVector4f src) {
106 | x = src.getX();
107 | y = src.getY();
108 | z = src.getZ();
109 | w = src.getW();
110 | return this;
111 | }
112 |
113 | /**
114 | * @return the length squared of the vector
115 | */
116 | public float lengthSquared() {
117 | return x * x + y * y + z * z + w * w;
118 | }
119 |
120 | /**
121 | * Translate a vector
122 | * @param x The translation in x
123 | * @param y the translation in y
124 | * @return this
125 | */
126 | public Vector4f translate(float x, float y, float z, float w) {
127 | this.x += x;
128 | this.y += y;
129 | this.z += z;
130 | this.w += w;
131 | return this;
132 | }
133 |
134 | /**
135 | * Add a vector to another vector and place the result in a destination
136 | * vector.
137 | * @param left The LHS vector
138 | * @param right The RHS vector
139 | * @param dest The destination vector, or null if a new vector is to be created
140 | * @return the sum of left and right in dest
141 | */
142 | public static Vector4f add(Vector4f left, Vector4f right, Vector4f dest) {
143 | if (dest == null)
144 | return new Vector4f(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
145 | else {
146 | dest.set(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
147 | return dest;
148 | }
149 | }
150 |
151 | /**
152 | * Subtract a vector from another vector and place the result in a destination
153 | * vector.
154 | * @param left The LHS vector
155 | * @param right The RHS vector
156 | * @param dest The destination vector, or null if a new vector is to be created
157 | * @return left minus right in dest
158 | */
159 | public static Vector4f sub(Vector4f left, Vector4f right, Vector4f dest) {
160 | if (dest == null)
161 | return new Vector4f(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
162 | else {
163 | dest.set(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
164 | return dest;
165 | }
166 | }
167 |
168 |
169 | /**
170 | * Negate a vector
171 | * @return this
172 | */
173 | public Vector negate() {
174 | x = -x;
175 | y = -y;
176 | z = -z;
177 | w = -w;
178 | return this;
179 | }
180 |
181 | /**
182 | * Negate a vector and place the result in a destination vector.
183 | * @param dest The destination vector or null if a new vector is to be created
184 | * @return the negated vector
185 | */
186 | public Vector4f negate(Vector4f dest) {
187 | if (dest == null)
188 | dest = new Vector4f();
189 | dest.x = -x;
190 | dest.y = -y;
191 | dest.z = -z;
192 | dest.w = -w;
193 | return dest;
194 | }
195 |
196 |
197 | /**
198 | * Normalise this vector and place the result in another vector.
199 | * @param dest The destination vector, or null if a new vector is to be created
200 | * @return the normalised vector
201 | */
202 | public Vector4f normalise(Vector4f dest) {
203 | float l = length();
204 |
205 | if (dest == null)
206 | dest = new Vector4f(x / l, y / l, z / l, w / l);
207 | else
208 | dest.set(x / l, y / l, z / l, w / l);
209 |
210 | return dest;
211 | }
212 |
213 | /**
214 | * The dot product of two vectors is calculated as
215 | * v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w
216 | * @param left The LHS vector
217 | * @param right The RHS vector
218 | * @return left dot right
219 | */
220 | public static float dot(Vector4f left, Vector4f right) {
221 | return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w;
222 | }
223 |
224 | /**
225 | * Calculate the angle between two vectors, in radians
226 | * @param a A vector
227 | * @param b The other vector
228 | * @return the angle between the two vectors, in radians
229 | */
230 | public static float angle(Vector4f a, Vector4f b) {
231 | float dls = dot(a, b) / (a.length() * b.length());
232 | if (dls < -1f)
233 | dls = -1f;
234 | else if (dls > 1.0f)
235 | dls = 1.0f;
236 | return (float)Math.acos(dls);
237 | }
238 |
239 | /* (non-Javadoc)
240 | * @see org.lwjgl.vector.Vector#load(FloatBuffer)
241 | */
242 | public Vector load(FloatBuffer buf) {
243 | x = buf.get();
244 | y = buf.get();
245 | z = buf.get();
246 | w = buf.get();
247 | return this;
248 | }
249 |
250 | /* (non-Javadoc)
251 | * @see org.lwjgl.vector.Vector#scale(float)
252 | */
253 | public Vector scale(float scale) {
254 | x *= scale;
255 | y *= scale;
256 | z *= scale;
257 | w *= scale;
258 | return this;
259 | }
260 |
261 | /* (non-Javadoc)
262 | * @see org.lwjgl.vector.Vector#store(FloatBuffer)
263 | */
264 | public Vector store(FloatBuffer buf) {
265 |
266 | buf.put(x);
267 | buf.put(y);
268 | buf.put(z);
269 | buf.put(w);
270 |
271 | return this;
272 | }
273 |
274 | public String toString() {
275 | return "Vector4f: " + x + " " + y + " " + z + " " + w;
276 | }
277 |
278 | /**
279 | * @return x
280 | */
281 | public final float getX() {
282 | return x;
283 | }
284 |
285 | /**
286 | * @return y
287 | */
288 | public final float getY() {
289 | return y;
290 | }
291 |
292 | /**
293 | * Set X
294 | * @param x
295 | */
296 | public final void setX(float x) {
297 | this.x = x;
298 | }
299 |
300 | /**
301 | * Set Y
302 | * @param y
303 | */
304 | public final void setY(float y) {
305 | this.y = y;
306 | }
307 |
308 | /**
309 | * Set Z
310 | * @param z
311 | */
312 | public void setZ(float z) {
313 | this.z = z;
314 | }
315 |
316 |
317 | /* (Overrides)
318 | * @see org.lwjgl.vector.ReadableVector3f#getZ()
319 | */
320 | public float getZ() {
321 | return z;
322 | }
323 |
324 | /**
325 | * Set W
326 | * @param w
327 | */
328 | public void setW(float w) {
329 | this.w = w;
330 | }
331 |
332 | /* (Overrides)
333 | * @see org.lwjgl.vector.ReadableVector3f#getZ()
334 | */
335 | public float getW() {
336 | return w;
337 | }
338 |
339 | public boolean equals(Object obj) {
340 | if (this == obj) return true;
341 | if (obj == null) return false;
342 | if (getClass() != obj.getClass()) return false;
343 | Vector4f other = (Vector4f)obj;
344 |
345 | if (x == other.x && y == other.y && z == other.z && w == other.w) return true;
346 |
347 | return false;
348 | }
349 | }
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/openal/AL.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright LWJGL. All rights reserved.
3 | * License terms: https://www.lwjgl.org/license
4 | */
5 | package org.lwjgl.openal;
6 |
7 | import static org.lwjgl.openal.AL10.AL_EXTENSIONS;
8 | import static org.lwjgl.openal.AL10.AL_NO_ERROR;
9 | import static org.lwjgl.openal.AL10.AL_VERSION;
10 | import static org.lwjgl.openal.EXTThreadLocalContext.alcGetThreadContext;
11 | import static org.lwjgl.system.APIUtil.apiFilterExtensions;
12 | import static org.lwjgl.system.APIUtil.apiLog;
13 | import static org.lwjgl.system.APIUtil.apiLogMissing;
14 | import static org.lwjgl.system.APIUtil.apiParseVersion;
15 | import static org.lwjgl.system.JNI.invokeI;
16 | import static org.lwjgl.system.JNI.invokeP;
17 | import static org.lwjgl.system.JNI.invokePP;
18 | import static org.lwjgl.system.JNI.invokePZ;
19 | import static org.lwjgl.system.MemoryStack.stackGet;
20 | import static org.lwjgl.system.MemoryUtil.NULL;
21 | import static org.lwjgl.system.MemoryUtil.memASCIISafe;
22 | import static org.lwjgl.system.MemoryUtil.memAddress;
23 |
24 | import java.nio.IntBuffer;
25 | import java.util.HashSet;
26 | import java.util.Set;
27 | import java.util.StringTokenizer;
28 | import java.util.function.IntFunction;
29 |
30 | import javax.annotation.Nullable;
31 |
32 | import org.lwjgl.BufferUtils;
33 | import org.lwjgl.LWJGLException;
34 | import org.lwjgl.PointerBuffer;
35 | import org.lwjgl.system.APIUtil.APIVersion;
36 | import org.lwjgl.system.Checks;
37 | import org.lwjgl.system.Configuration;
38 | import org.lwjgl.system.FunctionProvider;
39 | import org.lwjgl.system.MemoryStack;
40 | import org.lwjgl.system.ThreadLocalUtil;
41 |
42 | public final class AL {
43 |
44 | @Nullable
45 | private static ALCapabilities processCaps;
46 |
47 | private static final ThreadLocal capabilitiesTLS = new ThreadLocal<>();
48 |
49 | private static ICD icd = new ICDStatic();
50 |
51 | private static long _contextPtr;
52 | private static long _devicePtr;
53 | private static boolean _created;
54 |
55 | private AL() {
56 | }
57 |
58 | public static boolean isCreated() {
59 | return _created;
60 | }
61 |
62 | public static void create(String deviceArguments, int contextFrequency, int contextRefresh,
63 | boolean contextSynchronized) throws LWJGLException {
64 | create(deviceArguments, contextFrequency, contextRefresh, contextSynchronized, true);
65 | }
66 |
67 | public static void create(String deviceArguments, int contextFrequency, int contextRefresh,
68 | boolean contextSynchronized, boolean openDevice) throws LWJGLException {
69 | if (_created) {
70 | throw new IllegalStateException("Only one OpenAL context may be instantiated at any one time.");
71 | } else {
72 | init(deviceArguments, contextFrequency, contextRefresh, contextSynchronized, openDevice);
73 | _created = true;
74 | }
75 | }
76 |
77 | private static void init(String deviceArguments, int contextFrequency, int contextRefresh,
78 | boolean contextSynchronized, boolean openDevice) throws LWJGLException {
79 | try {
80 | if (openDevice) {
81 | _devicePtr = ALC10.alcOpenDevice(deviceArguments);
82 | if (_devicePtr == -1L) {
83 | throw new LWJGLException("Could not open ALC device");
84 | }
85 |
86 | ALCCapabilities deviceCaps = ALC.createCapabilities(_devicePtr);
87 | if (contextFrequency == -1) {
88 | _contextPtr = ALC10.alcCreateContext(_devicePtr, (IntBuffer) null);
89 | } else {
90 | MemoryStack stack = MemoryStack.stackPush();
91 | long var8 = _devicePtr;
92 | int var10003 = contextSynchronized ? 1 : 0;
93 | _contextPtr = ALC10.alcCreateContext(var8,
94 | createAttributeList(contextFrequency, contextRefresh, var10003, stack));
95 | stack.close();
96 | }
97 |
98 | ALC10.alcMakeContextCurrent(_contextPtr);
99 | createCapabilities(deviceCaps);
100 | }
101 |
102 | } catch (LWJGLException var7) {
103 | destroy();
104 | throw var7;
105 | }
106 | }
107 |
108 | public static void create() throws LWJGLException {
109 | create(null, 44100, 60, false);
110 | }
111 |
112 | private static final IntBuffer createAttributeList(int contextFrequency, int contextRefresh,
113 | int contextSynchronized, MemoryStack stack) {
114 | IntBuffer buffer = stack.callocInt(7);
115 | buffer.put(0, 4103);
116 | buffer.put(1, contextFrequency);
117 | buffer.put(2, 4104);
118 | buffer.put(3, contextRefresh);
119 | buffer.put(4, 4105);
120 | buffer.put(5, contextSynchronized);
121 | buffer.put(6, 0);
122 | return buffer;
123 | }
124 |
125 | public static void destroy() {
126 | if (_contextPtr != -1L) {
127 | ALC10.alcMakeContextCurrent(0L);
128 | ALC10.alcDestroyContext(_contextPtr);
129 | _contextPtr = -1L;
130 | }
131 |
132 | if (_devicePtr != -1L) {
133 | ALC10.alcCloseDevice(_devicePtr);
134 | _devicePtr = -1L;
135 | }
136 |
137 | _created = false;
138 | al_destroy();
139 | }
140 |
141 | static void init() {
142 | }
143 |
144 | static void al_destroy() {
145 | setCurrentProcess(null);
146 | }
147 |
148 | public static void setCurrentProcess(@Nullable ALCapabilities caps) {
149 | processCaps = caps;
150 | capabilitiesTLS.set(null);
151 | icd.set(caps);
152 | }
153 |
154 | public static void setCurrentThread(@Nullable ALCapabilities caps) {
155 | capabilitiesTLS.set(caps);
156 | icd.set(caps);
157 | }
158 |
159 | public static ALCapabilities getCapabilities() {
160 | ALCapabilities caps = capabilitiesTLS.get();
161 | if (caps == null) {
162 | caps = processCaps;
163 | }
164 |
165 | return checkCapabilities(caps);
166 | }
167 |
168 | private static ALCapabilities checkCapabilities(@Nullable ALCapabilities caps) {
169 | if (caps == null) {
170 | throw new IllegalStateException(
171 | "No ALCapabilities instance set for the current thread or process. Possible solutions:\n"
172 | + "\ta) Call AL.createCapabilities() after making a context current.\n"
173 | + "\tb) Call AL.setCurrentProcess() or AL.setCurrentThread() if an ALCapabilities instance already exists.");
174 | }
175 | return caps;
176 | }
177 |
178 | public static ALCapabilities createCapabilities(ALCCapabilities alcCaps) {
179 | return createCapabilities(alcCaps, null);
180 | }
181 |
182 | public static ALCapabilities createCapabilities(ALCCapabilities alcCaps,
183 | @Nullable IntFunction bufferFactory) {
184 |
185 | long alGetProcAddress = ALC.getFunctionProvider().getFunctionAddress(NULL, "alGetProcAddress");
186 | if (alGetProcAddress == NULL) {
187 | throw new RuntimeException(
188 | "A core AL function is missing. Make sure that the OpenAL library has been loaded correctly.");
189 | }
190 |
191 | FunctionProvider functionProvider = functionName -> {
192 | long address = invokePP(memAddress(functionName), alGetProcAddress);
193 | if (address == NULL && Checks.DEBUG_FUNCTIONS) {
194 | apiLogMissing("AL", functionName);
195 | }
196 | return address;
197 | };
198 |
199 | long GetString = functionProvider.getFunctionAddress("alGetString");
200 | long GetError = functionProvider.getFunctionAddress("alGetError");
201 | long IsExtensionPresent = functionProvider.getFunctionAddress("alIsExtensionPresent");
202 | if (GetString == NULL || GetError == NULL || IsExtensionPresent == NULL) {
203 | throw new IllegalStateException(
204 | "Core OpenAL functions could not be found. Make sure that the OpenAL library has been loaded correctly.");
205 | }
206 |
207 | String versionString = memASCIISafe(invokeP(AL_VERSION, GetString));
208 | if (versionString == null || invokeI(GetError) != AL_NO_ERROR) {
209 | throw new IllegalStateException("There is no OpenAL context current in the current thread or process.");
210 | }
211 |
212 | APIVersion apiVersion = apiParseVersion(versionString);
213 |
214 | int majorVersion = apiVersion.major;
215 | int minorVersion = apiVersion.minor;
216 |
217 | int[][] AL_VERSIONS = { { 0, 1 } };
218 |
219 | Set supportedExtensions = new HashSet<>(32);
220 |
221 | for (int major = 1; major <= AL_VERSIONS.length; major++) {
222 | int[] minors = AL_VERSIONS[major - 1];
223 | for (int minor : minors) {
224 | if (major < majorVersion || (major == majorVersion && minor <= minorVersion)) {
225 | supportedExtensions.add("OpenAL" + major + minor);
226 | }
227 | }
228 | }
229 |
230 | String extensionsString = memASCIISafe(invokeP(AL_EXTENSIONS, GetString));
231 | if (extensionsString != null) {
232 | MemoryStack stack = stackGet();
233 |
234 | StringTokenizer tokenizer = new StringTokenizer(extensionsString);
235 | while (tokenizer.hasMoreTokens()) {
236 | String extName = tokenizer.nextToken();
237 | try (MemoryStack frame = stack.push()) {
238 | if (invokePZ(memAddress(frame.ASCII(extName, true)), IsExtensionPresent)) {
239 | supportedExtensions.add(extName);
240 | }
241 | }
242 | }
243 | }
244 |
245 | if (alcCaps.ALC_EXT_EFX) {
246 | supportedExtensions.add("ALC_EXT_EFX");
247 | }
248 | apiFilterExtensions(supportedExtensions, Configuration.OPENAL_EXTENSION_FILTER);
249 |
250 | ALCapabilities caps = new ALCapabilities(functionProvider, supportedExtensions,
251 | bufferFactory == null ? BufferUtils::createPointerBuffer : bufferFactory);
252 |
253 | if (alcCaps.ALC_EXT_thread_local_context && alcGetThreadContext() != NULL) {
254 | setCurrentThread(caps);
255 | } else {
256 | setCurrentProcess(caps);
257 | }
258 |
259 | return caps;
260 | }
261 |
262 | static ALCapabilities getICD() {
263 | return ALC.check(icd.get());
264 | }
265 |
266 | private interface ICD {
267 | default void set(@Nullable ALCapabilities caps) {
268 | }
269 |
270 | @Nullable
271 | ALCapabilities get();
272 | }
273 |
274 | private static class ICDStatic implements ICD {
275 |
276 | @Nullable
277 | private static ALCapabilities tempCaps;
278 |
279 | @Override
280 | public void set(@Nullable ALCapabilities caps) {
281 | if (tempCaps == null) {
282 | tempCaps = caps;
283 | } else if (caps != null && caps != tempCaps
284 | && ThreadLocalUtil.areCapabilitiesDifferent(tempCaps.addresses, caps.addresses)) {
285 | apiLog("[WARNING] Incompatible context detected. Falling back to thread/process lookup for AL contexts.");
286 | icd = AL::getCapabilities;
287 | }
288 | }
289 |
290 | @Override
291 | public ALCapabilities get() {
292 | return WriteOnce.caps;
293 | }
294 |
295 | private static final class WriteOnce {
296 |
297 | static final ALCapabilities caps;
298 |
299 | static {
300 | ALCapabilities tempCaps = ICDStatic.tempCaps;
301 | if (tempCaps == null) {
302 | throw new IllegalStateException("No ALCapabilities instance has been set");
303 | }
304 | caps = tempCaps;
305 | }
306 | }
307 |
308 | }
309 |
310 | }
311 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/util/vector/Vector3f.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.util.vector;
33 |
34 | import java.io.Serializable;
35 | import java.nio.FloatBuffer;
36 |
37 | /**
38 | *
39 | * Holds a 3-tuple vector.
40 | *
41 | * @author cix_foo
42 | * @version $Revision$
43 | * $Id$
44 | */
45 |
46 | public class Vector3f extends Vector implements Serializable, ReadableVector3f, WritableVector3f {
47 |
48 | private static final long serialVersionUID = 1L;
49 |
50 | public float x, y, z;
51 |
52 | /**
53 | * Constructor for Vector3f.
54 | */
55 | public Vector3f() {
56 | super();
57 | }
58 |
59 | /**
60 | * Constructor
61 | */
62 | public Vector3f(ReadableVector3f src) {
63 | set(src);
64 | }
65 |
66 | /**
67 | * Constructor
68 | */
69 | public Vector3f(float x, float y, float z) {
70 | set(x, y, z);
71 | }
72 |
73 | /* (non-Javadoc)
74 | * @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
75 | */
76 | public void set(float x, float y) {
77 | this.x = x;
78 | this.y = y;
79 | }
80 |
81 | /* (non-Javadoc)
82 | * @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float)
83 | */
84 | public void set(float x, float y, float z) {
85 | this.x = x;
86 | this.y = y;
87 | this.z = z;
88 | }
89 |
90 | /**
91 | * Load from another Vector3f
92 | * @param src The source vector
93 | * @return this
94 | */
95 | public Vector3f set(ReadableVector3f src) {
96 | x = src.getX();
97 | y = src.getY();
98 | z = src.getZ();
99 | return this;
100 | }
101 |
102 | /**
103 | * @return the length squared of the vector
104 | */
105 | public float lengthSquared() {
106 | return x * x + y * y + z * z;
107 | }
108 |
109 | /**
110 | * Translate a vector
111 | * @param x The translation in x
112 | * @param y the translation in y
113 | * @return this
114 | */
115 | public Vector3f translate(float x, float y, float z) {
116 | this.x += x;
117 | this.y += y;
118 | this.z += z;
119 | return this;
120 | }
121 |
122 | /**
123 | * Add a vector to another vector and place the result in a destination
124 | * vector.
125 | * @param left The LHS vector
126 | * @param right The RHS vector
127 | * @param dest The destination vector, or null if a new vector is to be created
128 | * @return the sum of left and right in dest
129 | */
130 | public static Vector3f add(Vector3f left, Vector3f right, Vector3f dest) {
131 | if (dest == null)
132 | return new Vector3f(left.x + right.x, left.y + right.y, left.z + right.z);
133 | else {
134 | dest.set(left.x + right.x, left.y + right.y, left.z + right.z);
135 | return dest;
136 | }
137 | }
138 |
139 | /**
140 | * Subtract a vector from another vector and place the result in a destination
141 | * vector.
142 | * @param left The LHS vector
143 | * @param right The RHS vector
144 | * @param dest The destination vector, or null if a new vector is to be created
145 | * @return left minus right in dest
146 | */
147 | public static Vector3f sub(Vector3f left, Vector3f right, Vector3f dest) {
148 | if (dest == null)
149 | return new Vector3f(left.x - right.x, left.y - right.y, left.z - right.z);
150 | else {
151 | dest.set(left.x - right.x, left.y - right.y, left.z - right.z);
152 | return dest;
153 | }
154 | }
155 |
156 | /**
157 | * The cross product of two vectors.
158 | *
159 | * @param left The LHS vector
160 | * @param right The RHS vector
161 | * @param dest The destination result, or null if a new vector is to be created
162 | * @return left cross right
163 | */
164 | public static Vector3f cross(
165 | Vector3f left,
166 | Vector3f right,
167 | Vector3f dest)
168 | {
169 |
170 | if (dest == null)
171 | dest = new Vector3f();
172 |
173 | dest.set(
174 | left.y * right.z - left.z * right.y,
175 | right.x * left.z - right.z * left.x,
176 | left.x * right.y - left.y * right.x
177 | );
178 |
179 | return dest;
180 | }
181 |
182 |
183 |
184 | /**
185 | * Negate a vector
186 | * @return this
187 | */
188 | public Vector negate() {
189 | x = -x;
190 | y = -y;
191 | z = -z;
192 | return this;
193 | }
194 |
195 | /**
196 | * Negate a vector and place the result in a destination vector.
197 | * @param dest The destination vector or null if a new vector is to be created
198 | * @return the negated vector
199 | */
200 | public Vector3f negate(Vector3f dest) {
201 | if (dest == null)
202 | dest = new Vector3f();
203 | dest.x = -x;
204 | dest.y = -y;
205 | dest.z = -z;
206 | return dest;
207 | }
208 |
209 |
210 | /**
211 | * Normalise this vector and place the result in another vector.
212 | * @param dest The destination vector, or null if a new vector is to be created
213 | * @return the normalised vector
214 | */
215 | public Vector3f normalise(Vector3f dest) {
216 | float l = length();
217 |
218 | if (dest == null)
219 | dest = new Vector3f(x / l, y / l, z / l);
220 | else
221 | dest.set(x / l, y / l, z / l);
222 |
223 | return dest;
224 | }
225 |
226 | /**
227 | * The dot product of two vectors is calculated as
228 | * v1.x * v2.x + v1.y * v2.y + v1.z * v2.z
229 | * @param left The LHS vector
230 | * @param right The RHS vector
231 | * @return left dot right
232 | */
233 | public static float dot(Vector3f left, Vector3f right) {
234 | return left.x * right.x + left.y * right.y + left.z * right.z;
235 | }
236 |
237 | /**
238 | * Calculate the angle between two vectors, in radians
239 | * @param a A vector
240 | * @param b The other vector
241 | * @return the angle between the two vectors, in radians
242 | */
243 | public static float angle(Vector3f a, Vector3f b) {
244 | float dls = dot(a, b) / (a.length() * b.length());
245 | if (dls < -1f)
246 | dls = -1f;
247 | else if (dls > 1.0f)
248 | dls = 1.0f;
249 | return (float)Math.acos(dls);
250 | }
251 |
252 | /* (non-Javadoc)
253 | * @see org.lwjgl.vector.Vector#load(FloatBuffer)
254 | */
255 | public Vector load(FloatBuffer buf) {
256 | x = buf.get();
257 | y = buf.get();
258 | z = buf.get();
259 | return this;
260 | }
261 |
262 | /* (non-Javadoc)
263 | * @see org.lwjgl.vector.Vector#scale(float)
264 | */
265 | public Vector scale(float scale) {
266 |
267 | x *= scale;
268 | y *= scale;
269 | z *= scale;
270 |
271 | return this;
272 |
273 | }
274 |
275 | /* (non-Javadoc)
276 | * @see org.lwjgl.vector.Vector#store(FloatBuffer)
277 | */
278 | public Vector store(FloatBuffer buf) {
279 |
280 | buf.put(x);
281 | buf.put(y);
282 | buf.put(z);
283 |
284 | return this;
285 | }
286 |
287 | /* (non-Javadoc)
288 | * @see java.lang.Object#toString()
289 | */
290 | public String toString() {
291 | StringBuilder sb = new StringBuilder(64);
292 |
293 | sb.append("Vector3f[");
294 | sb.append(x);
295 | sb.append(", ");
296 | sb.append(y);
297 | sb.append(", ");
298 | sb.append(z);
299 | sb.append(']');
300 | return sb.toString();
301 | }
302 |
303 | /**
304 | * @return x
305 | */
306 | public final float getX() {
307 | return x;
308 | }
309 |
310 | /**
311 | * @return y
312 | */
313 | public final float getY() {
314 | return y;
315 | }
316 |
317 | /**
318 | * Set X
319 | * @param x
320 | */
321 | public final void setX(float x) {
322 | this.x = x;
323 | }
324 |
325 | /**
326 | * Set Y
327 | * @param y
328 | */
329 | public final void setY(float y) {
330 | this.y = y;
331 | }
332 |
333 | /**
334 | * Set Z
335 | * @param z
336 | */
337 | public void setZ(float z) {
338 | this.z = z;
339 | }
340 |
341 | /* (Overrides)
342 | * @see org.lwjgl.vector.ReadableVector3f#getZ()
343 | */
344 | public float getZ() {
345 | return z;
346 | }
347 |
348 | public boolean equals(Object obj) {
349 | if (this == obj) return true;
350 | if (obj == null) return false;
351 | if (getClass() != obj.getClass()) return false;
352 | Vector3f other = (Vector3f)obj;
353 |
354 | if (x == other.x && y == other.y && z == other.z) return true;
355 |
356 | return false;
357 | }
358 | }
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/util/glu/MipMap.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.util.glu;
33 |
34 | import java.nio.ByteBuffer;
35 |
36 | import org.lwjgl.BufferUtils;
37 |
38 | import static org.lwjgl.opengl.GL11.*;
39 | import static org.lwjgl.util.glu.GLU.*;
40 |
41 | /**
42 | * MipMap.java
43 | *
44 | *
45 | * Created 11-jan-2004
46 | * @author Erik Duijs
47 | */
48 | public class MipMap extends Util {
49 |
50 | /**
51 | * Method gluBuild2DMipmaps
52 | *
53 | * @param target
54 | * @param components
55 | * @param width
56 | * @param height
57 | * @param format
58 | * @param type
59 | * @param data
60 | * @return int
61 | */
62 | public static int gluBuild2DMipmaps(final int target,
63 | final int components, final int width, final int height,
64 | final int format, final int type, final ByteBuffer data) {
65 | if ( width < 1 || height < 1 ) return GLU_INVALID_VALUE;
66 |
67 | final int bpp = bytesPerPixel(format, type);
68 | if ( bpp == 0 )
69 | return GLU_INVALID_ENUM;
70 |
71 | final int maxSize = glGetInteger(GL_MAX_TEXTURE_SIZE);
72 |
73 | int w = nearestPower(width);
74 | if ( w > maxSize )
75 | w = maxSize;
76 |
77 | int h = nearestPower(height);
78 | if ( h > maxSize )
79 | h = maxSize;
80 |
81 | // Get current glPixelStore state
82 | PixelStoreState pss = new PixelStoreState();
83 |
84 | // set pixel packing
85 | glPixelStorei(GL_PACK_ROW_LENGTH, 0);
86 | glPixelStorei(GL_PACK_ALIGNMENT, 1);
87 | glPixelStorei(GL_PACK_SKIP_ROWS, 0);
88 | glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
89 |
90 | ByteBuffer image;
91 | int retVal = 0;
92 | boolean done = false;
93 |
94 | if ( w != width || h != height ) {
95 | // must rescale image to get "top" mipmap texture image
96 | image = BufferUtils.createByteBuffer((w + 4) * h * bpp);
97 | int error = gluScaleImage(format, width, height, type, data, w, h, type, image);
98 | if ( error != 0 ) {
99 | retVal = error;
100 | done = true;
101 | }
102 |
103 | /* set pixel unpacking */
104 | glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
105 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
106 | glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
107 | glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
108 | } else {
109 | image = data;
110 | }
111 |
112 | ByteBuffer bufferA = null;
113 | ByteBuffer bufferB = null;
114 |
115 | int level = 0;
116 | while ( !done ) {
117 | if (image != data) {
118 | /* set pixel unpacking */
119 | glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
120 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
121 | glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
122 | glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
123 | }
124 |
125 | glTexImage2D(target, level, components, w, h, 0, format, type, image);
126 |
127 | if ( w == 1 && h == 1 )
128 | break;
129 |
130 | final int newW = (w < 2) ? 1 : w >> 1;
131 | final int newH = (h < 2) ? 1 : h >> 1;
132 |
133 | final ByteBuffer newImage;
134 |
135 | if ( bufferA == null )
136 | newImage = (bufferA = BufferUtils.createByteBuffer((newW + 4) * newH * bpp));
137 | else if ( bufferB == null )
138 | newImage = (bufferB = BufferUtils.createByteBuffer((newW + 4) * newH * bpp));
139 | else
140 | newImage = bufferB;
141 |
142 | int error = gluScaleImage(format, w, h, type, image, newW, newH, type, newImage);
143 | if ( error != 0 ) {
144 | retVal = error;
145 | done = true;
146 | }
147 |
148 | image = newImage;
149 | if ( bufferB != null )
150 | bufferB = bufferA;
151 |
152 | w = newW;
153 | h = newH;
154 | level++;
155 | }
156 |
157 | // Restore original glPixelStore state
158 | pss.save();
159 |
160 | return retVal;
161 | }
162 |
163 | /**
164 | * Method gluScaleImage.
165 | * @param format
166 | * @param widthIn
167 | * @param heightIn
168 | * @param typein
169 | * @param dataIn
170 | * @param widthOut
171 | * @param heightOut
172 | * @param typeOut
173 | * @param dataOut
174 | * @return int
175 | */
176 | public static int gluScaleImage(int format,
177 | int widthIn, int heightIn, int typein, ByteBuffer dataIn,
178 | int widthOut, int heightOut, int typeOut, ByteBuffer dataOut) {
179 |
180 | final int components = compPerPix(format);
181 | if ( components == -1 )
182 | return GLU_INVALID_ENUM;
183 |
184 | int i, j, k;
185 | float[] tempIn, tempOut;
186 | float sx, sy;
187 | int sizein, sizeout;
188 | int rowstride, rowlen;
189 |
190 | // temp image data
191 | tempIn = new float[widthIn * heightIn * components];
192 | tempOut = new float[widthOut * heightOut * components];
193 |
194 | // Determine bytes per input type
195 | switch ( typein ) {
196 | case GL_UNSIGNED_BYTE:
197 | sizein = 1;
198 | break;
199 | case GL_FLOAT:
200 | sizein = 4;
201 | break;
202 | default:
203 | return GL_INVALID_ENUM;
204 | }
205 |
206 | // Determine bytes per output type
207 | switch ( typeOut ) {
208 | case GL_UNSIGNED_BYTE:
209 | sizeout = 1;
210 | break;
211 | case GL_FLOAT:
212 | sizeout = 4;
213 | break;
214 | default:
215 | return GL_INVALID_ENUM;
216 | }
217 |
218 | // Get glPixelStore state
219 | PixelStoreState pss = new PixelStoreState();
220 |
221 | //Unpack the pixel data and convert to floating point
222 | if ( pss.unpackRowLength > 0 )
223 | rowlen = pss.unpackRowLength;
224 | else
225 | rowlen = widthIn;
226 |
227 | if ( sizein >= pss.unpackAlignment )
228 | rowstride = components * rowlen;
229 | else
230 | rowstride = pss.unpackAlignment / sizein * ceil(components * rowlen * sizein, pss.unpackAlignment);
231 |
232 | switch ( typein ) {
233 | case GL_UNSIGNED_BYTE:
234 | k = 0;
235 | dataIn.rewind();
236 | for ( i = 0; i < heightIn; i++ ) {
237 | int ubptr = i * rowstride + pss.unpackSkipRows * rowstride + pss.unpackSkipPixels * components;
238 | for ( j = 0; j < widthIn * components; j++ ) {
239 | tempIn[k++] = dataIn.get(ubptr++) & 0xff;
240 | }
241 | }
242 | break;
243 | case GL_FLOAT:
244 | k = 0;
245 | dataIn.rewind();
246 | for ( i = 0; i < heightIn; i++ )
247 | {
248 | int fptr = 4 * (i * rowstride + pss.unpackSkipRows * rowstride + pss.unpackSkipPixels * components);
249 | for ( j = 0; j < widthIn * components; j++ )
250 | {
251 | tempIn[k++] = dataIn.getFloat(fptr);
252 | fptr += 4;
253 | }
254 | }
255 | break;
256 | default:
257 | return GLU_INVALID_ENUM;
258 | }
259 |
260 | // Do scaling
261 | sx = (float)widthIn / (float)widthOut;
262 | sy = (float)heightIn / (float)heightOut;
263 |
264 | float[] c = new float[components];
265 | int src, dst;
266 |
267 | for ( int iy = 0; iy < heightOut; iy++ ) {
268 | for ( int ix = 0; ix < widthOut; ix++ ) {
269 | int x0 = (int)(ix * sx);
270 | int x1 = (int)((ix + 1) * sx);
271 | int y0 = (int)(iy * sy);
272 | int y1 = (int)((iy + 1) * sy);
273 |
274 | int readPix = 0;
275 |
276 | // reset weighted pixel
277 | for ( int ic = 0; ic < components; ic++ ) {
278 | c[ic] = 0;
279 | }
280 |
281 | // create weighted pixel
282 | for ( int ix0 = x0; ix0 < x1; ix0++ ) {
283 | for ( int iy0 = y0; iy0 < y1; iy0++ ) {
284 |
285 | src = (iy0 * widthIn + ix0) * components;
286 |
287 | for ( int ic = 0; ic < components; ic++ ) {
288 | c[ic] += tempIn[src + ic];
289 | }
290 |
291 | readPix++;
292 | }
293 | }
294 |
295 | // store weighted pixel
296 | dst = (iy * widthOut + ix) * components;
297 |
298 | if ( readPix == 0 ) {
299 | // Image is sized up, caused by non power of two texture as input
300 | src = (y0 * widthIn + x0) * components;
301 | for ( int ic = 0; ic < components; ic++ ) {
302 | tempOut[dst++] = tempIn[src + ic];
303 | }
304 | } else {
305 | // sized down
306 | for ( k = 0; k < components; k++ ) {
307 | tempOut[dst++] = c[k] / readPix;
308 | }
309 | }
310 | }
311 | }
312 |
313 |
314 | // Convert temp output
315 | if ( pss.packRowLength > 0 )
316 | rowlen = pss.packRowLength;
317 | else
318 | rowlen = widthOut;
319 |
320 | if ( sizeout >= pss.packAlignment )
321 | rowstride = components * rowlen;
322 | else
323 | rowstride = pss.packAlignment / sizeout * ceil(components * rowlen * sizeout, pss.packAlignment);
324 |
325 | switch ( typeOut ) {
326 | case GL_UNSIGNED_BYTE:
327 | k = 0;
328 | for ( i = 0; i < heightOut; i++ ) {
329 | int ubptr = i * rowstride + pss.packSkipRows * rowstride + pss.packSkipPixels * components;
330 |
331 | for ( j = 0; j < widthOut * components; j++ ) {
332 | dataOut.put(ubptr++, (byte)tempOut[k++]);
333 | }
334 | }
335 | break;
336 | case GL_FLOAT:
337 | k = 0;
338 | for ( i = 0; i < heightOut; i++ ) {
339 | int fptr = 4 * (i * rowstride + pss.unpackSkipRows * rowstride + pss.unpackSkipPixels * components);
340 |
341 | for ( j = 0; j < widthOut * components; j++ ) {
342 | dataOut.putFloat(fptr, tempOut[k++]);
343 | fptr += 4;
344 | }
345 | }
346 | break;
347 | default:
348 | return GLU_INVALID_ENUM;
349 | }
350 |
351 | return 0;
352 | }
353 | }
354 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/fusion/glfw/GLFWKeyboardImplementation.java:
--------------------------------------------------------------------------------
1 | package org.lwjgl.fusion.glfw;
2 |
3 | import java.nio.ByteBuffer;
4 |
5 | import org.lwjgl.fusion.input.KeyboardImplementation;
6 | import org.lwjgl.glfw.GLFW;
7 | import org.lwjgl.glfw.GLFWCharCallback;
8 | import org.lwjgl.glfw.GLFWKeyCallback;
9 | import org.lwjgl.input.Keyboard;
10 | import org.lwjgl.opengl.Display;
11 | import org.lwjgl.opengl.EventQueue;
12 |
13 | /**
14 | * @author Zarzelcow
15 | * @created 28/09/2022 - 2:14 PM
16 | */
17 | public class GLFWKeyboardImplementation implements KeyboardImplementation {
18 | private GLFWKeyCallback keyCallback;
19 | private GLFWCharCallback charCallback;
20 | private long windowHandle;
21 |
22 | private final byte[] key_down_buffer = new byte[Keyboard.KEYBOARD_SIZE];
23 | private final EventQueue event_queue = new EventQueue(Keyboard.EVENT_SIZE);
24 |
25 | private final ByteBuffer tmp_event = ByteBuffer.allocate(Keyboard.EVENT_SIZE);
26 |
27 | @Override
28 | public void createKeyboard() {
29 |
30 | this.keyCallback = GLFWKeyCallback.create((window, glfwKey, scancode, action, mods) -> {
31 |
32 | int key = translateKeyFromGLFW(glfwKey);
33 |
34 | if (action == GLFW.GLFW_PRESS) {
35 | this.key_down_buffer[key] = 1;
36 | } else if (action == GLFW.GLFW_RELEASE) {
37 | this.key_down_buffer[key] = 0;
38 | }
39 |
40 | putKeyboardEvent(key, this.key_down_buffer[key], 0, System.nanoTime(), action == GLFW.GLFW_REPEAT);
41 | });
42 |
43 | this.charCallback = GLFWCharCallback.create((window, codepoint) -> {
44 | // if the keycode is 0 minecraft instead uses the character code as the key pressed, not sure why
45 | // but a keycode of -1 is used instead to fix this issue
46 | putKeyboardEvent(-1, (byte) 1, codepoint, System.nanoTime(), false);
47 | });
48 |
49 | this.windowHandle = Display.getHandle();
50 | GLFW.glfwSetKeyCallback(this.windowHandle, this.keyCallback);
51 | GLFW.glfwSetCharCallback(this.windowHandle, this.charCallback);
52 | }
53 |
54 | private void putKeyboardEvent(int keycode, byte state, int ch, long nanos, boolean repeat) {
55 | this.tmp_event.clear();
56 | this.tmp_event.putInt(keycode).put(state).putInt(ch).putLong(nanos).put(repeat ? (byte)1 : (byte)0);
57 | this.tmp_event.flip();
58 | this.event_queue.putEvent(this.tmp_event);
59 | }
60 |
61 | @Override
62 | public void destroyKeyboard() {
63 | this.keyCallback.free();
64 | this.charCallback.free();
65 | }
66 |
67 | @Override
68 | public void pollKeyboard(ByteBuffer keyDownBuffer) {
69 | int old_position = keyDownBuffer.position();
70 | keyDownBuffer.put(this.key_down_buffer);
71 | keyDownBuffer.position(old_position);
72 | }
73 |
74 | @Override
75 | public void readKeyboard(ByteBuffer readBuffer) {
76 | event_queue.copyEvents(readBuffer);
77 | }
78 |
79 | private static final int[] GLFW2LWJGL = new int[Keyboard.KEYBOARD_SIZE];
80 |
81 | public static int translateKeyFromGLFW(int key) {
82 | if (key == -1) {
83 | return GLFW2LWJGL[0];
84 | } else if (key < GLFW2LWJGL.length) {
85 | return GLFW2LWJGL[key];
86 | } else {
87 | return key;
88 | }
89 | }
90 |
91 | static {
92 | GLFW2LWJGL[0x00] = Keyboard.KEY_NONE;
93 | GLFW2LWJGL[GLFW.GLFW_KEY_SPACE] = Keyboard.KEY_SPACE;
94 | GLFW2LWJGL[GLFW.GLFW_KEY_APOSTROPHE] = Keyboard.KEY_APOSTROPHE;
95 | GLFW2LWJGL[GLFW.GLFW_KEY_COMMA] = Keyboard.KEY_COMMA;
96 | GLFW2LWJGL[GLFW.GLFW_KEY_MINUS] = Keyboard.KEY_MINUS;
97 | GLFW2LWJGL[GLFW.GLFW_KEY_PERIOD] = Keyboard.KEY_PERIOD;
98 | GLFW2LWJGL[GLFW.GLFW_KEY_SLASH] = Keyboard.KEY_SLASH;
99 | GLFW2LWJGL[GLFW.GLFW_KEY_0] = Keyboard.KEY_0;
100 | GLFW2LWJGL[GLFW.GLFW_KEY_1] = Keyboard.KEY_1;
101 | GLFW2LWJGL[GLFW.GLFW_KEY_2] = Keyboard.KEY_2;
102 | GLFW2LWJGL[GLFW.GLFW_KEY_3] = Keyboard.KEY_3;
103 | GLFW2LWJGL[GLFW.GLFW_KEY_4] = Keyboard.KEY_4;
104 | GLFW2LWJGL[GLFW.GLFW_KEY_5] = Keyboard.KEY_5;
105 | GLFW2LWJGL[GLFW.GLFW_KEY_6] = Keyboard.KEY_6;
106 | GLFW2LWJGL[GLFW.GLFW_KEY_7] = Keyboard.KEY_7;
107 | GLFW2LWJGL[GLFW.GLFW_KEY_8] = Keyboard.KEY_8;
108 | GLFW2LWJGL[GLFW.GLFW_KEY_9] = Keyboard.KEY_9;
109 | GLFW2LWJGL[GLFW.GLFW_KEY_SEMICOLON] = Keyboard.KEY_SEMICOLON;
110 | GLFW2LWJGL[GLFW.GLFW_KEY_EQUAL] = Keyboard.KEY_EQUALS;
111 | GLFW2LWJGL[GLFW.GLFW_KEY_A] = Keyboard.KEY_A;
112 | GLFW2LWJGL[GLFW.GLFW_KEY_B] = Keyboard.KEY_B;
113 | GLFW2LWJGL[GLFW.GLFW_KEY_C] = Keyboard.KEY_C;
114 | GLFW2LWJGL[GLFW.GLFW_KEY_D] = Keyboard.KEY_D;
115 | GLFW2LWJGL[GLFW.GLFW_KEY_E] = Keyboard.KEY_E;
116 | GLFW2LWJGL[GLFW.GLFW_KEY_F] = Keyboard.KEY_F;
117 | GLFW2LWJGL[GLFW.GLFW_KEY_G] = Keyboard.KEY_G;
118 | GLFW2LWJGL[GLFW.GLFW_KEY_H] = Keyboard.KEY_H;
119 | GLFW2LWJGL[GLFW.GLFW_KEY_I] = Keyboard.KEY_I;
120 | GLFW2LWJGL[GLFW.GLFW_KEY_J] = Keyboard.KEY_J;
121 | GLFW2LWJGL[GLFW.GLFW_KEY_K] = Keyboard.KEY_K;
122 | GLFW2LWJGL[GLFW.GLFW_KEY_L] = Keyboard.KEY_L;
123 | GLFW2LWJGL[GLFW.GLFW_KEY_M] = Keyboard.KEY_M;
124 | GLFW2LWJGL[GLFW.GLFW_KEY_N] = Keyboard.KEY_N;
125 | GLFW2LWJGL[GLFW.GLFW_KEY_O] = Keyboard.KEY_O;
126 | GLFW2LWJGL[GLFW.GLFW_KEY_P] = Keyboard.KEY_P;
127 | GLFW2LWJGL[GLFW.GLFW_KEY_Q] = Keyboard.KEY_Q;
128 | GLFW2LWJGL[GLFW.GLFW_KEY_R] = Keyboard.KEY_R;
129 | GLFW2LWJGL[GLFW.GLFW_KEY_S] = Keyboard.KEY_S;
130 | GLFW2LWJGL[GLFW.GLFW_KEY_T] = Keyboard.KEY_T;
131 | GLFW2LWJGL[GLFW.GLFW_KEY_U] = Keyboard.KEY_U;
132 | GLFW2LWJGL[GLFW.GLFW_KEY_V] = Keyboard.KEY_V;
133 | GLFW2LWJGL[GLFW.GLFW_KEY_W] = Keyboard.KEY_W;
134 | GLFW2LWJGL[GLFW.GLFW_KEY_X] = Keyboard.KEY_X;
135 | GLFW2LWJGL[GLFW.GLFW_KEY_Y] = Keyboard.KEY_Y;
136 | GLFW2LWJGL[GLFW.GLFW_KEY_Z] = Keyboard.KEY_Z;
137 | GLFW2LWJGL[GLFW.GLFW_KEY_LEFT_BRACKET] = Keyboard.KEY_LBRACKET;
138 | GLFW2LWJGL[GLFW.GLFW_KEY_BACKSLASH] = Keyboard.KEY_BACKSLASH;
139 | GLFW2LWJGL[GLFW.GLFW_KEY_RIGHT_BRACKET] = Keyboard.KEY_RBRACKET;
140 | GLFW2LWJGL[GLFW.GLFW_KEY_GRAVE_ACCENT] = Keyboard.KEY_GRAVE;
141 | GLFW2LWJGL[GLFW.GLFW_KEY_WORLD_1] = Keyboard.KEY_WORLD_1;
142 | GLFW2LWJGL[GLFW.GLFW_KEY_WORLD_2] = Keyboard.KEY_WORLD_2;
143 | GLFW2LWJGL[GLFW.GLFW_KEY_ESCAPE] = Keyboard.KEY_ESCAPE;
144 | GLFW2LWJGL[GLFW.GLFW_KEY_ENTER] = Keyboard.KEY_RETURN;
145 | GLFW2LWJGL[GLFW.GLFW_KEY_TAB] = Keyboard.KEY_TAB;
146 | GLFW2LWJGL[GLFW.GLFW_KEY_BACKSPACE] = Keyboard.KEY_BACK;
147 | GLFW2LWJGL[GLFW.GLFW_KEY_INSERT] = Keyboard.KEY_INSERT;
148 | GLFW2LWJGL[GLFW.GLFW_KEY_DELETE] = Keyboard.KEY_DELETE;
149 | GLFW2LWJGL[GLFW.GLFW_KEY_RIGHT] = Keyboard.KEY_RIGHT;
150 | GLFW2LWJGL[GLFW.GLFW_KEY_LEFT] = Keyboard.KEY_LEFT;
151 | GLFW2LWJGL[GLFW.GLFW_KEY_DOWN] = Keyboard.KEY_DOWN;
152 | GLFW2LWJGL[GLFW.GLFW_KEY_UP] = Keyboard.KEY_UP;
153 | GLFW2LWJGL[GLFW.GLFW_KEY_PAGE_UP] = Keyboard.KEY_PRIOR;
154 | GLFW2LWJGL[GLFW.GLFW_KEY_PAGE_DOWN] = Keyboard.KEY_NEXT;
155 | GLFW2LWJGL[GLFW.GLFW_KEY_HOME] = Keyboard.KEY_HOME;
156 | GLFW2LWJGL[GLFW.GLFW_KEY_END] = Keyboard.KEY_END;
157 | GLFW2LWJGL[GLFW.GLFW_KEY_CAPS_LOCK] = Keyboard.KEY_CAPITAL;
158 | GLFW2LWJGL[GLFW.GLFW_KEY_SCROLL_LOCK] = Keyboard.KEY_SCROLL;
159 | GLFW2LWJGL[GLFW.GLFW_KEY_NUM_LOCK] = Keyboard.KEY_NUMLOCK;
160 | GLFW2LWJGL[GLFW.GLFW_KEY_PRINT_SCREEN] = Keyboard.KEY_PRINT_SCREEN;
161 | GLFW2LWJGL[GLFW.GLFW_KEY_PAUSE] = Keyboard.KEY_PAUSE;
162 | GLFW2LWJGL[GLFW.GLFW_KEY_F1] = Keyboard.KEY_F1;
163 | GLFW2LWJGL[GLFW.GLFW_KEY_F2] = Keyboard.KEY_F2;
164 | GLFW2LWJGL[GLFW.GLFW_KEY_F3] = Keyboard.KEY_F3;
165 | GLFW2LWJGL[GLFW.GLFW_KEY_F4] = Keyboard.KEY_F4;
166 | GLFW2LWJGL[GLFW.GLFW_KEY_F5] = Keyboard.KEY_F5;
167 | GLFW2LWJGL[GLFW.GLFW_KEY_F6] = Keyboard.KEY_F6;
168 | GLFW2LWJGL[GLFW.GLFW_KEY_F7] = Keyboard.KEY_F7;
169 | GLFW2LWJGL[GLFW.GLFW_KEY_F8] = Keyboard.KEY_F8;
170 | GLFW2LWJGL[GLFW.GLFW_KEY_F9] = Keyboard.KEY_F9;
171 | GLFW2LWJGL[GLFW.GLFW_KEY_F10] = Keyboard.KEY_F10;
172 | GLFW2LWJGL[GLFW.GLFW_KEY_F11] = Keyboard.KEY_F11;
173 | GLFW2LWJGL[GLFW.GLFW_KEY_F12] = Keyboard.KEY_F12;
174 | GLFW2LWJGL[GLFW.GLFW_KEY_F13] = Keyboard.KEY_F13;
175 | GLFW2LWJGL[GLFW.GLFW_KEY_F14] = Keyboard.KEY_F14;
176 | GLFW2LWJGL[GLFW.GLFW_KEY_F15] = Keyboard.KEY_F15;
177 | GLFW2LWJGL[GLFW.GLFW_KEY_F16] = Keyboard.KEY_F16;
178 | GLFW2LWJGL[GLFW.GLFW_KEY_F17] = Keyboard.KEY_F17;
179 | GLFW2LWJGL[GLFW.GLFW_KEY_F18] = Keyboard.KEY_F18;
180 | GLFW2LWJGL[GLFW.GLFW_KEY_F19] = Keyboard.KEY_F19;
181 | GLFW2LWJGL[GLFW.GLFW_KEY_F20] = Keyboard.KEY_F20;
182 | GLFW2LWJGL[GLFW.GLFW_KEY_F21] = Keyboard.KEY_F21;
183 | GLFW2LWJGL[GLFW.GLFW_KEY_F22] = Keyboard.KEY_F22;
184 | GLFW2LWJGL[GLFW.GLFW_KEY_F23] = Keyboard.KEY_F23;
185 | GLFW2LWJGL[GLFW.GLFW_KEY_F24] = Keyboard.KEY_F24;
186 | GLFW2LWJGL[GLFW.GLFW_KEY_F25] = Keyboard.KEY_F25;
187 | GLFW2LWJGL[GLFW.GLFW_KEY_KP_0] = Keyboard.KEY_NUMPAD0;
188 | GLFW2LWJGL[GLFW.GLFW_KEY_KP_1] = Keyboard.KEY_NUMPAD1;
189 | GLFW2LWJGL[GLFW.GLFW_KEY_KP_2] = Keyboard.KEY_NUMPAD2;
190 | GLFW2LWJGL[GLFW.GLFW_KEY_KP_3] = Keyboard.KEY_NUMPAD3;
191 | GLFW2LWJGL[GLFW.GLFW_KEY_KP_4] = Keyboard.KEY_NUMPAD4;
192 | GLFW2LWJGL[GLFW.GLFW_KEY_KP_5] = Keyboard.KEY_NUMPAD5;
193 | GLFW2LWJGL[GLFW.GLFW_KEY_KP_6] = Keyboard.KEY_NUMPAD6;
194 | GLFW2LWJGL[GLFW.GLFW_KEY_KP_7] = Keyboard.KEY_NUMPAD7;
195 | GLFW2LWJGL[GLFW.GLFW_KEY_KP_8] = Keyboard.KEY_NUMPAD8;
196 | GLFW2LWJGL[GLFW.GLFW_KEY_KP_9] = Keyboard.KEY_NUMPAD9;
197 | GLFW2LWJGL[GLFW.GLFW_KEY_KP_DECIMAL] = Keyboard.KEY_DECIMAL;
198 | GLFW2LWJGL[GLFW.GLFW_KEY_KP_DIVIDE] = Keyboard.KEY_DIVIDE;
199 | GLFW2LWJGL[GLFW.GLFW_KEY_KP_MULTIPLY] = Keyboard.KEY_MULTIPLY;
200 | GLFW2LWJGL[GLFW.GLFW_KEY_KP_SUBTRACT] = Keyboard.KEY_SUBTRACT;
201 | GLFW2LWJGL[GLFW.GLFW_KEY_KP_ADD] = Keyboard.KEY_ADD;
202 | GLFW2LWJGL[GLFW.GLFW_KEY_KP_ENTER] = Keyboard.KEY_NUMPADENTER;
203 | GLFW2LWJGL[GLFW.GLFW_KEY_KP_EQUAL] = Keyboard.KEY_NUMPADEQUALS;
204 | GLFW2LWJGL[GLFW.GLFW_KEY_LEFT_SHIFT] = Keyboard.KEY_LSHIFT;
205 | GLFW2LWJGL[GLFW.GLFW_KEY_LEFT_CONTROL] = Keyboard.KEY_LCONTROL;
206 | GLFW2LWJGL[GLFW.GLFW_KEY_LEFT_ALT] = Keyboard.KEY_LMENU;
207 | GLFW2LWJGL[GLFW.GLFW_KEY_LEFT_SUPER] = Keyboard.KEY_LMETA;
208 | GLFW2LWJGL[GLFW.GLFW_KEY_RIGHT_SHIFT] = Keyboard.KEY_RSHIFT;
209 | GLFW2LWJGL[GLFW.GLFW_KEY_RIGHT_CONTROL] = Keyboard.KEY_RCONTROL;
210 | GLFW2LWJGL[GLFW.GLFW_KEY_RIGHT_ALT] = Keyboard.KEY_RMENU;
211 | GLFW2LWJGL[GLFW.GLFW_KEY_RIGHT_SUPER] = Keyboard.KEY_RMETA;
212 | GLFW2LWJGL[GLFW.GLFW_KEY_MENU] = Keyboard.KEY_MENU;
213 | }
214 | }
215 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/util/vector/Matrix2f.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.util.vector;
33 |
34 | import java.io.Serializable;
35 | import java.nio.FloatBuffer;
36 |
37 | /**
38 | *
39 | * Holds a 2x2 matrix
40 | *
41 | * @author cix_foo
42 | * @version $Revision$
43 | * $Id$
44 | */
45 |
46 | public class Matrix2f extends Matrix implements Serializable {
47 |
48 | private static final long serialVersionUID = 1L;
49 |
50 | public float m00, m01, m10, m11;
51 |
52 | /**
53 | * Constructor for Matrix2f. The matrix is initialised to the identity.
54 | */
55 | public Matrix2f() {
56 | setIdentity();
57 | }
58 |
59 | /**
60 | * Constructor
61 | */
62 | public Matrix2f(Matrix2f src) {
63 | load(src);
64 | }
65 |
66 | /**
67 | * Load from another matrix
68 | * @param src The source matrix
69 | * @return this
70 | */
71 | public Matrix2f load(Matrix2f src) {
72 | return load(src, this);
73 | }
74 |
75 | /**
76 | * Copy the source matrix to the destination matrix.
77 | * @param src The source matrix
78 | * @param dest The destination matrix, or null if a new one should be created.
79 | * @return The copied matrix
80 | */
81 | public static Matrix2f load(Matrix2f src, Matrix2f dest) {
82 | if (dest == null)
83 | dest = new Matrix2f();
84 |
85 | dest.m00 = src.m00;
86 | dest.m01 = src.m01;
87 | dest.m10 = src.m10;
88 | dest.m11 = src.m11;
89 |
90 | return dest;
91 | }
92 |
93 | /**
94 | * Load from a float buffer. The buffer stores the matrix in column major
95 | * (OpenGL) order.
96 | *
97 | * @param buf A float buffer to read from
98 | * @return this
99 | */
100 | public Matrix load(FloatBuffer buf) {
101 |
102 | m00 = buf.get();
103 | m01 = buf.get();
104 | m10 = buf.get();
105 | m11 = buf.get();
106 |
107 | return this;
108 | }
109 |
110 | /**
111 | * Load from a float buffer. The buffer stores the matrix in row major
112 | * (mathematical) order.
113 | *
114 | * @param buf A float buffer to read from
115 | * @return this
116 | */
117 | public Matrix loadTranspose(FloatBuffer buf) {
118 |
119 | m00 = buf.get();
120 | m10 = buf.get();
121 | m01 = buf.get();
122 | m11 = buf.get();
123 |
124 | return this;
125 | }
126 |
127 | /**
128 | * Store this matrix in a float buffer. The matrix is stored in column
129 | * major (openGL) order.
130 | * @param buf The buffer to store this matrix in
131 | */
132 | public Matrix store(FloatBuffer buf) {
133 | buf.put(m00);
134 | buf.put(m01);
135 | buf.put(m10);
136 | buf.put(m11);
137 | return this;
138 | }
139 |
140 | /**
141 | * Store this matrix in a float buffer. The matrix is stored in row
142 | * major (maths) order.
143 | * @param buf The buffer to store this matrix in
144 | */
145 | public Matrix storeTranspose(FloatBuffer buf) {
146 | buf.put(m00);
147 | buf.put(m10);
148 | buf.put(m01);
149 | buf.put(m11);
150 | return this;
151 | }
152 |
153 |
154 |
155 | /**
156 | * Add two matrices together and place the result in a third matrix.
157 | * @param left The left source matrix
158 | * @param right The right source matrix
159 | * @param dest The destination matrix, or null if a new one is to be created
160 | * @return the destination matrix
161 | */
162 | public static Matrix2f add(Matrix2f left, Matrix2f right, Matrix2f dest) {
163 | if (dest == null)
164 | dest = new Matrix2f();
165 |
166 | dest.m00 = left.m00 + right.m00;
167 | dest.m01 = left.m01 + right.m01;
168 | dest.m10 = left.m10 + right.m10;
169 | dest.m11 = left.m11 + right.m11;
170 |
171 | return dest;
172 | }
173 |
174 | /**
175 | * Subtract the right matrix from the left and place the result in a third matrix.
176 | * @param left The left source matrix
177 | * @param right The right source matrix
178 | * @param dest The destination matrix, or null if a new one is to be created
179 | * @return the destination matrix
180 | */
181 | public static Matrix2f sub(Matrix2f left, Matrix2f right, Matrix2f dest) {
182 | if (dest == null)
183 | dest = new Matrix2f();
184 |
185 | dest.m00 = left.m00 - right.m00;
186 | dest.m01 = left.m01 - right.m01;
187 | dest.m10 = left.m10 - right.m10;
188 | dest.m11 = left.m11 - right.m11;
189 |
190 | return dest;
191 | }
192 |
193 | /**
194 | * Multiply the right matrix by the left and place the result in a third matrix.
195 | * @param left The left source matrix
196 | * @param right The right source matrix
197 | * @param dest The destination matrix, or null if a new one is to be created
198 | * @return the destination matrix
199 | */
200 | public static Matrix2f mul(Matrix2f left, Matrix2f right, Matrix2f dest) {
201 | if (dest == null)
202 | dest = new Matrix2f();
203 |
204 | float m00 = left.m00 * right.m00 + left.m10 * right.m01;
205 | float m01 = left.m01 * right.m00 + left.m11 * right.m01;
206 | float m10 = left.m00 * right.m10 + left.m10 * right.m11;
207 | float m11 = left.m01 * right.m10 + left.m11 * right.m11;
208 |
209 | dest.m00 = m00;
210 | dest.m01 = m01;
211 | dest.m10 = m10;
212 | dest.m11 = m11;
213 |
214 | return dest;
215 | }
216 |
217 | /**
218 | * Transform a Vector by a matrix and return the result in a destination
219 | * vector.
220 | * @param left The left matrix
221 | * @param right The right vector
222 | * @param dest The destination vector, or null if a new one is to be created
223 | * @return the destination vector
224 | */
225 | public static Vector2f transform(Matrix2f left, Vector2f right, Vector2f dest) {
226 | if (dest == null)
227 | dest = new Vector2f();
228 |
229 | float x = left.m00 * right.x + left.m10 * right.y;
230 | float y = left.m01 * right.x + left.m11 * right.y;
231 |
232 | dest.x = x;
233 | dest.y = y;
234 |
235 | return dest;
236 | }
237 |
238 | /**
239 | * Transpose this matrix
240 | * @return this
241 | */
242 | public Matrix transpose() {
243 | return transpose(this);
244 | }
245 |
246 | /**
247 | * Transpose this matrix and place the result in another matrix.
248 | * @param dest The destination matrix or null if a new matrix is to be created
249 | * @return the transposed matrix
250 | */
251 | public Matrix2f transpose(Matrix2f dest) {
252 | return transpose(this, dest);
253 | }
254 |
255 | /**
256 | * Transpose the source matrix and place the result in the destination matrix.
257 | * @param src The source matrix or null if a new matrix is to be created
258 | * @param dest The destination matrix or null if a new matrix is to be created
259 | * @return the transposed matrix
260 | */
261 | public static Matrix2f transpose(Matrix2f src, Matrix2f dest) {
262 | if (dest == null)
263 | dest = new Matrix2f();
264 |
265 | float m01 = src.m10;
266 | float m10 = src.m01;
267 |
268 | dest.m01 = m01;
269 | dest.m10 = m10;
270 |
271 | return dest;
272 | }
273 |
274 | /**
275 | * Invert this matrix
276 | * @return this if successful, null otherwise
277 | */
278 | public Matrix invert() {
279 | return invert(this, this);
280 | }
281 |
282 | /**
283 | * Invert the source matrix and place the result in the destination matrix.
284 | * @param src The source matrix to be inverted
285 | * @param dest The destination matrix or null if a new matrix is to be created
286 | * @return The inverted matrix, or null if source can't be reverted.
287 | */
288 | public static Matrix2f invert(Matrix2f src, Matrix2f dest) {
289 | /*
290 | *inv(A) = 1/det(A) * adj(A);
291 | */
292 |
293 | float determinant = src.determinant();
294 | if (determinant != 0) {
295 | if (dest == null)
296 | dest = new Matrix2f();
297 | float determinant_inv = 1f/determinant;
298 | float t00 = src.m11*determinant_inv;
299 | float t01 = -src.m01*determinant_inv;
300 | float t11 = src.m00*determinant_inv;
301 | float t10 = -src.m10*determinant_inv;
302 |
303 | dest.m00 = t00;
304 | dest.m01 = t01;
305 | dest.m10 = t10;
306 | dest.m11 = t11;
307 | return dest;
308 | } else
309 | return null;
310 | }
311 |
312 | /**
313 | * Returns a string representation of this matrix
314 | */
315 | public String toString() {
316 | StringBuilder buf = new StringBuilder();
317 | buf.append(m00).append(' ').append(m10).append(' ').append('\n');
318 | buf.append(m01).append(' ').append(m11).append(' ').append('\n');
319 | return buf.toString();
320 | }
321 |
322 | /**
323 | * Negate this matrix
324 | * @return this
325 | */
326 | public Matrix negate() {
327 | return negate(this);
328 | }
329 |
330 | /**
331 | * Negate this matrix and stash the result in another matrix.
332 | * @param dest The destination matrix, or null if a new matrix is to be created
333 | * @return the negated matrix
334 | */
335 | public Matrix2f negate(Matrix2f dest) {
336 | return negate(this, dest);
337 | }
338 |
339 | /**
340 | * Negate the source matrix and stash the result in the destination matrix.
341 | * @param src The source matrix to be negated
342 | * @param dest The destination matrix, or null if a new matrix is to be created
343 | * @return the negated matrix
344 | */
345 | public static Matrix2f negate(Matrix2f src, Matrix2f dest) {
346 | if (dest == null)
347 | dest = new Matrix2f();
348 |
349 | dest.m00 = -src.m00;
350 | dest.m01 = -src.m01;
351 | dest.m10 = -src.m10;
352 | dest.m11 = -src.m11;
353 |
354 | return dest;
355 | }
356 |
357 | /**
358 | * Set this matrix to be the identity matrix.
359 | * @return this
360 | */
361 | public Matrix setIdentity() {
362 | return setIdentity(this);
363 | }
364 |
365 | /**
366 | * Set the source matrix to be the identity matrix.
367 | * @param src The matrix to set to the identity.
368 | * @return The source matrix
369 | */
370 | public static Matrix2f setIdentity(Matrix2f src) {
371 | src.m00 = 1.0f;
372 | src.m01 = 0.0f;
373 | src.m10 = 0.0f;
374 | src.m11 = 1.0f;
375 | return src;
376 | }
377 |
378 | /**
379 | * Set this matrix to 0.
380 | * @return this
381 | */
382 | public Matrix setZero() {
383 | return setZero(this);
384 | }
385 |
386 | public static Matrix2f setZero(Matrix2f src) {
387 | src.m00 = 0.0f;
388 | src.m01 = 0.0f;
389 | src.m10 = 0.0f;
390 | src.m11 = 0.0f;
391 | return src;
392 | }
393 |
394 | /* (non-Javadoc)
395 | * @see org.lwjgl.vector.Matrix#determinant()
396 | */
397 | public float determinant() {
398 | return m00 * m11 - m01*m10;
399 | }
400 | }
401 |
--------------------------------------------------------------------------------
/src/main/java/org/lwjgl/util/glu/Project.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2002-2008 LWJGL Project
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | *
12 | * * Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | *
16 | * * Neither the name of 'LWJGL' nor the names of
17 | * its contributors may be used to endorse or promote products derived
18 | * from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.lwjgl.util.glu;
33 |
34 | import java.nio.FloatBuffer;
35 | import java.nio.IntBuffer;
36 |
37 | import org.lwjgl.BufferUtils;
38 |
39 | import static org.lwjgl.opengl.GL11.*;
40 |
41 | /**
42 | * Project.java
43 | *
44 | *
45 | * Created 11-jan-2004
46 | *
47 | * @author Erik Duijs
48 | */
49 | public class Project extends Util {
50 |
51 | private static final float[] IDENTITY_MATRIX =
52 | new float[] {
53 | 1.0f, 0.0f, 0.0f, 0.0f,
54 | 0.0f, 1.0f, 0.0f, 0.0f,
55 | 0.0f, 0.0f, 1.0f, 0.0f,
56 | 0.0f, 0.0f, 0.0f, 1.0f };
57 |
58 | private static final FloatBuffer matrix = BufferUtils.createFloatBuffer(16);
59 | private static final FloatBuffer finalMatrix = BufferUtils.createFloatBuffer(16);
60 |
61 | private static final FloatBuffer tempMatrix = BufferUtils.createFloatBuffer(16);
62 | private static final float[] in = new float[4];
63 | private static final float[] out = new float[4];
64 |
65 | private static final float[] forward = new float[3];
66 | private static final float[] side = new float[3];
67 | private static final float[] up = new float[3];
68 |
69 | /**
70 | * Make matrix an identity matrix
71 | */
72 | private static void __gluMakeIdentityf(FloatBuffer m) {
73 | int oldPos = m.position();
74 | m.put(IDENTITY_MATRIX);
75 | m.position(oldPos);
76 | }
77 |
78 | /**
79 | * Method __gluMultMatrixVecf
80 | *
81 | * @param finalMatrix
82 | * @param in
83 | * @param out
84 | */
85 | private static void __gluMultMatrixVecf(FloatBuffer finalMatrix, float[] in, float[] out) {
86 | for (int i = 0; i < 4; i++) {
87 | out[i] =
88 | in[0] * finalMatrix.get(finalMatrix.position() + i)
89 | + in[1] * finalMatrix.get(finalMatrix.position() + 4 + i)
90 | + in[2] * finalMatrix.get(finalMatrix.position() + 2*4 + i)
91 | + in[3] * finalMatrix.get(finalMatrix.position() + 3*4 + i);
92 |
93 | }
94 | }
95 |
96 | /**
97 | * @param src
98 | * @param inverse
99 | *
100 | * @return true if the matrix was succesfully inverted
101 | */
102 | private static boolean __gluInvertMatrixf(FloatBuffer src, FloatBuffer inverse) {
103 | int i, j, k, swap;
104 | float t;
105 | FloatBuffer temp = Project.tempMatrix;
106 |
107 |
108 | for (i = 0; i < 16; i++) {
109 | temp.put(i, src.get(i + src.position()));
110 | }
111 | __gluMakeIdentityf(inverse);
112 |
113 | for (i = 0; i < 4; i++) {
114 | /*
115 | * * Look for largest element in column
116 | */
117 | swap = i;
118 | for (j = i + 1; j < 4; j++) {
119 | /*
120 | * if (fabs(temp[j][i]) > fabs(temp[i][i])) { swap = j;
121 | */
122 | if (Math.abs(temp.get(j*4 + i)) > Math.abs(temp.get(i* 4 + i))) {
123 | swap = j;
124 | }
125 | }
126 |
127 | if (swap != i) {
128 | /*
129 | * * Swap rows.
130 | */
131 | for (k = 0; k < 4; k++) {
132 | t = temp.get(i*4 + k);
133 | temp.put(i*4 + k, temp.get(swap*4 + k));
134 | temp.put(swap*4 + k, t);
135 |
136 | t = inverse.get(i*4 + k);
137 | inverse.put(i*4 + k, inverse.get(swap*4 + k));
138 | //inverse.put((i << 2) + k, inverse.get((swap << 2) + k));
139 | inverse.put(swap*4 + k, t);
140 | //inverse.put((swap << 2) + k, t);
141 | }
142 | }
143 |
144 | if (temp.get(i*4 + i) == 0) {
145 | /*
146 | * * No non-zero pivot. The matrix is singular, which shouldn't *
147 | * happen. This means the user gave us a bad matrix.
148 | */
149 | return false;
150 | }
151 |
152 | t = temp.get(i*4 + i);
153 | for (k = 0; k < 4; k++) {
154 | temp.put(i*4 + k, temp.get(i*4 + k)/t);
155 | inverse.put(i*4 + k, inverse.get(i*4 + k)/t);
156 | }
157 | for (j = 0; j < 4; j++) {
158 | if (j != i) {
159 | t = temp.get(j*4 + i);
160 | for (k = 0; k < 4; k++) {
161 | temp.put(j*4 + k, temp.get(j*4 + k) - temp.get(i*4 + k) * t);
162 | inverse.put(j*4 + k, inverse.get(j*4 + k) - inverse.get(i*4 + k) * t);
163 | /*inverse.put(
164 | (j << 2) + k,
165 | inverse.get((j << 2) + k) - inverse.get((i << 2) + k) * t);*/
166 | }
167 | }
168 | }
169 | }
170 | return true;
171 | }
172 |
173 | /**
174 | * @param a
175 | * @param b
176 | * @param r
177 | */
178 | private static void __gluMultMatricesf(FloatBuffer a, FloatBuffer b, FloatBuffer r) {
179 | for (int i = 0; i < 4; i++) {
180 | for (int j = 0; j < 4; j++) {
181 | r.put(r.position() + i*4 + j,
182 | a.get(a.position() + i*4 + 0) * b.get(b.position() + 0*4 + j) + a.get(a.position() + i*4 + 1) * b.get(b.position() + 1*4 + j) + a.get(a.position() + i*4 + 2) * b.get(b.position() + 2*4 + j) + a.get(a.position() + i*4 + 3) * b.get(b.position() + 3*4 + j));
183 | }
184 | }
185 | }
186 |
187 | /**
188 | * Method gluPerspective.
189 | *
190 | * @param fovy
191 | * @param aspect
192 | * @param zNear
193 | * @param zFar
194 | */
195 | public static void gluPerspective(float fovy, float aspect, float zNear, float zFar) {
196 | float sine, cotangent, deltaZ;
197 | float radians = (float) (fovy / 2 * Math.PI / 180);
198 |
199 | deltaZ = zFar - zNear;
200 | sine = (float) Math.sin(radians);
201 |
202 | if ((deltaZ == 0) || (sine == 0) || (aspect == 0)) {
203 | return;
204 | }
205 |
206 | cotangent = (float) Math.cos(radians) / sine;
207 |
208 | __gluMakeIdentityf(matrix);
209 |
210 | matrix.put(0 * 4 + 0, cotangent / aspect);
211 | matrix.put(1 * 4 + 1, cotangent);
212 | matrix.put(2 * 4 + 2, - (zFar + zNear) / deltaZ);
213 | matrix.put(2 * 4 + 3, -1);
214 | matrix.put(3 * 4 + 2, -2 * zNear * zFar / deltaZ);
215 | matrix.put(3 * 4 + 3, 0);
216 |
217 | glMultMatrixf(matrix);
218 | }
219 |
220 | /**
221 | * Method gluLookAt
222 | *
223 | * @param eyex
224 | * @param eyey
225 | * @param eyez
226 | * @param centerx
227 | * @param centery
228 | * @param centerz
229 | * @param upx
230 | * @param upy
231 | * @param upz
232 | */
233 | public static void gluLookAt(
234 | float eyex,
235 | float eyey,
236 | float eyez,
237 | float centerx,
238 | float centery,
239 | float centerz,
240 | float upx,
241 | float upy,
242 | float upz) {
243 | float[] forward = Project.forward;
244 | float[] side = Project.side;
245 | float[] up = Project.up;
246 |
247 | forward[0] = centerx - eyex;
248 | forward[1] = centery - eyey;
249 | forward[2] = centerz - eyez;
250 |
251 | up[0] = upx;
252 | up[1] = upy;
253 | up[2] = upz;
254 |
255 | normalize(forward);
256 |
257 | /* Side = forward x up */
258 | cross(forward, up, side);
259 | normalize(side);
260 |
261 | /* Recompute up as: up = side x forward */
262 | cross(side, forward, up);
263 |
264 | __gluMakeIdentityf(matrix);
265 | matrix.put(0 * 4 + 0, side[0]);
266 | matrix.put(1 * 4 + 0, side[1]);
267 | matrix.put(2 * 4 + 0, side[2]);
268 |
269 | matrix.put(0 * 4 + 1, up[0]);
270 | matrix.put(1 * 4 + 1, up[1]);
271 | matrix.put(2 * 4 + 1, up[2]);
272 |
273 | matrix.put(0 * 4 + 2, -forward[0]);
274 | matrix.put(1 * 4 + 2, -forward[1]);
275 | matrix.put(2 * 4 + 2, -forward[2]);
276 |
277 | glMultMatrixf(matrix);
278 | glTranslatef(-eyex, -eyey, -eyez);
279 | }
280 |
281 | /**
282 | * Method gluProject
283 | *
284 | * @param objx
285 | * @param objy
286 | * @param objz
287 | * @param modelMatrix
288 | * @param projMatrix
289 | * @param viewport
290 | * @param win_pos
291 | */
292 | public static boolean gluProject(
293 | float objx,
294 | float objy,
295 | float objz,
296 | FloatBuffer modelMatrix,
297 | FloatBuffer projMatrix,
298 | IntBuffer viewport,
299 | FloatBuffer win_pos) {
300 |
301 | float[] in = Project.in;
302 | float[] out = Project.out;
303 |
304 | in[0] = objx;
305 | in[1] = objy;
306 | in[2] = objz;
307 | in[3] = 1.0f;
308 |
309 | __gluMultMatrixVecf(modelMatrix, in, out);
310 | __gluMultMatrixVecf(projMatrix, out, in);
311 |
312 | if (in[3] == 0.0)
313 | return false;
314 |
315 | in[3] = (1.0f / in[3]) * 0.5f;
316 |
317 | // Map x, y and z to range 0-1
318 | in[0] = in[0] * in[3] + 0.5f;
319 | in[1] = in[1] * in[3] + 0.5f;
320 | in[2] = in[2] * in[3] + 0.5f;
321 |
322 | // Map x,y to viewport
323 | win_pos.put(0, in[0] * viewport.get(viewport.position() + 2) + viewport.get(viewport.position() + 0));
324 | win_pos.put(1, in[1] * viewport.get(viewport.position() + 3) + viewport.get(viewport.position() + 1));
325 | win_pos.put(2, in[2]);
326 |
327 | return true;
328 | }
329 |
330 | /**
331 | * Method gluUnproject
332 | *
333 | * @param winx
334 | * @param winy
335 | * @param winz
336 | * @param modelMatrix
337 | * @param projMatrix
338 | * @param viewport
339 | * @param obj_pos
340 | */
341 | public static boolean gluUnProject(
342 | float winx,
343 | float winy,
344 | float winz,
345 | FloatBuffer modelMatrix,
346 | FloatBuffer projMatrix,
347 | IntBuffer viewport,
348 | FloatBuffer obj_pos) {
349 | float[] in = Project.in;
350 | float[] out = Project.out;
351 |
352 | __gluMultMatricesf(modelMatrix, projMatrix, finalMatrix);
353 |
354 | if (!__gluInvertMatrixf(finalMatrix, finalMatrix))
355 | return false;
356 |
357 | in[0] = winx;
358 | in[1] = winy;
359 | in[2] = winz;
360 | in[3] = 1.0f;
361 |
362 | // Map x and y from window coordinates
363 | in[0] = (in[0] - viewport.get(viewport.position() + 0)) / viewport.get(viewport.position() + 2);
364 | in[1] = (in[1] - viewport.get(viewport.position() + 1)) / viewport.get(viewport.position() + 3);
365 |
366 | // Map to range -1 to 1
367 | in[0] = in[0] * 2 - 1;
368 | in[1] = in[1] * 2 - 1;
369 | in[2] = in[2] * 2 - 1;
370 |
371 | __gluMultMatrixVecf(finalMatrix, in, out);
372 |
373 | if (out[3] == 0.0)
374 | return false;
375 |
376 | out[3] = 1.0f / out[3];
377 |
378 | obj_pos.put(obj_pos.position() + 0, out[0] * out[3]);
379 | obj_pos.put(obj_pos.position() + 1, out[1] * out[3]);
380 | obj_pos.put(obj_pos.position() + 2, out[2] * out[3]);
381 |
382 | return true;
383 | }
384 |
385 | /**
386 | * Method gluPickMatrix
387 | *
388 | * @param x
389 | * @param y
390 | * @param deltaX
391 | * @param deltaY
392 | * @param viewport
393 | */
394 | public static void gluPickMatrix(
395 | float x,
396 | float y,
397 | float deltaX,
398 | float deltaY,
399 | IntBuffer viewport) {
400 | if (deltaX <= 0 || deltaY <= 0) {
401 | return;
402 | }
403 |
404 | /* Translate and scale the picked region to the entire window */
405 | glTranslatef(
406 | (viewport.get(viewport.position() + 2) - 2 * (x - viewport.get(viewport.position() + 0))) / deltaX,
407 | (viewport.get(viewport.position() + 3) - 2 * (y - viewport.get(viewport.position() + 1))) / deltaY,
408 | 0);
409 | glScalef(viewport.get(viewport.position() + 2) / deltaX, viewport.get(viewport.position() + 3) / deltaY, 1.0f);
410 | }
411 | }
--------------------------------------------------------------------------------