Jump to content

CommNet Occlusion [Solved]


Recommended Posts

For my beamed power mod, I was working on getting planetary occlusion data from CommNet. I was wondering how to get a list of all celestial bodies in the game. Is it necessary for me to loop through each celestial body to get it's transform and input that into the constructor OccluderHorizonCulling. Also, what does it mean by radiusX? Reading the website they give a link to in the API, they discuss ellipsoids, aren't planets in ksp spherical?

Here is my code so far:

public class BPOcclusion : OccluderHorizonCulling
{
  public BPOcclusion() : base()
  {

  }
  public string CheckIfOccluded(Vessel Source, Vessel Dest, string state, out bool occluded)
  {
    OccluderHorizonCulling horizonCulling = new OccluderHorizonCulling(transform, radiusXRecip, radiusYRecip, radiusZRecip);
    QuaternionD invrot = invRotation;
    Vector3d source = Source.GetTransform().localPosition;
    Vector3d dest = Dest.GetTransform().localPosition;

    occluded = horizonCulling.Raycast(source, dest);
    if (occluded)
    {
      state = "Occluded by" + body.GetDisplayName();
    }
    return state;
  }
}

 There are no parameters for the base class constructor for now, until I can understand what the parameters mean. I'm currently getting a nullref exception in the log, likely due to transform not being assigned to anything yet.

Any help on this is much appreciated, I might've misunderstood all of this.

Edited by Aniruddh
Link to comment
Share on other sites

The celestial bodies list is FlightGlobals.Bodies

The transform for OccluderHorizonCulling is a CelestialBody.transform.

The radius are the body radius. Not all KSP planet are perfect sphere but you can use CelestialBody.radius to keep it simple.

And with horizonCulling.Raycast using double precision vectors it it likely that that you should use Vessel.GetWorldPos3D() for the source and dest values.

Link to comment
Share on other sites

I think I'm almost there in getting this working, one final question, what does it mean by invRotation? I haven't seen that listed anywhere under the Vessel or CelestialBody classes. How would I get this value?

EDIT: I'm guessing it's this one:

invRotation = FlightGlobals.Bodies[x].transform.rotation.Inverse();

 

Edited by Aniruddh
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...