summaryrefslogtreecommitdiff
path: root/movieobjects/dmeshape.cpp
blob: 33a1f2023328794e3c46f94a0432e324300de0b4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================
#include "movieobjects/dmeshape.h"
#include "datamodel/dmelementfactoryhelper.h"
#include "movieobjects_interfaces.h"
#include "movieobjects/dmedag.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"


//-----------------------------------------------------------------------------
// Expose this class to the scene database 
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmeShape, CDmeShape );


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CDmeShape::OnConstruction()
{
	m_visible.InitAndSet( this, "visible", true );
}

void CDmeShape::OnDestruction()
{
}

void CDmeShape::Draw( const matrix3x4_t &shapeToWorld, CDmeDrawSettings *pDrawSettings /* = NULL */ )
{
	Assert( 0 );
}


//-----------------------------------------------------------------------------
// The default bounding sphere is empty at the origin
//-----------------------------------------------------------------------------
void CDmeShape::GetBoundingSphere( Vector &c, float &r ) const
{
	c.Zero();
	r = 0.0f;
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
int CDmeShape::GetParentCount() const
{
	int nReferringDags = 0;

	DmAttributeReferenceIterator_t i = g_pDataModel->FirstAttributeReferencingElement( GetHandle() );
	while ( i != DMATTRIBUTE_REFERENCE_ITERATOR_INVALID )
	{
		CDmAttribute *pAttribute = g_pDataModel->GetAttribute( i );
		CDmeDag *pDag = CastElement< CDmeDag >( pAttribute->GetOwner() );
		const static UtlSymId_t symShape = g_pDataModel->GetSymbol( "shape" );
		if ( pDag && pAttribute->GetNameSymbol() == symShape && pDag->GetFileId() == GetFileId()  )
		{
			++nReferringDags;
		}

		i = g_pDataModel->NextAttributeReferencingElement( i );
	}

	return nReferringDags;
}


//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
CDmeDag *CDmeShape::GetParent( int nParentIndex /*= 0 */ ) const
{
	int nReferringDags = 0;

	DmAttributeReferenceIterator_t i = g_pDataModel->FirstAttributeReferencingElement( GetHandle() );
	while ( i != DMATTRIBUTE_REFERENCE_ITERATOR_INVALID )
	{
		CDmAttribute *pAttribute = g_pDataModel->GetAttribute( i );
		CDmeDag *pDag = CastElement< CDmeDag >( pAttribute->GetOwner() );
		const static UtlSymId_t symShape = g_pDataModel->GetSymbol( "shape" );
		if ( pDag && pAttribute->GetNameSymbol() == symShape && pDag->GetFileId() == GetFileId()  )
		{
			if ( nReferringDags == nParentIndex )
				return pDag;

			++nReferringDags;
		}

		i = g_pDataModel->NextAttributeReferencingElement( i );
	}

	return NULL;
}


//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CDmeShape::GetShapeToWorldTransform( matrix3x4_t &mat, int nParentIndex /*= 0 */ ) const
{
	CDmeDag *pDag = GetParent( nParentIndex );

	if ( pDag )
	{
		pDag->GetShapeToWorldTransform( mat );
	}
	else
	{
		SetIdentityMatrix( mat );
	}
}