📄 mlr_i_c_pmesh.cpp
字号:
//===========================================================================//
// Copyright (C) Microsoft Corporation. All rights reserved. //
//===========================================================================//
#include "MLRHeaders.hpp"
#if defined(TRACE_ENABLED) && defined(MLR_TRACE)
BitTrace *MLR_I_C_PMesh_Clip;
#endif
//#############################################################################
//###### MLR_I_C_PMesh with color but no lighting one texture layer #####
//#############################################################################
MLR_I_C_PMesh::ClassData*
MLR_I_C_PMesh::DefaultData = NULL;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
MLR_I_C_PMesh::InitializeClass()
{
Verify(!DefaultData);
Verify(gos_GetCurrentHeap() == StaticHeap);
DefaultData =
new ClassData(
MLR_I_C_PMeshClassID,
"MidLevelRenderer::MLR_I_C_PMesh",
MLR_I_PMesh::DefaultData,
(MLRPrimitiveBase::Factory)&Make
);
Register_Object(DefaultData);
#if defined(TRACE_ENABLED) && defined(MLR_TRACE)
MLR_I_C_PMesh_Clip = new BitTrace("MLR_I_C_PMesh_Clip");
Register_Object(MLR_I_C_PMesh_Clip);
#endif
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
MLR_I_C_PMesh::TerminateClass()
{
Unregister_Object(DefaultData);
delete DefaultData;
DefaultData = NULL;
#if defined(TRACE_ENABLED) && defined(MLR_TRACE)
Unregister_Object(MLR_I_C_PMesh_Clip);
delete MLR_I_C_PMesh_Clip;
#endif
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MLR_I_C_PMesh::MLR_I_C_PMesh(
ClassData *class_data,
MemoryStream *stream,
int version
):
MLR_I_PMesh(class_data, stream, version)
{
Verify(gos_GetCurrentHeap() == Heap);
Check_Pointer(this);
Check_Pointer(stream);
switch(version)
{
case 1:
case 2:
{
STOP(("This class got created only after version 2 !"));
}
break;
default:
{
#if COLOR_AS_DWORD
MemoryStreamIO_Read(stream, &colors);
#else
Stuff::DynamicArrayOf<DWORD> smallColors;
MemoryStreamIO_Read(stream, &smallColors);
int i, len = smallColors.GetLength();
colors.SetLength(len);
DWORD theColor;
for(i=0;i<len;i++)
{
theColor = smallColors[i];
colors[i].blue = (theColor & 0xff) * One_Over_256;
theColor = theColor>>8;
colors[i].green = (theColor & 0xff) * One_Over_256;
theColor = theColor>>8;
colors[i].red = (theColor & 0xff) * One_Over_256;
theColor = theColor>>8;
colors[i].alpha = (theColor & 0xff) * One_Over_256;
}
#endif
}
break;
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MLR_I_C_PMesh::MLR_I_C_PMesh(ClassData *class_data):
MLR_I_PMesh(class_data), colors(0)
{
Check_Pointer(this);
Verify(gos_GetCurrentHeap() == Heap);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*
void
MLR_I_C_PMesh::Copy(MLRIndexedPolyMesh *polyMesh)
{
Check_Pointer(this);
int len;
#if COLOR_AS_DWORD
DWORD *_colors;
#else
RGBAColor *_colors;
#endif
MLR_I_PMesh::Copy(polyMesh);
polyMesh->GetColorData(&_colors, &len);
SetColorData(_colors, len);
}
*/
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MLR_I_C_PMesh::~MLR_I_C_PMesh()
{
Check_Object(this);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MLR_I_C_PMesh*
MLR_I_C_PMesh::Make(
MemoryStream *stream,
int version
)
{
Check_Object(stream);
gos_PushCurrentHeap(Heap);
MLR_I_C_PMesh *mesh = new MLR_I_C_PMesh(DefaultData, stream, version);
gos_PopCurrentHeap();
return mesh;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
MLR_I_C_PMesh::Save(MemoryStream *stream)
{
Check_Object(this);
Check_Object(stream);
MLR_I_PMesh::Save(stream);
#if COLOR_AS_DWORD
MemoryStreamIO_Write(stream, &colors);
#else
Stuff::DynamicArrayOf<DWORD> smallColors;
int i, len = colors.GetLength();
const Stuff::RGBAColor *data = colors.GetData();
smallColors.SetLength(len);
for(i=0;i<len;i++)
{
smallColors[i] = GOSCopyColor(data+i);
}
MemoryStreamIO_Write(stream, &smallColors);
#endif
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
MLR_I_C_PMesh::TestInstance() const
{
Verify(IsDerivedFrom(DefaultData));
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
MLR_I_C_PMesh::SetColorData(
#if COLOR_AS_DWORD
const DWORD *data,
#else
const RGBAColor *data,
#endif
int dataSize
)
{
Check_Object(this);
Check_Pointer(data);
Verify(coords.GetLength() == 0 || dataSize == coords.GetLength());
Verify(texCoords.GetLength() == 0 || dataSize == texCoords.GetLength());
colors.AssignData(data, dataSize);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
MLR_I_C_PMesh::GetColorData(
#if COLOR_AS_DWORD
DWORD **data,
#else
RGBAColor **data,
#endif
int *dataSize
)
{
Check_Object(this);
*data = colors.GetData();
*dataSize = colors.GetLength();
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
MLR_I_C_PMesh::PaintMe(
#if COLOR_AS_DWORD
const DWORD *paintMe
#else
const RGBAColor *paintMe
#endif
)
{
Check_Object(this);
// original color is lost !!!;
int k, len = colors.GetLength();
#if COLOR_AS_DWORD
DWORD argb = GOSCopyColor(paintMe);
for(k=0;k<len;k++)
{
colors[k] = argb;
}
#else
for(k=0;k<len;k++)
{
colors[k] = *paintMe;
}
#endif
}
#undef I_SAY_YES_TO_DUAL_TEXTURES
#define I_SAY_YES_TO_COLOR
#undef I_SAY_YES_TO_LIGHTING
#define CLASSNAME MLR_I_C_PMesh
#if defined(TRACE_ENABLED) && defined(MLR_TRACE)
#define SET_MLR_PMESH_CLIP() MLR_I_C_PMesh_Clip->Set()
#define CLEAR_MLR_PMESH_CLIP() MLR_I_C_PMesh_Clip->Clear()
#else
#define SET_MLR_PMESH_CLIP()
#define CLEAR_MLR_PMESH_CLIP()
#endif
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This include contains follwing functions:
// void MLR_I_C_PMesh::TransformNoClip(Matrix4D*, GOSVertexPool*);
// int MLR_I_C_PMesh::Clip(MLRClippingState, GOSVertexPool*);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <MLR\MLRPrimitiveClipping.hpp>
#undef I_SAY_YES_TO_COLOR
#undef CLASSNAME
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MLR_I_C_PMesh*
MidLevelRenderer::CreateIndexedCube_Color_NoLit(
Scalar half,
RGBAColor *eightColors,
MLRState *state
)
{
gos_PushCurrentHeap(Heap);
MLR_I_C_PMesh *ret = new MLR_I_C_PMesh;
Register_Object(ret);
Point3D *coords = new Point3D [8];
Register_Pointer(coords);
coords[0] = Point3D( half, -half, half);
coords[1] = Point3D(-half, -half, half);
coords[2] = Point3D( half, -half, -half);
coords[3] = Point3D(-half, -half, -half);
coords[4] = Point3D(-half, half, half);
coords[5] = Point3D( half, half, half);
coords[6] = Point3D( half, half, -half);
coords[7] = Point3D(-half, half, -half);
unsigned char *lengths = new unsigned char [6];
Register_Pointer(lengths);
int i;
for(i=0;i<6;i++)
{
lengths[i] = 4;
}
ret->SetSubprimitiveLengths(lengths, 6);
Unregister_Pointer(lengths);
delete [] lengths;
ret->SetCoordData(coords, 8);
Unregister_Pointer(coords);
delete [] coords;
unsigned short *index = new unsigned short [6*4];
Register_Pointer(index);
index[0] = 0;
index[1] = 2;
index[2] = 6;
index[3] = 5;
index[4] = 0;
index[5] = 5;
index[6] = 4;
index[7] = 1;
index[8] = 5;
index[9] = 6;
index[10] = 7;
index[11] = 4;
index[12] = 2;
index[13] = 3;
index[14] = 7;
index[15] = 6;
index[16] = 1;
index[17] = 4;
index[18] = 7;
index[19] = 3;
index[20] = 0;
index[21] = 1;
index[22] = 3;
index[23] = 2;
ret->SetIndexData(index, 6*4);
Unregister_Pointer(index);
delete [] index;
ret->FindFacePlanes();
if(eightColors!=NULL)
{
#if COLOR_AS_DWORD
DWORD *dwColor = new DWORD [8];
Register_Pointer(dwColor);
for(i=0;i<8;i++)
{
dwColor[i] = GOSCopyColor(eightColors+i);
}
ret->SetColorData(dwColor, 8);
Unregister_Pointer(dwColor);
delete [] dwColor;
#else
ret->SetColorData(eightColors, 8);
#endif
}
Vector2DScalar *texCoords = new Vector2DScalar[8];
Register_Pointer(texCoords);
texCoords[0] = Vector2DScalar(0.0f, 0.0f);
texCoords[1] = Vector2DScalar(0.0f, 0.0f);
texCoords[2] = Vector2DScalar(0.0f, 0.0f);
texCoords[3] = Vector2DScalar(0.0f, 0.0f);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -