removing parts of Math
removing examples removed small doc
|
@ -1 +0,0 @@
|
|||
Lightweight Java Game Library Javadocs
|
Before Width: | Height: | Size: 40 KiB |
Before Width: | Height: | Size: 125 KiB |
Before Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 41 KiB |
BIN
res/data/mud.png
Before Width: | Height: | Size: 126 KiB |
Before Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 8.4 KiB |
BIN
res/data/tim.png
Before Width: | Height: | Size: 102 KiB |
Before Width: | Height: | Size: 7.6 KiB |
|
@ -1,160 +0,0 @@
|
|||
|
||||
NUMPOLLIES 36
|
||||
|
||||
// Floor 1
|
||||
-3.0 0.0 -3.0 0.0 6.0
|
||||
-3.0 0.0 3.0 0.0 0.0
|
||||
3.0 0.0 3.0 6.0 0.0
|
||||
|
||||
-3.0 0.0 -3.0 0.0 6.0
|
||||
3.0 0.0 -3.0 6.0 6.0
|
||||
3.0 0.0 3.0 6.0 0.0
|
||||
|
||||
// Ceiling 1
|
||||
-3.0 1.0 -3.0 0.0 6.0
|
||||
-3.0 1.0 3.0 0.0 0.0
|
||||
3.0 1.0 3.0 6.0 0.0
|
||||
-3.0 1.0 -3.0 0.0 6.0
|
||||
3.0 1.0 -3.0 6.0 6.0
|
||||
3.0 1.0 3.0 6.0 0.0
|
||||
|
||||
// A1
|
||||
|
||||
-2.0 1.0 -2.0 0.0 1.0
|
||||
-2.0 0.0 -2.0 0.0 0.0
|
||||
-0.5 0.0 -2.0 1.5 0.0
|
||||
-2.0 1.0 -2.0 0.0 1.0
|
||||
-0.5 1.0 -2.0 1.5 1.0
|
||||
-0.5 0.0 -2.0 1.5 0.0
|
||||
|
||||
// A2
|
||||
|
||||
2.0 1.0 -2.0 2.0 1.0
|
||||
2.0 0.0 -2.0 2.0 0.0
|
||||
0.5 0.0 -2.0 0.5 0.0
|
||||
2.0 1.0 -2.0 2.0 1.0
|
||||
0.5 1.0 -2.0 0.5 1.0
|
||||
0.5 0.0 -2.0 0.5 0.0
|
||||
|
||||
// B1
|
||||
|
||||
-2.0 1.0 2.0 2.0 1.0
|
||||
-2.0 0.0 2.0 2.0 0.0
|
||||
-0.5 0.0 2.0 0.5 0.0
|
||||
-2.0 1.0 2.0 2.0 1.0
|
||||
-0.5 1.0 2.0 0.5 1.0
|
||||
-0.5 0.0 2.0 0.5 0.0
|
||||
|
||||
// B2
|
||||
|
||||
2.0 1.0 2.0 2.0 1.0
|
||||
2.0 0.0 2.0 2.0 0.0
|
||||
0.5 0.0 2.0 0.5 0.0
|
||||
2.0 1.0 2.0 2.0 1.0
|
||||
0.5 1.0 2.0 0.5 1.0
|
||||
0.5 0.0 2.0 0.5 0.0
|
||||
|
||||
// C1
|
||||
|
||||
-2.0 1.0 -2.0 0.0 1.0
|
||||
-2.0 0.0 -2.0 0.0 0.0
|
||||
-2.0 0.0 -0.5 1.5 0.0
|
||||
-2.0 1.0 -2.0 0.0 1.0
|
||||
-2.0 1.0 -0.5 1.5 1.0
|
||||
-2.0 0.0 -0.5 1.5 0.0
|
||||
|
||||
// C2
|
||||
|
||||
-2.0 1.0 2.0 2.0 1.0
|
||||
-2.0 0.0 2.0 2.0 0.0
|
||||
-2.0 0.0 0.5 0.5 0.0
|
||||
-2.0 1.0 2.0 2.0 1.0
|
||||
-2.0 1.0 0.5 0.5 1.0
|
||||
-2.0 0.0 0.5 0.5 0.0
|
||||
|
||||
// D1
|
||||
|
||||
2.0 1.0 -2.0 0.0 1.0
|
||||
2.0 0.0 -2.0 0.0 0.0
|
||||
2.0 0.0 -0.5 1.5 0.0
|
||||
2.0 1.0 -2.0 0.0 1.0
|
||||
2.0 1.0 -0.5 1.5 1.0
|
||||
2.0 0.0 -0.5 1.5 0.0
|
||||
|
||||
// D2
|
||||
|
||||
2.0 1.0 2.0 2.0 1.0
|
||||
2.0 0.0 2.0 2.0 0.0
|
||||
2.0 0.0 0.5 0.5 0.0
|
||||
2.0 1.0 2.0 2.0 1.0
|
||||
2.0 1.0 0.5 0.5 1.0
|
||||
2.0 0.0 0.5 0.5 0.0
|
||||
|
||||
// Upper hallway - L
|
||||
-0.5 1.0 -3.0 0.0 1.0
|
||||
-0.5 0.0 -3.0 0.0 0.0
|
||||
-0.5 0.0 -2.0 1.0 0.0
|
||||
-0.5 1.0 -3.0 0.0 1.0
|
||||
-0.5 1.0 -2.0 1.0 1.0
|
||||
-0.5 0.0 -2.0 1.0 0.0
|
||||
|
||||
// Upper hallway - R
|
||||
0.5 1.0 -3.0 0.0 1.0
|
||||
0.5 0.0 -3.0 0.0 0.0
|
||||
0.5 0.0 -2.0 1.0 0.0
|
||||
0.5 1.0 -3.0 0.0 1.0
|
||||
0.5 1.0 -2.0 1.0 1.0
|
||||
0.5 0.0 -2.0 1.0 0.0
|
||||
|
||||
// Lower hallway - L
|
||||
-0.5 1.0 3.0 0.0 1.0
|
||||
-0.5 0.0 3.0 0.0 0.0
|
||||
-0.5 0.0 2.0 1.0 0.0
|
||||
-0.5 1.0 3.0 0.0 1.0
|
||||
-0.5 1.0 2.0 1.0 1.0
|
||||
-0.5 0.0 2.0 1.0 0.0
|
||||
|
||||
// Lower hallway - R
|
||||
0.5 1.0 3.0 0.0 1.0
|
||||
0.5 0.0 3.0 0.0 0.0
|
||||
0.5 0.0 2.0 1.0 0.0
|
||||
0.5 1.0 3.0 0.0 1.0
|
||||
0.5 1.0 2.0 1.0 1.0
|
||||
0.5 0.0 2.0 1.0 0.0
|
||||
|
||||
|
||||
// Left hallway - Lw
|
||||
|
||||
-3.0 1.0 0.5 1.0 1.0
|
||||
-3.0 0.0 0.5 1.0 0.0
|
||||
-2.0 0.0 0.5 0.0 0.0
|
||||
-3.0 1.0 0.5 1.0 1.0
|
||||
-2.0 1.0 0.5 0.0 1.0
|
||||
-2.0 0.0 0.5 0.0 0.0
|
||||
|
||||
// Left hallway - Hi
|
||||
|
||||
-3.0 1.0 -0.5 1.0 1.0
|
||||
-3.0 0.0 -0.5 1.0 0.0
|
||||
-2.0 0.0 -0.5 0.0 0.0
|
||||
-3.0 1.0 -0.5 1.0 1.0
|
||||
-2.0 1.0 -0.5 0.0 1.0
|
||||
-2.0 0.0 -0.5 0.0 0.0
|
||||
|
||||
// Right hallway - Lw
|
||||
|
||||
3.0 1.0 0.5 1.0 1.0
|
||||
3.0 0.0 0.5 1.0 0.0
|
||||
2.0 0.0 0.5 0.0 0.0
|
||||
3.0 1.0 0.5 1.0 1.0
|
||||
2.0 1.0 0.5 0.0 1.0
|
||||
2.0 0.0 0.5 0.0 0.0
|
||||
|
||||
// Right hallway - Hi
|
||||
|
||||
3.0 1.0 -0.5 1.0 1.0
|
||||
3.0 0.0 -0.5 1.0 0.0
|
||||
2.0 0.0 -0.5 0.0 0.0
|
||||
3.0 1.0 -0.5 1.0 1.0
|
||||
2.0 1.0 -0.5 0.0 1.0
|
||||
2.0 0.0 -0.5 0.0 0.0
|
|
@ -56,677 +56,6 @@ public final class Math {
|
|||
/** Floating point version of pi */
|
||||
public static final float PI = (float) java.lang.Math.PI;
|
||||
|
||||
/*
|
||||
* Unary matrix operations
|
||||
*/
|
||||
private static abstract class UnaryMatrixOperation {
|
||||
private final int enum;
|
||||
private final String name;
|
||||
|
||||
UnaryMatrixOperation(int enum, String name) {
|
||||
this.enum = enum;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
abstract MatrixOpClassification classify();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A matrix operation is unsafe if the source and destination overlap,
|
||||
* and either the strides are not equal, or destination > source, which
|
||||
* would give an undefined result
|
||||
*/
|
||||
private static final MatrixOpClassification MATRIXOP_UNSAFE = new MatrixOpClassification() {
|
||||
protected MatrixOpClassification unsafe() { return this; }
|
||||
protected MatrixOpClassification safe() { return this; }
|
||||
protected MatrixOpClassification direct() { return this; }
|
||||
boolean isSafe() { return false; }
|
||||
|
||||
void execute(
|
||||
int leftSourceAddress,
|
||||
int leftSourceStride,
|
||||
int leftElements,
|
||||
int leftSourceWidth,
|
||||
int leftSourceHeight,
|
||||
boolean transposeLeftSource,
|
||||
int rightSourceAddress,
|
||||
int rightSourceStride,
|
||||
int rightElements,
|
||||
int rightSourceWidth,
|
||||
int rightSourceHeight,
|
||||
boolean transposeRightSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest)
|
||||
{
|
||||
throw new IllegalArgumentException("Unsafe matrix operation.");
|
||||
}
|
||||
|
||||
void execute(
|
||||
int sourceAddress,
|
||||
int sourceStride,
|
||||
int numElements,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
boolean transposeSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest)
|
||||
{
|
||||
throw new IllegalArgumentException("Unsafe matrix operation.");
|
||||
}
|
||||
};
|
||||
|
||||
/** Straight copy */
|
||||
private static final class MatrixOpCopy extends UnaryMatrixOperation {
|
||||
|
||||
MatrixOpCopy() {
|
||||
super(0, "copy");
|
||||
}
|
||||
|
||||
MatrixOpClassification classify() {
|
||||
return MATRIXOP_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unclassified (initial state) matrix operation.
|
||||
*/
|
||||
private final MatrixOpClassification MATRIXOP_NONE = new MatrixOpClassification() {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return MATRIXOP_SAFE; }
|
||||
protected MatrixOpClassification direct() { return MATRIXOP_DIRECT; }
|
||||
boolean isSafe() { return false; }
|
||||
};
|
||||
|
||||
/**
|
||||
* A matrix operation is direct if the source and destination addresses
|
||||
* are the same, and the strides are the same.
|
||||
*/
|
||||
private final class MatrixOpDirect extends MatrixOpClassification {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return this; }
|
||||
protected MatrixOpClassification direct() { return this; }
|
||||
boolean isSafe() { return false; }
|
||||
native void execute(
|
||||
int sourceAddress,
|
||||
int sourceStride,
|
||||
int numElements,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
boolean transposeSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest);
|
||||
};
|
||||
private final MatrixOpDirect MATRIXOP_DIRECT = new MatrixOpDirect();
|
||||
|
||||
/**
|
||||
* A matrix operation is safe if the source and destination do not
|
||||
* overlap in any way
|
||||
*/
|
||||
private final class MatrixOpSafe extends MatrixOpClassification {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return MATRIXOP_SAFE; }
|
||||
protected MatrixOpClassification direct() { return MATRIXOP_DIRECT; }
|
||||
boolean isSafe() { return true; }
|
||||
native void execute(
|
||||
int sourceAddress,
|
||||
int sourceStride,
|
||||
int numElements,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
boolean transposeSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest);
|
||||
};
|
||||
private final MatrixOpSafe MATRIXOP_SAFE = new MatrixOpSafe();
|
||||
};
|
||||
public static final MatrixOpCopy MATRIXOP_COPY = new MatrixOpCopy();
|
||||
|
||||
/** Negate the vector */
|
||||
private static final class MatrixOpNegate extends UnaryMatrixOperation {
|
||||
|
||||
MatrixOpNegate() {
|
||||
super(1, "negate");
|
||||
}
|
||||
|
||||
MatrixOpClassification classify() {
|
||||
return MATRIXOP_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unclassified (initial state) matrix operation.
|
||||
*/
|
||||
private final MatrixOpClassification MATRIXOP_NONE = new MatrixOpClassification() {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return MATRIXOP_SAFE; }
|
||||
protected MatrixOpClassification direct() { return MATRIXOP_DIRECT; }
|
||||
boolean isSafe() { return false; }
|
||||
};
|
||||
|
||||
/**
|
||||
* A matrix operation is direct if the source and destination addresses
|
||||
* are the same, and the strides are the same.
|
||||
*/
|
||||
private final class MatrixOpDirect extends MatrixOpClassification {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return this; }
|
||||
protected MatrixOpClassification direct() { return this; }
|
||||
boolean isSafe() { return false; }
|
||||
native void execute(
|
||||
int sourceAddress,
|
||||
int sourceStride,
|
||||
int numElements,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
boolean transposeSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest);
|
||||
};
|
||||
private final MatrixOpDirect MATRIXOP_DIRECT = new MatrixOpDirect();
|
||||
|
||||
/**
|
||||
* A matrix operation is safe if the source and destination do not
|
||||
* overlap in any way
|
||||
*/
|
||||
private final class MatrixOpSafe extends MatrixOpClassification {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return MATRIXOP_SAFE; }
|
||||
protected MatrixOpClassification direct() { return MATRIXOP_DIRECT; }
|
||||
boolean isSafe() { return true; }
|
||||
native void execute(
|
||||
int sourceAddress,
|
||||
int sourceStride,
|
||||
int numElements,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
boolean transposeSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest);
|
||||
};
|
||||
private final MatrixOpSafe MATRIXOP_SAFE = new MatrixOpSafe();
|
||||
};
|
||||
public static final MatrixOpNegate MATRIXOP_NEGATE = new MatrixOpNegate();
|
||||
|
||||
/** Normalise the vector (set to length 1) */
|
||||
private static final class MatrixOpNormalise extends UnaryMatrixOperation {
|
||||
|
||||
MatrixOpNormalise() {
|
||||
super(2, "normalise");
|
||||
}
|
||||
|
||||
MatrixOpClassification classify() {
|
||||
return MATRIXOP_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unclassified (initial state) matrix operation.
|
||||
*/
|
||||
private final MatrixOpClassification MATRIXOP_NONE = new MatrixOpClassification() {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return MATRIXOP_SAFE; }
|
||||
protected MatrixOpClassification direct() { return MATRIXOP_DIRECT; }
|
||||
boolean isSafe() { return true; }
|
||||
};
|
||||
|
||||
/**
|
||||
* A matrix operation is direct if the source and destination addresses
|
||||
* are the same, and the strides are the same.
|
||||
*/
|
||||
private final class MatrixOpDirect extends MatrixOpClassification {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return this; }
|
||||
protected MatrixOpClassification direct() { return this; }
|
||||
boolean isSafe() { return false; }
|
||||
native void execute(
|
||||
int sourceAddress,
|
||||
int sourceStride,
|
||||
int numElements,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
boolean transposeSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest);
|
||||
};
|
||||
private final MatrixOpDirect MATRIXOP_DIRECT = new MatrixOpDirect();
|
||||
|
||||
/**
|
||||
* A matrix operation is safe if the source and destination do not
|
||||
* overlap in any way
|
||||
*/
|
||||
private final class MatrixOpSafe extends MatrixOpClassification {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return MATRIXOP_SAFE; }
|
||||
protected MatrixOpClassification direct() { return MATRIXOP_DIRECT; }
|
||||
boolean isSafe() { return true; }
|
||||
native void execute(
|
||||
int sourceAddress,
|
||||
int sourceStride,
|
||||
int numElements,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
boolean transposeSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest);
|
||||
};
|
||||
private final MatrixOpSafe MATRIXOP_SAFE = new MatrixOpSafe();
|
||||
};
|
||||
public static final MatrixOpNormalise MATRIXOP_NORMALISE = new MatrixOpNormalise();
|
||||
|
||||
/** Compute the inverse matrix */
|
||||
private static final class MatrixOpInvert extends UnaryMatrixOperation {
|
||||
|
||||
MatrixOpInvert() {
|
||||
super(3, "invert");
|
||||
}
|
||||
|
||||
MatrixOpClassification classify() {
|
||||
return MATRIXOP_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unclassified (initial state) matrix operation.
|
||||
*/
|
||||
private final MatrixOpClassification MATRIXOP_NONE = new MatrixOpClassification() {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return MATRIXOP_SAFE; }
|
||||
protected MatrixOpClassification direct() { return MATRIXOP_DIRECT; }
|
||||
boolean isSafe() { return false; }
|
||||
};
|
||||
|
||||
/**
|
||||
* A matrix operation is direct if the source and destination addresses
|
||||
* are the same, and the strides are the same.
|
||||
*/
|
||||
private final class MatrixOpDirect extends MatrixOpClassification {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return this; }
|
||||
protected MatrixOpClassification direct() { return this; }
|
||||
boolean isSafe() { return false; }
|
||||
native void execute(
|
||||
int sourceAddress,
|
||||
int sourceStride,
|
||||
int numElements,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
boolean transposeSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest);
|
||||
};
|
||||
private final MatrixOpDirect MATRIXOP_DIRECT = new MatrixOpDirect();
|
||||
|
||||
/**
|
||||
* A matrix operation is safe if the source and destination do not
|
||||
* overlap in any way
|
||||
*/
|
||||
private final class MatrixOpSafe extends MatrixOpClassification {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return MATRIXOP_SAFE; }
|
||||
protected MatrixOpClassification direct() { return MATRIXOP_DIRECT; }
|
||||
boolean isSafe() { return true; }
|
||||
native void execute(
|
||||
int sourceAddress,
|
||||
int sourceStride,
|
||||
int numElements,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
boolean transposeSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest);
|
||||
};
|
||||
private final MatrixOpSafe MATRIXOP_SAFE = new MatrixOpSafe();
|
||||
};
|
||||
public static final MatrixOpInvert MATRIXOP_INVERT = new MatrixOpInvert();
|
||||
|
||||
/*
|
||||
* Binary matrix operations
|
||||
*/
|
||||
private static abstract class BinaryMatrixOperation {
|
||||
private final int enum;
|
||||
private final String name;
|
||||
|
||||
BinaryMatrixOperation(int enum, String name) {
|
||||
this.enum = enum;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the compatibility of a binary matrix operation.
|
||||
* @return the miniumum stride, in bytes
|
||||
* @throws IllegalArgumentException if the source and destinations are not
|
||||
* compatible
|
||||
*/
|
||||
abstract int checkCompatibility(
|
||||
int leftSourceWidth,
|
||||
int leftSourceHeight,
|
||||
boolean transposeLeftSource,
|
||||
int rightSourceWidth,
|
||||
int rightSourceHeight,
|
||||
boolean transposeRightSource,
|
||||
boolean transposeDest);
|
||||
|
||||
|
||||
|
||||
abstract MatrixOpClassification classify();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** Multiply left source by right source */
|
||||
private static final class MatrixOpMultiply extends BinaryMatrixOperation {
|
||||
|
||||
MatrixOpMultiply() {
|
||||
super(0, "multiply");
|
||||
}
|
||||
|
||||
int checkCompatibility(
|
||||
int leftSourceWidth,
|
||||
int leftSourceHeight,
|
||||
boolean transposeLeftSource,
|
||||
int rightSourceWidth,
|
||||
int rightSourceHeight,
|
||||
boolean transposeRightSource,
|
||||
boolean transposeDest)
|
||||
{
|
||||
// Left matrix width must be the same as right matrix height.
|
||||
int leftWidth = transposeLeftSource ? leftSourceHeight : leftSourceWidth;
|
||||
int rightHeight = transposeRightSource ? rightSourceWidth : rightSourceHeight;
|
||||
if (leftWidth != rightHeight)
|
||||
throw new IllegalArgumentException("Left and right matrices are not compatible.");
|
||||
int leftHeight = transposeLeftSource ? leftSourceWidth : leftSourceHeight;
|
||||
int rightWidth = transposeRightSource ? rightSourceHeight : rightSourceWidth;
|
||||
return (rightWidth * leftHeight) << 2;
|
||||
}
|
||||
MatrixOpClassification classify() {
|
||||
return MATRIXOP_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unclassified (initial state) matrix operation.
|
||||
*/
|
||||
private final MatrixOpClassification MATRIXOP_NONE = new MatrixOpClassification() {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return MATRIXOP_SAFE; }
|
||||
protected MatrixOpClassification direct() { return MATRIXOP_DIRECT; }
|
||||
boolean isSafe() { return false; }
|
||||
};
|
||||
|
||||
/**
|
||||
* A matrix operation is direct if the source and destination addresses
|
||||
* are the same, and the strides are the same.
|
||||
*/
|
||||
private final class MatrixOpDirect extends MatrixOpClassification {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return this; }
|
||||
protected MatrixOpClassification direct() { return this; }
|
||||
boolean isSafe() { return false; }
|
||||
native void execute(
|
||||
int leftSourceAddress,
|
||||
int leftSourceStride,
|
||||
int leftElements,
|
||||
int leftSourceWidth,
|
||||
int leftSourceHeight,
|
||||
boolean transposeLeftSource,
|
||||
int rightSourceAddress,
|
||||
int rightSourceStride,
|
||||
int rightElements,
|
||||
int rightSourceWidth,
|
||||
int rightSourceHeight,
|
||||
boolean transposeRightSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest);
|
||||
};
|
||||
private final MatrixOpDirect MATRIXOP_DIRECT = new MatrixOpDirect();
|
||||
|
||||
|
||||
/**
|
||||
* A matrix operation is safe if the source and destination do not
|
||||
* overlap in any way
|
||||
*/
|
||||
private final class MatrixOpSafe extends MatrixOpClassification {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return MATRIXOP_SAFE; }
|
||||
protected MatrixOpClassification direct() { return MATRIXOP_DIRECT; }
|
||||
boolean isSafe() { return true; }
|
||||
native void execute(
|
||||
int leftSourceAddress,
|
||||
int leftSourceStride,
|
||||
int leftElements,
|
||||
int leftSourceWidth,
|
||||
int leftSourceHeight,
|
||||
boolean transposeLeftSource,
|
||||
int rightSourceAddress,
|
||||
int rightSourceStride,
|
||||
int rightElements,
|
||||
int rightSourceWidth,
|
||||
int rightSourceHeight,
|
||||
boolean transposeRightSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest);
|
||||
};
|
||||
private final MatrixOpSafe MATRIXOP_SAFE = new MatrixOpSafe();
|
||||
};
|
||||
public static final MatrixOpMultiply MATRIXOP_MULTIPLY = new MatrixOpMultiply();
|
||||
|
||||
/** Add right source to left source */
|
||||
private static final class MatrixOpAdd extends BinaryMatrixOperation {
|
||||
|
||||
MatrixOpAdd() {
|
||||
super(1, "add");
|
||||
}
|
||||
|
||||
int checkCompatibility(
|
||||
int leftSourceWidth,
|
||||
int leftSourceHeight,
|
||||
boolean transposeLeftSource,
|
||||
int rightSourceWidth,
|
||||
int rightSourceHeight,
|
||||
boolean transposeRightSource,
|
||||
boolean transposeDest)
|
||||
{
|
||||
if (transposeLeftSource == transposeRightSource) {
|
||||
// Left and right must be the same size
|
||||
if (leftSourceWidth != rightSourceWidth || leftSourceHeight != rightSourceHeight)
|
||||
throw new IllegalArgumentException("Left and right matrices are not the same size.");
|
||||
} else {
|
||||
// Left and right must be the same size but one of them is transposed
|
||||
if (leftSourceWidth != rightSourceHeight || leftSourceHeight != rightSourceWidth)
|
||||
throw new IllegalArgumentException("Left and right matrices are not the same size.");
|
||||
}
|
||||
return (leftSourceWidth * leftSourceHeight) << 2;
|
||||
}
|
||||
|
||||
MatrixOpClassification classify() {
|
||||
return MATRIXOP_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unclassified (initial state) matrix operation.
|
||||
*/
|
||||
private final MatrixOpClassification MATRIXOP_NONE = new MatrixOpClassification() {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return MATRIXOP_SAFE; }
|
||||
protected MatrixOpClassification direct() { return MATRIXOP_DIRECT; }
|
||||
boolean isSafe() { return false; }
|
||||
};
|
||||
|
||||
/**
|
||||
* A matrix operation is direct if the source and destination addresses
|
||||
* are the same, and the strides are the same.
|
||||
*/
|
||||
private final class MatrixOpDirect extends MatrixOpClassification {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return this; }
|
||||
protected MatrixOpClassification direct() { return this; }
|
||||
boolean isSafe() { return false; }
|
||||
native void execute(
|
||||
int leftSourceAddress,
|
||||
int leftSourceStride,
|
||||
int leftElements,
|
||||
int leftSourceWidth,
|
||||
int leftSourceHeight,
|
||||
boolean transposeLeftSource,
|
||||
int rightSourceAddress,
|
||||
int rightSourceStride,
|
||||
int rightElements,
|
||||
int rightSourceWidth,
|
||||
int rightSourceHeight,
|
||||
boolean transposeRightSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest);
|
||||
};
|
||||
private final MatrixOpDirect MATRIXOP_DIRECT = new MatrixOpDirect();
|
||||
|
||||
|
||||
/**
|
||||
* A matrix operation is safe if the source and destination do not
|
||||
* overlap in any way
|
||||
*/
|
||||
private final class MatrixOpSafe extends MatrixOpClassification {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return MATRIXOP_SAFE; }
|
||||
protected MatrixOpClassification direct() { return MATRIXOP_DIRECT; }
|
||||
boolean isSafe() { return true; }
|
||||
native void execute(
|
||||
int leftSourceAddress,
|
||||
int leftSourceStride,
|
||||
int leftElements,
|
||||
int leftSourceWidth,
|
||||
int leftSourceHeight,
|
||||
boolean transposeLeftSource,
|
||||
int rightSourceAddress,
|
||||
int rightSourceStride,
|
||||
int rightElements,
|
||||
int rightSourceWidth,
|
||||
int rightSourceHeight,
|
||||
boolean transposeRightSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest);
|
||||
};
|
||||
private final MatrixOpSafe MATRIXOP_SAFE = new MatrixOpSafe();
|
||||
};
|
||||
public static final MatrixOpAdd MATRIXOP_ADD = new MatrixOpAdd();
|
||||
|
||||
/** Subtract right source from left source */
|
||||
private static final class MatrixOpSubtract extends BinaryMatrixOperation {
|
||||
|
||||
MatrixOpSubtract() {
|
||||
super(2, "subtract");
|
||||
}
|
||||
|
||||
int checkCompatibility(
|
||||
int leftSourceWidth,
|
||||
int leftSourceHeight,
|
||||
boolean transposeLeftSource,
|
||||
int rightSourceWidth,
|
||||
int rightSourceHeight,
|
||||
boolean transposeRightSource,
|
||||
boolean transposeDest)
|
||||
{
|
||||
// Same as for add, obviously...
|
||||
return MATRIXOP_ADD.checkCompatibility(
|
||||
leftSourceWidth,
|
||||
leftSourceHeight,
|
||||
transposeLeftSource,
|
||||
rightSourceWidth,
|
||||
rightSourceHeight,
|
||||
transposeRightSource,
|
||||
transposeDest
|
||||
);
|
||||
}
|
||||
MatrixOpClassification classify() {
|
||||
return MATRIXOP_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unclassified (initial state) matrix operation.
|
||||
*/
|
||||
private final MatrixOpClassification MATRIXOP_NONE = new MatrixOpClassification() {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return MATRIXOP_SAFE; }
|
||||
protected MatrixOpClassification direct() { return MATRIXOP_DIRECT; }
|
||||
boolean isSafe() { return false; }
|
||||
};
|
||||
|
||||
/**
|
||||
* A matrix operation is direct if the source and destination addresses
|
||||
* are the same, and the strides are the same.
|
||||
*/
|
||||
private final class MatrixOpDirect extends MatrixOpClassification {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return this; }
|
||||
protected MatrixOpClassification direct() { return this; }
|
||||
boolean isSafe() { return false; }
|
||||
native void execute(
|
||||
int leftSourceAddress,
|
||||
int leftSourceStride,
|
||||
int leftElements,
|
||||
int leftSourceWidth,
|
||||
int leftSourceHeight,
|
||||
boolean transposeLeftSource,
|
||||
int rightSourceAddress,
|
||||
int rightSourceStride,
|
||||
int rightElements,
|
||||
int rightSourceWidth,
|
||||
int rightSourceHeight,
|
||||
boolean transposeRightSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest);
|
||||
};
|
||||
private final MatrixOpDirect MATRIXOP_DIRECT = new MatrixOpDirect();
|
||||
|
||||
|
||||
/**
|
||||
* A matrix operation is safe if the source and destination do not
|
||||
* overlap in any way
|
||||
*/
|
||||
private final class MatrixOpSafe extends MatrixOpClassification {
|
||||
protected MatrixOpClassification unsafe() { return MATRIXOP_UNSAFE; }
|
||||
protected MatrixOpClassification safe() { return MATRIXOP_SAFE; }
|
||||
protected MatrixOpClassification direct() { return MATRIXOP_DIRECT; }
|
||||
boolean isSafe() { return true; }
|
||||
native void execute(
|
||||
int leftSourceAddress,
|
||||
int leftSourceStride,
|
||||
int leftElements,
|
||||
int leftSourceWidth,
|
||||
int leftSourceHeight,
|
||||
boolean transposeLeftSource,
|
||||
int rightSourceAddress,
|
||||
int rightSourceStride,
|
||||
int rightElements,
|
||||
int rightSourceWidth,
|
||||
int rightSourceHeight,
|
||||
boolean transposeRightSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest);
|
||||
};
|
||||
private final MatrixOpSafe MATRIXOP_SAFE = new MatrixOpSafe();
|
||||
};
|
||||
public static final MatrixOpSubtract MATRIXOP_SUBTRACT = new MatrixOpSubtract();
|
||||
|
||||
/**
|
||||
* No constructor for Math.
|
||||
*/
|
||||
|
@ -825,311 +154,4 @@ public final class Math {
|
|||
public static float sqrt(float x) {
|
||||
return 1.0f / invsqrt(x);
|
||||
}
|
||||
|
||||
/*
|
||||
* Matrix operation classifications
|
||||
*/
|
||||
private static abstract class MatrixOpClassification {
|
||||
|
||||
abstract MatrixOpClassification unsafe();
|
||||
abstract MatrixOpClassification safe();
|
||||
abstract MatrixOpClassification direct();
|
||||
/**
|
||||
* Execute a unary matrix operation.
|
||||
* The default implementation does nothing.
|
||||
*/
|
||||
void execute(
|
||||
int sourceAddress,
|
||||
int sourceStride,
|
||||
int numElements,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
boolean transposeSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a binary matrix operation.
|
||||
* The default implementation does nothing.
|
||||
*/
|
||||
void execute(
|
||||
int leftSourceAddress,
|
||||
int leftSourceStride,
|
||||
int leftElements,
|
||||
int leftSourceWidth,
|
||||
int leftSourceHeight,
|
||||
boolean transposeLeftSource,
|
||||
int rightSourceAddress,
|
||||
int rightSourceStride,
|
||||
int rightElements,
|
||||
int rightSourceWidth,
|
||||
int rightSourceHeight,
|
||||
boolean transposeRightSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a binary operation to make sure that when dealing with n x n
|
||||
* result sets that when both n's are greater than 1 the operation must
|
||||
* be safe; otherwise if is direct, then the side where n > 1 must be
|
||||
* the destination.
|
||||
*/
|
||||
MatrixOpClassification checkBinaryOp(
|
||||
int leftSourceElements,
|
||||
int rightSourceElements,
|
||||
int leftSourceAddress,
|
||||
int rightSourceAddress,
|
||||
int destinationAddress
|
||||
) {
|
||||
|
||||
if (leftSourceElements > 1 && rightSourceElements > 1) {
|
||||
if (isSafe())
|
||||
return this;
|
||||
else
|
||||
return MATRIXOP_UNSAFE;
|
||||
} else if (leftSourceElements == 1 && rightSourceElements > 1) {
|
||||
if (isSafe())
|
||||
return this;
|
||||
else if (destinationAddress == rightSourceAddress)
|
||||
return this;
|
||||
else
|
||||
return MATRIXOP_UNSAFE;
|
||||
} else if (rightSourceElements == 1 && leftSourceElements > 1) {
|
||||
if (isSafe())
|
||||
return this;
|
||||
else if (destinationAddress == leftSourceAddress)
|
||||
return this;
|
||||
else
|
||||
return MATRIXOP_UNSAFE;
|
||||
} else if (leftSourceElements == 1 && rightSourceElements == 1) {
|
||||
return this; // even though this seems silly it is needed
|
||||
}
|
||||
else {
|
||||
return MATRIXOP_UNSAFE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this is a safe classification
|
||||
*/
|
||||
abstract boolean isSafe();
|
||||
|
||||
public final MatrixOpClassification check(
|
||||
int sourceAddress,
|
||||
int sourceStride,
|
||||
int numElements,
|
||||
int destAddress,
|
||||
int destStride)
|
||||
{
|
||||
int sourceEnd = sourceAddress + sourceStride * numElements;
|
||||
int destEnd = destAddress + destStride * numElements;
|
||||
// Check to see if source is somewhere inside the destination
|
||||
if ((sourceAddress >= destAddress && sourceAddress <= destEnd)
|
||||
|| (sourceEnd >= destAddress && sourceEnd <= destEnd)) {
|
||||
|
||||
// Check out the strides first
|
||||
if (destAddress > sourceAddress || sourceStride != destStride)
|
||||
return unsafe();
|
||||
else if (destAddress < sourceAddress)
|
||||
return safe();
|
||||
else
|
||||
return direct();
|
||||
|
||||
} else {
|
||||
|
||||
// Completely safe
|
||||
return safe();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Apply a unary matrix operation to an array of matrices.
|
||||
* @param operation A unary vector operation which must be one of
|
||||
* MATRIXOP_NOOP,
|
||||
* MATRIXOP_NEGATE,
|
||||
* MATRIXOP_NORMALIZE, etc.
|
||||
* @param sourceAddress The address of the source matrices
|
||||
* @param sourceStride The distance between source matrices, in bytes; if 0,
|
||||
* it is assumed that the matrices are tightly packed. This is equivalent to
|
||||
* sourceStride == sourceWidth * sourceHeight * 4
|
||||
* @param numElements The number of matrices
|
||||
* @param sourceWidth The width of the source matrix. Must be > 0.
|
||||
* @param sourceHeight The height of the source matrix. Must be > 0.
|
||||
* @param transposeSource The source can be transposed automatically before
|
||||
* the operation is performed on it
|
||||
* @param destAddress The results are placed here. This may overlap the
|
||||
* source and can even be the same, which performs the unary operation
|
||||
* in-situ
|
||||
* @param destStride The distance between destination matrices, in bytes,
|
||||
* similar to sourceStride. Note that if the source and destination address
|
||||
* overlap and the strides are different then the result is undefined.
|
||||
* @param transposeDest The destination can be transposed before being
|
||||
* written
|
||||
*/
|
||||
public static void matrixOp(
|
||||
UnaryMatrixOperation operation,
|
||||
int sourceAddress,
|
||||
int sourceStride,
|
||||
int numElements,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
boolean transposeSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest) {
|
||||
|
||||
// Check that certain parameters are legal in the first place
|
||||
assert sourceAddress != 0 : "0 source address";
|
||||
assert sourceStride >= 0 : "Illegal source stride";
|
||||
assert numElements >= 0 : "Illegal number of elements";
|
||||
assert sourceWidth >= 1 : "Illegal source width";
|
||||
assert sourceHeight >= 1 : "Illegal source height";
|
||||
assert destAddress != 0 : "0 dest address";
|
||||
assert destStride >= 0 : "Illegal dest stride";
|
||||
|
||||
// Calculate actual strides
|
||||
if (sourceStride == 0)
|
||||
sourceStride = (sourceWidth * sourceHeight) << 2;
|
||||
if (destStride == 0)
|
||||
destStride = sourceStride;
|
||||
|
||||
// Check unary matrix operation type
|
||||
MatrixOpClassification op = operation.classify().check(sourceAddress, sourceStride, numElements, destAddress, destStride);
|
||||
|
||||
op.execute(
|
||||
sourceAddress,
|
||||
sourceStride,
|
||||
numElements,
|
||||
sourceWidth,
|
||||
sourceHeight,
|
||||
transposeSource,
|
||||
destAddress,
|
||||
destStride,
|
||||
transposeDest
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a binary matrix operation to two arrays of matrices. The results
|
||||
* are computed by applying the first right element to each of the left
|
||||
* elements in turn; then the second right element to each left element;
|
||||
* and so on.
|
||||
* @param operation A binary vector operation which must be one of
|
||||
* MATRIXOP_MUTLIPLY,
|
||||
* MATRIXOP_ADD,
|
||||
* MATRIXOP_SUBTRACT, etc.
|
||||
* @param leftSourceAddress The address of the source matrices
|
||||
* @param leftSourceStride The distance between source matrices, in bytes; if 0,
|
||||
* it is assumed that the matrices are tightly packed. This is equivalent to
|
||||
* sourceStride == sourceWidth * sourceHeight * 4
|
||||
* @param leftElements The number of left-hand-side matrices
|
||||
* @param leftSourceWidth The width of the left source matrix. Must be > 0.
|
||||
* @param leftSourceHeight The height of the left source matrix. Must be > 0.
|
||||
* @param transposeLeftSource The left source can be transposed automatically before
|
||||
* the operation is performed on it
|
||||
* @param rightSourceAddress The address of the right source matrices
|
||||
* @param rightSourceStride The distance between right source matrices, in bytes; if 0,
|
||||
* it is assumed that the matrices are tightly packed. This is equivalent to
|
||||
* sourceStride == sourceWidth * sourceHeight * 4
|
||||
* @param rightElements The number of right-hand-side matrices
|
||||
* @param rightSourceWidth The width of the right source matrix. Must be > 0.
|
||||
* @param rightSourceHeight The height of the right source matrix. Must be > 0.
|
||||
* @param transposeRightSource The right source can be transposed automatically before
|
||||
* the operation is performed on it
|
||||
* @param destAddress The results are placed here. This may overlap the
|
||||
* sources and can even be the same, which performs the binary operation
|
||||
* in-situ
|
||||
* @param destStride The distance between destination matrices, in bytes,
|
||||
* similar to sourceStride. Note that if the source and destination address
|
||||
* overlap and the strides are different then the result is undefined.
|
||||
* @param transposeDest The destination can be transposed before being
|
||||
* written
|
||||
* @throws IllegalArgumentException if the source matrices are incompatible
|
||||
*/
|
||||
public static void matrixOp(
|
||||
BinaryMatrixOperation operation,
|
||||
int leftSourceAddress,
|
||||
int leftSourceStride,
|
||||
int leftElements,
|
||||
int leftSourceWidth,
|
||||
int leftSourceHeight,
|
||||
boolean transposeLeftSource,
|
||||
int rightSourceAddress,
|
||||
int rightSourceStride,
|
||||
int rightElements,
|
||||
int rightSourceWidth,
|
||||
int rightSourceHeight,
|
||||
boolean transposeRightSource,
|
||||
int destAddress,
|
||||
int destStride,
|
||||
boolean transposeDest) {
|
||||
|
||||
// Check that certain parameters are legal in the first place
|
||||
assert leftSourceAddress != 0 : "0 left source address";
|
||||
assert leftSourceStride >= 0 : "Illegal left source stride";
|
||||
assert leftElements >= 0 : "Illegal number of left elements";
|
||||
assert leftSourceWidth >= 1 : "Illegal left source width";
|
||||
assert leftSourceHeight >= 1 : "Illegal left source height";
|
||||
assert rightSourceAddress != 0 : "0 right source address";
|
||||
assert rightSourceStride >= 0 : "Illegal right source stride";
|
||||
assert rightElements >= 0 : "Illegal number of right elements";
|
||||
assert rightSourceWidth >= 1 : "Illegal right source width";
|
||||
assert rightSourceHeight >= 1 : "Illegal right source height";
|
||||
assert destAddress != 0 : "0 dest address";
|
||||
assert destStride >= 0 : "Illegal dest stride";
|
||||
|
||||
// Calculate actual strides
|
||||
if (leftSourceStride == 0)
|
||||
leftSourceStride = (leftSourceWidth * leftSourceHeight) << 2;
|
||||
if (rightSourceStride == 0)
|
||||
rightSourceStride = (rightSourceWidth * rightSourceHeight) << 2;
|
||||
|
||||
// Ensure the source and destination matrices are compatible
|
||||
int minStride = operation.checkCompatibility(
|
||||
leftSourceWidth,
|
||||
leftSourceHeight,
|
||||
transposeLeftSource,
|
||||
rightSourceWidth,
|
||||
rightSourceHeight,
|
||||
transposeRightSource,
|
||||
transposeDest);
|
||||
|
||||
if (destStride == 0)
|
||||
destStride = minStride;
|
||||
|
||||
// Check unary matrix operation type
|
||||
MatrixOpClassification op = operation.classify().check(leftSourceAddress, leftSourceStride, leftElements, destAddress, destStride);
|
||||
op = op.check(rightSourceAddress, rightSourceStride, rightElements, destAddress, destStride);
|
||||
op = op.checkBinaryOp(leftElements, rightElements, leftSourceAddress, rightSourceAddress, destAddress);
|
||||
op.execute(
|
||||
leftSourceAddress,
|
||||
leftSourceStride,
|
||||
leftElements,
|
||||
leftSourceWidth,
|
||||
leftSourceHeight,
|
||||
transposeLeftSource,
|
||||
rightSourceAddress,
|
||||
rightSourceStride,
|
||||
rightElements,
|
||||
rightSourceWidth,
|
||||
rightSourceHeight,
|
||||
transposeRightSource,
|
||||
destAddress,
|
||||
destStride,
|
||||
transposeDest
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
package org.lwjgl.test.vector;
|
||||
|
||||
import java.nio.*;
|
||||
|
||||
import org.lwjgl.*;
|
||||
|
||||
public class MathTest {
|
||||
public static void main(String[] args) {
|
||||
ByteBuffer buf = ByteBuffer.allocateDirect(100);
|
||||
buf.order(ByteOrder.nativeOrder());
|
||||
FloatBuffer float_buf = buf.asFloatBuffer();
|
||||
float f = 0f;
|
||||
while (float_buf.hasRemaining()) {
|
||||
f += 0.5f;
|
||||
float_buf.put(f);
|
||||
}
|
||||
float_buf.rewind();
|
||||
System.out.println("Src buffer:");
|
||||
while (float_buf.hasRemaining())
|
||||
System.out.print(float_buf.get() + " ");
|
||||
System.out.println("");
|
||||
int buf_address = Sys.getDirectBufferAddress(float_buf);
|
||||
org.lwjgl.Math.matrixOp(org.lwjgl.Math.MATRIXOP_NEGATE, buf_address, 0, 100, 1, 1, false, buf_address, 0, false);
|
||||
System.out.println("Negated result:");
|
||||
float_buf.rewind();
|
||||
while (float_buf.hasRemaining())
|
||||
System.out.print(float_buf.get() + " ");
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Light Weight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* math library.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include "org_lwjgl_Math_MatrixOpAdd_MatrixOpDirect.h"
|
||||
#include "MatrixOpCommon.h"
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpAdd_MatrixOpDirect
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpAdd_00024MatrixOpDirect_execute
|
||||
(
|
||||
JNIEnv * env,
|
||||
jobject obj,
|
||||
jint leftSourceAddress,
|
||||
jint leftSourceStride,
|
||||
jint leftElements,
|
||||
jint leftSourceWidth,
|
||||
jint leftSourceHeight,
|
||||
jboolean transposeLeftSource,
|
||||
jint rightSourceAddress,
|
||||
jint rightSourceStride,
|
||||
jint rightElements,
|
||||
jint rightSourceWidth,
|
||||
jint rightSourceHeight,
|
||||
jboolean transposeRightSource,
|
||||
jint destAddress,
|
||||
jint destStride,
|
||||
jboolean transposeDest
|
||||
)
|
||||
{
|
||||
MatrixSrc left (leftSourceAddress, leftSourceStride,
|
||||
leftSourceWidth, leftSourceHeight, leftElements, transposeLeftSource);
|
||||
MatrixSrc right (rightSourceAddress, leftSourceStride,
|
||||
rightSourceWidth, rightSourceHeight, rightElements, transposeRightSource);
|
||||
MatrixDst dest (destAddress, destStride,
|
||||
left.width, left.height, left.elements * right.elements, transposeDest);
|
||||
|
||||
dest.configureBuffer(left, right);
|
||||
|
||||
float * leftMatrix, * rightMatrix, * destMatrix;
|
||||
|
||||
left.rewind();
|
||||
for (int i = 0; i < left.elements; i++)
|
||||
{
|
||||
leftMatrix = left.nextMatrix();
|
||||
|
||||
right.rewind();
|
||||
for (int j = 0; j < right.elements; j++)
|
||||
{
|
||||
rightMatrix = right.nextMatrix();
|
||||
destMatrix = dest.nextMatrix();
|
||||
|
||||
int k = dest.width * dest.height;
|
||||
while (k--)
|
||||
destMatrix[k] = leftMatrix[k] + rightMatrix[k];
|
||||
|
||||
dest.writeComplete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_lwjgl_Math_MatrixOpAdd_MatrixOpDirect */
|
||||
|
||||
#ifndef _Included_org_lwjgl_Math_MatrixOpAdd_MatrixOpDirect
|
||||
#define _Included_org_lwjgl_Math_MatrixOpAdd_MatrixOpDirect
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpAdd_MatrixOpDirect
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpAdd_00024MatrixOpDirect_execute
|
||||
(JNIEnv *, jobject, jint, jint, jint, jint, jint, jboolean, jint, jint, jint, jint, jint, jboolean, jint, jint, jboolean);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,102 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Light Weight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* math library.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include "org_lwjgl_Math_MatrixOpAdd_MatrixOpSafe.h"
|
||||
#include "MatrixOpCommon.h"
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpAdd_MatrixOpSafe
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpAdd_00024MatrixOpSafe_execute
|
||||
(
|
||||
JNIEnv * env,
|
||||
jobject obj,
|
||||
jint leftSourceAddress,
|
||||
jint leftSourceStride,
|
||||
jint leftElements,
|
||||
jint leftSourceWidth,
|
||||
jint leftSourceHeight,
|
||||
jboolean transposeLeftSource,
|
||||
jint rightSourceAddress,
|
||||
jint rightSourceStride,
|
||||
jint rightElements,
|
||||
jint rightSourceWidth,
|
||||
jint rightSourceHeight,
|
||||
jboolean transposeRightSource,
|
||||
jint destAddress,
|
||||
jint destStride,
|
||||
jboolean transposeDest
|
||||
)
|
||||
{
|
||||
MatrixSrc left (leftSourceAddress, leftSourceStride,
|
||||
leftSourceWidth, leftSourceHeight, leftElements, transposeLeftSource);
|
||||
MatrixSrc right (rightSourceAddress, leftSourceStride,
|
||||
rightSourceWidth, rightSourceHeight, rightElements, transposeRightSource);
|
||||
MatrixDst dest (destAddress, destStride,
|
||||
left.width, left.height, left.elements * right.elements, transposeDest);
|
||||
|
||||
float * leftMatrix, * rightMatrix, * destMatrix;
|
||||
|
||||
left.rewind();
|
||||
for (int i = 0; i < leftElements; i++)
|
||||
{
|
||||
leftMatrix = left.nextMatrix();
|
||||
right.rewind();
|
||||
|
||||
for (int j = 0; j < rightElements; j++)
|
||||
{
|
||||
rightMatrix = right.nextMatrix();
|
||||
destMatrix = dest.nextMatrix();
|
||||
|
||||
int k = dest.width * dest.height;
|
||||
while (k--)
|
||||
destMatrix[k] = leftMatrix[k] + rightMatrix[k];
|
||||
|
||||
dest.writeComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_lwjgl_Math_MatrixOpAdd_MatrixOpSafe */
|
||||
|
||||
#ifndef _Included_org_lwjgl_Math_MatrixOpAdd_MatrixOpSafe
|
||||
#define _Included_org_lwjgl_Math_MatrixOpAdd_MatrixOpSafe
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpAdd_MatrixOpSafe
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpAdd_00024MatrixOpSafe_execute
|
||||
(JNIEnv *, jobject, jint, jint, jint, jint, jint, jboolean, jint, jint, jint, jint, jint, jboolean, jint, jint, jboolean);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,93 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Light Weight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* math library.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include "org_lwjgl_Math_MatrixOpCopy_MatrixOpDirect.h"
|
||||
#include "MatrixOpCommon.h"
|
||||
#include <string.h>
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpCopy_MatrixOpDirect
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpCopy_00024MatrixOpDirect_execute
|
||||
(
|
||||
JNIEnv * env,
|
||||
jobject obj,
|
||||
jint sourceAddress,
|
||||
jint sourceStride,
|
||||
jint numElements,
|
||||
jint sourceWidth,
|
||||
jint sourceHeight,
|
||||
jboolean transposeSource,
|
||||
jint destAddress,
|
||||
jint destStride,
|
||||
jboolean transposeDest
|
||||
)
|
||||
{
|
||||
if (transposeSource == transposeDest)
|
||||
{
|
||||
transposeSource = false;
|
||||
transposeDest = false;
|
||||
}
|
||||
|
||||
MatrixSrc source (sourceAddress, sourceStride, sourceWidth, sourceHeight, numElements, transposeSource);
|
||||
MatrixDst dest (destAddress, destStride, source.width, source.height, source.elements, transposeDest);
|
||||
|
||||
dest.configureBuffer(source);
|
||||
|
||||
float * srcMatrix, * destMatrix;
|
||||
int matrixByteCount = source.width*source.height*sizeof(jfloat);
|
||||
|
||||
for (int i = 0; i < source.elements; i++)
|
||||
{
|
||||
srcMatrix = source.nextMatrix();
|
||||
destMatrix = dest.nextMatrix();
|
||||
|
||||
// just do a straight memory copy
|
||||
memcpy(destMatrix, srcMatrix, matrixByteCount);
|
||||
dest.writeComplete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_lwjgl_Math_MatrixOpCopy_MatrixOpDirect */
|
||||
|
||||
#ifndef _Included_org_lwjgl_Math_MatrixOpCopy_MatrixOpDirect
|
||||
#define _Included_org_lwjgl_Math_MatrixOpCopy_MatrixOpDirect
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpCopy_MatrixOpDirect
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpCopy_00024MatrixOpDirect_execute
|
||||
(JNIEnv *, jobject, jint, jint, jint, jint, jint, jboolean, jint, jint, jboolean);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,90 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Light Weight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* math library.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include "org_lwjgl_Math_MatrixOpCopy_MatrixOpSafe.h"
|
||||
#include "MatrixOpCommon.h"
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpCopy_MatrixOpSafe
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpCopy_00024MatrixOpSafe_execute
|
||||
(
|
||||
JNIEnv * env,
|
||||
jobject obj,
|
||||
jint sourceAddress,
|
||||
jint sourceStride,
|
||||
jint numElements,
|
||||
jint sourceWidth,
|
||||
jint sourceHeight,
|
||||
jboolean transposeSource,
|
||||
jint destAddress,
|
||||
jint destStride,
|
||||
jboolean transposeDest
|
||||
)
|
||||
{
|
||||
// remove any unnecessary copying
|
||||
if (transposeSource == transposeDest)
|
||||
{
|
||||
transposeSource = false;
|
||||
transposeDest = false;
|
||||
}
|
||||
|
||||
MatrixSrc source (sourceAddress, sourceStride, sourceWidth, sourceHeight, numElements, transposeSource);
|
||||
MatrixDst dest (destAddress, destStride, source.width, source.height, source.elements, transposeDest);
|
||||
|
||||
float * srcMatrix, * destMatrix;
|
||||
int matrixByteCount = source.width*source.height*sizeof(jfloat);
|
||||
|
||||
for (int i = 0; i < source.elements; i++)
|
||||
{
|
||||
srcMatrix = source.nextMatrix();
|
||||
destMatrix = dest.nextMatrix();
|
||||
|
||||
// just do a straight memory copy
|
||||
memcpy(destMatrix, srcMatrix, matrixByteCount);
|
||||
dest.writeComplete();
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_lwjgl_Math_MatrixOpCopy_MatrixOpSafe */
|
||||
|
||||
#ifndef _Included_org_lwjgl_Math_MatrixOpCopy_MatrixOpSafe
|
||||
#define _Included_org_lwjgl_Math_MatrixOpCopy_MatrixOpSafe
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpCopy_MatrixOpSafe
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpCopy_00024MatrixOpSafe_execute
|
||||
(JNIEnv *, jobject, jint, jint, jint, jint, jint, jboolean, jint, jint, jboolean);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,147 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Light Weight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* math library.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "org_lwjgl_Math_MatrixOpInvert_MatrixOpDirect.h"
|
||||
#include "MatrixOpCommon.h"
|
||||
#ifdef _DEBUG
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpInvert_MatrixOpDirect
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpInvert_00024MatrixOpDirect_execute
|
||||
(
|
||||
JNIEnv * env,
|
||||
jobject obj,
|
||||
jint sourceAddress,
|
||||
jint sourceStride,
|
||||
jint numElements,
|
||||
jint sourceWidth,
|
||||
jint sourceHeight,
|
||||
jboolean transposeSource,
|
||||
jint destAddress,
|
||||
jint destStride,
|
||||
jboolean transposeDest
|
||||
)
|
||||
{
|
||||
static float * temp_matrix = 0;
|
||||
static int temp_matrix_size = 0;
|
||||
|
||||
if (transposeSource == transposeDest)
|
||||
{
|
||||
transposeSource = JNI_FALSE;
|
||||
transposeDest = JNI_FALSE;
|
||||
}
|
||||
|
||||
|
||||
// We are under the assumption that sourceWidth == sourceHeight and the matrix
|
||||
// defined within is invertable
|
||||
|
||||
MatrixSrc source (sourceAddress, sourceStride,
|
||||
sourceWidth, sourceHeight, numElements, transposeSource);
|
||||
MatrixDst dest (destAddress, destStride,
|
||||
source.width, source.height, source.elements, transposeDest);
|
||||
|
||||
dest.configureBuffer(source);
|
||||
|
||||
float * srcMatrix, * destMatrix;
|
||||
|
||||
int temp_side = source.width-1;
|
||||
|
||||
if (temp_matrix_size < temp_side) {
|
||||
if (temp_matrix)
|
||||
delete[] temp_matrix;
|
||||
temp_matrix = new float[temp_side * temp_side];
|
||||
temp_matrix_size = temp_side;
|
||||
}
|
||||
|
||||
for (int i = 0; i < source.elements; i++)
|
||||
{
|
||||
srcMatrix = source.nextMatrix();
|
||||
destMatrix = dest .nextMatrix();
|
||||
|
||||
// calculate the determinant
|
||||
float det = determinant(srcMatrix, source.width);
|
||||
|
||||
#ifdef _DEBUG
|
||||
printf("Matrix Determinant: %f\n", det);
|
||||
printf("Matrix Determinant - 1 = %f\n", det -1);
|
||||
#endif
|
||||
|
||||
float sign;
|
||||
|
||||
for (int col = 0; col < source.width; col++)
|
||||
{
|
||||
/*
|
||||
Maintain sign:
|
||||
|
||||
+ - + - ...
|
||||
- + - + ..
|
||||
+ - + - ..
|
||||
- + - + ..
|
||||
: : : : \
|
||||
*/
|
||||
|
||||
sign = (col & 1) ? -1.0f : 1.0f;
|
||||
|
||||
for (int row = 0; row < source.height; row++)
|
||||
{
|
||||
// get the sub matrix
|
||||
subMatrix(srcMatrix, source.width, temp_matrix, col, row);
|
||||
|
||||
// transpose the result
|
||||
destMatrix[col + row * source.height]
|
||||
= (sign / det) * determinant(temp_matrix, temp_side);
|
||||
|
||||
// swap signs
|
||||
sign *= -1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
dest.writeComplete();
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_lwjgl_Math_MatrixOpInvert_MatrixOpDirect */
|
||||
|
||||
#ifndef _Included_org_lwjgl_Math_MatrixOpInvert_MatrixOpDirect
|
||||
#define _Included_org_lwjgl_Math_MatrixOpInvert_MatrixOpDirect
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpInvert_MatrixOpDirect
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpInvert_00024MatrixOpDirect_execute
|
||||
(JNIEnv *, jobject, jint, jint, jint, jint, jint, jboolean, jint, jint, jboolean);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,147 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Light Weight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Win32 math library.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include "org_lwjgl_Math_MatrixOpInvert_MatrixOpSafe.h"
|
||||
#include "MatrixOpCommon.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpInvert_MatrixOpSafe
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpInvert_00024MatrixOpSafe_execute
|
||||
(
|
||||
JNIEnv * env,
|
||||
jobject obj,
|
||||
jint sourceAddress,
|
||||
jint sourceStride,
|
||||
jint numElements,
|
||||
jint sourceWidth,
|
||||
jint sourceHeight,
|
||||
jboolean transposeSource,
|
||||
jint destAddress,
|
||||
jint destStride,
|
||||
jboolean transposeDest
|
||||
)
|
||||
{
|
||||
|
||||
static float * temp_matrix = 0;
|
||||
static int temp_matrix_size = 0;
|
||||
|
||||
if (transposeSource == transposeDest)
|
||||
{
|
||||
transposeSource = JNI_FALSE;
|
||||
transposeDest = JNI_FALSE;
|
||||
}
|
||||
|
||||
// We are under the assumption that sourceWidth == sourceHeight and the matrix
|
||||
// defined within is invertable
|
||||
|
||||
MatrixSrc source (sourceAddress, sourceStride,
|
||||
sourceWidth, sourceHeight, numElements, transposeSource);
|
||||
MatrixDst dest (destAddress, destStride,
|
||||
source.width, source.height, source.elements, transposeDest);
|
||||
|
||||
float * srcMatrix, * destMatrix;
|
||||
|
||||
int temp_side = source.width-1;
|
||||
|
||||
if (temp_matrix_size < temp_side) {
|
||||
if (temp_matrix)
|
||||
delete[] temp_matrix;
|
||||
temp_matrix = new float[temp_side * temp_side];
|
||||
temp_matrix_size = temp_side;
|
||||
}
|
||||
|
||||
for (int i = 0; i < source.elements; i++)
|
||||
{
|
||||
srcMatrix = source.nextMatrix();
|
||||
destMatrix = dest.nextMatrix();
|
||||
|
||||
// calculate the determinant
|
||||
float det = determinant(srcMatrix, source.width);
|
||||
|
||||
#ifdef _DEBUG
|
||||
printf("Matrix Determinant: %f\n", det);
|
||||
printf("Matrix Determinant - 1: %f\n", det-1);
|
||||
#endif
|
||||
|
||||
float sign;
|
||||
|
||||
for (int col = 0; col < source.width; col++)
|
||||
{
|
||||
/*
|
||||
Maintain sign:
|
||||
|
||||
+ - + - ...
|
||||
- + - + ..
|
||||
+ - + - ..
|
||||
- + - + ..
|
||||
: : : : \
|
||||
*/
|
||||
|
||||
sign = (col & 1) ? -1.0f : 1.0f;
|
||||
|
||||
for (int row = 0; row < source.height; row++)
|
||||
{
|
||||
// get the sub matrix
|
||||
subMatrix(srcMatrix, source.width, temp_matrix, col, row);
|
||||
|
||||
// transpose the result
|
||||
destMatrix[col + row * source.height]
|
||||
= (sign / det) * determinant(temp_matrix, temp_side);
|
||||
|
||||
// swap signs
|
||||
sign *= -1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
dest.writeComplete();
|
||||
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_lwjgl_Math_MatrixOpInvert_MatrixOpSafe */
|
||||
|
||||
#ifndef _Included_org_lwjgl_Math_MatrixOpInvert_MatrixOpSafe
|
||||
#define _Included_org_lwjgl_Math_MatrixOpInvert_MatrixOpSafe
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpInvert_MatrixOpSafe
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpInvert_00024MatrixOpSafe_execute
|
||||
(JNIEnv *, jobject, jint, jint, jint, jint, jint, jboolean, jint, jint, jboolean);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,138 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Light Weight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* math library.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "org_lwjgl_Math_MatrixOpMultiply_MatrixOpDirect.h"
|
||||
#include "MatrixOpCommon.h"
|
||||
#include <cstring>
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpMultiply_MatrixOpDirect
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpMultiply_00024MatrixOpDirect_execute
|
||||
(
|
||||
JNIEnv * env,
|
||||
jobject obj,
|
||||
jint leftSourceAddress,
|
||||
jint leftSourceStride,
|
||||
jint leftElements,
|
||||
jint leftSourceWidth,
|
||||
jint leftSourceHeight,
|
||||
jboolean transposeLeftSource,
|
||||
jint rightSourceAddress,
|
||||
jint rightSourceStride,
|
||||
jint rightElements,
|
||||
jint rightSourceWidth,
|
||||
jint rightSourceHeight,
|
||||
jboolean transposeRightSource,
|
||||
jint destAddress,
|
||||
jint destStride,
|
||||
jboolean transposeDest
|
||||
)
|
||||
{
|
||||
if (transposeLeftSource && transposeRightSource)
|
||||
{
|
||||
transposeLeftSource = false;
|
||||
transposeRightSource = false;
|
||||
transposeDest = !transposeDest;
|
||||
}
|
||||
|
||||
|
||||
MatrixSrc left (leftSourceAddress, leftSourceStride,
|
||||
leftSourceWidth, leftSourceHeight, leftElements, transposeLeftSource);
|
||||
MatrixSrc right (rightSourceAddress, leftSourceStride,
|
||||
rightSourceWidth, rightSourceHeight, rightElements, transposeRightSource);
|
||||
MatrixDst dest (destAddress, destStride,
|
||||
right.width, left.height, left.elements * right.elements, transposeDest);
|
||||
|
||||
dest.configureBuffer(left, right);
|
||||
|
||||
float * leftMatrix, * rightMatrix, * destMatrix;
|
||||
|
||||
// check out discussions envolving ordering
|
||||
|
||||
|
||||
left.rewind();
|
||||
for (int i = 0; i < left.elements; i++)
|
||||
{
|
||||
leftMatrix = left.nextMatrix();
|
||||
|
||||
right.rewind();
|
||||
for (int j = 0; j < right.elements; j++)
|
||||
{
|
||||
rightMatrix = right.nextMatrix();
|
||||
destMatrix = dest.nextMatrix();
|
||||
|
||||
// zero the elements of the destination matrix
|
||||
for (int d = 0; d < dest.width * dest.height; d++)
|
||||
destMatrix[d] = 0;
|
||||
|
||||
// loop through each column of the right matrix
|
||||
int rightCell = 0;
|
||||
for (int rightCol = 0; rightCol < right.width; rightCol++)
|
||||
{
|
||||
// [RxC] * [RxC]
|
||||
// dest has same height as left
|
||||
// dest has same width as right
|
||||
|
||||
int leftCell = 0;
|
||||
for (int leftCol = 0; leftCol < left.width; leftCol++)
|
||||
{
|
||||
for (int leftRow = 0; leftRow < left.height; leftRow++)
|
||||
{
|
||||
destMatrix[leftRow] += rightMatrix[rightCell] * leftMatrix[leftCell++];
|
||||
}
|
||||
rightCell ++ ;
|
||||
}
|
||||
|
||||
//rightMatrix = &rightMatrix[right.height];
|
||||
destMatrix = &destMatrix[dest.height];
|
||||
|
||||
}
|
||||
dest.writeComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_lwjgl_Math_MatrixOpMultiply_MatrixOpDirect */
|
||||
|
||||
#ifndef _Included_org_lwjgl_Math_MatrixOpMultiply_MatrixOpDirect
|
||||
#define _Included_org_lwjgl_Math_MatrixOpMultiply_MatrixOpDirect
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpMultiply_MatrixOpDirect
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpMultiply_00024MatrixOpDirect_execute
|
||||
(JNIEnv *, jobject, jint, jint, jint, jint, jint, jboolean, jint, jint, jint, jint, jint, jboolean, jint, jint, jboolean);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,138 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Light Weight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Win32 math library.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include "org_lwjgl_Math_MatrixOpMultiply_MatrixOpSafe.h"
|
||||
#include "MatrixOpCommon.h"
|
||||
#include <cstring>
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpMultiply_MatrixOpSafe
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpMultiply_00024MatrixOpSafe_execute
|
||||
(
|
||||
JNIEnv * env,
|
||||
jobject obj,
|
||||
jint leftSourceAddress,
|
||||
jint leftSourceStride,
|
||||
jint leftElements,
|
||||
jint leftSourceWidth,
|
||||
jint leftSourceHeight,
|
||||
jboolean transposeLeftSource,
|
||||
jint rightSourceAddress,
|
||||
jint rightSourceStride,
|
||||
jint rightElements,
|
||||
jint rightSourceWidth,
|
||||
jint rightSourceHeight,
|
||||
jboolean transposeRightSource,
|
||||
jint destAddress,
|
||||
jint destStride,
|
||||
jboolean transposeDest
|
||||
)
|
||||
{
|
||||
if (transposeLeftSource && transposeRightSource)
|
||||
{
|
||||
transposeLeftSource = false;
|
||||
transposeRightSource = false;
|
||||
transposeDest = !transposeDest;
|
||||
}
|
||||
|
||||
|
||||
MatrixSrc left (leftSourceAddress, leftSourceStride,
|
||||
leftSourceWidth, leftSourceHeight, leftElements, transposeLeftSource);
|
||||
MatrixSrc right (rightSourceAddress, leftSourceStride,
|
||||
rightSourceWidth, rightSourceHeight, rightElements, transposeRightSource);
|
||||
MatrixDst dest (destAddress, destStride,
|
||||
right.width, left.height, left.elements * right.elements, transposeDest);
|
||||
|
||||
float * leftMatrix, * rightMatrix, * destMatrix;
|
||||
|
||||
// check out discussions envolving ordering
|
||||
|
||||
|
||||
left.rewind();
|
||||
for (int i = 0; i < left.elements; i++)
|
||||
{
|
||||
leftMatrix = left.nextMatrix();
|
||||
|
||||
right.rewind();
|
||||
for (int j = 0; j < right.elements; j++)
|
||||
{
|
||||
rightMatrix = right.nextMatrix();
|
||||
destMatrix = dest.nextMatrix();
|
||||
|
||||
// zero the elements of the destination matrix
|
||||
for (int d = 0; d < dest.width * dest.height; d++)
|
||||
destMatrix[d] = 0;
|
||||
|
||||
// loop through each column of the right matrix
|
||||
int rightCell = 0;
|
||||
for (int rightCol = 0; rightCol < right.width; rightCol++)
|
||||
{
|
||||
// [RxC] * [RxC]
|
||||
// dest has same height as left
|
||||
// dest has same width as right
|
||||
|
||||
int leftCell = 0;
|
||||
for (int leftCol = 0; leftCol < left.width; leftCol++)
|
||||
{
|
||||
for (int leftRow = 0; leftRow < left.height; leftRow++)
|
||||
{
|
||||
destMatrix[leftRow] += rightMatrix[rightCell] * leftMatrix[leftCell++];
|
||||
}
|
||||
rightCell ++ ;
|
||||
}
|
||||
|
||||
//rightMatrix = &rightMatrix[right.height];
|
||||
destMatrix = &destMatrix[dest.height];
|
||||
|
||||
}
|
||||
dest.writeComplete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_lwjgl_Math_MatrixOpMultiply_MatrixOpSafe */
|
||||
|
||||
#ifndef _Included_org_lwjgl_Math_MatrixOpMultiply_MatrixOpSafe
|
||||
#define _Included_org_lwjgl_Math_MatrixOpMultiply_MatrixOpSafe
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpMultiply_MatrixOpSafe
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpMultiply_00024MatrixOpSafe_execute
|
||||
(JNIEnv *, jobject, jint, jint, jint, jint, jint, jboolean, jint, jint, jint, jint, jint, jboolean, jint, jint, jboolean);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Light Weight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* math library.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include "org_lwjgl_Math_MatrixOpNegate_MatrixOpDirect.h"
|
||||
#include "MatrixOpCommon.h"
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpNegate_MatrixOpDirect
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpNegate_00024MatrixOpDirect_execute
|
||||
(
|
||||
JNIEnv * env,
|
||||
jobject obj,
|
||||
jint sourceAddress,
|
||||
jint sourceStride,
|
||||
jint numElements,
|
||||
jint sourceWidth,
|
||||
jint sourceHeight,
|
||||
jboolean transposeSource,
|
||||
jint destAddress,
|
||||
jint destStride,
|
||||
jboolean transposeDest
|
||||
)
|
||||
{
|
||||
MatrixSrc source (sourceAddress, sourceStride, sourceWidth, sourceHeight, numElements, transposeSource);
|
||||
MatrixDst dest (destAddress, destStride, source.width, source.height, numElements, transposeDest);
|
||||
|
||||
dest.configureBuffer(source);
|
||||
|
||||
int * srcMatrix, * destMatrix;
|
||||
|
||||
for (int i = 0; i < source.elements; i++)
|
||||
{
|
||||
srcMatrix = (int *) source.nextMatrix();
|
||||
destMatrix = (int *) dest.nextMatrix();
|
||||
|
||||
// we can cheat and use the less expensive xor
|
||||
// to switch the sign bit of the float
|
||||
// single precision format 1 - sign 8 - exponent (excess 127) 23 - mantisa
|
||||
|
||||
int j = source.width*source.height;
|
||||
while (j--)
|
||||
destMatrix[j] = srcMatrix[j] ^ 0x80000000;
|
||||
|
||||
dest.writeComplete();
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_lwjgl_Math_MatrixOpNegate_MatrixOpDirect */
|
||||
|
||||
#ifndef _Included_org_lwjgl_Math_MatrixOpNegate_MatrixOpDirect
|
||||
#define _Included_org_lwjgl_Math_MatrixOpNegate_MatrixOpDirect
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpNegate_MatrixOpDirect
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpNegate_00024MatrixOpDirect_execute
|
||||
(JNIEnv *, jobject, jint, jint, jint, jint, jint, jboolean, jint, jint, jboolean);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,88 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Light Weight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* math library.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "org_lwjgl_Math_MatrixOpNegate_MatrixOpSafe.h"
|
||||
#include "MatrixOpCommon.h"
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpNegate_MatrixOpSafe
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpNegate_00024MatrixOpSafe_execute
|
||||
(
|
||||
JNIEnv * env,
|
||||
jobject obj,
|
||||
jint sourceAddress,
|
||||
jint sourceStride,
|
||||
jint numElements,
|
||||
jint sourceWidth,
|
||||
jint sourceHeight,
|
||||
jboolean transposeSource,
|
||||
jint destAddress,
|
||||
jint destStride,
|
||||
jboolean transposeDest
|
||||
)
|
||||
{
|
||||
MatrixSrc source (sourceAddress, sourceStride, sourceWidth, sourceHeight, numElements, transposeSource);
|
||||
MatrixDst dest (destAddress, destStride, source.width, source.height, numElements, transposeDest);
|
||||
|
||||
int * srcMatrix, * destMatrix;
|
||||
|
||||
for (int i = 0; i < source.elements; i++)
|
||||
{
|
||||
srcMatrix = (int *) source.nextMatrix();
|
||||
destMatrix = (int *) dest.nextMatrix();
|
||||
|
||||
// we can cheat and use the less expensive xor
|
||||
// to switch the sign bit of the float
|
||||
// single precision format 1 - sign 8 - exponent (excess 127) 23 - mantisa
|
||||
|
||||
int j = source.width*source.height;
|
||||
while (j--)
|
||||
destMatrix[j] = srcMatrix[j] ^ 0x80000000;
|
||||
|
||||
dest.writeComplete();
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_lwjgl_Math_MatrixOpNegate_MatrixOpSafe */
|
||||
|
||||
#ifndef _Included_org_lwjgl_Math_MatrixOpNegate_MatrixOpSafe
|
||||
#define _Included_org_lwjgl_Math_MatrixOpNegate_MatrixOpSafe
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpNegate_MatrixOpSafe
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpNegate_00024MatrixOpSafe_execute
|
||||
(JNIEnv *, jobject, jint, jint, jint, jint, jint, jboolean, jint, jint, jboolean);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Light Weight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* math library.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "org_lwjgl_Math_MatrixOpNormalise_MatrixOpDirect.h"
|
||||
#include "MatrixOpCommon.h"
|
||||
#include <cmath>
|
||||
|
||||
//using namespace std;
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpNormalise_MatrixOpDirect
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpNormalise_00024MatrixOpDirect_execute
|
||||
(
|
||||
JNIEnv * env,
|
||||
jobject obj,
|
||||
jint sourceAddress,
|
||||
jint sourceStride,
|
||||
jint numElements,
|
||||
jint sourceWidth,
|
||||
jint sourceHeight,
|
||||
jboolean transposeSource,
|
||||
jint destAddress,
|
||||
jint destStride,
|
||||
jboolean transposeDest
|
||||
)
|
||||
{
|
||||
MatrixSrc source (sourceAddress, sourceStride, sourceWidth, sourceHeight, numElements, transposeSource);
|
||||
MatrixDst dest (destAddress, destStride, source.width, source.height, source.elements, transposeDest);
|
||||
|
||||
dest.configureBuffer(source);
|
||||
|
||||
float * srcMatrix, * destMatrix;
|
||||
float magnitude, magnitude_squared;
|
||||
|
||||
int i, j, matrixFloatCount = source.width * source.height;
|
||||
|
||||
for (i = 0; i < source.elements; i++)
|
||||
{
|
||||
magnitude_squared = 0;
|
||||
srcMatrix = source.nextMatrix();
|
||||
destMatrix = dest.nextMatrix();
|
||||
|
||||
j = matrixFloatCount;
|
||||
while (j--)
|
||||
magnitude_squared += srcMatrix[j] * srcMatrix[j];
|
||||
|
||||
magnitude = (float) sqrt((double) magnitude_squared);
|
||||
|
||||
j = matrixFloatCount;
|
||||
while (j--)
|
||||
destMatrix[j] = srcMatrix[j] / magnitude;
|
||||
|
||||
dest.writeComplete();
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_lwjgl_Math_MatrixOpNormalise_MatrixOpDirect */
|
||||
|
||||
#ifndef _Included_org_lwjgl_Math_MatrixOpNormalise_MatrixOpDirect
|
||||
#define _Included_org_lwjgl_Math_MatrixOpNormalise_MatrixOpDirect
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpNormalise_MatrixOpDirect
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpNormalise_00024MatrixOpDirect_execute
|
||||
(JNIEnv *, jobject, jint, jint, jint, jint, jint, jboolean, jint, jint, jboolean);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,98 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Light Weight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* math library.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "org_lwjgl_Math_MatrixOpNormalise_MatrixOpSafe.h"
|
||||
#include "MatrixOpCommon.h"
|
||||
#include <cmath>
|
||||
|
||||
//using namespace std;
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpNormalise_MatrixOpSafe
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpNormalise_00024MatrixOpSafe_execute
|
||||
(
|
||||
JNIEnv * env,
|
||||
jobject obj,
|
||||
jint sourceAddress,
|
||||
jint sourceStride,
|
||||
jint numElements,
|
||||
jint sourceWidth,
|
||||
jint sourceHeight,
|
||||
jboolean transposeSource,
|
||||
jint destAddress,
|
||||
jint destStride,
|
||||
jboolean transposeDest
|
||||
)
|
||||
{
|
||||
MatrixSrc source (sourceAddress, sourceStride, sourceWidth, sourceHeight, numElements, transposeSource);
|
||||
MatrixDst dest (destAddress, destStride, source.width, source.height, source.elements, transposeDest);
|
||||
|
||||
float * srcMatrix, * destMatrix;
|
||||
float magnitude, magnitude_squared;
|
||||
|
||||
int i, j, matrixFloatCount = source.width * source.height;
|
||||
|
||||
for (i = 0; i < source.elements; i++)
|
||||
{
|
||||
magnitude_squared = 0;
|
||||
srcMatrix = source.nextMatrix();
|
||||
destMatrix = dest.nextMatrix();
|
||||
|
||||
j = matrixFloatCount;
|
||||
while (j--)
|
||||
magnitude_squared += srcMatrix[j] * srcMatrix[j];
|
||||
|
||||
magnitude = (float) sqrt((double) magnitude_squared);
|
||||
|
||||
j = matrixFloatCount;
|
||||
while (j--)
|
||||
destMatrix[j] = srcMatrix[j] / magnitude;
|
||||
|
||||
dest.writeComplete();
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_lwjgl_Math_MatrixOpNormalise_MatrixOpSafe */
|
||||
|
||||
#ifndef _Included_org_lwjgl_Math_MatrixOpNormalise_MatrixOpSafe
|
||||
#define _Included_org_lwjgl_Math_MatrixOpNormalise_MatrixOpSafe
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpNormalise_MatrixOpSafe
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpNormalise_00024MatrixOpSafe_execute
|
||||
(JNIEnv *, jobject, jint, jint, jint, jint, jint, jboolean, jint, jint, jboolean);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Light Weight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* math library.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "org_lwjgl_Math_MatrixOpSubtract_MatrixOpDirect.h"
|
||||
#include "MatrixOpCommon.h"
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpSubtract_MatrixOpDirect
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpSubtract_00024MatrixOpDirect_execute
|
||||
(
|
||||
JNIEnv * env,
|
||||
jobject obj,
|
||||
jint leftSourceAddress,
|
||||
jint leftSourceStride,
|
||||
jint leftElements,
|
||||
jint leftSourceWidth,
|
||||
jint leftSourceHeight,
|
||||
jboolean transposeLeftSource,
|
||||
jint rightSourceAddress,
|
||||
jint rightSourceStride,
|
||||
jint rightElements,
|
||||
jint rightSourceWidth,
|
||||
jint rightSourceHeight,
|
||||
jboolean transposeRightSource,
|
||||
jint destAddress,
|
||||
jint destStride,
|
||||
jboolean transposeDest
|
||||
)
|
||||
{
|
||||
if (transposeLeftSource && transposeRightSource)
|
||||
{
|
||||
transposeLeftSource = false;
|
||||
transposeRightSource = false;
|
||||
transposeDest = !transposeDest;
|
||||
}
|
||||
|
||||
MatrixSrc left (leftSourceAddress, leftSourceStride,
|
||||
leftSourceWidth, leftSourceHeight, leftElements, transposeLeftSource);
|
||||
MatrixSrc right (rightSourceAddress, leftSourceStride,
|
||||
rightSourceWidth, rightSourceHeight, rightElements, transposeRightSource);
|
||||
MatrixDst dest (destAddress, destStride,
|
||||
left.width, left.height, left.elements * right.elements, transposeDest);
|
||||
|
||||
dest.configureBuffer(left, right);
|
||||
|
||||
float * leftMatrix, * rightMatrix, * destMatrix;
|
||||
|
||||
left.rewind();
|
||||
for (int i = 0; i < left.elements; i++)
|
||||
{
|
||||
leftMatrix = left.nextMatrix();
|
||||
|
||||
right.rewind();
|
||||
for (int j = 0; j < right.elements; j++)
|
||||
{
|
||||
rightMatrix = right.nextMatrix();
|
||||
destMatrix = dest.nextMatrix();
|
||||
|
||||
int k = dest.width * dest.height;
|
||||
while (k--)
|
||||
destMatrix[k] = leftMatrix[k] - rightMatrix[k];
|
||||
|
||||
dest.writeComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_lwjgl_Math_MatrixOpSubtract_MatrixOpDirect */
|
||||
|
||||
#ifndef _Included_org_lwjgl_Math_MatrixOpSubtract_MatrixOpDirect
|
||||
#define _Included_org_lwjgl_Math_MatrixOpSubtract_MatrixOpDirect
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpSubtract_MatrixOpDirect
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpSubtract_00024MatrixOpDirect_execute
|
||||
(JNIEnv *, jobject, jint, jint, jint, jint, jint, jboolean, jint, jint, jint, jint, jint, jboolean, jint, jint, jboolean);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Light Weight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* math library.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "org_lwjgl_Math_MatrixOpSubtract_MatrixOpSafe.h"
|
||||
#include "MatrixOpCommon.h"
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpSubtract_MatrixOpSafe
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpSubtract_00024MatrixOpSafe_execute
|
||||
(
|
||||
JNIEnv * env,
|
||||
jobject obj,
|
||||
jint leftSourceAddress,
|
||||
jint leftSourceStride,
|
||||
jint leftElements,
|
||||
jint leftSourceWidth,
|
||||
jint leftSourceHeight,
|
||||
jboolean transposeLeftSource,
|
||||
jint rightSourceAddress,
|
||||
jint rightSourceStride,
|
||||
jint rightElements,
|
||||
jint rightSourceWidth,
|
||||
jint rightSourceHeight,
|
||||
jboolean transposeRightSource,
|
||||
jint destAddress,
|
||||
jint destStride,
|
||||
jboolean transposeDest
|
||||
)
|
||||
{
|
||||
if (transposeLeftSource && transposeRightSource)
|
||||
{
|
||||
transposeLeftSource = false;
|
||||
transposeRightSource = false;
|
||||
transposeDest = !transposeDest;
|
||||
}
|
||||
|
||||
MatrixSrc left (leftSourceAddress, leftSourceStride,
|
||||
leftSourceWidth, leftSourceHeight, leftElements, transposeLeftSource);
|
||||
MatrixSrc right (rightSourceAddress, leftSourceStride,
|
||||
rightSourceWidth, rightSourceHeight, rightElements, transposeRightSource);
|
||||
MatrixDst dest (destAddress, destStride,
|
||||
left.width, left.height, left.elements * right.elements, transposeDest);
|
||||
|
||||
float * leftMatrix, * rightMatrix, * destMatrix;
|
||||
|
||||
left.rewind();
|
||||
for (int i = 0; i < left.elements; i++)
|
||||
{
|
||||
leftMatrix = left.nextMatrix();
|
||||
|
||||
right.rewind();
|
||||
for (int j = 0; j < right.elements; j++)
|
||||
{
|
||||
rightMatrix = right.nextMatrix();
|
||||
destMatrix = dest.nextMatrix();
|
||||
|
||||
int k = dest.width * dest.height;
|
||||
while (k--)
|
||||
destMatrix[k] = leftMatrix[k] - rightMatrix[k];
|
||||
|
||||
dest.writeComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_lwjgl_Math_MatrixOpSubtract_MatrixOpSafe */
|
||||
|
||||
#ifndef _Included_org_lwjgl_Math_MatrixOpSubtract_MatrixOpSafe
|
||||
#define _Included_org_lwjgl_Math_MatrixOpSubtract_MatrixOpSafe
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpSubtract_MatrixOpSafe
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpSubtract_00024MatrixOpSafe_execute
|
||||
(JNIEnv *, jobject, jint, jint, jint, jint, jint, jboolean, jint, jint, jint, jint, jint, jboolean, jint, jint, jboolean);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|