Picking can be done this way: http://www.jpct.net/wiki/index.php?title=Picking#The_recommended_way
Just make sure that your touch coordinates are the ones that you think they are. The default behaviour is that the FrameBuffer starts at 0,0 beneath an existing title bar (if there is one) but the touch coordinates don't this into account, so that their origin is located below the title bar at the first visible pixel on the upper left. More info on that can be found here: http://www.jpct.net/forum2/index.php/topic,4181.msg29291.html
About grouping the models: The easiest way is to use parent/child relations between the objects. How you assign these is up to you, but one solution would be to add a dummy object. So you basically do something like this:
Object3D parent=Object3D.createDummyObj();
parent.build();
for(Object3D part:parts) {
part.addParent(parent);
}
...and then transform the parent only to transform the whole group. The dummy object can be part of the World instance if you need that for some reason, but it doesn't have to.
Hello again. Now rotating working fine, I try to implement model parts picking.
This is my code for touch handling:
val pos = getWorldPosition()
if(pos != null) {
val res = world.calcMinDistanceAndObject3D(camera.getPosition, getWorldPosition(), 1000f)
if(res[1] != null) {
if(selectedObject != null) {
}
selectedObject = res[1] as Object3D
selectedObject!!.setTexture("red")
selectedObject!!.touch()
Log.v("Inspector", "CATCH COLLISION name " + selectedObject!!.name)
}
}
private fun getWorldPosition(): SimpleVector? {
var pos: SimpleVector? = null
val ray = Interact2D.reproject2D3DWS(world!!.getCamera(), fb, x, y)
if (ray != null) {
var norm = ray.normalize() // Just to be sure...
val f = world!!.calcMinDistance(world!!.getCamera().position, norm, 1000f)
if (f != Object3D.COLLISION_NONE) {
val offset = SimpleVector(norm)
norm.scalarMul(f)
norm = norm.calcSub(offset)
pos = SimpleVector(norm)
pos.add(world!!.getCamera().position)
}
}
return pos
}
I'm faced with situation, when getWorldPosition return non-null pos, but Object3D [] returned by calcMinDistance have 1.0E12 as 0 element and null as 1 element. So, I cant detect object
Also, I'm remove toolbar on my activity. And one more moment: collision detects correctly in method getWorldPosition() (return pos only when I click on some model part), but calcMinDistance always return array[2] with null second value
Note : I'm using serialized models