Sign in to follow this  

BSP Leaf Finding (solved)

This topic is 3864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello ! I'm trying to find the leaf of a BSP the camera is in. Here's my code
  //  Find node
  i := 0;
  while (i >= 0) do
   begin
    Node := fNodes[i];
    Plane := fPlanes[Node.Plane];

    Distance := Plane.Normal[0] * pos[0] +
                Plane.Normal[1] * pos[1] +
                Plane.Normal[2] * pos[2] - Plane.Distance;

    if (Distance >= 0) then
      i := Node.Children[0]
     else
      i := Node.Children[1];
   end;

  //  Return
  Result := -(i+1);
It doesn't work since for most leafs the cluster is -1 which means the camera is outside of the map. I suspect this is the code that is failing. Any ideeas? PS: version 46 BSP (Quake 3) EDIT: I solved this a few days ago. It was actually an error when switching axes of the plane normals (I was doing something like "aux = n[i][1]; n[2][1] = n[i][2]; n[i][2] = -aux"; Note the 2 instead of an i :) ). That was it ... stupid error. Stupid stupid error. [Edited by - Rimio on May 28, 2007 12:54:13 AM]

Share this post


Link to post
Share on other sites

This topic is 3864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this