wavelength 1.0.0
Loading...
Searching...
No Matches
rndlight.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4
5#include "math/color.h"
6#include "os/binstream.h"
7#include "os/mem.h"
8#include "os/prnstream.h"
10
16class RndLight : public RndTransformable {
17public:
24
33 explicit RndLight(const char *pszName);
34
41 ~RndLight() override;
42
49 void *operator new(size_t nSize) {
50 return PoolMemAlloc(static_cast<int>(nSize), "Light", 0);
51 }
52
58 void operator delete(void *pBlock) {
59 PoolMemFree(pBlock);
60 }
61
69 virtual void SetColor(const Color &color) {
70 mColor = color;
71 }
72
80 virtual void SetType(int nType) {
81 mType = nType;
82 }
83
91 virtual void SetRange(float fRange) {
92 mRange = fRange;
93 }
94
105 virtual void SetAngles(float fInnerAng, float fOuterAng) {
106 mOuterAng = fOuterAng;
107 mInnerAng = fInnerAng;
108 }
109
121 virtual void SetAttenuation(float fConstant, float fLinear, float fQuadratic) {
122 mQuadraticAtten = fQuadratic;
123 mConstantAtten = fConstant;
124 mLinearAtten = fLinear;
125 }
126
135 virtual void Sync() {
136 }
137
145 void DumpText(PrnStream &stream) override;
146
154 void Save(BinStream &stream) override;
155
164 void Replace(RndObject *pFrom, RndObject *pTo) override;
165
173 const char *ClassName() const override {
174 return sClassName;
175 }
176
185 void Copy(const RndObject *pSource, int nFlags) override;
186
194 void Load(BinStream &stream) override;
195
205 static void CreateDefault();
206
215 static RndObject *New(const char *pszName) {
216 return new RndLight(pszName);
217 }
218
226
233 static const char *sClassName;
234
241 static int sRev;
242
244 const Color &GetColor() const {
245 return mColor;
246 }
247
249 float GetRange() const {
250 return mRange;
251 }
252
254 int GetType() const {
255 return mType;
256 }
257
258private:
259 Color mColor;
260 float mInnerAng;
261 float mOuterAng;
262 float mRange;
263 float mConstantAtten;
264 float mLinearAtten;
265 float mQuadraticAtten;
266 int mType;
267};
268
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
Text output stream.
Definition prnstream.h:16
virtual void SetAttenuation(float fConstant, float fLinear, float fQuadratic)
Set the attenuation.
Definition rndlight.h:121
static void CreateDefault()
Create the default light, add it to the default environment, and place it under the default camera.
static RndLight * sDefault
The light CreateDefault() made.
Definition rndlight.h:225
static int sRev
The format version Save() writes and Load() accepts.
Definition rndlight.h:241
void Load(BinStream &stream) override
Read what Save() wrote, or an earlier version of it, then pass the settings to the back end.
int GetType() const
Definition rndlight.h:254
void Replace(RndObject *pFrom, RndObject *pTo) override
Replace a referenced object with another in the base.
static const char * sClassName
The class name a .rnd file writes, Light.
Definition rndlight.h:233
virtual void Sync()
Pass the settings to the back end.
Definition rndlight.h:135
const Color & GetColor() const
Definition rndlight.h:244
virtual void SetColor(const Color &color)
Set the colour.
Definition rndlight.h:69
void Save(BinStream &stream) override
Write the light and its base.
void DumpText(PrnStream &stream) override
Write a description of the light and its base.
static RndObject * New(const char *pszName)
Create a light.
Definition rndlight.h:215
void Copy(const RndObject *pSource, int nFlags) override
Copy another light and its base, then pass the settings to the back end.
virtual void SetRange(float fRange)
Set the range.
Definition rndlight.h:91
RndLight(const char *pszName)
Construct a white directional light with a range of 1000, cone angles of a quarter turn,...
~RndLight() override
Destroy the light.
float GetRange() const
Definition rndlight.h:249
virtual void SetType(int nType)
Set the kind of light.
Definition rndlight.h:80
virtual void SetAngles(float fInnerAng, float fOuterAng)
Set the angles of the cone of a spot light.
Definition rndlight.h:105
const char * ClassName() const override
Report the class name.
Definition rndlight.h:173
Type
The kinds of light.
Definition rndlight.h:19
@ kTypePoint
Definition rndlight.h:20
@ kTypeDirectional
Definition rndlight.h:21
@ kTypeSpot
Definition rndlight.h:22
RndObject(const char *pszName)
Construct an object and register it under a name.
RndTransformable()
Construct a transformable with identity transforms, no origin offset, and no billboard.
void * PoolMemAlloc(int nSize, const char *pszTag, int nAlign)
Allocate a block from the pool heaps and bill it to a tag.
void PoolMemFree(void *pBlock)
Return a block PoolMemAlloc() handed out to the pool heap that owns it.
PrnStream & operator<<(PrnStream &stream, RndLight::Type eType)
Write the name of a kind of light.
Linear colour with four float components.
Definition color.h:12