### view-frustum culling implementation with jit.gen & matrices

Pointed there by Robert R., i'm trying to implement view-frustum culling into my system.

I'm using : http://www.lighthouse3d.com/tutorials/view-frustum-culling/ which seems to be a great reference (I saw this link a bit everywhere)

I'm currently into the Geometric Approach and, for sure, I need some generous hands to help me.

I understood the demo there : http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-extracting-the-planes/

This is the global description.

Implementation is a bit more tricky (for me)

http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-implementation/

As attached, I'm okay (I guess) with the setCamInternals.

I'm stuck in implementing the setCamDef which has to compute 3 vectors and to render the 8 points of the frustum (=the 6 planes used for checking which object has to be sent to the openGL pipeline)

I'm stuck because I don't know how to grab those 3 vectors required.

The first one is ok, this is the position of the cam.

The second one is "a point to where the camera is pointing" … How can I find/calculate it ?

The third is the up vector, same .. . how can I grab it ??

ANY help would be amazing for me.

[attachment=196441,4030]

"The second one is "a point to where the camera is pointing" … How can I find/calculate it ?

The third is the up vector, same .. . how can I grab it ??"

both of these attributes can be retrieved.

you have to attach a jit.anim.node to your jit.gl.camera in order to make it work. (this requirement will be removed in an upcoming release)

the camera-point-position is the @lookat attribute of jit.anim.node.

the up vector can be calculated from the anim.node’s @quat attribute, by sending it to a jit.quat object, and querrying the yaxis attribute. (the up vector is the Y axis transformed by the camera’s current quaternion)

check out the patch below.

**all**of the following text. Then, in Max, select

*New From Clipboard*.

```
----------begin_max5_patcher----------
1042.3ocyY1sjZCBEG+Z8ofIW6lIP9vXuZeJ5Mc53fF1HaS.Kg3Zam9tWfDs
wVMAccwbShgPfC+37+vA7WSm3shumT4A9D3KfIS90zISLEoKXR6yS7Jw6WWf
qLUyaMurjvjdyZdmjrWZJufy+F9XwuvYxJ5OI5WAQ9AsEuUPpTeLVR4rkBxZ
YSOmfRTUAD0bKn8B3qseEqtjWKKHRiEbrsvx0anr7NsSbp4aCSL2RizWQwcZ
IZlwV4qd8Iz7t1JCWZrUuOSDYXF16ucMkcnmgsEtpd0ph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zjgHd61cDQUaaZLEUhyuxMIgmLy7Hk07noE8DjczC0O
dpt098z+.96x.3C
-----------end_max5_patcher-----------
```

Hi Robert,

a big thanks to you.

I even understood how jit.anim.node object worked :)

implementing my calculation about view-frustum culling in next hours and posting here the result!!

I finally have little problem to retrieve ratio parameter :-/ (in setCamInternals : http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-implementation/)

I guess it is the ratio between height and wide of frustum?!

so, I have some difficulties about 2 things:

- to retrieve the ratio parameter in order to calculate my 8 points defining my 6 planes for the culling

- to put that into my jit.gen.

basically, here is my current implementation on jit.gen

ratio & planes implementation are missing, and of course, the objects matching test.

probably, I'll create a matrix with my 8 points, then another jit.gen which would be fed by objects positions matrix + my 8 points matrix, calculating which objects is in or out of scope…

would you help me with that Robert, or Wes or ?

[attachment=196574,4037]

ratio is window-width divided by window-height.

Hi Julien

a month ago I solved the modelviewprojection transformation with a max patch:

http://cycling74.com/forums/topic.php?id=39855

this patch calculates the xy-pos on the screen for one vertice. maybe it could be used to do what you wanna achieve?

cheers

martin

@Robert.. thanks for this obvious thing I didn’t even notice :-/

@maybites: thanks a lot for your link.

I don’t know how to apply your nice patch (which I understood btw) to my "case"

I’m trying to implement http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-implementation

if I sent an n planes matrix to a jit.gen, what is the rule to retrieve a particular plane ??

I’m currently sending an 1×1 matrix with 4 planes to the first inlet of my jit.gen

I’m mapping the in 1 to a codebox, on the first inlet too

so in1.x, .y, .z are the first 3 planes

how can I have the fourth ?

so here is where I went.

I have that huge jit.gen (finally not that big)

It takes some parameters as input:

- position of the cam

- a point on the view direction of the cam (lookat)

- the up vector

It takes also cam parameters like:

- lens angle

- ratio of the view (w/h)

- nearClip distance

- farClip distance

it processes the whole parameters to render the 8 points of the view frustum.

As shown there: http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-extracting-the-planes/

The calculation is there:

http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-implementation/

first question:

I need to normalize a vector inside the codebox.

I did the basic calculation including sqrt()

does it exist a better way inside GenExpr / codebox ?

Now, I have my eight point defining my view.

They defines my 6 planes too.

I have to "test" all my object according to those planes in order to have a list of objects I have to inactivate and activate, according to the position & orientation of my cam.

That part is done in the second codebox and has to be done for the 6 planes.

Knowing I have a matrix with all my objects' positions, how can I test each one against those 6 planes ??

any help would be appreciate.

I don't know if this is the best implementation I could make of that concept.

[attachment=196798,4050]

Only to clarify my approach (which is quick and dirty compare to the road you are taking).

As far as I understand you wanna have a tool that tells you if your object is inside the viewing frustum. my patch does that insofar, that it calculates the x-y screen-coordinates of a 3d vertex. if the x-y coordinates are not inside the screen, the vertex would be outside the frustum.

But I might have missunderstood your problem.

hi there,

x,y aren’t enough because my cam doesn’t have to be locked in only one plane.

if I understand you correctly: my patch works with all sorts of camera-transformations.

this would be nice if I could test it.

I’m currently trying to make a calculation for all objects around the cam for pure sound purpose. I already need that.

The position of the object relatively to the cam would be defined by azimuth/elevation/distance.

Then, I’d like to make a one pass calculation and calculate if the object has to be activated or not according to azimuth/elevation.

Indeed, all in one could be nice & efficient.