36 #include "Core-Level-JR.h"
38 laLitterPools::laLitterPools(
void)
42 laLitterPools::~laLitterPools(
void)
46 laPoint3 laLitterPools::getRandomPosition()
48 laPoint3 pos = _ptPivot;
50 pos[0] += ((rand()%1000)/1000.0) * __ptSize.x();
51 pos[1] += ((rand()%1000)/1000.0) * __ptSize.y();
52 pos[2] += ((rand()%1000)/1000.0) * __ptSize.z();
57 unsigned laLitterPools::getRandomPopulation()
59 if(_nMaxPolulation!=_nMinPolulation)
60 return rand()%(_nMaxPolulation-_nMinPolulation) + _nMinPolulation + 1;
61 else return _nMinPolulation;
64 unsigned laLitterPools::getRandomElement()
66 return _arPools[rand()%_nPoolsz];
69 double laLitterPools::getRandomAngle()
71 return ((rand()%1000)/1000.0) * _dAngleVar;
75 void laLitterPools::setTS(
laTileset* pTileset)
79 for(
unsigned i=0; i<_nPoolsz; i++)
81 _arPools[i] = _pTileset->getElementIndex(_strNames+i*64);
83 if(_arPools[i]==_pTileset->getElementCnt())
84 throw laError(
"Element '%s' requested as litter Pools element was not found",
91 fp->readText(_strName);
92 fp->readObj(&_ptPivot);
93 fp->readObj(&__ptSize, M_FALSE);
95 fp->readDouble(&_dAngleVar);
96 fp->readObj(&_AngleVector, M_FALSE);
101 fp->readUnsigned(&_nMinPolulation);
102 fp->readUnsigned(&_nMaxPolulation, M_FALSE);
103 fp->readUnsigned(&_nPoolsz);
105 _arPools =
new unsigned[_nPoolsz];
106 _strNames =
new char[_nPoolsz*64];
108 for(
unsigned i=0; i<_nPoolsz; i++)
110 fp->readText(_strNames+i*64);
114 laLitterBox::laLitterBox(
void)
117 _strPoolsName[0] =
'\0';
121 laLitterBox::~laLitterBox(
void)
126 void laLitterBox::litter(
laTileset* pTileset)
129 unsigned nLitterPools;
132 _pTileset = pTileset;
133 nLitterPools = _pTileset->getLitterPoolsIndex(_strPoolsName);
135 if(nLitterPools>=_pTileset->getLitterPoolsCount())
136 throw laError(
"Invalid litter Pools index %d for Pools size %d",
137 nLitterPools, _pTileset->getLitterPoolsCount());
139 if(nLitterPools>=_pTileset->getLitterPoolsCount())
140 throw laError(
"Litter Pools '%s' was requested but not found in the tileset",
143 pPools = _pTileset->getLitterPools(nLitterPools);
146 _nObjectCount = pPools->getRandomPopulation();
148 _arObjects =
new unsigned[_nObjectCount];
149 _arPositions =
new laPoint3[_nObjectCount];
150 _arAngles =
new double[_nObjectCount];
152 _AngleVector = pPools->getAngleVector();
154 for(
unsigned i=0; i<_nObjectCount; i++)
156 _arObjects[i] = pPools->getRandomElement();
157 _arPositions[i] = pPools->getRandomPosition();
158 _arAngles[i] = pPools->getRandomAngle();
163 void laLitterBox::drawGeometry(
laRenderer *r, laPoint3 pos)
165 for(
unsigned i=0; i<_nObjectCount; i++)
167 laPoint3 mod_pos = pos;
168 mod_pos += _arPositions[i];
171 r->transTranslate(mod_pos);
172 r->transRotate(_arAngles[i], _AngleVector);
174 _pTileset->getElement(_arObjects[i])->drawGeometry(r);
180 void laLitterBox::drawFx(
laRenderer *r, laPoint3 pos)
182 for(
unsigned i=0; i<_nObjectCount; i++)
184 laPoint3 mod_pos = pos;
185 mod_pos += _arPositions[i];
188 r->transTranslate(mod_pos);
189 r->transRotate(_arAngles[i], _AngleVector);
191 _pTileset->getElement(_arObjects[i])->drawFx(r);
200 fp->readText(_strPoolsName, M_FALSE);
#define M_UNIT
Unit of 1 meter.
"Litter pools" to be used for populating laLitterBox
Virtual interface for the Engine graphics renderer.