jni: add GLMatrix proj2d/3d
This commit is contained in:
parent
c34bc3306c
commit
59ab24da90
@ -98,7 +98,7 @@ static inline void
|
||||
matrix4_proj(float* mat, float* vec);
|
||||
|
||||
static inline void
|
||||
matrix4_proj2D(float* mat, float* vec);
|
||||
matrix4_proj2D(float* mat, float* vec, float *out);
|
||||
|
||||
jlong JNI(alloc)(JNIEnv *env, jclass* clazz)
|
||||
{
|
||||
@ -273,14 +273,33 @@ void JNI(prj2D)(JNIEnv* env, jclass* clazz, jlong ptr, jfloatArray obj_vec, int
|
||||
float* m = CAST(ptr);
|
||||
float* vec = (float*) (*env)->GetPrimitiveArrayCritical(env, obj_vec, 0);
|
||||
|
||||
int length = cnt * 2;
|
||||
offset *= 2;
|
||||
|
||||
for (int i = offset * 2; i < length; i += 2)
|
||||
matrix4_proj2D(m, (vec + i));
|
||||
for (int end = offset + cnt * 2; offset < end; offset += 2)
|
||||
matrix4_proj2D(m, (vec + offset), (vec + offset));
|
||||
|
||||
(*env)->ReleasePrimitiveArrayCritical(env, obj_vec, vec, 0);
|
||||
}
|
||||
|
||||
void JNI(prj2D2)(JNIEnv* env, jclass* clazz, jlong ptr,
|
||||
jfloatArray obj_src_vec, int src_offset,
|
||||
jfloatArray obj_dst_vec, int dst_offset, int cnt)
|
||||
{
|
||||
float* m = CAST(ptr);
|
||||
float* src = (float*) (*env)->GetPrimitiveArrayCritical(env, obj_src_vec, 0);
|
||||
float* dst = (float*) (*env)->GetPrimitiveArrayCritical(env, obj_dst_vec, 0);
|
||||
|
||||
int off_src = src_offset * 2;
|
||||
int off_dst = dst_offset * 2;
|
||||
|
||||
|
||||
for (int end = off_src + cnt * 2; off_src < end; off_src += 2, off_dst += 2)
|
||||
matrix4_proj2D(m, (src + off_src), (dst + off_dst));
|
||||
|
||||
(*env)->ReleasePrimitiveArrayCritical(env, obj_dst_vec, dst, 0);
|
||||
(*env)->ReleasePrimitiveArrayCritical(env, obj_src_vec, src, 0);
|
||||
}
|
||||
|
||||
static float someRandomEpsilon = 1.0f / (1 << 11);
|
||||
|
||||
void JNI(addDepthOffset)(JNIEnv* env, jclass* clazz, jlong ptr, jint delta)
|
||||
@ -519,13 +538,13 @@ matrix4_proj(float* mat, float* vec)
|
||||
}
|
||||
|
||||
static inline void
|
||||
matrix4_proj2D(float* mat, float* vec)
|
||||
matrix4_proj2D(float* mat, float* vec, float *out)
|
||||
{
|
||||
|
||||
float inv_w = 1.0f / (vec[0] * mat[M30] + vec[1] * mat[M31] + mat[M33]);
|
||||
float x = (vec[0] * mat[M00] + vec[1] * mat[M01] + mat[M03]) * inv_w;
|
||||
float y = (vec[0] * mat[M10] + vec[1] * mat[M11] + mat[M13]) * inv_w;
|
||||
|
||||
vec[0] = x;
|
||||
vec[1] = y;
|
||||
out[0] = x;
|
||||
out[1] = y;
|
||||
}
|
||||
|
@ -81,11 +81,11 @@ public class JniBuilder {
|
||||
android.cppFlags += cflags;
|
||||
android.linkerFlags += " -llog";
|
||||
|
||||
BuildTarget ios = BuildTarget.newDefaultTarget(TargetOs.IOS, false);
|
||||
ios.headerDirs = headers;
|
||||
ios.cIncludes = sources;
|
||||
ios.cFlags += cflags;
|
||||
ios.cppFlags += cflags;
|
||||
BuildTarget ios = BuildTarget.newDefaultTarget(TargetOs.IOS, false);
|
||||
ios.headerDirs = headers;
|
||||
ios.cIncludes = sources;
|
||||
ios.cFlags += cflags;
|
||||
ios.cppFlags += cflags;
|
||||
|
||||
//new NativeCodeGenerator().generate();
|
||||
new AntScriptGenerator().generate(new BuildConfig("vtm-jni"),
|
||||
@ -94,9 +94,10 @@ public class JniBuilder {
|
||||
// win32,
|
||||
// win64,
|
||||
// lin32,
|
||||
//lin64,
|
||||
//android
|
||||
ios);
|
||||
lin64,
|
||||
android
|
||||
//ios
|
||||
);
|
||||
|
||||
// BuildExecutor.executeAnt("jni/build-windows32home.xml", "-v clean");
|
||||
// BuildExecutor.executeAnt("jni/build-windows32home.xml", "-v");
|
||||
|
@ -126,6 +126,10 @@ public class GLMatrix {
|
||||
vec[2] = z;
|
||||
}
|
||||
|
||||
public void prj3D(float[] vec, int offset, int cnt) {
|
||||
throw new RuntimeException("unimplemented");
|
||||
}
|
||||
|
||||
public void prj2D(float[] vec, int offset, int cnt) {
|
||||
offset <<= 1;
|
||||
cnt <<= 1;
|
||||
@ -138,6 +142,33 @@ public class GLMatrix {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Project Vectors with Matrix
|
||||
*
|
||||
*
|
||||
* @param vec2 Vector to project
|
||||
*/
|
||||
public void prj2D(float[] src, int src_offset, float[] dst, int dst_offset, int length) {
|
||||
if (src == null || src_offset < 0 || length + src_offset * 2 > src.length)
|
||||
throw new IllegalArgumentException(INVALID_INPUT);
|
||||
|
||||
int x = (src_offset << 1);
|
||||
int y = x + 1;
|
||||
|
||||
int end = x + (length << 1);
|
||||
|
||||
dst_offset <<= 1;
|
||||
|
||||
while (x < end) {
|
||||
float inv_w = 1.0f / (src[x] * val[M30] + src[y] * val[M31] + val[M33]);
|
||||
|
||||
dst[dst_offset++] = (src[x] * val[M00] + src[y] * val[M01] + val[M03]) * inv_w;
|
||||
dst[dst_offset++] = (src[x] * val[M10] + src[y] * val[M11] + val[M13]) * inv_w;
|
||||
x += 2;
|
||||
y += 2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply rhs onto Matrix.
|
||||
*
|
||||
|
@ -88,11 +88,11 @@ public class GLMatrix {
|
||||
*
|
||||
* @param vec3 Vector to project
|
||||
*/
|
||||
public void prj3D(float[] vec3, int start, int cnt) {
|
||||
if (vec3 == null || vec3.length / (start + cnt) < 1)
|
||||
public void prj3D(float[] vec3, int offset, int length) {
|
||||
if (vec3 == null || vec3.length / (offset + length) < 1)
|
||||
throw new IllegalArgumentException(INVALID_INPUT);
|
||||
|
||||
prj3D(pointer, vec3, start, cnt);
|
||||
prj3D(pointer, vec3, offset, length);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,11 +100,24 @@ public class GLMatrix {
|
||||
*
|
||||
* @param vec2 Vector to project
|
||||
*/
|
||||
public void prj2D(float[] vec2, int start, int cnt) {
|
||||
if (vec2 == null || vec2.length % 2 == 1)
|
||||
public void prj2D(float[] vec2, int offset, int length) {
|
||||
if (vec2 == null || offset < 0 || (length + offset) * 2 > vec2.length)
|
||||
throw new IllegalArgumentException(INVALID_INPUT);
|
||||
|
||||
prj2D(pointer, vec2, start, cnt);
|
||||
prj2D(pointer, vec2, offset, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Project Vectors with Matrix
|
||||
*
|
||||
*
|
||||
* @param vec2 Vector to project
|
||||
*/
|
||||
public void prj2D(float[] src, int src_offset, float[] dst, int dst_offset, int length) {
|
||||
if (src == null || src_offset < 0 || length + src_offset * 2 > src.length)
|
||||
throw new IllegalArgumentException(INVALID_INPUT);
|
||||
|
||||
prj2D2(pointer, src, src_offset, dst, dst_offset, length);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -239,6 +252,53 @@ public class GLMatrix {
|
||||
delete(pointer);
|
||||
}
|
||||
|
||||
private native static long alloc();
|
||||
|
||||
private native static void delete(long self);
|
||||
|
||||
private native static void set(long self, float[] m);
|
||||
|
||||
private native static void copy(long self, long other);
|
||||
|
||||
private native static void identity(long self);
|
||||
|
||||
private native static void get(long self, float[] m);
|
||||
|
||||
private native static void mul(long self, long lhs_ptr);
|
||||
|
||||
private native static void smul(long self, long rhs_ptr, long lhs_ptr);
|
||||
|
||||
private native static void smulrhs(long self, long rhs_ptr);
|
||||
|
||||
private native static void smullhs(long self, long lhs_ptr);
|
||||
|
||||
private native static void strans(long self, long rhs_ptr);
|
||||
|
||||
private native static void prj(long self, float[] vec3);
|
||||
|
||||
private native static void prj3D(long self, float[] vec3, int start, int cnt);
|
||||
|
||||
private native static void prj2D(long self, float[] vec2, int start, int cnt);
|
||||
|
||||
private native static void prj2D2(long self, float[] vec2, int src_offset,
|
||||
float[] dst_vec, int dst_offset, int length);
|
||||
|
||||
private native static void setRotation(long self, float a, float x, float y, float z);
|
||||
|
||||
private native static void setScale(long self, float x, float y, float z);
|
||||
|
||||
private native static void setTranslation(long self, float x, float y, float z);
|
||||
|
||||
private native static void setTransScale(long self, float tx, float ty, float scale);
|
||||
|
||||
//private native static void setAsUniform(long self, int handle);
|
||||
|
||||
private native static void setValueAt(long self, int pos, float value);
|
||||
|
||||
private native static void addDepthOffset(long self, int delta);
|
||||
|
||||
private native static ByteBuffer getBuffer(long self);
|
||||
|
||||
/* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -436,48 +496,4 @@ public class GLMatrix {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private native static long alloc();
|
||||
|
||||
private native static void delete(long self);
|
||||
|
||||
private native static void set(long self, float[] m);
|
||||
|
||||
private native static void copy(long self, long other);
|
||||
|
||||
private native static void identity(long self);
|
||||
|
||||
private native static void get(long self, float[] m);
|
||||
|
||||
private native static void mul(long self, long lhs_ptr);
|
||||
|
||||
private native static void smul(long self, long rhs_ptr, long lhs_ptr);
|
||||
|
||||
private native static void smulrhs(long self, long rhs_ptr);
|
||||
|
||||
private native static void smullhs(long self, long lhs_ptr);
|
||||
|
||||
private native static void strans(long self, long rhs_ptr);
|
||||
|
||||
private native static void prj(long self, float[] vec3);
|
||||
|
||||
private native static void prj3D(long self, float[] vec3, int start, int cnt);
|
||||
|
||||
private native static void prj2D(long self, float[] vec2, int start, int cnt);
|
||||
|
||||
private native static void setRotation(long self, float a, float x, float y, float z);
|
||||
|
||||
private native static void setScale(long self, float x, float y, float z);
|
||||
|
||||
private native static void setTranslation(long self, float x, float y, float z);
|
||||
|
||||
private native static void setTransScale(long self, float tx, float ty, float scale);
|
||||
|
||||
//private native static void setAsUniform(long self, int handle);
|
||||
|
||||
private native static void setValueAt(long self, int pos, float value);
|
||||
|
||||
private native static void addDepthOffset(long self, int delta);
|
||||
|
||||
private native static ByteBuffer getBuffer(long self);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user