From 1333673bb502e3afd08be6d55f7da718f73c21e9 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 1 Sep 2003 12:45:47 +0000 Subject: [PATCH] More vector fixes by cfmdobbie --- src/java/org/lwjgl/vector/Matrix3f.java | 37 ++++++++------ src/java/org/lwjgl/vector/Matrix4f.java | 53 +++++++++++--------- src/native/Makefile.am | 1 - src/native/acinclude.m4 | 66 +++++++++++++++++++++++++ src/native/autogen.sh | 5 +- src/native/configure.in | 11 ++++- 6 files changed, 129 insertions(+), 44 deletions(-) create mode 100644 src/native/acinclude.m4 diff --git a/src/java/org/lwjgl/vector/Matrix3f.java b/src/java/org/lwjgl/vector/Matrix3f.java index 51922f44..cdc00caf 100644 --- a/src/java/org/lwjgl/vector/Matrix3f.java +++ b/src/java/org/lwjgl/vector/Matrix3f.java @@ -330,22 +330,27 @@ public class Matrix3f extends Matrix implements Serializable { * @return the transposed matrix */ public Matrix3f transpose(Matrix3f dest) { - if (dest == null) { - dest = new Matrix3f(); - dest.m00 = m00; - dest.m01 = m10; - dest.m02 = m20; - dest.m10 = m01; - dest.m11 = m11; - dest.m12 = m21; - dest.m20 = m02; - dest.m21 = m12; - dest.m22 = m22; - return dest; - } else { - transpose(); - return this; - } + if (dest == null) { + // New matrix needed to store transpose + dest = new Matrix3f(); + } + if (this == dest) { + // Destination and source are the same! Run the in-place + // transpose instead as the copy transpose will be destructive. + transpose(); + } else { + // Destination differs from source. Perform copy transpose + dest.m00 = m00; + dest.m01 = m10; + dest.m02 = m20; + dest.m10 = m01; + dest.m11 = m11; + dest.m12 = m21; + dest.m20 = m02; + dest.m21 = m12; + dest.m22 = m22; + } + return dest; } /** diff --git a/src/java/org/lwjgl/vector/Matrix4f.java b/src/java/org/lwjgl/vector/Matrix4f.java index c46923db..93dd97eb 100644 --- a/src/java/org/lwjgl/vector/Matrix4f.java +++ b/src/java/org/lwjgl/vector/Matrix4f.java @@ -635,30 +635,35 @@ public class Matrix4f extends Matrix implements Serializable { * @return the transposed matrix */ public Matrix4f transpose(Matrix4f dest) { - if (dest == null) { - dest = new Matrix4f(); - dest.m00 = m00; - dest.m01 = m10; - dest.m02 = m20; - dest.m03 = m30; - dest.m10 = m01; - dest.m11 = m11; - dest.m12 = m21; - dest.m13 = m31; - dest.m20 = m02; - dest.m21 = m12; - dest.m22 = m22; - dest.m23 = m32; - dest.m30 = m03; - dest.m31 = m13; - dest.m32 = m23; - dest.m33 = m33; - return dest; - } else { - transpose(); - return this; - } - } + if (dest == null) { + // New matrix needed to store transpose + dest = new Matrix4f(); + } + if (this == dest) { + // Destination and source are the same! Run the in-place + // transpose instead as the copy transpose will be destructive. + transpose(); + } else { + // Destination differs from source. Perform copy transpose + dest.m00 = m00; + dest.m01 = m10; + dest.m02 = m20; + dest.m03 = m30; + dest.m10 = m01; + dest.m11 = m11; + dest.m12 = m21; + dest.m13 = m31; + dest.m20 = m02; + dest.m21 = m12; + dest.m22 = m22; + dest.m23 = m32; + dest.m30 = m03; + dest.m31 = m13; + dest.m32 = m23; + dest.m33 = m33; + } + return dest; + } /** * @return the determinant of the matrix diff --git a/src/native/Makefile.am b/src/native/Makefile.am index 0dfab6db..96aca240 100644 --- a/src/native/Makefile.am +++ b/src/native/Makefile.am @@ -1,4 +1,3 @@ SUBDIRS = common linux lib_LTLIBRARIES = liblwjgl.la -liblwjgl_LDADD diff --git a/src/native/acinclude.m4 b/src/native/acinclude.m4 new file mode 100644 index 00000000..ca7ca14a --- /dev/null +++ b/src/native/acinclude.m4 @@ -0,0 +1,66 @@ +dnl Available from the GNU Autoconf Macro Archive at: +dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_jni_include_dirs.html +dnl +AC_DEFUN(AC_JNI_INCLUDE_DIR,[ + +JNI_INCLUDE_DIRS="" + +test "x$JAVAC" = x && JAVAC=javac +AC_PATH_PROG(_ACJNI_JAVAC, $JAVAC, no) +test "x$_ACJNI_JAVAC" = xno && AC_MSG_ERROR([$JAVAC could not be found in path]) + +_ACJNI_FOLLOW_SYMLINKS("$_ACJNI_JAVAC") +_JTOPDIR=`echo "$_ACJNI_FOLLOWED" | sed -e 's://*:/:g' -e 's:/[[^/]]*$::'` +case "$host_os" in + darwin*) _JTOPDIR=`echo "$_JTOPDIR" | sed -e 's:/[[^/]]*$::'` + _JINC="$_JTOPDIR/Headers";; + *) _JINC="$_JTOPDIR/include";; +esac +if test -f "$_JINC/jni.h"; then + JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $_JINC" +else + _JTOPDIR=`echo "$_JTOPDIR" | sed -e 's:/[[^/]]*$::'` + if test -f "$_JTOPDIR/include/jni.h"; then + JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $_JTOPDIR/include" + else + AC_MSG_ERROR([cannot find java include files]) + fi +fi + +# get the likely subdirectories for system specific java includes +case "$host_os" in +bsdi*) _JNI_INC_SUBDIRS="bsdos";; +linux*) _JNI_INC_SUBDIRS="linux genunix";; +osf*) _JNI_INC_SUBDIRS="alpha";; +solaris*) _JNI_INC_SUBDIRS="solaris";; +*) _JNI_INC_SUBDIRS="genunix";; +esac + +# add any subdirectories that are present +for JINCSUBDIR in $_JNI_INC_SUBDIRS +do + if test -d "$_JTOPDIR/include/$JINCSUBDIR"; then + JNI_INCLUDE_DIRS="$JNI_INCLUDE_DIRS $_JTOPDIR/include/$JINCSUBDIR" + fi +done +]) + +# _ACJNI_FOLLOW_SYMLINKS +# Follows symbolic links on , +# finally setting variable _ACJNI_FOLLOWED +# -------------------- +AC_DEFUN(_ACJNI_FOLLOW_SYMLINKS,[ +# find the include directory relative to the javac executable +_cur="$1" +while ls -ld "$_cur" 2>/dev/null | grep " -> " >/dev/null; do + AC_MSG_CHECKING(symlink for $_cur) + _slink=`ls -ld "$_cur" | sed 's/.* -> //'` + case "$_slink" in + /*) _cur="$_slink";; + # 'X' avoids triggering unwanted echo options. + *) _cur=`echo "X$_cur" | sed -e 's/^X//' -e 's:[[^/]]*$::'`"$_slink";; + esac + AC_MSG_RESULT($_cur) +done +_ACJNI_FOLLOWED="$_cur" +])# _ACJNI diff --git a/src/native/autogen.sh b/src/native/autogen.sh index 0d3ba69a..fc3cc728 100755 --- a/src/native/autogen.sh +++ b/src/native/autogen.sh @@ -2,7 +2,8 @@ #WANT_AUTOMAKE_1_5=1 #autoheader linux -libtoolize --force aclocal -automake --foreign --include-deps --add-missing --copy +autoheader +libtoolize --force autoconf +automake --foreign --include-deps --add-missing --copy diff --git a/src/native/configure.in b/src/native/configure.in index ce1194e5..91b03315 100644 --- a/src/native/configure.in +++ b/src/native/configure.in @@ -5,6 +5,7 @@ AC_PREREQ(2.57) AC_INIT AM_INIT_AUTOMAKE(LWJGL, 0.7) AC_CONFIG_SRCDIR([autogen.sh]) +AM_CONFIG_HEADER([config.h]) AC_DISABLE_STATIC AC_LIBTOOL_DLOPEN @@ -24,7 +25,15 @@ AC_PROG_LIBTOOL # Checks for header files. AC_PATH_X AC_HEADER_STDC -AC_CHECK_HEADERS([stddef.h stdlib.h string.h sys/time.h]) + +AC_JNI_INCLUDE_DIR + +for JNI_INCLUDE_DIR in $JNI_INCLUDE_DIRS +do + CPPFLAGS="$CPPFLAGS -I$JNI_INCLUDE_DIR" +done + +AC_CHECK_HEADER([stddef.h stdlib.h string.h sys/time.h]) # Checks for typedefs, structures, and compiler characteristics. AC_HEADER_STDBOOL