/*
* ScoreSummary.cs (Obsolete)
* Authors: August Zinsser
*
* Copyright Matthew Belmonte 2007
*/
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using System.Diagnostics;
using Pina3D.Particles;
using tAC_Engine;
namespace Astropolis
{
///
/// THIS CLASS IS OBSOLETE AND SHOULD NOT BE USED BY ANY NEW CLASSES. IT EXISTS ONLY FOR BACKWARDS COMPATIBILITY WITH METEOR MADNESS.
///
/// Defines a basic 3D coordinate system where +x is to the right of the screen, +y is down, and +z is into the screen.
/// Holds the locations of entities in this space, but doesn't apply any logic to them.
/// This is essentially a render queue for 2D objects in parallax worlds.
///
[Obsolete]
class Space3D
{
private SpriteBatch mSpriteBatch; // Internal buffer
private List mEntities; // General entities to render
private List mDots; // Keep the dots separate so this class isn't asked to sort >1000 entities each tick (purely an optimization)
private float mMaxZ; // Far clipping plane
private float mMinZ; // Near clipping plane
///
/// This clipping plane needs to be farther out than the game's clipping plane since the boss goes farther back than other objects in the shooter phase
///
public float MaxZ { set { mMaxZ = value; } get { return mMaxZ; } }
public float MinZ { set { mMinZ = value; } get { return mMinZ; } }
///
/// Constructor
///
public Space3D()
{
mSpriteBatch = new SpriteBatch(GenericBaseApplication.GameManager.GraphicsDevice);
mEntities = new List();
mDots = new List();
mMaxZ = 100.0F;
mMinZ = -1.0F;
}
///
/// Adds a new Entity into the field and sorts them for drawing
///
///
public void AddEntity(Entity newEntity)
{
mEntities.Add(newEntity);
mEntities.Sort();
}
///
/// Adds a new dot to the render queue
///
public void AddDot(Dot newDot)
{
mDots.Add(newDot);
}
///
/// Removes an entity from the field
///
///
public void RemoveEntity(Entity oldEntity)
{
mEntities.Remove(oldEntity);
}
///
/// Draws all registered visible entities
///
public void Render()
{
mSpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);
GenericBaseApplication.GameManager.GraphicsDevice.RenderState.DepthBufferEnable = true;
GenericBaseApplication.GameManager.GraphicsDevice.RenderState.DepthBufferWriteEnable = true;
// First draw general entities
for (int i = 0; i < mEntities.Count; i++)
{
Entity e = mEntities[i];
// Special case draws that require special handling
if (e is Wormhole)
{
Wormhole hole = (Wormhole)e;
hole.Draw(mSpriteBatch, this);
}
else if (e is CheetahFighter)
{
// Draw the cheetah at its source image aspect, but keep it's bounding box almost square for game collisions
float depth = e.Z - mMinZ + AstroBaseApplication.GameManager.MeteorCameraFocalLength;
float depthRange = MaxZ - mMinZ + AstroBaseApplication.GameManager.MeteorCameraFocalLength;
Rectangle proj = Project(e.X, e.Y, e.Z, e.Width, e.Height, mMinZ);
proj.Height = (int)(proj.Width * e.Texture.Height / e.Texture.Width);
e.Draw(mSpriteBatch, proj, depth / depthRange);
}
// General draws
else if (e.Visible && isInView(e))
{
float depth = e.Z - mMinZ + AstroBaseApplication.GameManager.MeteorCameraFocalLength;
float depthRange = MaxZ - mMinZ + AstroBaseApplication.GameManager.MeteorCameraFocalLength;
e.Draw(mSpriteBatch, Project(e.X, e.Y, e.Z, e.Width, e.Height, mMinZ), depth / depthRange);
}
}
// Now draw the dots
for (int i = 0; i < mDots.Count; i++)
{
Dot d = mDots[i];
if (isInView(d))
{
float depth = d.Z - mMinZ + AstroBaseApplication.GameManager.MeteorCameraFocalLength;
float depthRange = MaxZ - mMinZ + AstroBaseApplication.GameManager.MeteorCameraFocalLength;
d.Draw(mSpriteBatch, Project(d.X, d.Y, d.Z, d.Width, d.Height, mMinZ), depth / depthRange);
}
}
mSpriteBatch.End();
}
///
/// Translates coordinates from Space3D into screen pixels
///
/// X-coordinate of the center
/// Y-coordinate of the center
/// Width
/// Height
///
public static Rectangle Project(float X, float Y, float Z, float W, float H, float minZ)
{
float projX, projY, projW, projH;
int screenX, screenY, screenW, screenH;
float depth, scaleFactor;
// Calculate the apparent increase/decrease in size of an object based on its distance from the camera
depth = 1f + Z + AstroBaseApplication.GameManager.MeteorCameraFocalLength;
scaleFactor = (AstroBaseApplication.GameManager.MeteorCameraFocalLength + 1.0F) / depth;
projX = scaleFactor * X;
projY = scaleFactor * Y;
projW = scaleFactor * W;
projH = scaleFactor * H;
// Translate into screen coordinates
screenX = (int)((projX + 1.0F) * .5F * (float)AstroBaseApplication.GameManager.ScreenWidth);
screenY = (int)((projY + 1.0F) * .5F * (float)AstroBaseApplication.GameManager.ScreenHeight);
screenW = (int)(projW * (float)AstroBaseApplication.GameManager.ScreenWidth);
screenH = (int)(projH * (float)AstroBaseApplication.GameManager.ScreenWidth); // Use the screen width so that the sprites do not get squished by the fact the screen is not square
Rectangle retRect = new Rectangle(screenX, screenY, screenW, screenH);
return retRect;
}
///
/// Check if the entity is behind the camera. The farplane for meteor madness is used more as a guideline for spawning/killing not for
/// rendering purposes.
///
///
///
private bool isInView(Entity ent)
{
if (ent.Z < mMinZ - AstroBaseApplication.GameManager.MeteorCameraFocalLength ||
ent.Z > mMaxZ)
return false;
return true;
}
}
///
/// THIS CLASS IS OBSOLETE AND SHOULD NOT BE USED. IT EXISTS FOR BACKWARDS COMPATIBILITY WITH METEOR MADNESS.
///
/// Holds a set of Space3D coordinates
///
[Obsolete]
class ProjectedEmitter
{
public Vector3 Space3DCoords = Vector3.Zero;
public Emitter Emitter;
//public ProjectedEmitter(string name, Vector3 position, Vector3 minTraj, Vector3 maxTraj, float minMuzzleVel, float maxMuzzleVel, bool immortal, float lifeSpan, float spawnRate)
// : base(name, position, minTraj, maxTraj, minMuzzleVel, maxMuzzleVel, immortal, lifeSpan, spawnRate)
//{}
public ProjectedEmitter(ref Emitter emitter)
{
Emitter = emitter;
}
}
}