فهرست منبع

More minor code, comment and tab-to-spaces changes. Use the more specific TrailPoint struct name instead of Point, and export it in case a derived class wants to manipulate them. Add RibbonTrail to documentation's drawable class list.

Lasse Öörni 9 سال پیش
والد
کامیت
6d046d57c8
3فایلهای تغییر یافته به همراه26 افزوده شده و 28 حذف شده
  1. 1 0
      Docs/Reference.dox
  2. 13 13
      Source/Urho3D/Graphics/RibbonTrail.cpp
  3. 12 15
      Source/Urho3D/Graphics/RibbonTrail.h

+ 1 - 0
Docs/Reference.dox

@@ -961,6 +961,7 @@ The rendering-related components defined by the %Graphics and %UI libraries are:
 - AnimationController: drives animations forward automatically and controls animation fade-in/out.
 - BillboardSet: a group of camera-facing billboards, which can have varying sizes, rotations and texture coordinates.
 - ParticleEmitter: a subclass of BillboardSet that emits particle billboards.
+- RibbonTrail: creates tail geometry following an object.
 - Light: illuminates the scene. Can optionally cast shadows.
 - Terrain: renders heightmap terrain.
 - CustomGeometry: renders runtime-defined unindexed geometry. The geometry data is not serialized or replicated over the network.

+ 13 - 13
Source/Urho3D/Graphics/RibbonTrail.cpp

@@ -49,7 +49,7 @@ const char* trailTypeNames[] =
     0
 };
 
-inline bool CompareTails(Point* lhs, Point* rhs)
+inline bool CompareTails(TrailPoint* lhs, TrailPoint* rhs)
 {
     return lhs->sortDistance_ > rhs->sortDistance_;
 }
@@ -102,7 +102,7 @@ void RibbonTrail::RegisterObject(Context* context)
 
     URHO3D_ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, true, AM_DEFAULT);
     URHO3D_COPY_BASE_ATTRIBUTES(Drawable);
-	URHO3D_MIXED_ACCESSOR_ATTRIBUTE("Material", GetMaterialAttr, SetMaterialAttr, ResourceRef, ResourceRef(Material::GetTypeStatic()), AM_DEFAULT);
+    URHO3D_MIXED_ACCESSOR_ATTRIBUTE("Material", GetMaterialAttr, SetMaterialAttr, ResourceRef, ResourceRef(Material::GetTypeStatic()), AM_DEFAULT);
     URHO3D_ACCESSOR_ATTRIBUTE("Emittting", IsEmitting, SetEmitting, bool, true, AM_DEFAULT);
     URHO3D_ENUM_ACCESSOR_ATTRIBUTE("Trail Type", GetTrailType, SetTrailType, TrailType, trailTypeNames, TT_FACE_CAMERA, AM_DEFAULT);
     URHO3D_ACCESSOR_ATTRIBUTE("Tail Lifetime", GetLifetime, SetLifetime, float, 1.0f, AM_DEFAULT);
@@ -259,12 +259,12 @@ void RibbonTrail::UpdateTail()
     {
         Vector3 forwardmotion = (previousPosition_ - worldPosition).Normalized();
 
-        Point startPoint;
+        TrailPoint startPoint;
         startPoint.position_ = previousPosition_;
         startPoint.lifetime_ = 0.0f;
         startPoint.forward_ = forwardmotion;
 
-        Point nextPoint;
+        TrailPoint nextPoint;
         nextPoint.position_ = worldPosition;
         nextPoint.lifetime_ = 0.0f;
         nextPoint.forward_ = forwardmotion;
@@ -291,7 +291,7 @@ void RibbonTrail::UpdateTail()
         // Add more points if path exceeded tail length
         if (path > vertexDistance_)
         {
-            Point newPoint;
+            TrailPoint newPoint;
             newPoint.position_ = worldPosition;
             newPoint.lifetime_ = 0.0f;
             newPoint.forward_ = forwardmotion;
@@ -399,7 +399,7 @@ void RibbonTrail::UpdateGeometry(const FrameInfo& frame)
 }
 
 UpdateGeometryType RibbonTrail::GetUpdateGeometryType()
-{	
+{
     if (bufferDirty_ || bufferSizeDirty_ || vertexBuffer_->IsDataLost() || indexBuffer_->IsDataLost())
         return UPDATE_MAIN_THREAD;
     else
@@ -546,7 +546,7 @@ void RibbonTrail::UpdateVertexBuffer(const FrameInfo& frame)
     sortedPoints_.Resize(numPoints_);
     for (unsigned i = 0; i < numPoints_; ++i)
     {
-        Point& point = points_[i];
+        TrailPoint& point = points_[i];
         sortedPoints_[i] = &point;
         if (sorted_)
             point.sortDistance_ = frame.camera_->GetDistanceSquared(point.position_);
@@ -580,7 +580,7 @@ void RibbonTrail::UpdateVertexBuffer(const FrameInfo& frame)
     {
         for (unsigned i = 0; i < numPoints_; ++i)
         {
-            Point& point = *sortedPoints_[i];
+            TrailPoint& point = *sortedPoints_[i];
 
             if (sortedPoints_[i] == &points_.Back()) continue;
 
@@ -682,7 +682,7 @@ void RibbonTrail::UpdateVertexBuffer(const FrameInfo& frame)
     {
         for (unsigned i = 0; i < numPoints_; ++i)
         {
-            Point& point = *sortedPoints_[i];
+            TrailPoint& point = *sortedPoints_[i];
 
             if (sortedPoints_[i] == &points_.Back()) continue;
 
@@ -819,15 +819,15 @@ void RibbonTrail::SetVertexDistance(float length)
     Commit();
 }
 
-void RibbonTrail::SetEndColor(const Color& c)
+void RibbonTrail::SetEndColor(const Color& color)
 {
-    endColor_ = Color(c.r_, c.g_, c.b_, c.a_);
+    endColor_ = color;
     Commit();
 }
 
-void RibbonTrail::SetStartColor(const Color& c)
+void RibbonTrail::SetStartColor(const Color& color)
 {
-    startColor_ = Color(c.r_, c.g_, c.b_, c.a_);
+    startColor_ = color;
     Commit();
 }
 

+ 12 - 15
Source/Urho3D/Graphics/RibbonTrail.h

@@ -37,8 +37,7 @@ class IndexBuffer;
 class VertexBuffer;
 
 /// Trail is consisting of series of tails. Two connected points make a tail.
-//struct URHO3D_API Point
-struct Point
+struct URHO3D_API TrailPoint
 {
     /// Position.
     Vector3 position_;
@@ -49,19 +48,17 @@ struct Point
     /// Elapsed length inside the trail.
     float elapsedLength_;
     /// Next point to make a tail.
-    Point* next_;
+    TrailPoint* next_;
     /// Tail time to live.
     float lifetime_;
     /// Distance for sorting.
     float sortDistance_;
 };
 
-//static const unsigned MAX_TAILS = 65536 / 6;
-
-/// Custom component that creates a tail
+/// Drawable component that creates a tail.
 class URHO3D_API RibbonTrail : public Drawable
 {
-	URHO3D_OBJECT(RibbonTrail, Drawable);
+    URHO3D_OBJECT(RibbonTrail, Drawable);
 
 public:
     /// Construct.
@@ -92,9 +89,9 @@ public:
     /// Set width of the tail. Only works for face camera trail type.
     void SetWidth(float width);
     /// Set vertex blended color for start of trail.
-    void SetStartColor(const Color& c);
+    void SetStartColor(const Color& color);
     /// Set vertex blended scale for end of trail.
-    void SetEndColor(const Color& c);
+    void SetEndColor(const Color& color);
     /// Set vertex blended color for start of trail.
     void SetStartScale(float startScale);
     /// Set vertex blended scale for end of trail.
@@ -164,7 +161,7 @@ protected:
     /// Mark vertex buffer to need an update.
     void MarkPositionsDirty();
     /// Tails.
-    PODVector<Point> points_;
+    PODVector<TrailPoint> points_;
     /// Tails sorted flag.
     bool sorted_;
     /// Animation LOD bias.
@@ -182,8 +179,8 @@ private:
     void UpdateBufferSize();
     /// Rewrite RibbonTrail vertex buffer.
     void UpdateVertexBuffer(const FrameInfo& frame);
-	/// Update/Rebuild tail mesh only if position changed (called by UpdateBatches())
-	void UpdateTail();
+    /// Update/Rebuild tail mesh only if position changed (called by UpdateBatches())
+    void UpdateTail();
     /// Geometry.
     SharedPtr<Geometry> geometry_;
     /// Vertex buffer.
@@ -226,15 +223,15 @@ private:
     unsigned sortFrameNumber_;
     /// Previous offset to camera for determining whether sorting is necessary.
     Vector3 previousOffset_;
-    /// Billboard pointers for sorting.
-    Vector<Point*> sortedPoints_;
+    /// Trail pointers for sorting.
+    Vector<TrailPoint*> sortedPoints_;
     /// Force update flag (ignore animation LOD momentarily.)
     bool forceUpdate_;
     /// Currently emitting flag.
     bool emitting_;
 
     /// End of trail point for smoother tail dissapearance.
-    Point endTail_;
+    TrailPoint endTail_;
     /// The time the tail become end of trail.
     float startEndTailTime_;
 };