void Start() { // calculate AABB and add to context bounds = GetMaxBounds(); isInHeadSlice = IsWithinPlayerHeadSlice(bounds); if (isInHeadSlice) { AABB properties = CalculateAABB(bounds); id = PlaneverbContext.AddGeometry(properties); } }
void Update() { // only add if object is at player head slice bounds = GetMaxBounds(); isInHeadSlice = IsWithinPlayerHeadSlice(bounds); if (isInHeadSlice) { // calculate the AABB AABB properties = CalculateAABB(bounds); // update geometry in the context if (id == INVALID_ID) { id = PlaneverbContext.AddGeometry(properties); } else { PlaneverbContext.UpdateGeometry(id, properties); } } else if (id != INVALID_ID) { PlaneverbContext.RemoveGeometry(id); id = INVALID_ID; } if (PlaneverbContext.GetInstance().debugDraw) { Color drawColor; if (isInHeadSlice) { drawColor = new Color(0f, 1f, 0f); } else { drawColor = new Color(1f, 0f, 0f); } // debug draw the bounds Vector3 c = bounds.center; Vector3 e = bounds.extents; // half extents Vector3 bbl = c - e; // bottom back left Vector3 bbr = new Vector3(c.x + e.x, c.y - e.y, c.z - e.z); // bottom back right Vector3 tbl = new Vector3(c.x - e.x, c.y + e.y, c.z - e.z); // top back left Vector3 tbr = new Vector3(c.x + e.x, c.y + e.y, c.z - e.z); // top back right Vector3 bfl = new Vector3(c.x - e.x, c.y - e.y, c.z + e.z); // bottom front left Vector3 bfr = new Vector3(c.x + e.x, c.y - e.y, c.z + e.z); // bottom front right Vector3 tfl = new Vector3(c.x - e.x, c.y + e.y, c.z + e.z); // top front left Vector3 tfr = c + e; // top front right // connect all the points Debug.DrawLine(bbl, bbr, drawColor); Debug.DrawLine(bbl, bfl, drawColor); Debug.DrawLine(bbl, tbl, drawColor); Debug.DrawLine(bbr, tbr, drawColor); Debug.DrawLine(bbr, bfr, drawColor); Debug.DrawLine(bfl, bfr, drawColor); Debug.DrawLine(bfl, tfl, drawColor); Debug.DrawLine(bfr, tfr, drawColor); Debug.DrawLine(tbl, tbr, drawColor); Debug.DrawLine(tbl, tfl, drawColor); Debug.DrawLine(tbr, tfr, drawColor); Debug.DrawLine(tfl, tfr, drawColor); } }