On scrren test

Is there a method to test whether or not an object is on screen?

Obviously I can test the objects position. Just wondering if Panda included a more elegant solution.

Thanks

Paul

Not really. One problem with asking this question is that, in a more general environment, for instance with multiple cameras and/or multiple windows, an object might be “onscreen” in one camera and not in others. Another problem is that you won’t really know what’s “onscreen” until the frame is rendered, which is the last thing that happens in the frame–so even if Panda did answer this question for you, it would always be one frame out of date. A final problem is that Panda doesn’t necessarily know what’s onscreen, even after the frame has been rendered–it knows what’s within the viewing frustum, but the object might be located behind a wall and Panda has no good way of finding this out.

So although it sounds like a simple question, it’s actually quite complicated. :slight_smile: You’re better off just checking the position, if that’s an option for you in your application.

That being said, you can ask if a particular point is in front of your camera (that is, within the viewing frustum) with the call base.camNode.isInView(Point3(x, y, z)). You’ll have to convert the point into your camera’s space first if it’s not already; for instance, if it’s in the coordinate space of myObject, use:


base.camNode.isInView(base.cam.getRelativePoint(myObject, Point3(x, y, z))

David

What are saying makes sense but just incase Im missing somethin I’ll explain the situation.

I want to wrap an object. That is as an object disappears off the top of the screen I want it to appear at the bottom.

I’m wrapping asteroids style at the moment testing the position of the object unfortunately the obejct is oblong so this isn’t ideal.

Is there a panda method for this?

In your case, the test you require is much simpler than the sophisticated question of “is this object onscreen”. All you need to know is “is this object’s position within this range.”

Just check the object’s position, with something like this:

if obj.getX() < 0.0:
  obj.setX(obj.getX() + 1.0)
elif obj.getX() > 1.0:
  obj.setX(obj.getX() - 1.0)

and similarly for Y (or Z, however you’ve got it set up).

This will make your asteriods “pop” from one side of the screen to the other. If you want to make them appear to slide smoothly across, so that you can simultaneously see part of the asteroid on both sides of the screen, you will have to get fancier and temporarily replicate the asteroid in both places. Not hard, but it does complicate the whole thing; I don’t recommend doing this unless you’re feeling obsessive about replicating the feel of the original arcade game exactly.

David

ta david

in this case I’m obsessive time to make triplicates of every object I guess.

Another simple answer is to let the objects slide completely offscreen before they appear on the opposite side. You can do this simply by making the wraparound margins a little wide than the actual screen edges.

David

Yeah that is what I am doing at the moment. I don’t think it looks very finished though so I’m going to reolicate the objects as they move off the screen.

With that in mind I have a couple of questions.

Firstly I understand that when a node is given a parent the nodes position is relative to the parent. What I want to know is does the position stay relative when the parent node is moved?

Secondly Panda seems to include some collision testing methods what sort of collision testing is available, spherical, oobb etc?

Also if you include a parent node in a collision test does it automatically test the children too?

I know I can find this out by trying/reading the manual but I’m at work at the moment plus I prefer to ask.

Thanks

Paul

Yes. This is a key feature of the scene graph.


Secondly Panda seems to include some collision testing methods what sort of collision testing is available, spherical, oobb etc?

For this question I will direct you to the manual.


Also if you include a parent node in a collision test does it automatically test the children too?

You should probably read the manual for this one too. The collision system does not work on a node-by-node basis, but rather you create special collision objects, for instance, invisible spheres, that you attach to key places in your scene graph and that do all of the collisions for you.


I know I can find this out by trying/reading the manual but I'm at work at the moment plus I prefer to ask. 

While I appreciate your outward and social nature, I hope you will not be offended if I respectfully request that you do always try to research questions before asking them here in the forum. We have been working hard on putting that manual together, after all, and there’s nothing like direct experience to answer some questions. :slight_smile:

David

Thanks for your response.

I, erm, have read the collision detection section in the manual now and it seems straight forward enough no doubt you’ll get more questions when I try it out.

Hi Traiger,

The collision detection is pretty straight forward. However, looking at your posts, did you look at the tutorials included with Panda? There is a basic asteroid clone included. Also, check out some of the other ones aswell as they contain some info on coliisions. Lastly, check out the airblade source.

Good luck with your project!

Sandman yeah I am refering to the asteroids clone in the Tasks example. However I am looking to make something a little more extravagant so its really just for a reference to coding in python in a context thats relavent more than copying exactly what is written there.

For example you can guess without checking that the example only uses a sphere test for collision and I’m after a little more precise. Although looking at the options a combination of sphere and cylinders will probably do me it would be handy to create a kind of collision mesh or in this case as the poly count is so low use the models meshes for collision testing.

Out of curiosity where should the airblade example be I don’t seem to have it?

Airblade is not a part of the panda3d download. But you can find it in the same place (under Downloads->Software). It might help you out if your just wondering how things were done.

Take care.