📄 scenerygamecomponent.cs
字号:
if (m_Root != null)
{
return m_Root.BoundingBox.Min.Z;
}
return 0.0f;
}
}
/// <summary>
/// Obtiene el l韒ite m醲imo de profundidad
/// </summary>
public float MaxLong
{
get
{
if (m_Root != null)
{
return m_Root.BoundingBox.Max.Z;
}
return 0.0f;
}
}
/// <summary>
/// Obtiene el l韒ite m韓imo de altura
/// </summary>
public float MinHeight
{
get
{
if (m_Root != null)
{
return m_Root.BoundingBox.Min.Y;
}
return 0.0f;
}
}
/// <summary>
/// Obtiene el l韒ite m醲imo de altura
/// </summary>
public float MaxHeight
{
get
{
if (m_Root != null)
{
return m_Root.BoundingBox.Max.Y;
}
return 0.0f;
}
}
/// <summary>
/// Obtiene el punto central del terreno
/// </summary>
public Vector3 Center
{
get
{
return new Vector3((MaxWidth - MinWidth) / 2.0f, (MaxHeight - MinHeight) / 2.0f, (MaxLong - MinLong) / 2.0f);
}
}
#region DEV
// Indica el nivel de detalle a dibujar
private LOD m_Lod = LOD.None;
/// <summary>
/// Obtiene o establece el nivel de detalle a dibujar
/// </summary>
public LOD Lod
{
get
{
return m_Lod;
}
set
{
m_Lod = value;
}
}
// Indica el modo de relleno a usar
private FillMode m_FillMode = FillMode.Solid;
/// <summary>
/// Obtiene o establece el modo de relleno a usar
/// </summary>
public FillMode FillMode
{
get
{
return m_FillMode;
}
set
{
m_FillMode = value;
}
}
#endregion
/// <summary>
/// Constructor
/// </summary>
public SceneryGameComponent(Game game)
: base(game)
{
content = (ContentManager)game.Services.GetService(typeof(ContentManager));
}
/// <summary>
/// Inicializar
/// </summary>
public override void Initialize()
{
base.Initialize();
}
/// <summary>
/// Cargar el contenito del componente
/// </summary>
/// <param name="loadAllContent">Tipo de contenidos a cargar</param>
protected override void LoadGraphicsContent(bool loadAllContent)
{
base.LoadGraphicsContent(loadAllContent);
// Crear el terreno
this.BuildGeometry(content.Load<Texture2D>(@"Content\Terrain\HM2"), 32.0f);
// Crear el efecto para renderizar
if (m_Effect == null)
{
this.m_Effect = content.Load<Effect>(@"Content\Terrain\terrain");
this.m_Effect.Parameters["xSandTexture"].SetValue(content.Load<Texture2D>(@"Content\Terrain\sand"));
this.m_Effect.Parameters["xGrassTexture"].SetValue(content.Load<Texture2D>(@"Content\Terrain\grass"));
this.m_Effect.Parameters["xRockTexture"].SetValue(content.Load<Texture2D>(@"Content\Terrain\rock"));
this.m_Effect.Parameters["xSnowTexture"].SetValue(content.Load<Texture2D>(@"Content\Terrain\snow"));
}
}
/// <summary>
/// Actualizar el estado del componente
/// </summary>
/// <param name="gameTime">Tiempo de juego</param>
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
/// <summary>
/// Dibujar el contenido gr醘ico del componente
/// </summary>
/// <param name="gameTime">Tiempo de juego</param>
public override void Draw(GameTime gameTime)
{
if (m_Effect != null)
{
if (m_Root != null)
{
FillMode currentMode = this.GraphicsDevice.RenderState.FillMode;
this.GraphicsDevice.RenderState.FillMode = m_FillMode;
this.GraphicsDevice.VertexDeclaration = m_VertexDeclaration;
this.GraphicsDevice.Vertices[0].SetSource(m_VertexBuffer, 0, VertexMultitextured.SizeInBytes);
// Establecer los par醡etros en el efecto
this.m_Effect.CurrentTechnique = m_Effect.Techniques["MultiTextured"];
this.m_Effect.Parameters["xProjection"].SetValue(BaseCameraGameComponent.gGlobalProjectionMatrix);
this.m_Effect.Parameters["xView"].SetValue(BaseCameraGameComponent.gViewMatrix);
this.m_Effect.Parameters["xWorld"].SetValue(Matrix.Identity);
this.m_Effect.Parameters["xEnableLighting"].SetValue(SceneryEnvironment.Ambient.Light0Enable);
this.m_Effect.Parameters["xLightDirection"].SetValue(SceneryEnvironment.Ambient.Light0Direction);
this.m_Effect.Parameters["xAmbient"].SetValue(0.2f);
//SceneryEnvironment.Fog.SetFogToEffect(m_Effect);
// Inicializar los nodos para el dibujado
m_Root.PrepareForDrawing();
// Dibujar el nivel de detall m醲imo
LODDraw(gameTime, LOD.High);
// Dibujar el nivel de detalle medio
LODDraw(gameTime, LOD.Medium);
// Dibujar el nivel de menos detalle
LODDraw(gameTime, LOD.Low);
this.GraphicsDevice.RenderState.FillMode = currentMode;
}
}
}
/// <summary>
/// Dibuja el contenido gr醘ico del componente atendiendo al nivel de detalle
/// </summary>
/// <param name="gameTime">Tiempo de juego</param>
/// <param name="lod">Nivel de detalle</param>
private void LODDraw(GameTime gameTime, LOD lod)
{
SceneryNode[] nodesToDraw = m_Root.GetNodesToDraw(lod);
if (nodesToDraw.Length > 0)
{
if ((m_Lod != LOD.None) && (m_Lod != lod))
{
return;
}
this.GraphicsDevice.Indices = m_LODIndexBuffers[lod];
m_Effect.Begin();
foreach (EffectPass pass in m_Effect.CurrentTechnique.Passes)
{
pass.Begin();
foreach (SceneryNode node in nodesToDraw)
{
SceneryPrimitiveNode triNode = node as SceneryPrimitiveNode;
if (triNode != null)
{
this.GraphicsDevice.DrawIndexedPrimitives(
PrimitiveType.TriangleList,
0,
0,
m_VertexCount,
triNode.GetStartIndex(lod),
triNode.GetPrimitiveCount(lod));
}
}
pass.End();
}
m_Effect.End();
}
}
/// <summary>
/// Obtiene el punto del terreno en las coordenadas especificadas
/// </summary>
/// <param name="x">Componente x de la posici髇</param>
/// <param name="z">Componente y de la posici髇</param>
/// <returns>Punto especificado en el terreno</returns>
/// <remarks>Si devuelve null est
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -