public List <Vector4> Update(Vector3 viewerPositon) { var dist = Vector3.Distance(viewerPositon, bounds.ClosestPoint(viewerPositon)); if (parentChunk != null) { var distParent = Vector3.Distance(viewerPositon, parentChunk.GetBounds().ClosestPoint(viewerPositon)); if (distParent > parentChunk.GetScale() * chunkSize) { parentChunk.MergeChunk(); return(positionsList); } } if (scale * chunkSize > dist) { SubDivide(viewerPositon); } else { positionsList.Clear(); directionList.Clear(); positionsList.Add(positionToDraw); directionList.Add(directionX); } return(positionsList); }
public void Update(Vector3 viewerPositon, bool isStillVisible, Vector3 positionA, float newScale) { //pokud uživatel změnil nějaká data, tak uzel musí přepočítat svoji novou pozici if (positionA != position) { scale = newScale; position = positionA; Vector3 newPosition = CalculePositionOfSphere(positionA); bounds.center = newPosition; bounds.size = (new Vector3(1, 1, 1) - newPosition.normalized) * scale; RecalculSteps(); positionToDraw = new Vector4((position.x), (position.y), (position.z), scale); } //test nu frustum culling if (isStillVisible) { isVisible = FrustumCulling.Frustum(camera, bounds.center, scale * 0.5f, bounds); } if (!isVisible) { return; } //Vypočet vzdálenosti pozorovatele s jebližší bodem na bounding boxu var dist = Vector3.Distance(viewerPositon, bounds.ClosestPoint(viewerPositon)); if (parentChunk != null) { var distParent = Vector3.Distance(viewerPositon, parentChunk.GetBounds().ClosestPoint(viewerPositon)); //Zde pokud podmínka plati tak se provede merge---- takzvane se odstrani všichni potomci if (distParent / 2 > parentChunk.GetScale()) { parentChunk.MergeChunk(); return; } } //aktualizace uzlu if (chunkTree != null) { int i = 0; foreach (var item in chunkTree) { item.Update(viewerPositon, isVisible, steps[i], scale * 0.5f); i++; } } //Uzel si vytvoří 4 poduzly else if (scale * 2 > dist) { SubDivide(viewerPositon); } // Finalista na vykresleni else { isVisible = FrustumCulling.horizont(camera, bounds.center); } return; }