BillboardSet.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. //
  2. // Copyright (c) 2008-2015 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "../Precompiled.h"
  23. #include "../Core/Context.h"
  24. #include "../Core/Profiler.h"
  25. #include "../Graphics/Batch.h"
  26. #include "../Atomic3D/BillboardSet.h"
  27. #include "../Graphics/Camera.h"
  28. #include "../Graphics/Geometry.h"
  29. #include "../Graphics/Graphics.h"
  30. #include "../Graphics/IndexBuffer.h"
  31. #include "../Graphics/Material.h"
  32. #include "../Graphics/OctreeQuery.h"
  33. #include "../Graphics/VertexBuffer.h"
  34. #include "../IO/MemoryBuffer.h"
  35. #include "../Resource/ResourceCache.h"
  36. #include "../Scene/Node.h"
  37. #include "../DebugNew.h"
  38. namespace Atomic
  39. {
  40. extern const char* GEOMETRY_CATEGORY;
  41. static const float INV_SQRT_TWO = 1.0f / sqrtf(2.0f);
  42. const char* faceCameraModeNames[] =
  43. {
  44. "None",
  45. "Rotate XYZ",
  46. "Rotate Y",
  47. "LookAt XYZ",
  48. "LookAt Y",
  49. 0
  50. };
  51. inline bool CompareBillboards(Billboard* lhs, Billboard* rhs)
  52. {
  53. return lhs->GetSortDistance() > rhs->GetSortDistance();
  54. }
  55. Billboard::Billboard()
  56. {
  57. }
  58. Billboard::~Billboard()
  59. {
  60. }
  61. BillboardSet::BillboardSet(Context* context) :
  62. Drawable(context, DRAWABLE_GEOMETRY),
  63. animationLodBias_(1.0f),
  64. animationLodTimer_(0.0f),
  65. relative_(true),
  66. scaled_(true),
  67. sorted_(false),
  68. faceCameraMode_(FC_ROTATE_XYZ),
  69. geometry_(new Geometry(context)),
  70. vertexBuffer_(new VertexBuffer(context_)),
  71. indexBuffer_(new IndexBuffer(context_)),
  72. bufferSizeDirty_(true),
  73. bufferDirty_(true),
  74. forceUpdate_(false),
  75. sortThisFrame_(false),
  76. sortFrameNumber_(0),
  77. previousOffset_(Vector3::ZERO)
  78. {
  79. geometry_->SetVertexBuffer(0, vertexBuffer_, MASK_POSITION | MASK_COLOR | MASK_TEXCOORD1 | MASK_TEXCOORD2);
  80. geometry_->SetIndexBuffer(indexBuffer_);
  81. batches_.Resize(1);
  82. batches_[0].geometry_ = geometry_;
  83. batches_[0].geometryType_ = GEOM_BILLBOARD;
  84. batches_[0].worldTransform_ = &transforms_[0];
  85. }
  86. BillboardSet::~BillboardSet()
  87. {
  88. }
  89. void BillboardSet::RegisterObject(Context* context)
  90. {
  91. context->RegisterFactory<BillboardSet>(GEOMETRY_CATEGORY);
  92. ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
  93. MIXED_ACCESSOR_ATTRIBUTE("Material", GetMaterialAttr, SetMaterialAttr, ResourceRef, ResourceRef(Material::GetTypeStatic()),
  94. AM_DEFAULT);
  95. ACCESSOR_ATTRIBUTE("Relative Position", IsRelative, SetRelative, bool, true, AM_DEFAULT);
  96. ACCESSOR_ATTRIBUTE("Relative Scale", IsScaled, SetScaled, bool, true, AM_DEFAULT);
  97. ACCESSOR_ATTRIBUTE("Sort By Distance", IsSorted, SetSorted, bool, false, AM_DEFAULT);
  98. ACCESSOR_ATTRIBUTE("Can Be Occluded", IsOccludee, SetOccludee, bool, true, AM_DEFAULT);
  99. ATTRIBUTE("Cast Shadows", bool, castShadows_, false, AM_DEFAULT);
  100. ENUM_ATTRIBUTE("Face Camera Mode", faceCameraMode_, faceCameraModeNames, FC_ROTATE_XYZ, AM_DEFAULT);
  101. ACCESSOR_ATTRIBUTE("Draw Distance", GetDrawDistance, SetDrawDistance, float, 0.0f, AM_DEFAULT);
  102. ACCESSOR_ATTRIBUTE("Shadow Distance", GetShadowDistance, SetShadowDistance, float, 0.0f, AM_DEFAULT);
  103. ACCESSOR_ATTRIBUTE("Animation LOD Bias", GetAnimationLodBias, SetAnimationLodBias, float, 1.0f, AM_DEFAULT);
  104. COPY_BASE_ATTRIBUTES(Drawable);
  105. MIXED_ACCESSOR_ATTRIBUTE("Billboards", GetBillboardsAttr, SetBillboardsAttr, VariantVector, Variant::emptyVariantVector,
  106. AM_FILE);
  107. ACCESSOR_ATTRIBUTE("Network Billboards", GetNetBillboardsAttr, SetNetBillboardsAttr, PODVector<unsigned char>,
  108. Variant::emptyBuffer, AM_NET | AM_NOEDIT);
  109. }
  110. void BillboardSet::ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results)
  111. {
  112. // If no billboard-level testing, use the Drawable test
  113. if (query.level_ < RAY_TRIANGLE)
  114. {
  115. Drawable::ProcessRayQuery(query, results);
  116. return;
  117. }
  118. // Check ray hit distance to AABB before proceeding with billboard-level tests
  119. if (query.ray_.HitDistance(GetWorldBoundingBox()) >= query.maxDistance_)
  120. return;
  121. const Matrix3x4& worldTransform = node_->GetWorldTransform();
  122. Matrix3x4 billboardTransform = relative_ ? worldTransform : Matrix3x4::IDENTITY;
  123. Vector3 billboardScale = scaled_ ? worldTransform.Scale() : Vector3::ONE;
  124. for (unsigned i = 0; i < billboards_.Size(); ++i)
  125. {
  126. if (!billboards_[i]->enabled_)
  127. continue;
  128. // Approximate the billboards as spheres for raycasting
  129. float size = INV_SQRT_TWO * (billboards_[i]->size_.x_ * billboardScale.x_ + billboards_[i]->size_.y_ * billboardScale.y_);
  130. Vector3 center = billboardTransform * billboards_[i]->position_;
  131. Sphere billboardSphere(center, size);
  132. float distance = query.ray_.HitDistance(billboardSphere);
  133. if (distance < query.maxDistance_)
  134. {
  135. // If the code reaches here then we have a hit
  136. RayQueryResult result;
  137. result.position_ = query.ray_.origin_ + distance * query.ray_.direction_;
  138. result.normal_ = -query.ray_.direction_;
  139. result.distance_ = distance;
  140. result.drawable_ = this;
  141. result.node_ = node_;
  142. result.subObject_ = i;
  143. results.Push(result);
  144. }
  145. }
  146. }
  147. void BillboardSet::UpdateBatches(const FrameInfo& frame)
  148. {
  149. // If beginning a new frame, assume no sorting first
  150. if (frame.frameNumber_ != sortFrameNumber_)
  151. {
  152. sortThisFrame_ = false;
  153. sortFrameNumber_ = frame.frameNumber_;
  154. }
  155. Vector3 worldPos = node_->GetWorldPosition();
  156. Vector3 offset = (worldPos - frame.camera_->GetNode()->GetWorldPosition());
  157. // Sort if position relative to camera has changed
  158. if (offset != previousOffset_ & sorted_)
  159. sortThisFrame_ = true;
  160. distance_ = frame.camera_->GetDistance(GetWorldBoundingBox().Center());
  161. // Calculate scaled distance for animation LOD
  162. float scale = GetWorldBoundingBox().Size().DotProduct(DOT_SCALE);
  163. // If there are no billboards, the size becomes zero, and LOD'ed updates no longer happen. Disable LOD in that case
  164. if (scale > M_EPSILON)
  165. lodDistance_ = frame.camera_->GetLodDistance(distance_, scale, lodBias_);
  166. else
  167. lodDistance_ = 0.0f;
  168. batches_[0].distance_ = distance_;
  169. batches_[0].numWorldTransforms_ = 2;
  170. // Billboard positioning
  171. transforms_[0] = relative_ ? node_->GetWorldTransform() : Matrix3x4::IDENTITY;
  172. // Billboard rotation
  173. transforms_[1] = Matrix3x4(Vector3::ZERO, faceCameraMode_ != FC_NONE ? frame.camera_->GetFaceCameraRotation(
  174. node_->GetWorldPosition(), node_->GetWorldRotation(), faceCameraMode_) : node_->GetWorldRotation(), Vector3::ONE);
  175. }
  176. void BillboardSet::UpdateGeometry(const FrameInfo& frame)
  177. {
  178. if (bufferSizeDirty_ || indexBuffer_->IsDataLost())
  179. UpdateBufferSize();
  180. if (bufferDirty_ || sortThisFrame_ || vertexBuffer_->IsDataLost())
  181. UpdateVertexBuffer(frame);
  182. // If using camera facing, re-update the rotation for the current view now
  183. if (faceCameraMode_ != FC_NONE)
  184. {
  185. transforms_[1] = Matrix3x4(Vector3::ZERO, frame.camera_->GetFaceCameraRotation(node_->GetWorldPosition(),
  186. node_->GetWorldRotation(), faceCameraMode_), Vector3::ONE);
  187. }
  188. }
  189. UpdateGeometryType BillboardSet::GetUpdateGeometryType()
  190. {
  191. // If using camera facing, always need some kind of geometry update, in case the billboard set is rendered from several views
  192. if (bufferDirty_ || bufferSizeDirty_ || vertexBuffer_->IsDataLost() || indexBuffer_->IsDataLost() || sortThisFrame_)
  193. return UPDATE_MAIN_THREAD;
  194. else if (faceCameraMode_ != FC_NONE)
  195. return UPDATE_WORKER_THREAD;
  196. else
  197. return UPDATE_NONE;
  198. }
  199. void BillboardSet::SetMaterial(Material* material)
  200. {
  201. batches_[0].material_ = material;
  202. MarkNetworkUpdate();
  203. }
  204. void BillboardSet::SetNumBillboards(unsigned num)
  205. {
  206. // Prevent negative value being assigned from the editor
  207. if (num > M_MAX_INT)
  208. num = 0;
  209. if (num > MAX_BILLBOARDS)
  210. num = MAX_BILLBOARDS;
  211. unsigned oldNum = billboards_.Size();
  212. billboards_.Resize(num);
  213. // Set default values to new billboards
  214. for (unsigned i = oldNum; i < num; ++i)
  215. {
  216. SharedPtr<Billboard> bb(new Billboard());
  217. bb->position_ = Vector3::ZERO;
  218. bb->size_ = Vector2::ONE;
  219. bb->uv_ = Rect::POSITIVE;
  220. bb->color_ = Color(1.0f, 1.0f, 1.0f);
  221. bb->rotation_ = 0.0f;
  222. bb->enabled_ = false;
  223. billboards_[i] = bb;
  224. }
  225. bufferSizeDirty_ = true;
  226. Commit();
  227. }
  228. void BillboardSet::SetRelative(bool enable)
  229. {
  230. relative_ = enable;
  231. Commit();
  232. }
  233. void BillboardSet::SetScaled(bool enable)
  234. {
  235. scaled_ = enable;
  236. Commit();
  237. }
  238. void BillboardSet::SetSorted(bool enable)
  239. {
  240. sorted_ = enable;
  241. Commit();
  242. }
  243. void BillboardSet::SetFaceCameraMode(FaceCameraMode mode)
  244. {
  245. faceCameraMode_ = mode;
  246. MarkNetworkUpdate();
  247. }
  248. void BillboardSet::SetAnimationLodBias(float bias)
  249. {
  250. animationLodBias_ = Max(bias, 0.0f);
  251. MarkNetworkUpdate();
  252. }
  253. void BillboardSet::Commit()
  254. {
  255. MarkPositionsDirty();
  256. MarkNetworkUpdate();
  257. }
  258. Material* BillboardSet::GetMaterial() const
  259. {
  260. return batches_[0].material_;
  261. }
  262. Billboard* BillboardSet::GetBillboard(unsigned index)
  263. {
  264. return index < billboards_.Size() ? billboards_[index] : (Billboard*)0;
  265. }
  266. void BillboardSet::SetMaterialAttr(const ResourceRef& value)
  267. {
  268. ResourceCache* cache = GetSubsystem<ResourceCache>();
  269. SetMaterial(cache->GetResource<Material>(value.name_));
  270. }
  271. void BillboardSet::SetBillboardsAttr(const VariantVector& value)
  272. {
  273. unsigned index = 0;
  274. unsigned numBillboards = index < value.Size() ? value[index++].GetUInt() : 0;
  275. SetNumBillboards(numBillboards);
  276. for (Vector<SharedPtr<Billboard>>::Iterator i = billboards_.Begin(); i != billboards_.End() && index < value.Size(); ++i)
  277. {
  278. Billboard *bb = i->Get();
  279. bb->position_ = value[index++].GetVector3();
  280. bb->size_ = value[index++].GetVector2();
  281. Vector4 uv = value[index++].GetVector4();
  282. bb->uv_ = Rect(uv.x_, uv.y_, uv.z_, uv.w_);
  283. bb->color_ = value[index++].GetColor();
  284. bb->rotation_ = value[index++].GetFloat();
  285. bb->enabled_ = value[index++].GetBool();
  286. }
  287. Commit();
  288. }
  289. void BillboardSet::SetNetBillboardsAttr(const PODVector<unsigned char>& value)
  290. {
  291. MemoryBuffer buf(value);
  292. unsigned numBillboards = buf.ReadVLE();
  293. SetNumBillboards(numBillboards);
  294. for (Vector<SharedPtr<Billboard>>::Iterator i = billboards_.Begin(); i != billboards_.End(); ++i)
  295. {
  296. Billboard *bb = i->Get();
  297. bb->position_ = buf.ReadVector3();
  298. bb->size_ = buf.ReadVector2();
  299. bb->uv_ = buf.ReadRect();
  300. bb->color_ = buf.ReadColor();
  301. bb->rotation_ = buf.ReadFloat();
  302. bb->enabled_ = buf.ReadBool();
  303. }
  304. Commit();
  305. }
  306. ResourceRef BillboardSet::GetMaterialAttr() const
  307. {
  308. return GetResourceRef(batches_[0].material_, Material::GetTypeStatic());
  309. }
  310. VariantVector BillboardSet::GetBillboardsAttr() const
  311. {
  312. VariantVector ret;
  313. ret.Reserve(billboards_.Size() * 6 + 1);
  314. ret.Push(billboards_.Size());
  315. for (Vector<SharedPtr<Billboard>>::ConstIterator i = billboards_.Begin(); i != billboards_.End(); ++i)
  316. {
  317. Billboard *bb = i->Get();
  318. ret.Push(bb->position_);
  319. ret.Push(bb->size_);
  320. ret.Push(Vector4(bb->uv_.min_.x_, bb->uv_.min_.y_, bb->uv_.max_.x_, bb->uv_.max_.y_));
  321. ret.Push(bb->color_);
  322. ret.Push(bb->rotation_);
  323. ret.Push(bb->enabled_);
  324. }
  325. return ret;
  326. }
  327. const PODVector<unsigned char>& BillboardSet::GetNetBillboardsAttr() const
  328. {
  329. attrBuffer_.Clear();
  330. attrBuffer_.WriteVLE(billboards_.Size());
  331. for (Vector<SharedPtr<Billboard>>::ConstIterator i = billboards_.Begin(); i != billboards_.End(); ++i)
  332. {
  333. Billboard *bb = i->Get();
  334. attrBuffer_.WriteVector3(bb->position_);
  335. attrBuffer_.WriteVector2(bb->size_);
  336. attrBuffer_.WriteRect(bb->uv_);
  337. attrBuffer_.WriteColor(bb->color_);
  338. attrBuffer_.WriteFloat(bb->rotation_);
  339. attrBuffer_.WriteBool(bb->enabled_);
  340. }
  341. return attrBuffer_.GetBuffer();
  342. }
  343. void BillboardSet::OnWorldBoundingBoxUpdate()
  344. {
  345. unsigned enabledBillboards = 0;
  346. const Matrix3x4& worldTransform = node_->GetWorldTransform();
  347. Matrix3x4 billboardTransform = relative_ ? worldTransform : Matrix3x4::IDENTITY;
  348. Vector3 billboardScale = scaled_ ? worldTransform.Scale() : Vector3::ONE;
  349. BoundingBox worldBox;
  350. for (unsigned i = 0; i < billboards_.Size(); ++i)
  351. {
  352. if (!billboards_[i]->enabled_)
  353. continue;
  354. float size = INV_SQRT_TWO * (billboards_[i]->size_.x_ * billboardScale.x_ + billboards_[i]->size_.y_ * billboardScale.y_);
  355. Vector3 center = billboardTransform * billboards_[i]->position_;
  356. Vector3 edge = Vector3::ONE * size;
  357. worldBox.Merge(BoundingBox(center - edge, center + edge));
  358. ++enabledBillboards;
  359. }
  360. // Always merge the node's own position to ensure particle emitter updates continue when the relative mode is switched
  361. worldBox.Merge(node_->GetWorldPosition());
  362. worldBoundingBox_ = worldBox;
  363. }
  364. void BillboardSet::UpdateBufferSize()
  365. {
  366. unsigned numBillboards = billboards_.Size();
  367. if (vertexBuffer_->GetVertexCount() != numBillboards * 4)
  368. vertexBuffer_->SetSize(numBillboards * 4, MASK_POSITION | MASK_COLOR | MASK_TEXCOORD1 | MASK_TEXCOORD2, true);
  369. if (indexBuffer_->GetIndexCount() != numBillboards * 6)
  370. indexBuffer_->SetSize(numBillboards * 6, false);
  371. bufferSizeDirty_ = false;
  372. bufferDirty_ = true;
  373. forceUpdate_ = true;
  374. if (!numBillboards)
  375. return;
  376. // Indices do not change for a given billboard capacity
  377. unsigned short* dest = (unsigned short*)indexBuffer_->Lock(0, numBillboards * 6, true);
  378. if (!dest)
  379. return;
  380. unsigned vertexIndex = 0;
  381. while (numBillboards--)
  382. {
  383. dest[0] = (unsigned short)vertexIndex;
  384. dest[1] = (unsigned short)(vertexIndex + 1);
  385. dest[2] = (unsigned short)(vertexIndex + 2);
  386. dest[3] = (unsigned short)(vertexIndex + 2);
  387. dest[4] = (unsigned short)(vertexIndex + 3);
  388. dest[5] = (unsigned short)vertexIndex;
  389. dest += 6;
  390. vertexIndex += 4;
  391. }
  392. indexBuffer_->Unlock();
  393. indexBuffer_->ClearDataLost();
  394. }
  395. void BillboardSet::UpdateVertexBuffer(const FrameInfo& frame)
  396. {
  397. // If using animation LOD, accumulate time and see if it is time to update
  398. if (animationLodBias_ > 0.0f && lodDistance_ > 0.0f)
  399. {
  400. animationLodTimer_ += animationLodBias_ * frame.timeStep_ * ANIMATION_LOD_BASESCALE;
  401. if (animationLodTimer_ >= lodDistance_)
  402. animationLodTimer_ = fmodf(animationLodTimer_, lodDistance_);
  403. else
  404. {
  405. // No LOD if immediate update forced
  406. if (!forceUpdate_)
  407. return;
  408. }
  409. }
  410. unsigned numBillboards = billboards_.Size();
  411. unsigned enabledBillboards = 0;
  412. const Matrix3x4& worldTransform = node_->GetWorldTransform();
  413. Matrix3x4 billboardTransform = relative_ ? worldTransform : Matrix3x4::IDENTITY;
  414. Vector3 billboardScale = scaled_ ? worldTransform.Scale() : Vector3::ONE;
  415. // First check number of enabled billboards
  416. for (unsigned i = 0; i < numBillboards; ++i)
  417. {
  418. if (billboards_[i]->enabled_)
  419. ++enabledBillboards;
  420. }
  421. sortedBillboards_.Resize(enabledBillboards);
  422. unsigned index = 0;
  423. // Then set initial sort order and distances
  424. for (unsigned i = 0; i < numBillboards; ++i)
  425. {
  426. SharedPtr<Billboard> billboard = billboards_[i];
  427. if (billboard->enabled_)
  428. {
  429. sortedBillboards_[index++] = billboard;
  430. if (sorted_)
  431. billboard->sortDistance_ = frame.camera_->GetDistanceSquared(billboardTransform * billboards_[i]->position_);
  432. }
  433. }
  434. batches_[0].geometry_->SetDrawRange(TRIANGLE_LIST, 0, enabledBillboards * 6, false);
  435. bufferDirty_ = false;
  436. forceUpdate_ = false;
  437. if (!enabledBillboards)
  438. return;
  439. if (sorted_)
  440. {
  441. Sort(sortedBillboards_.Begin(), sortedBillboards_.End(), CompareBillboards);
  442. Vector3 worldPos = node_->GetWorldPosition();
  443. // Store the "last sorted position" now
  444. previousOffset_ = (worldPos - frame.camera_->GetNode()->GetWorldPosition());
  445. }
  446. float* dest = (float*)vertexBuffer_->Lock(0, enabledBillboards * 4, true);
  447. if (!dest)
  448. return;
  449. for (unsigned i = 0; i < enabledBillboards; ++i)
  450. {
  451. Billboard& billboard = *sortedBillboards_[i];
  452. Vector2 size(billboard.size_.x_ * billboardScale.x_, billboard.size_.y_ * billboardScale.y_);
  453. unsigned color = billboard.color_.ToUInt();
  454. float rotationMatrix[2][2];
  455. rotationMatrix[0][0] = Cos(billboard.rotation_);
  456. rotationMatrix[0][1] = Sin(billboard.rotation_);
  457. rotationMatrix[1][0] = -rotationMatrix[0][1];
  458. rotationMatrix[1][1] = rotationMatrix[0][0];
  459. dest[0] = billboard.position_.x_;
  460. dest[1] = billboard.position_.y_;
  461. dest[2] = billboard.position_.z_;
  462. ((unsigned&)dest[3]) = color;
  463. dest[4] = billboard.uv_.min_.x_;
  464. dest[5] = billboard.uv_.min_.y_;
  465. dest[6] = -size.x_ * rotationMatrix[0][0] + size.y_ * rotationMatrix[0][1];
  466. dest[7] = -size.x_ * rotationMatrix[1][0] + size.y_ * rotationMatrix[1][1];
  467. dest[8] = billboard.position_.x_;
  468. dest[9] = billboard.position_.y_;
  469. dest[10] = billboard.position_.z_;
  470. ((unsigned&)dest[11]) = color;
  471. dest[12] = billboard.uv_.max_.x_;
  472. dest[13] = billboard.uv_.min_.y_;
  473. dest[14] = size.x_ * rotationMatrix[0][0] + size.y_ * rotationMatrix[0][1];
  474. dest[15] = size.x_ * rotationMatrix[1][0] + size.y_ * rotationMatrix[1][1];
  475. dest[16] = billboard.position_.x_;
  476. dest[17] = billboard.position_.y_;
  477. dest[18] = billboard.position_.z_;
  478. ((unsigned&)dest[19]) = color;
  479. dest[20] = billboard.uv_.max_.x_;
  480. dest[21] = billboard.uv_.max_.y_;
  481. dest[22] = size.x_ * rotationMatrix[0][0] - size.y_ * rotationMatrix[0][1];
  482. dest[23] = size.x_ * rotationMatrix[1][0] - size.y_ * rotationMatrix[1][1];
  483. dest[24] = billboard.position_.x_;
  484. dest[25] = billboard.position_.y_;
  485. dest[26] = billboard.position_.z_;
  486. ((unsigned&)dest[27]) = color;
  487. dest[28] = billboard.uv_.min_.x_;
  488. dest[29] = billboard.uv_.max_.y_;
  489. dest[30] = -size.x_ * rotationMatrix[0][0] - size.y_ * rotationMatrix[0][1];
  490. dest[31] = -size.x_ * rotationMatrix[1][0] - size.y_ * rotationMatrix[1][1];
  491. dest += 32;
  492. }
  493. vertexBuffer_->Unlock();
  494. vertexBuffer_->ClearDataLost();
  495. }
  496. void BillboardSet::MarkPositionsDirty()
  497. {
  498. Drawable::OnMarkedDirty(node_);
  499. bufferDirty_ = true;
  500. }
  501. }