call objects in an specific matrix

hi, everyone
is it possible to set a matrix by an cube vertex points and to get all objects in this matrix without calling all scene.objects?

like, if an object in an cube get obj.id

also like, the frustum call objects in came range

it should be not intensive to the logic rate, not really with an radar or ray sensor or modul!

that is the box inside test if this matrix(box) in frustum field of the camera


import bge
		
		scene = bge.logic.getCurrentScene()
		camList = scene.cameras
		cam = camList["security_cam"]
		Box = [ ]
		
		Box.append([ -1.0, -1.0, -1.0])
		Box.append([ -1.0, -1.0,  1.0])
		Box.append([ -1.0,  1.0, -1.0])
		Box.append([ -1.0,  1.0,  1.0])
		Box.append([  1.0, -1.0, -1.0])
		Box.append([  1.0, -1.0,  1.0])
		Box.append([  1.0,  1.0, -1.0])
		Box.append([  1.0,  1.0,  1.0])
		
		if cam.boxInsideFrustum(Box) == cam.INSIDE:
.........



and I want that for an 4x4 matrix to check objects inside

hope you get it?!

thanks for help

Does the object have to be fully inside the cube to register?

I think no one edge/vertex is enough.

Why don’t you use a physics object with a collision sensor?
Set it to be ghost and invisible, then if someone collides with it they trigger an alarm or whatever.

I think if you wanted, for all your objects in your scene you could have an “if” check to test whether or not it is inside a given frustum of the camera you define (so your camera is the “matrix checker”) using the boxInsideFrustum() method here: https://www.blender.org/api/blender_python_api_2_66_6/bge.types.KX_Camera.html#bge.types.KX_Camera.boxInsideFrustum

With this (untested) method, you could use globalDict to store objects that are inside the frustum, then retrieve those objects later.

Or, if you don’t have any objects that are collision type “no collision” (or maybe even navigation mesh, etc.), you could do smoking’s suggestion. Or that suggestion might be what you were looking for all along anyway.

I think what you’re asking for is really difficult, because you can’t use ray/radar sensors, you can’t get all objects in the scene, and it can’t significantly affect the framerate. If you have a ton of objects, the framerate can become a problem.

What you describe is not a matrix. These are corners of a cube. The name Box describes it pretty good.

By default there is no chance to get the requested objects without checking each single object within the scene.

Preparation
You can organize your scene in a way that you might be able to reduce the number of considered objects. Be aware this adds restrictions and maybe additional processing time.

For example:

  • You could assume that all cloud objects are above z=0. This allows you to ignore them when the box is below z=0.

Sounds to abstract? how about the opposite you assume that all amphibia are below z=0.

Caching
You still need an efficient method to get the remaining objects. Filtering will not work that well as you would still need to touch all objects. But you can reduce the amount of filtering. E.g. you filter the object just once and reuse the result again and again. This reduces the effort from O(n²) to O(n).

The assumptions are:
A) the criteria does not change on an object
B) the criteria has no influence on the box checking (= no position, rotation, scale, not even parent relationship when the parent isn’t fixed in place).
C) rarely adding and removing objects as this requires to update the cache

Hierarchical organization (tree)
You could structure your scene in a way that it is very efficient to identify objects that can be ignored (or be considered).

The idea is you cut the scene into pieces. A simple and efficient way are cubes. Example:

Root = cube
= 8x lvl 1 Branches
= 8x8 lvl 2 Branches (each Branch consists of 8 sub-branches)

Here we go into the direction of the already mentioned tree datastructure. We look top down from lowest detail to highest detail.

Root:
A) if the bounding box of the root does not intersects the box -> there is no object inside
B) otherwise look at the branches

Branch:
A) if the bounding box of the branch does not intersects the box -> there is no object inside -> continue with the other branches
B) otherwise look at the branches of the branch

Branch:
A) if the bounding box of the branch does not intersects the box -> there is no object inside -> continue with the other branches
B) otherwise look at the branches of the branch

This way you do not iterate over all objects but the cubes. Which are much less.

The problem here is, that objects can move from one cube to another. This could be an expensive operation as the tree needs to be restructured (find object, remove from branch, find new branch, add object). So this is efficient on many static (non-moving) objects.

Remarks

I’m sure there are many other ways to reduce the number of objects to consider. It is important that the additional effort does not exceed the efford you need to spend without it.

What method is effective for you depends on your use case. So why do you think you need this operation? And why do you think it needs to be very fast?

@cannibal
I don’t think you can do it without loops, you should be fine if you minimize the inside frustum test to a few objects instead of against the entire scene.objects list

I have all my agents in a list, when a new agent is spawned it automatically adds itself to this list. Same with particles, they get their own list. Same with level meshes etc…
When an agent is ended it is removed from the list.
This allows me to check quickly to see if an agent is in an area or find the nearest agent to the player or other important checks.
Furthermore in most of my games the agents interact with the level through a tile based dictionary. Looking at any tile I can find out if there is an agent there and if so get a reference to it.
That gives me two ways of checking for an agent which are both efficient in their own particular ways.

@Smoking_Mirror that can’t work if the object in an other object the “cube” is empty and will detect nothing.

@Monster of course this is a great way but I would copy the area who to look if objects in to an moving object like a player or other things, so the grid way is not an option but to check if some camera in this cube area is easier