summaryrefslogtreecommitdiff
path: root/hammer/maplightcone.h
blob: c8b282d6ab33413d21e5371dc48f656b6683cab3 (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
116
117
118
119
120
121
122
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#ifndef MAPLIGHTCONE_H
#define MAPLIGHTCONE_H
#ifdef _WIN32
#pragma once
#endif


#include "MapHelper.h"
#include "MapFace.h"
#include "fgdlib/WCKeyValues.h"


class CHelperInfo;
class CRender3D;


class CMapLightCone : public CMapHelper
{
public:

	DECLARE_MAPCLASS(CMapLightCone,CMapHelper);
	
	//
	// Factory for building from a list of string parameters.
	//
	static CMapClass *Create(CHelperInfo *pInfo, CMapEntity *pParent);
	
	//
	// Construction/destruction:
	//
	CMapLightCone(void);
	~CMapLightCone(void);

	void CalcBounds(BOOL bFullUpdate = FALSE);

	virtual CMapClass *Copy(bool bUpdateDependencies);
	virtual CMapClass *CopyFrom(CMapClass *pFrom, bool bUpdateDependencies);

	void Render3D(CRender3D *pRender);

	int SerializeRMF(std::fstream &File, BOOL bRMF);
	int SerializeMAP(std::fstream &File, BOOL bRMF);

	virtual void PostloadWorld(CMapWorld *pWorld);

	virtual bool IsVisualElement(void) { return(false); } // Only visible when parent entity is selected.
	virtual bool IsClutter(void) { return true; }
	virtual bool IsCulledByCordon(const Vector &vecMins, const Vector &vecMaxs) { return false; } // We don't hide unless our parent hides.

	virtual CMapClass *PrepareSelection(SelectMode_t eSelectMode);
		
	const char* GetDescription() { return("Light cone helper"); }

	void OnParentKeyChanged( const char* key, const char* value );
	bool ShouldRenderLast(void) { return(true); }
	void GetAngles(QAngle& fAngles);

	float GetInnerConeAngle(void) const
	{
		return m_fInnerConeAngle;
	}

	float GetOuterConeAngle(void) const
	{
		return m_fOuterConeAngle;
	}

	Vector GetColor(void) const
	{
		float multiplier=m_fBrightness/256.0;
		Vector ret;
		ret.x=GammaToLinear(m_LightColor.x/255.0)*multiplier;
		ret.y=GammaToLinear(m_LightColor.y/255.0)*multiplier;
		ret.z=GammaToLinear(m_LightColor.z/255.0)*multiplier;
		return ret;
	}

	float m_fQuadraticAttn;
	float m_fLinearAttn;
	float m_fConstantAttn;

	float m_fFiftyPercentDistance;							// "_fifty_percent_distance" <0 = not
															// using this mode
	float m_fZeroPercentDistance;							// "_zero_percent_distance"


protected:

	void BuildCone(void);
	float GetBrightnessAtDist(float fDistance);
	float GetLightDist(float fBrightness);
	bool SolveQuadratic(float &x, float y, float A, float B, float C);

	Vector m_LightColor;
	float m_fBrightness;


	float m_fInnerConeAngle;
	float m_fOuterConeAngle;

	QAngle m_Angles;

	bool m_bPitchSet;
	float m_fPitch;

	float m_fFocus;

	CMapFaceList m_Faces;

	char m_szColorKeyName[KEYVALUE_MAX_KEY_LENGTH];
	char m_szInnerConeKeyName[KEYVALUE_MAX_KEY_LENGTH];
	char m_szOuterConeKeyName[KEYVALUE_MAX_KEY_LENGTH];
	float m_flPitchScale;
};

#endif // MAPLIGHTCONE_H