123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- //===========================================================================//
- // Copyright (C) Microsoft Corporation. All rights reserved. //
- //===========================================================================//
- #include "MLRHeaders.hpp"
- #if defined(TRACE_ENABLED) && defined(MLR_TRACE)
- BitTrace *MLR_Terrain_Clip;
- #endif
- //#############################################################################
- //## MLRTerrain with no color no lighting w/ detail texture, uv's from xyz ###
- //#############################################################################
- MLR_Terrain::ClassData*
- MLR_Terrain::DefaultData = NULL;
- DynamicArrayOf<Vector2DScalar>
- *MLR_Terrain::clipTexCoords;
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLR_Terrain::InitializeClass()
- {
- Verify(!DefaultData);
- Verify(gos_GetCurrentHeap() == StaticHeap);
- DefaultData =
- new ClassData(
- MLR_TerrainClassID,
- "MidLevelRenderer::MLR_Terrain",
- MLR_I_DeT_TMesh::DefaultData,
- (MLRPrimitiveBase::Factory)&Make
- );
- Register_Object(DefaultData);
-
- clipTexCoords = new DynamicArrayOf<Vector2DScalar> (Limits::Max_Number_Vertices_Per_Mesh);
- Register_Object(clipTexCoords);
- #if defined(TRACE_ENABLED) && defined(MLR_TRACE)
- MLR_Terrain_Clip = new BitTrace("MLR_Terrain_Clip");
- Register_Object(MLR_Terrain_Clip);
- #endif
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLR_Terrain::TerminateClass()
- {
- Unregister_Object(DefaultData);
- delete DefaultData;
- DefaultData = NULL;
- Unregister_Object(clipTexCoords);
- delete clipTexCoords;
- #if defined(TRACE_ENABLED) && defined(MLR_TRACE)
- Unregister_Object(MLR_Terrain_Clip);
- delete MLR_Terrain_Clip;
- #endif
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- MLR_Terrain::MLR_Terrain(
- ClassData *class_data,
- MemoryStream *stream,
- int version
- ):
- MLR_I_DeT_TMesh(class_data, stream, version)
- {
- Check_Pointer(this);
- Check_Pointer(stream);
- Verify(gos_GetCurrentHeap() == Heap);
- texCoords.SetLength(0);
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- MLR_Terrain::MLR_Terrain(ClassData *class_data):
- MLR_I_DeT_TMesh(class_data)
- {
- Check_Pointer(this);
- Verify(gos_GetCurrentHeap() == Heap);
- texCoords.SetLength(0);
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- MLR_Terrain::~MLR_Terrain()
- {
- Check_Object(this);
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- MLR_Terrain*
- MLR_Terrain::Make(
- MemoryStream *stream,
- int version
- )
- {
- Check_Object(stream);
- gos_PushCurrentHeap(Heap);
- MLR_Terrain *terrain = new MLR_Terrain(DefaultData, stream, version);
- gos_PopCurrentHeap();
- return terrain;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLR_Terrain::Save(MemoryStream *stream)
- {
- Check_Object(this);
- Check_Object(stream);
- MLR_I_DeT_TMesh::Save(stream);
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLR_Terrain::TestInstance() const
- {
- Verify(IsDerivedFrom(DefaultData));
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- void
- MLR_Terrain::SetUVData(
- Stuff::Scalar bpf,
- Stuff::Scalar xmin,
- Stuff::Scalar xmax,
- Stuff::Scalar zmin,
- Stuff::Scalar zmax
- )
- {
- borderPixelFun = bpf;
- minX = xmin;
- minZ = zmin;
- xUVFac = (1.0f-2*borderPixelFun)/(xmax-xmin);
- zUVFac = (1.0f-2*borderPixelFun)/(zmax-zmin);
- }
- #define I_SAY_YES_TO_DETAIL_TEXTURES
- #undef I_SAY_YES_TO_DUAL_TEXTURES
- #undef I_SAY_YES_TO_COLOR
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- #undef I_SAY_YES_TO_LIGHTING
- #define I_SAY_YES_TO_TERRAIN
- #define CLASSNAME MLR_Terrain
- #if defined(TRACE_ENABLED) && defined(MLR_TRACE)
- #define SET_MLR_TMESH_CLIP() MLR_Terrain_Clip->Set()
- #define CLEAR_MLR_TMESH_CLIP() MLR_Terrain_Clip->Clear()
- #else
- #define SET_MLR_TMESH_CLIP()
- #define CLEAR_MLR_TMESH_CLIP()
- #endif
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // This include contains follwing functions:
- // void MLR_Terrain::TransformNoClip(Matrix4D*, GOSVertexPool*);
- // int MLR_Terrain::Clip(MLRClippingState, GOSVertexPool*);
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- #include <MLR\MLRTriangleClipping.hpp>
- #undef I_SAY_YES_TO_DETAIL_TEXTURES
- #undef I_SAY_YES_TO_TERRAIN
- #undef CLASSNAME
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- //
- MLRShape*
- MidLevelRenderer::CreateIndexedTriIcosahedron_TerrainTest(
- IcoInfo& icoInfo,
- MLRState *state,
- MLRState *stateDet
- )
- {
- gos_PushCurrentHeap(Heap);
- MLRShape *ret = new MLRShape(20);
- Register_Object(ret);
- int i, j, k;
- long nrTri = (long) ceil (icoInfo.all * pow (4.0f, icoInfo.depth));
- Point3D v[3];
- if(3*nrTri >= Limits::Max_Number_Vertices_Per_Mesh)
- {
- nrTri = Limits::Max_Number_Vertices_Per_Mesh/3;
- }
- Point3D *coords = new Point3D [nrTri*3];
- Register_Pointer(coords);
-
- Point3D *collapsedCoords = NULL;
- if(icoInfo.indexed==true)
- {
- collapsedCoords = new Point3D [nrTri*3];
- Register_Pointer(collapsedCoords);
- }
- unsigned short *index = new unsigned short [nrTri*3];
- Register_Pointer(index);
- int uniquePoints = 0;
- for (k=0;k<20;k++)
- {
- triDrawn = 0;
- MLR_Terrain *mesh = new MLR_Terrain();
- Register_Object(mesh);
- mesh->SetUVData(2.0f, -1.0f, 1.0f, -1.0f, 1.0f);
- // setup vertex position information
- for (j=0;j<3;j++)
- {
- v[j].x = vdata[tindices[k][j]][0];
- v[j].y = vdata[tindices[k][j]][1];
- v[j].z = vdata[tindices[k][j]][2];
- }
- subdivide (coords, v[0], v[1], v[2], icoInfo.depth, nrTri, icoInfo.radius);
- mesh->SetSubprimitiveLengths(NULL, nrTri);
- if(icoInfo.indexed==true)
- {
- uniquePoints = 1;
- collapsedCoords[0] = coords[0];
- index[0] = 0;
- for(i=1;i<nrTri*3;i++)
- {
- for(j=0;j<uniquePoints;j++)
- {
- if(coords[i] == collapsedCoords[j])
- {
- break;
- }
- }
- if(j==uniquePoints)
- {
- collapsedCoords[uniquePoints++] = coords[i];
- }
- index[i] = static_cast<unsigned short>(j);
- }
- mesh->SetCoordData(collapsedCoords, uniquePoints);
- }
- else
- {
- uniquePoints = nrTri*3;
- for(i=0;i<nrTri*3;i++)
- {
- index[i] = static_cast<unsigned short>(i);
- }
- mesh->SetCoordData(coords, nrTri*3);
- }
- mesh->SetIndexData(index, nrTri*3);
- mesh->FindFacePlanes();
- if(state != NULL)
- {
- mesh->SetReferenceState(*state);
- }
- mesh->SetDetailData(0.0f, 0.0f, 16.0f, 16.0f, 50.0f, 70.0f);
- mesh->SetReferenceState(*stateDet, 1);
- ret->Add(mesh);
- mesh->DetachReference();
- }
- Unregister_Pointer(index);
- delete [] index;
- if(icoInfo.indexed==true)
- {
- Unregister_Pointer(collapsedCoords);
- delete [] collapsedCoords;
- }
-
- Unregister_Pointer(coords);
- delete [] coords;
- gos_PopCurrentHeap();
- return ret;
- }
|