Thx for this, interesting. Can you add some more about the var you init in the code please ? I'm sure if I can put it in my code. I'm looking for a way to place x.y.z my camera and look in the x.y.z right direction.
the init code variables refer to the variables used in the openGL function
gluPerspective(fieldOfView, aspectRatio, closeDistance, farDistance);
the number that is calculated is just a basic gradient value (used in a basic linear equation y = mx + c) m is the gradient.
this example is only for basic translations, and rotations. if doesnt really work if the rotations are all done in one call.
Basically what this code does, is positions the scene as if the camera were at position 0, 0, 0 with no rotation (camera normal, looking out at 0, 0, -1).
then the line equation test is run (y = mx + c) in this case there is no yIntercept (c) there fore the test run is:
y = mx, but to take into account the models/objects radius the test thats run is
y+radius = gradient * x. (this example checks if the object is ON the line, so less than or greather than signs are used to check if its in the screen)
this test is run for the top, bottom, left and right of the screen.
Assuming you camera is placed in the following way
translate(x, y, z);
rotate(yRot, 0, 1, 0);
here is a version that should work for you:
1 2 3 4
| public static void update() { a1 = (float)Math.cos(-Math.toRadians(Camera.yRot)); b1 = (float)Math.sin(-Math.toRadians(Camera.yRot)); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| public static float check(MapObject o, float radius) {
x = (o.xPos * a1) - (o.zPos * b1); z = (o.xPos * b1) + (o.zPos * a1); x -= Camera.xPos; y = o.yPos - Camera.yPos; z -= Camera.zPos;
if (y + radius < xGradient*z || x + radius < yGradient*z) return 0; z = -z; if (y - radius > xGradient*z || x - radius > yGradient*z) return 0; z = (float)Math.sqrt((x*x) + (y*y) + (z*z)); if (z > farDistance || z < closeDistance) return 0;
return z; } |