Is there a method which detect if some object is visible?
A cameras frustum is defined by the angle, aspect ratio, zNear and zFar. You need to see if the bounding box of the spatial is within this trapezoidal? view, not sure exactly what the right shape name is. I posted a link to a pic in the y rotation 180o thread. Cba to find it as I’m on my phone on the train atm. Perhaps there should be a camera.getFrustum().contains(spatial) method or something. How does jME know when to cull stuff, must be something similar to that? Idk. I really am just making stuff up atm lol
Well.The problem comes when the object is behind tree or something.
That shouldn’t make a difference, have a look for the pic I mentioned
There is no pic and the link is broken.Http/1.1 Service Unavailable
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies
uh there is a pic? check page 3. I’m back home and found that there is a cam.contains(BoundingVolume) already, and this is what is used for culling. You can use this and check for FrustumIntersect.Inside OR FrustumIntersect.Intersects, but from the javadoc:
[java] * NOTE: This method is used internally for culling, for public usage,
- the plane state of the bounding volume must be saved and restored, e.g:
- BoundingVolume bv;
- Camera c;
- int planeState = bv.getPlaneState();
- bv.setPlaneState(0);
- c.contains(bv);
- bv.setPlaneState(plateState);[/java]
So this will help me to check if the object is behind tree or not?
Oh… so do u wanna check if an object is completely being hid by another object, or just partially being hid?
for check if object is in screen(partially or not):
[java]cam.getScreenCoordinates(your vector here)[/java]
where vector is object vector.
and if im not wrong, it should give null(for out of screen), and if not, then it should give position out of resolution.
about checking if it is behind tree you could use RayCasting.
if it is behind, then first of Ray collisions will be a tree, then your object.
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_picking?s[]=ray
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:mouse_picking?s[]=ray
@wezrule said:
Oh.. so do u wanna check if an object is completely being hid by another object, or just partially being hid?
I want to check if the object is completely behind another object.
Work out the objects bounding box.
Project the 4 corners and center onto the screen.
Cast a line between the screen points and the bounding box corners.
No collisions = full view
Some collisions = partial
All collisions = total
The more lines you cast then the more accurate the results but also the more expensive the algorithm is to run.
Other way?
Explain what and why you are trying to achieve and there might be another way to go about it…
Well i will make a horror game.I want to check it he player sees the monster.
Why?
@nlcenslfew said:
Well i will make a horror game.I want to check it he player sees the monster.
What @zarch posted will do the work.
What's making me wonder is, why do you need to know if the player sees the mob?
To start the scary music and to start drain his health.
The music could be started with distance and heath drain could (should?) be started when the mob sees the player (because I would imagine that’s one of the mob’s ability) for example.
Actually, I think distance would be better since it’s a whole lot more worrying hearing the “scary music” when you can’t see the enemy than when you see it. But, maybe that wouldn’t work in your game.
I want to recreate this http://www.youtube.com/watch?v=1WOIB-JzYVU so i need to check if the player sees the mob.