I am currently trying to create an octree in Unity. I would like each node to have a list of pointers that point to the AABB's of the childnodes. The AABB's are a struct that looks like this:
public struct ABB
{
public float size;
public float centerX;
public float centerY;
public float centerZ;
public ABB(float size, float centerX, float centerY, float centerZ)
{
this.size = size;
this.centerX = centerX;
this.centerY = centerY;
this.centerZ = centerZ;
}
}
Each node contains a list of its children:
public OctreeNode[] children = null;
I would like to use the AABB's of the children of the node in a bursted job, but the OctreeNodes themselves are a class, which is not supported by burst. Therefore, I would like to get the AABB's, but storing a copy of them for each node seems a bit redundant. Therefore, storing a pointer to the AABB's of the children seems like the best solution for me. However, I fail to understand how to do this in C#.
Currently, I have an array of pointers
public ABB*[] childBounds = null;
My question is, how do I fill this array with pointers?
Something like:
if (children[0] == null)
{
children[0] = new OctreeNode(new ABB(childLength, nodeBounds.centerX + -quarter, nodeBounds.centerY + quarter, nodeBounds.centerZ + -quarter), this, rootSeed);
childBounds[0] = children[0].nodeBounds;
}
Gives me an error, essentially saying that
Cannot implicitly convert type AABB (children[0].nodeBounds) to AABB*
Could someone try to explain how to do this properly in C#?
Thanks to everyone in the comments who pointed me in the right direction.
Essentially, store the pointer in a temporary variable, and then assigned it in a fixed() statement, like so:
fixed(ABB* boundsPtr = &children[0].nodeBounds)
{
childBounds[0] = boundsPtr;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.