using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MTV3D65;
using System.Windows.Forms;
namespace gefx
{
public class Terrain
{
private TVTextureFactory TF;
public TVLandscape Land;
private TVMaterialFactory Mats;
public TVAtmosphere Atmos;
public List<string> LandTexturePack = new List<string>();
private int IDDiffuse;
private int IDMat;
private int IDLight;
private int IDGrass;
private int IDAlpha;
public TVLightEngine Lights;
int cloudsIntTex = new int();
public string Hmapa = "";
public string MTexture = "";
public string TGround;
public string TEnvT;
public string TAlfa;
private TVMaterialFactory _matFact;
public static TVLightEngine Light;
public void AddTexture(string Texture)
{
IDDiffuse = TF.LoadTexture(Texture, "LandDiffuseTextureXYZ", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);
IDMat = Mats.CreateLightMaterial(1, 1, 1, 1, 0.015f, 1, "basic_material_landscape");
Land.SetMaterial(IDMat, -1);
Land.SetTexture(IDDiffuse, -1);
Land.SetTextureScale(4, 4, -1);
IDLight = Lights.CreateDirectionalLight(new TV_3DVECTOR(-1, -1, 0), 1, 1, 1, "simple_directional_light", 0);
MTexture = Texture;
}
public void AddSplatTexture(string ground, string EnvTexture,string Alfa)
{
IDDiffuse = TF.LoadTexture(ground, "diffuse texture land", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);
IDGrass = TF.LoadTexture(EnvTexture, "grass texture lands", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_NO, true);
IDAlpha = TF.LoadTexture(Alfa , "grass alpha texture", -1, -1, CONST_TV_COLORKEY.TV_COLORKEY_USE_ALPHA_CHANNEL, true);
Land.EnableLOD(true, 256, CONST_TV_LANDSCAPE_PRECISION.TV_PRECISION_LOW, 100, true);
Land.AddSplattingTexture(IDGrass, 1, 15, 15, 0, 0);
Land.ExpandSplattingTexture(IDAlpha, IDGrass, 0, 0, 4, 4);
Land.SetSplattingEnable(true, -1);
Land.OptimizeSplatting();
TGround = ground;
TEnvT = EnvTexture;
TAlfa = Alfa;
}
public void SetTerrainCameraPos(ref Camera Cam )
{
float y = Land.GetHeight(0, 0) + 50;
TV_3DVECTOR t = new TV_3DVECTOR(0, y, 0);
Cam.SetUpCameraPosition(t);
}
public void AddLight(ref TVScene Scene, ref TVGlobals Globals)
{
TV_LIGHT pointLight = new TV_LIGHT();
Light = new TVLightEngine();
Light.SetSpecularLighting(true);
//pointLight = new TV_LIGHT();
pointLight.type = CONST_TV_LIGHTTYPE.TV_LIGHT_DIRECTIONAL;
pointLight.direction = new TV_3DVECTOR(0.5f, -0.5f, 0.8f);
pointLight.diffuse = new TV_COLOR(0.8f, 0.8f, 0.8f, 1);
pointLight.range = 2500;
pointLight.attenuation = new TV_3DVECTOR(0, 0, 0);
int lightNo = Light.CreateLight(ref pointLight, "Sunlight");
Light.EnableLight(lightNo, true);
Light.SetLightProperties(lightNo, true, true, false);
Light.SetGlobalAmbient(1f, 0, 0);
Scene.SetShadowParameters(Globals.RGBA(0, 0, 0, 0.5f), true);
}
public void AddTerrainPhysics(ref TVPhysics PP)
{
PP.CreateStaticTerrainBody(Land);
}
public void RenderTerenLight()
{
}
public void AddHeightMap(string HeightMap, ref TVScene Scene)
{
Land = new TVLandscape();
Land = Scene.CreateLandscape("TerrainLanScape");
Mats = new TVMaterialFactory();
_matFact = new TVMaterialFactory();
int matNo;
matNo = _matFact.CreateMaterial("MatteLandscape01");
_matFact.SetAmbient(matNo, 0.2f, 0.2f, 0.2f, 1f);
_matFact.SetDiffuse(matNo, 1f, 1f, 1f, 1f);
_matFact.SetEmissive(matNo, 0f, 0f, 0f, 0f);
_matFact.SetSpecular(matNo, 0f, 0f, 0f, 1f);
_matFact.SetPower(matNo, 1);
_matFact.SetOpacity(matNo, 1f);
Land.SetAffineLevel(CONST_TV_LANDSCAPE_AFFINE.TV_AFFINE_HIGH);
Land.GenerateTerrain(HeightMap,
CONST_TV_LANDSCAPE_PRECISION.TV_PRECISION_AVERAGE ,
4, 4, -512, 0, -512, true);
Land.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED);
Land.SetMaterial(matNo);
Land.SetDetailMode(CONST_TV_DETAILMAP_MODE.TV_DETAILMAP_MODULATE2X );
Land.EnableLOD(true, 800f, CONST_TV_LANDSCAPE_PRECISION.TV_PRECISION_AVERAGE, 0, false);
Land.SetProgressiveLOD(true);
Hmapa = HeightMap;
}
public void AddHeightMap(string HeightMap,bool ByTVM ,ref TVScene Scene)
{
Land = new TVLandscape();
Land = Scene.CreateLandscape("TerrainLanScape");
Mats = new TVMaterialFactory();
_matFact = new TVMaterialFactory();
int matNo;
matNo = _matFact.CreateMaterial("MatteLandscape01");
_matFact.SetAmbient(matNo, 0.2f, 0.2f, 0.2f, 1f);
_matFact.SetDiffuse(matNo, 1f, 1f, 1f, 1f);
_matFact.SetEmissive(matNo, 0f, 0f, 0f, 0f);
_matFact.SetSpecular(matNo, 0f, 0f, 0f, 1f);
_matFact.SetPower(matNo, 1);
_matFact.SetOpacity(matNo, 1f);
Land.SetAffineLevel(CONST_TV_LANDSCAPE_AFFINE.TV_AFFINE_HIGH);
if (ByTVM)
{
Land.LoadTerrainData(HeightMap);
}
else
{
Land.GenerateTerrain(HeightMap,
CONST_TV_LANDSCAPE_PRECISION.TV_PRECISION_AVERAGE,
4, 4, -512, 0, -512, true);
}
Land.SetLightingMode(CONST_TV_LIGHTINGMODE.TV_LIGHTING_MANAGED);
Land.SetMaterial(matNo);
Land.SetDetailMode(CONST_TV_DETAILMAP_MODE.TV_DETAILMAP_MODULATE2X);
Land.EnableLOD(true, 800f, CONST_TV_LANDSCAPE_PRECISION.TV_PRECISION_AVERAGE, 0, false);
Land.SetProgressiveLOD(true);
Hmapa = HeightMap;
}
public Terrain()
{
Lights = new TVLightEngine();
TF = new TVTextureFactory();
Atmos = new TVAtmosphere();
}
public void DrawTerrain()
{
if (Land != null)
{
Land.Render();
}
}
TVCollisionResult ColRez;
public TV_3DVECTOR GetTerreinPosition(ref TVScene Scene, int x, int y)
{
TV_3DVECTOR col1= new TV_3DVECTOR(0,0,0);
if (Land != null)
{
ColRez = Scene.MousePick(x, y, (int)CONST_TV_OBJECT_TYPE.TV_OBJECT_LANDSCAPE , CONST_TV_TESTTYPE.TV_TESTTYPE_ACCURATETESTING);
if (ColRez.IsCollision())
{
TV_3DVECTOR col = new TV_3DVECTOR(0, 0, 0);
col = ColRez.GetCollisionImpact();
col1.x = col.x;
col1.y = Land.GetHeight(col.x, col.z);
col1.z = col.z;
}
}
return col1;
}
}
}