简体   繁体   English

IntelliJ中的LWJGL控制器

[英]LWJGL Controllers in IntelliJ

Every time I try to build a basic example program for using LWJGL controllers, it crashes. 每次我尝试构建使用LWJGL控制器的基本示例程序时,它都会崩溃。 Here's the code: 这是代码:

package com.czipperz.blogspot.tests.controllers;


import org.lwjgl.LWJGLException;
import org.lwjgl.input.Controller;
import org.lwjgl.input.Controllers;

/**
 * Created by Chris on 10/23/2014.
 */
public class Main {
//left joystick x and y
private float x, y,
//right joystick x and y.  Like the commas?
              rx, ry;
//This Controller object MUST BE org.lwjgl.input.Controller NOT net.java.games.input.Controller
private Controller c;
private boolean start;

public static final int BUTTON_A = 1, BUTTON_B = 2, BUTTON_X = 3, BUTTON_Y = 4,
                        BUTTON_LEFT_BUMPER = 5, BUTTON_RIGHT_BUMPER = 6, BUTTON_SELECT = 7, BUTTON_START = 8,
                        //When you PRESS the joysticks (click)
                        BUTTON_LEFT_JOYSTICK = 9, BUTTON_RIGHT_JOYSTICK = 10;

public static void main(String[] args) {
    new Main();
}

public Main() {
    //Says, find controllers and store them in the Controllers class to JInput. Dont worry bout it.
    try {
        Controllers.create();
    } catch (LWJGLException e) {
        e.printStackTrace();
    }
    // Gets you a shiny "new" controller instance.
    // Think of index like you would think of an array.
    c = Controllers.getController(0);

    //Sets "deadband"
    float dead = .06f;
    c.setXAxisDeadZone(dead);
    c.setYAxisDeadZone(dead);
    c.setRXAxisDeadZone(dead);
    c.setRYAxisDeadZone(dead);

    //Using the controller requires you to call the poll() function to receive new data.
    c.poll();
    x = c.getXAxisValue();
    y = c.getYAxisValue();
    rx = c.getRXAxisValue();
    ry = c.getRYAxisDeadZone();
    //NOTE: getZAxisValue(), getRZAxisValue(), getZAxisDeadZone(), getRZAxisDeadZone() DO NOT WORK

    //DPAD = POV
    float povx = c.getPovX();
    float povy = c.getPovY();

    boolean lbumper = c.isButtonPressed(BUTTON_LEFT_BUMPER);
}
}

The problem is that every time I build, this is the log: (Sorry I just can't hit space that many times) 问题在于,每次构建时,都会出现以下日志:(对不起,我无法多次击中空间)

"C:\Program Files\Java\jdk1.8.0_25\bin\java" -Didea.launcher.port=7533 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains IntelliJ IDEA Community Edition 13.1.5\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_25\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\zipfs.jar;C:\Users\Chris\workspace\Controllers\out\production\Controllers;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lzma.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\jinput.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl_test.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl_util.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl-debug.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\asm-debug-all.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\lwjgl_util_applet.jar;C:\Users\Chris\workspace\lwjgl-2.9.1\jar\AppleJavaExtensions.jar;C:\Program Files (x86)\JetBrains IntelliJ IDEA Community Edition 13.1.5\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.czipperz.blogspot.tests.controllers.Main
WARNING: Found unknown Windows version: Windows 8.1
Attempting to use default windows plug-in.
Loading: net.java.games.input.DirectAndRawInputEnvironmentPlugin
java.lang.UnsatisfiedLinkError: no jinput-dx8_64 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1119)
at net.java.games.input.DirectInputEnvironmentPlugin$1.run(DirectInputEnvironmentPlugin.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at          net.java.games.input.DirectInputEnvironmentPlugin.loadLibrary(DirectInputEnvironmentPlugin.java:67)
at net.java.games.input.DirectInputEnvironmentPlugin.<clinit>(DirectInputEnvironmentPlugin.java:109)
at net.java.games.input.DirectAndRawInputEnvironmentPlugin.<init>(DirectAndRawInputEnvironmentPlugin.java:45)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Class.newInstance(Class.java:438)
at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:157)
at org.lwjgl.input.Controllers.create(Controllers.java:71)
at com.czipperz.blogspot.tests.controllers.Main.<init>(Main.java:32)
at com.czipperz.blogspot.tests.controllers.Main.main(Main.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
java.lang.UnsatisfiedLinkError: no jinput-raw_64 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1119)
at net.java.games.input.RawInputEnvironmentPlugin$1.run(RawInputEnvironmentPlugin.java:75)
at java.security.AccessController.doPrivileged(Native Method)
at net.java.games.input.RawInputEnvironmentPlugin.loadLibrary(RawInputEnvironmentPlugin.java:67)
at net.java.games.input.RawInputEnvironmentPlugin.<clinit>(RawInputEnvironmentPlugin.java:109)
at net.java.games.input.DirectAndRawInputEnvironmentPlugin.<init>    (DirectAndRawInputEnvironmentPlugin.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Class.newInstance(Class.java:438)
at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:157)
at org.lwjgl.input.Controllers.create(Controllers.java:71)
at com.czipperz.blogspot.tests.controllers.Main.<init>(Main.java:32)
at com.czipperz.blogspot.tests.controllers.Main.main(Main.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at org.lwjgl.input.Controllers.getController(Controllers.java:116)
at com.czipperz.blogspot.tests.controllers.Main.<init>(Main.java:38)
at com.czipperz.blogspot.tests.controllers.Main.main(Main.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
net.java.games.input.DirectAndRawInputEnvironmentPlugin is not supported

Process finished with exit code 1

I know this thread is old, but for people who are searching for the solution. 我知道这个线程很旧,但是对于正在寻找解决方案的人们来说。 The answer is, you have to include the native libs to your project. 答案是,您必须在项目中包含本机库。 For the use of jinput.jar you have to include following libs: 为了使用jinput.jar,您必须包括以下库:

  • jinput-dx8.dll jinput-dx8.dll
  • jinput-dx8_64.dll jinput-dx8_64.dll
  • jinput-raw.dll jinput-raw.dll
  • jinput-raw_64.dll jinput-raw_64.dll

You can download the natives here DOWNLOAD . 您可以在此处下载本地人。

  1. You will get a jar-file. 您将得到一个jar文件。 Unzip the file with winrar to get the dll-files. 使用winrar解压缩文件以获取dll文件。
  2. Now go to project and open the context menu with a click on the right mouse button -> Build Path -> Configure Build Path -> Choose the Libraries tab -> Click on the little arrow next to the jinput.jar to expand the view -> Make a double click with the left mouse button on Native library location -> Choose the directory of the dll-files. 现在转到项目,然后单击鼠标右键->构建路径->配置构建路径->选择库选项卡->单击jinput.jar旁边的小箭头以展开视图- >在本机库位置上用鼠标左键双击->选择dll文件的目录。
  3. Confirm the dialogs and try to run your program again. 确认对话框,然后尝试再次运行程序。

In LWJGL there is a "native/" folder containing the respective native libraries for each platform/OS. 在LWJGL中,有一个“本地/”文件夹,其中包含每个平台/ OS的相应本机库。 Just choose your platform and set java.library.path to that directory. 只需选择您的平台并将java.library.path设置到该目录即可。 This is your problem. 这是你的问题。

First Step: Create a folder and rename it to LWGJL_New then in that folder create two other folders and rename the first on libs and the second one natives. 第一步:创建一个文件夹并将其重命名为LWGJL_New,然后在该文件夹中创建另外两个文件夹,并将第一个文件夹重命名为libs,将第二个命名为natives。 Now go to the LWGJL library that you have downloaded. 现在转到已下载的LWGJL库。 Copy the jar files to LWGJL_New/libs. 将jar文件复制到LWGJL_New / libs。 Then go to the LWGJL library that you have downloaded, in it, there is a folder containing respective native libraries for each platform/OS. 然后转到已下载的LWGJL库,其中有一个文件夹,其中包含每个平台/ OS的相应本机库。 Choose one of them that you need and copy it to LWGJL_New/natives. 从中选择所需的一种,然后将其复制到LWGJL_New / natives。

Second step: Go to the module settings of your project(F4) then click library.Click add sign(+).Click on java. 第二步:转到项目的模块设置(F4),然后单击库。单击添加符号(+)。单击Java。 Now find the LWGJL_New folder and in it click on the jar folder and click ok. 现在找到LWGJL_New文件夹,在其中单击jar文件夹,然后单击“确定”。 Then Click on Apply and ok. 然后单击“应用”,然后单击确定。

Third step: Now if you run your project you will occur that problem, So go to the Edit Configuration part 第三步:现在,如果您运行项目,则会出现该问题,因此请转到“编辑配置”部分 菜单

Then in VM options write this: 然后在VM选项中输入以下内容:

-Djava.library.path="***"

Instead of star signs write the address of the native folder that we have just created. 代替星号,写上我们刚刚创建的本文件夹的地址。

For example -> 例如->

 D:\LWGJL_New\natives\windwos
 D:\LWGJL_New\natives\linux

Then click on OK. 然后单击确定。 Then run your project. 然后运行您的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM