void TrackPlayers() { Vector3 startingPoint = transform.position; startingPoint.z = 0f; cameraBounds = new BoundsBox(startingPoint); BoundsBox priorityBounds = new BoundsBox(startingPoint); foreach ( KeyValuePair<int,PlayerObject> playerPair in GameController.sActivePlayers) { PlayerObject player = playerPair.Value; cameraBounds.GrowTo(player.transform.position); priorityBounds.GrowTo(player.transform.position); } foreach( KeyValuePair<int, PlayerTeamObjectiveObject> objPair in GameController.sActiveObjects ) { PlayerTeamObjectiveObject player = objPair.Value; cameraBounds.GrowTo(player.transform.position); priorityBounds.GrowTo(player.transform.position); } foreach (KeyValuePair<int, BaseMonsterBrain> monstPair in GameController.sSpawnedMonsters) { BaseMonsterBrain monster = monstPair.Value; cameraBounds.GrowTo(monster.transform.position); } cameraBounds.GrowBy(m_cameraBoundsRadius); Vector3 centerPoint = priorityBounds.GetCenter(); float heightRatio = 0f; float maxDistance = cameraBounds.MaxDistance(); if (maxDistance > m_minPlayerDistance) { float distanceFromMin = maxDistance - m_minPlayerDistance; float maxDelta = m_maxPlayerDistance - m_minPlayerDistance; heightRatio = (distanceFromMin / maxDelta); } m_desiredCamHeight = Mathf.Lerp(lowestCamDistance, highestCamDistance, heightRatio); m_desiredCamPoint = centerPoint; m_desiredCamPoint.z = -10f; }
// Use this for initialization void Start () { cameraBounds = new BoundsBox(transform.position); sInstance = this; m_desiredCamPoint = transform.position; }
public override void Update(Timer timer) { SingletonFrameScene frameScene = WorldRef.GetSingletonComponent <SingletonFrameScene>(); Transform transform; Renderer renderer; //TODO: faster ordering optimization /*Entity[] entities = GetEntities(); * entities = entities.OrderBy(a => a.GetComponent<Renderer>().materialInfo.Queue) * .ThenBy(a => a.GetComponent<Renderer>().materialInfo.Name) * .ThenBy(a => a.GetComponent<Renderer>().meshInfo.Name).ToArray();*/ int index = 0; bool culled; foreach (Entity entity in SortedByRendererEntities) { culled = true; transform = entity.GetComponent <Transform>(); renderer = entity.GetComponent <Renderer>(); renderer.Bounds = BoundsBox.TransformAABBFast(renderer.meshInfo.Bounds, transform.TransformMatrix); foreach (var camera in frameScene.FrameData.CamerasList) { if (camera.Frustrum.Intersects(ref renderer.Bounds.boundingBox)) { culled = false; frameScene.FrameData.AddRendererDataToCamera(camera.index, index); } } foreach (var light in frameScene.FrameData.LightsList) { if (!light.IsCastShadows) { continue; } if (light.Frustrum.Intersects(ref renderer.Bounds.boundingBox)) { culled = false; frameScene.FrameData.AddRendererDataToLight(light.index, index); } } if (culled) { continue; } frameScene.FrameData.AddRendererData(new StandardFrameData.RendererData() { EntityId = entity.ID, PreviousTransformMatrix = transform.PreviousTransformMatrix, TransformMatrix = transform.TransformMatrix, MeshName = renderer.meshInfo.Name, MaterialName = renderer.materialInfo.Name, MaterialQueue = renderer.materialInfo.Queue, IsDynamic = renderer.IsDynamic, }); index++; } }