Look at my old getPickingRay method. return was:
farVector.sub(nearVector).normalize();
And it worked, but now it doesn't, just if I would stay in center of world and then just sensitive, when I move mouse just per 1 pixels, so it picks through 20 cubes far.
And I'm doing matrix only before ray picking check when rendering world objects.
world.render(); //Here
for(int i=0; i<world.objects.size(); i++) world.objects.get(i).selected = false;
if(world.rayPicking){
Vector3 destination = getPickingRay(Display.getWidth() / 2, Display.getHeight() / 2);
Ray rayPick = new Ray(new Vector3(control.position.x, control.position.y, control.position.z), destination);
int index = -1;
float minDepth = Float.MAX_VALUE;
for(int i = 0; i < world.objects.size(); i++) {
float depth = 0;
if(rayIntersection(rayPick, world.objects.get(i))){
depth = world.objects.get(i).z;
}else{
depth = Float.MAX_VALUE;
}
if(depth < minDepth){
minDepth = depth;
index = i;
}
}
if(index != -1) world.objects.get(index).selected = true;
selectedObjectIndex = index;
}
And after this code is doing matrix with player camera "lookThrough" method.
public void lookThrough(){
glRotatef(pitch, 1.0f, 0.0f, 0.0f);
glRotatef(yaw, 0.0f, 1.0f, 0.0f);
glTranslatef(-position.x, -position.y, -position.z);
}