1203 |
return (cs != 0); |
return (cs != 0); |
1204 |
} |
} |
1205 |
|
|
1206 |
|
struct Match { |
1207 |
|
int ind; |
1208 |
|
float depth; |
1209 |
|
bool operator<(const Match &m) const { |
1210 |
|
return depth < m.depth; |
1211 |
|
} |
1212 |
|
}; |
1213 |
|
|
1214 |
|
JNIEXPORT jintArray JNICALL Java_gzz_gfx_gl_GL_getAllCSAt |
1215 |
|
(JNIEnv *env, jclass, jint ninds, jintArray j_inds, jfloatArray j_pts, |
1216 |
|
jint parent, jfloat x, jfloat y) { |
1217 |
|
jint *inds = env->GetIntArrayElements(j_inds, 0); |
1218 |
|
jfloat *pts = env->GetFloatArrayElements(j_pts, 0); |
1219 |
|
|
1220 |
|
vector<Match> matches; |
1221 |
|
|
1222 |
|
Coords::CoordSet coordset; |
1223 |
|
coordset.clean(); |
1224 |
|
coordset.setPoints((int)ninds, (int*)inds, |
1225 |
|
(float*)pts, (int*)0, |
1226 |
|
(int*)0, (float*)0, |
1227 |
|
(float)0, (bool)true); |
1228 |
|
|
1229 |
|
ZPt screenpt(x, y, 0); |
1230 |
|
for(Coords::CoordSet::iterator iter = coordset.begin(); |
1231 |
|
iter != coordset.end(); iter++) { |
1232 |
|
// XXX Break encapsulation badly |
1233 |
|
if(!(inds[*iter] & Coords::CSFLAG_ACTIVE)) |
1234 |
|
continue; |
1235 |
|
Coords::CoordSys *cs = coordset.get(*iter); |
1236 |
|
|
1237 |
|
// Transform screen point to inside coordsys |
1238 |
|
ZPt pt = cs->getInverse()->transform(screenpt); |
1239 |
|
// See whether inside unit square |
1240 |
|
if(pt.x < 0 || pt.x > 1 || |
1241 |
|
pt.y < 0 || pt.y > 1) continue; |
1242 |
|
// Project to zero plane |
1243 |
|
pt.z = 0; |
1244 |
|
// Transform back to screen coordinates |
1245 |
|
pt = cs->transform(pt); |
1246 |
|
// Add match object |
1247 |
|
Match m = { *iter, pt.z }; |
1248 |
|
matches.push_back(m); |
1249 |
|
} |
1250 |
|
|
1251 |
|
// Sort the matches according to depth |
1252 |
|
std::sort(matches.begin(), matches.end()); |
1253 |
|
|
1254 |
|
// Put the matching indices into the output array. |
1255 |
|
jintArray arr = env->NewIntArray(matches.size()); |
1256 |
|
jint *els = env->GetIntArrayElements(arr, 0); |
1257 |
|
|
1258 |
|
for(unsigned i = 0; i<matches.size(); i++) |
1259 |
|
els[i] = matches[i].ind; |
1260 |
|
|
1261 |
|
env->ReleaseIntArrayElements(arr, els, 0); // Commit |
1262 |
|
|
1263 |
|
|
1264 |
|
env->ReleaseIntArrayElements(j_inds, inds, JNI_ABORT); |
1265 |
|
env->ReleaseFloatArrayElements(j_pts, pts, JNI_ABORT); |
1266 |
|
|
1267 |
|
return arr; |
1268 |
|
} |
1269 |
|
|
1270 |
|
|
1271 |
|
|
1272 |
using namespace Renderables; |
using namespace Renderables; |