📄 modelgeoset.cpp
字号:
}
if(!Mesh.LockVertexBuffer(&VertexPointer)) return FALSE;
if(!AnimatedMesh.LockVertexBuffer(&AnimatedVertexPointer))
{
Mesh.UnlockVertexBuffer();
return FALSE;
}
for(i = 0; i < GeosetData.VertexContainer.GetTotalSize(); i++)
{
if(!GeosetData.VertexContainer.ValidIndex(i)) continue;
GroupIndex = GeosetData.VertexContainer[i]->VertexGroup;
if(GeosetData.GroupContainer.ValidIndex(GroupIndex))
{
D3DXVECTOR3 TempVector;
D3DXVECTOR4 TempVector2;
D3DXVECTOR3 TempNormalTarget;
D3DXVECTOR4 TempNormalTarget2;
D3DXVECTOR3 NormalTarget;
D3DXVECTOR3 TransformedNormalTarget;
INT MatrixListSize;
FLOAT Scale;
GeosetGroup = GeosetData.GroupContainer[GroupIndex];
MatrixListSize = GeosetGroup->MatrixList.GetTotalSize();
AnimatedVertexPointer->Position = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
TransformedNormalTarget = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
for(j = 0; j < MatrixListSize; j++)
{
if(!GeosetGroup->MatrixList.ValidIndex(j)) continue;
GeosetGroupNode = GeosetGroup->MatrixList[j];
if(!GeosetGroupNode->Node.IsAttached())
{
AnimatedMesh.UnlockVertexBuffer();
Mesh.UnlockVertexBuffer();
return FALSE;
}
Node = GeosetGroupNode->Node.GetObjectData();
D3DXVec3Transform(&TempVector2, &(VertexPointer->Position), &(Node->Matrix()));
D3DXVec3Add(&NormalTarget, &VertexPointer->Position, &VertexPointer->Normal);
D3DXVec3Transform(&TempNormalTarget2, &NormalTarget, &(Node->Matrix()));
TempVector.x = TempVector2.x;
TempVector.y = TempVector2.y;
TempVector.z = TempVector2.z;
TempNormalTarget.x = TempNormalTarget2.x;
TempNormalTarget.y = TempNormalTarget2.y;
TempNormalTarget.z = TempNormalTarget2.z;
D3DXVec3Add(&(AnimatedVertexPointer->Position), &(AnimatedVertexPointer->Position), &TempVector);
D3DXVec3Add(&TransformedNormalTarget, &TransformedNormalTarget, &TempNormalTarget);
}
Scale = (MatrixListSize == 0) ? 0.0f : (1.0f / static_cast<FLOAT>(MatrixListSize));
D3DXVec3Scale(&(AnimatedVertexPointer->Position), &(AnimatedVertexPointer->Position), Scale);
D3DXVec3Scale(&TransformedNormalTarget, &TransformedNormalTarget, Scale);
AnimatedVertexPointer->Normal = TransformedNormalTarget - AnimatedVertexPointer->Position;
}
VertexPointer++;
AnimatedVertexPointer++;
}
AnimatedMesh.UnlockVertexBuffer();
Mesh.UnlockVertexBuffer();
return TRUE;
}
//+-----------------------------------------------------------------------------
//| Builds an animated texture
//+-----------------------------------------------------------------------------
BOOL MODEL_GEOSET::BuildAnimatedTexture(CONST SEQUENCE_TIME& Time, MODEL_TEXTURE_ANIMATION* TextureAnimation, FLOAT Alpha)
{
INT i;
INT Size;
D3DCOLOR RealColor;
D3DXVECTOR3 Translation;
VERTEX* VertexPointer;
VERTEX* AnimatedVertexPointer;
RealColor = D3DCOLOR_RGBA(static_cast<BYTE>(GeosetColor.r * 255.0f), static_cast<BYTE>(GeosetColor.g * 255.0f), static_cast<BYTE>(GeosetColor.b * 255.0f), static_cast<BYTE>((GeosetColor.a * Alpha) * 255.0f));
Size = GeosetData.VertexContainer.GetSize();
if(!Mesh.LockVertexBuffer(&VertexPointer)) return FALSE;
if(!AnimatedMesh.LockVertexBuffer(&AnimatedVertexPointer))
{
Mesh.UnlockVertexBuffer();
return FALSE;
}
for(i = 0; i < Size; i++)
{
if(TextureAnimation == NULL)
{
AnimatedVertexPointer->TexturePosition = VertexPointer->TexturePosition;
}
else
{
SEQUENCE_TIME TempTime;
if(TextureAnimation->Data().Translation.GlobalSequenceNode.IsAttached())
{
MODEL_GLOBAL_SEQUENCE* GlobalSequence;
GlobalSequence = TextureAnimation->Data().Translation.GlobalSequenceNode.GetObjectData();
TempTime.Time = GlobalSequence->Data().Time;
TempTime.IntervalStart = 0;
TempTime.IntervalEnd = GlobalSequence->Data().Duration;
}
else
{
TempTime = Time;
}
Translation = TextureAnimation->Data().Translation.GetVector3(TempTime);
AnimatedVertexPointer->TexturePosition = VertexPointer->TexturePosition;
AnimatedVertexPointer->TexturePosition.x += Translation.x;
AnimatedVertexPointer->TexturePosition.y += Translation.y;
}
AnimatedVertexPointer->Color = RealColor;
VertexPointer++;
AnimatedVertexPointer++;
}
AnimatedMesh.UnlockVertexBuffer();
Mesh.UnlockVertexBuffer();
return TRUE;
}
//+-----------------------------------------------------------------------------
//| Adds a new vertex
//+-----------------------------------------------------------------------------
BOOL MODEL_GEOSET::AddVertex(MODEL_GEOSET_VERTEX* Vertex)
{
if(!GeosetData.VertexContainer.Add(Vertex))
{
Error.SetMessage("Unable to add a new vertex!");
return FALSE;
}
MeshBuildt = FALSE;
return TRUE;
}
//+-----------------------------------------------------------------------------
//| Adds a new face
//+-----------------------------------------------------------------------------
BOOL MODEL_GEOSET::AddFace(MODEL_GEOSET_FACE* Face)
{
if(!GeosetData.FaceContainer.Add(Face))
{
Error.SetMessage("Unable to add a new face!");
return FALSE;
}
MeshBuildt = FALSE;
return TRUE;
}
//+-----------------------------------------------------------------------------
//| Adds a new group
//+-----------------------------------------------------------------------------
BOOL MODEL_GEOSET::AddGroup(MODEL_GEOSET_GROUP* Group)
{
if(!GeosetData.GroupContainer.Add(Group))
{
Error.SetMessage("Unable to add a new group!");
return FALSE;
}
return TRUE;
}
//+-----------------------------------------------------------------------------
//| Adds a new extent
//+-----------------------------------------------------------------------------
BOOL MODEL_GEOSET::AddExtent(EXTENT* Extent)
{
if(!GeosetData.ExtentContainer.Add(Extent))
{
Error.SetMessage("Unable to add a new extent!");
return FALSE;
}
return TRUE;
}
//+-----------------------------------------------------------------------------
//| Calculates the extent of the geoset
//+-----------------------------------------------------------------------------
VOID MODEL_GEOSET::CalculateExtent(EXTENT& Extent)
{
INT i;
INT NrOfSequences;
D3DXVECTOR3 Center;
std::vector<D3DXVECTOR3> VertexList;
NrOfSequences = Model.Data().SequenceContainer.GetSize();
VertexList.reserve(GeosetData.VertexContainer.GetSize());
for(i = 0; i < GeosetData.VertexContainer.GetTotalSize(); i++)
{
if(GeosetData.VertexContainer.ValidIndex(i))
{
VertexList.push_back(GeosetData.VertexContainer[i]->Position);
}
}
if(static_cast<INT>(VertexList.size()) <= 0)
{
Extent = EXTENT();
}
else
{
D3DXComputeBoundingBox(&VertexList[0], static_cast<INT>(VertexList.size()), sizeof(D3DXVECTOR3), &Extent.Min, &Extent.Max);
D3DXComputeBoundingSphere(&VertexList[0], static_cast<INT>(VertexList.size()), sizeof(D3DXVECTOR3), &Center, &Extent.Radius);
}
GeosetData.Extent = Extent;
SAFE_CLEAR(GeosetData.ExtentContainer);
for(i = 0; i < NrOfSequences; i++)
{
AddExtent(new EXTENT(GeosetData.Extent));
}
}
//+-----------------------------------------------------------------------------
//| Checks if a ray intersects the geoset
//+-----------------------------------------------------------------------------
BOOL MODEL_GEOSET::RayIntersects(CONST D3DXVECTOR3& RayPosition, CONST D3DXVECTOR3& RayDirection, BOOL Animated, FLOAT* Distance)
{
if(GeosetAlpha <= 0.01f) return FALSE;
if(Animated)
{
return AnimatedMesh.RayIntersects(RayPosition, RayDirection, Distance);
}
else
{
return Mesh.RayIntersects(RayPosition, RayDirection, Distance);
}
}
//+-----------------------------------------------------------------------------
//| Nullifys a matrix
//+-----------------------------------------------------------------------------
VOID MODEL_GEOSET::NullifyMatrix(D3DXMATRIX& Matrix)
{
Matrix._11 = 0.0f;
Matrix._12 = 0.0f;
Matrix._13 = 0.0f;
Matrix._14 = 0.0f;
Matrix._21 = 0.0f;
Matrix._22 = 0.0f;
Matrix._23 = 0.0f;
Matrix._24 = 0.0f;
Matrix._31 = 0.0f;
Matrix._32 = 0.0f;
Matrix._33 = 0.0f;
Matrix._34 = 0.0f;
Matrix._41 = 0.0f;
Matrix._42 = 0.0f;
Matrix._43 = 0.0f;
Matrix._44 = 0.0f;
}
//+-----------------------------------------------------------------------------
//| Adds two matrices together
//+-----------------------------------------------------------------------------
VOID MODEL_GEOSET::AddMatrix(D3DXMATRIX& Matrix, CONST D3DXMATRIX& AddedMatrix)
{
Matrix._11 += AddedMatrix._11;
Matrix._12 += AddedMatrix._12;
Matrix._13 += AddedMatrix._13;
Matrix._14 += AddedMatrix._14;
Matrix._21 += AddedMatrix._21;
Matrix._22 += AddedMatrix._22;
Matrix._23 += AddedMatrix._23;
Matrix._24 += AddedMatrix._24;
Matrix._31 += AddedMatrix._31;
Matrix._32 += AddedMatrix._32;
Matrix._33 += AddedMatrix._33;
Matrix._34 += AddedMatrix._34;
Matrix._41 += AddedMatrix._41;
Matrix._42 += AddedMatrix._42;
Matrix._43 += AddedMatrix._43;
Matrix._44 += AddedMatrix._44;
}
//+-----------------------------------------------------------------------------
//| Scales a matrix by a factor
//+-----------------------------------------------------------------------------
VOID MODEL_GEOSET::ScaleMatrix(D3DXMATRIX& Matrix, INT Factor)
{
FLOAT Scale;
Scale = (Factor == 0) ? 0.0f : (1.0f / static_cast<FLOAT>(Factor));
Matrix._11 *= Scale;
Matrix._22 *= Scale;
Matrix._33 *= Scale;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -