Skip to content

Commit

Permalink
better bridj sugar, filling in some preliminary functionality, fixing…
Browse files Browse the repository at this point in the history
… hmdError function to be more clean
  • Loading branch information
phr00t committed May 7, 2015
1 parent 2db6467 commit ba08774
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 31 deletions.
19 changes: 5 additions & 14 deletions nbproject/build-impl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ is divided into following sections:
</condition>
<condition property="have.sources">
<or>
<available file="${src.resources.dir}"/>
<available file="${src.test.dir}"/>
<available file="${src.dir}"/>
</or>
Expand Down Expand Up @@ -224,7 +223,6 @@ is divided into following sections:
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
<fail unless="src.resources.dir">Must set src.resources.dir</fail>
<fail unless="src.test.dir">Must set src.test.dir</fail>
<fail unless="src.dir">Must set src.dir</fail>
<fail unless="build.dir">Must set build.dir</fail>
Expand All @@ -247,7 +245,7 @@ is divided into following sections:
</target>
<target depends="-init-ap-cmdline-properties" if="ap.supported.internal" name="-init-macrodef-javac-with-processors">
<macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
<attribute default="${src.resources.dir}:${src.test.dir}:${src.dir}" name="srcdir"/>
<attribute default="${src.test.dir}:${src.dir}" name="srcdir"/>
<attribute default="${build.classes.dir}" name="destdir"/>
<attribute default="${javac.classpath}" name="classpath"/>
<attribute default="${javac.processorpath}" name="processorpath"/>
Expand Down Expand Up @@ -288,7 +286,7 @@ is divided into following sections:
</target>
<target depends="-init-ap-cmdline-properties" name="-init-macrodef-javac-without-processors" unless="ap.supported.internal">
<macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
<attribute default="${src.resources.dir}:${src.test.dir}:${src.dir}" name="srcdir"/>
<attribute default="${src.test.dir}:${src.dir}" name="srcdir"/>
<attribute default="${build.classes.dir}" name="destdir"/>
<attribute default="${javac.classpath}" name="classpath"/>
<attribute default="${javac.processorpath}" name="processorpath"/>
Expand Down Expand Up @@ -321,7 +319,7 @@ is divided into following sections:
</target>
<target depends="-init-macrodef-javac-with-processors,-init-macrodef-javac-without-processors" name="-init-macrodef-javac">
<macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-project/3">
<attribute default="${src.resources.dir}:${src.test.dir}:${src.dir}" name="srcdir"/>
<attribute default="${src.test.dir}:${src.dir}" name="srcdir"/>
<attribute default="${build.classes.dir}" name="destdir"/>
<attribute default="${javac.classpath}" name="classpath"/>
<sequential>
Expand Down Expand Up @@ -909,12 +907,11 @@ is divided into following sections:
<include name="*"/>
</dirset>
</pathconvert>
<j2seproject3:depend srcdir="${src.resources.dir}:${src.test.dir}:${src.dir}:${build.generated.subdirs}"/>
<j2seproject3:depend srcdir="${src.test.dir}:${src.dir}:${build.generated.subdirs}"/>
</target>
<target depends="init,deps-jar,-pre-pre-compile,-pre-compile, -copy-persistence-xml,-compile-depend" if="have.sources" name="-do-compile">
<j2seproject3:javac gensrcdir="${build.generated.sources.dir}"/>
<copy todir="${build.classes.dir}">
<fileset dir="${src.resources.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
<fileset dir="${src.test.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
<fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
</copy>
Expand All @@ -937,7 +934,7 @@ is divided into following sections:
<target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single">
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
<j2seproject3:force-recompile/>
<j2seproject3:javac excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}" sourcepath="${src.resources.dir}:${src.test.dir}:${src.dir}"/>
<j2seproject3:javac excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}" sourcepath="${src.test.dir}:${src.dir}"/>
</target>
<target name="-post-compile-single">
<!-- Empty placeholder for easier customization. -->
Expand Down Expand Up @@ -1203,9 +1200,6 @@ is divided into following sections:
<classpath>
<path path="${javac.classpath}"/>
</classpath>
<fileset dir="${src.resources.dir}" excludes="${bug5101868workaround},${excludes}" includes="${includes}">
<filename name="**/*.java"/>
</fileset>
<fileset dir="${src.test.dir}" excludes="${bug5101868workaround},${excludes}" includes="${includes}">
<filename name="**/*.java"/>
</fileset>
Expand All @@ -1219,9 +1213,6 @@ is divided into following sections:
<arg line="${javadoc.endorsed.classpath.cmd.line.arg}"/>
</javadoc>
<copy todir="${dist.javadoc.dir}">
<fileset dir="${src.resources.dir}" excludes="${excludes}" includes="${includes}">
<filename name="**/doc-files/**"/>
</fileset>
<fileset dir="${src.test.dir}" excludes="${excludes}" includes="${includes}">
<filename name="**/doc-files/**"/>
</fileset>
Expand Down
4 changes: 2 additions & 2 deletions nbproject/genfiles.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ build.xml.script.CRC32=79a29eb7
build.xml.stylesheet.CRC32=958a1d3e@1.32.1.45
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=8de14d53
nbproject/build-impl.xml.script.CRC32=125537a9
nbproject/build-impl.xml.data.CRC32=5fa6bc9e
nbproject/build-impl.xml.script.CRC32=3c0e51df
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48
1 change: 0 additions & 1 deletion nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,4 @@ run.test.classpath=\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
src.resources.dir=resources
src.test.dir=test
1 change: 0 additions & 1 deletion nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>JMonkeyVR</name>
<source-roots>
<root id="src.resources.dir" name="Resources"/>
<root id="src.test.dir"/>
<root id="src.dir"/>
</source-roots>
Expand Down
26 changes: 15 additions & 11 deletions src/jmevr/input/OpenVR.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import openvr_api.IVRSystem;
import openvr_api.Openvr_apiLibrary;
import org.bridj.Pointer;
import org.bridj.Pointer.StringType;
import org.bridj.PointerIO;

/**
*
Expand All @@ -23,23 +21,27 @@ public class OpenVR implements VRHMD {
private static IVRSystem vrsystem;
private static boolean forceInitialize = false;

private static Pointer hmdDeviceIndex;
private static Pointer hmdErrorStore;

@Override
public String getName() {
return "OpenVR";
}

@Override
public boolean initialize() {
Pointer l = Pointer.allocateLong();
Pointer<IVRSystem> pvr = openvr.vRInit(l);
if( pvr != null ) vrsystem = pvr.get();
long res = l.getLong();
if( res != 0 ) {
Pointer str = Pointer.pointerToAddress(openvr.vRGetStringForHmdError(res), (PointerIO)null);
System.out.println("OpenVR Initialize Result: " + str.getString(StringType.C));
hmdErrorStore = Pointer.allocateLong();
Pointer pvr = openvr.vRInit(hmdErrorStore);
if( pvr != null ) vrsystem = (IVRSystem)pvr.get();
if( hmdErrorStore.getLong() != 0 ) {
String errstr = openvr.vRGetStringForHmdError(hmdErrorStore);
System.out.println("OpenVR Initialize Result: " + errstr);
return false;
} else {
System.out.println("OpenVR initialized & VR connected.");
hmdDeviceIndex = Pointer.allocateLong();
hmdDeviceIndex.setLong(Openvr_apiLibrary.k_unTrackedDeviceIndex_Hmd);
return true;
}
}
Expand Down Expand Up @@ -87,7 +89,8 @@ public int getHResolution() {

@Override
public float getFOV() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
if( vrsystem == null ) return 130f;
return vrsystem.getFloatTrackedDeviceProperty(hmdDeviceIndex, Openvr_apiLibrary.TrackedDeviceProperty.Prop_FieldOfViewBottomDegrees_Float, hmdErrorStore);
}

@Override
Expand All @@ -97,7 +100,8 @@ public int getVResolution() {

@Override
public float getInterpupillaryDistance() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
if( vrsystem == null ) return 0.064f;
return vrsystem.getFloatTrackedDeviceProperty(hmdDeviceIndex, Openvr_apiLibrary.TrackedDeviceProperty.Prop_UserIpdMeters_Float, hmdErrorStore);
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions src/openvr_api/Openvr_apiLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import org.bridj.BridJ;
import org.bridj.IntValuedEnum;
import org.bridj.Pointer;
import org.bridj.Pointer.StringType;
import org.bridj.PointerIO;
import org.bridj.ann.Library;
import org.bridj.ann.Name;
Expand Down Expand Up @@ -56,8 +57,8 @@ public Pointer<IVRSystem > vRInit(Pointer<IOpenvr_api.HmdError > peError) {
* <i>native declaration : /usr/include/stdint.h:1357</i>
*/
@Name("VR_GetStringForHmdError")
public Pointer<Byte > vRGetStringForHmdError(Pointer<IOpenvr_api.HmdError> error) {
return (Pointer)Pointer.pointerToAddress(vRGetStringForHmdError(Pointer.getPeer(error)), Byte.class, null);
public String vRGetStringForHmdError(Pointer error) {
return ((Pointer)Pointer.pointerToAddress(vRGetStringForHmdError(error.getLong()), Byte.class, null)).getString(StringType.C);
}
@Name("VR_GetStringForHmdError")
@Ptr
Expand Down

0 comments on commit ba08774

Please sign in to comment.