view-frustum culling implementation with jit.gen & matrices

    Jun 12 2012 | 8:31 pm
    Pointed there by Robert R., i'm trying to implement view-frustum culling into my system. I'm using : 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.
    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.

    • Jun 13 2012 | 12:03 am
      "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 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.
    • Jun 13 2012 | 9:59 am
      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!!
    • Jun 13 2012 | 6:22 pm
      I finally have little problem to retrieve ratio parameter :-/ (in setCamInternals :
      I guess it is the ratio between height and wide of frustum?!
    • Jun 14 2012 | 9:43 am
      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 ?
    • Jun 14 2012 | 6:15 pm
      ratio is window-width divided by window-height.
    • Jun 14 2012 | 9:29 pm
      Hi Julien
      a month ago I solved the modelviewprojection transformation with a max patch:
      this patch calculates the xy-pos on the screen for one vertice. maybe it could be used to do what you wanna achieve?
    • Jun 15 2012 | 12:07 pm
      @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
    • Jun 15 2012 | 12:45 pm
      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 1x1 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 ?
    • Jun 16 2012 | 11:43 pm
      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:
      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.
    • Jul 05 2012 | 11:17 am
      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.
    • Jul 05 2012 | 11:20 am
      hi there, x,y aren't enough because my cam doesn't have to be locked in only one plane.
    • Jul 06 2012 | 4:27 pm
      if I understand you correctly: my patch works with all sorts of camera-transformations.
    • Jul 06 2012 | 7:10 pm
      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.