📄 mlr_i_c_det_tmesh.cpp
字号:
//===========================================================================//
// Copyright (C) Microsoft Corporation. All rights reserved. //
//===========================================================================//
#include "MLRHeaders.hpp"
#if defined(TRACE_ENABLED) && defined(MLR_TRACE)
BitTrace *MLR_I_C_DeT_TMesh_Clip;
#endif
//#############################################################################
//######## MLRIndexedTriMesh with color no lighting and detail texture ########
//#############################################################################
MLR_I_C_DeT_TMesh::ClassData*
MLR_I_C_DeT_TMesh::DefaultData = NULL;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
MLR_I_C_DeT_TMesh::InitializeClass()
{
Verify(!DefaultData);
Verify(gos_GetCurrentHeap() == StaticHeap);
DefaultData =
new ClassData(
MLR_I_C_DeT_TMeshClassID,
"MidLevelRenderer::MLR_I_C_DeT_TMesh",
MLR_I_DeT_TMesh::DefaultData,
(MLRPrimitiveBase::Factory)&Make
);
Register_Object(DefaultData);
#if defined(TRACE_ENABLED) && defined(MLR_TRACE)
MLR_I_C_DeT_TMesh_Clip = new BitTrace("MLR_I_C_DeT_TMesh_Clip");
Register_Object(MLR_I_C_DeT_TMesh_Clip);
#endif
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
MLR_I_C_DeT_TMesh::TerminateClass()
{
Unregister_Object(DefaultData);
delete DefaultData;
DefaultData = NULL;
#if defined(TRACE_ENABLED) && defined(MLR_TRACE)
Unregister_Object(MLR_I_C_DeT_TMesh_Clip);
delete MLR_I_C_DeT_TMesh_Clip;
#endif
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MLR_I_C_DeT_TMesh::MLR_I_C_DeT_TMesh(
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);
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;
}
actualColors = &colors;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MLR_I_C_DeT_TMesh::MLR_I_C_DeT_TMesh(ClassData *class_data):
MLR_I_DeT_TMesh(class_data), colors(0)
{
Check_Pointer(this);
Verify(gos_GetCurrentHeap() == Heap);
actualColors = &colors;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MLR_I_C_DeT_TMesh::~MLR_I_C_DeT_TMesh()
{
Check_Object(this);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MLR_I_C_DeT_TMesh*
MLR_I_C_DeT_TMesh::Make(
MemoryStream *stream,
int version
)
{
Check_Object(stream);
gos_PushCurrentHeap(Heap);
MLR_I_C_DeT_TMesh *mesh = new MLR_I_C_DeT_TMesh(DefaultData, stream, version);
gos_PopCurrentHeap();
return mesh;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
MLR_I_C_DeT_TMesh::Save(MemoryStream *stream)
{
Check_Object(this);
Check_Object(stream);
MLR_I_TMesh::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
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
bool
MLR_I_C_DeT_TMesh::Copy(MLR_I_C_DeT_PMesh *pMesh)
{
Check_Object(this);
Check_Object(pMesh);
int len;
#if COLOR_AS_DWORD
DWORD *_colors;
#else
RGBAColor *_colors;
#endif
MLR_I_DeT_TMesh::Copy(pMesh);
pMesh->GetColorData(&_colors, &len);
SetColorData(_colors, len);
return true;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
MLR_I_C_DeT_TMesh::Copy(
MLR_I_C_TMesh *tMesh,
MLRState detailState,
Stuff::Scalar xOff,
Stuff::Scalar yOff,
Stuff::Scalar xFac,
Stuff::Scalar yFac
)
{
Check_Object(this);
Check_Object(tMesh);
Verify(gos_GetCurrentHeap() == Heap);
int len;
#if COLOR_AS_DWORD
DWORD *_colors;
#else
RGBAColor *_colors;
#endif
MLR_I_DeT_TMesh::Copy(tMesh, detailState, xOff, yOff, xFac, yFac);
tMesh->GetColorData(&_colors, &len);
SetColorData(_colors, len);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
MLR_I_C_DeT_TMesh::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_DeT_TMesh::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_DeT_TMesh::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
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
MLR_I_C_DeT_TMesh::TestInstance() const
{
Verify(IsDerivedFrom(DefaultData));
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
MLR_I_C_DeT_TMesh::HurtMe(const Stuff::LinearMatrix4D& pain, Stuff::Scalar radius)
{
Check_Object(this);
Verify(colors.GetLength() == coords.GetLength());
int i, len = colors.GetLength();
Point3D painpoint;
Vector3D diff;
UnitVector3D up, left, forward;
Scalar x, y, sqRadius = radius*radius;
painpoint = pain;
pain.GetLocalLeftInWorld(&left);
pain.GetLocalUpInWorld(&up);
pain.GetLocalForwardInWorld(&forward);
if(FindBackFace(painpoint) && FindVisibleVertices())
{
for(i=0;i<len;i++)
{
if(visibleIndexedVertices[i]>0)
{
diff.Subtract(coords[i], painpoint);
x = diff*left;
y = diff*up;
if((x*x + y*y) < sqRadius)
{
#if COLOR_AS_DWORD
colors[i] |= 0xff000000;
#else
colors[i].alpha = 1.0f;
#endif
}
}
}
}
visibleIndexedVerticesKey = false;
}
extern DWORD gEnableTextureSort, gEnableAlphaSort;
#define I_SAY_YES_TO_DETAIL_TEXTURES
#undef I_SAY_YES_TO_DUAL_TEXTURES
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -