Forráskód Böngészése

Tabs to spaces. Change NavArea Bounds to BoundingBox to match Urho convention elsewhere. Added NavArea component Lua binding.

Lasse Öörni 10 éve
szülő
commit
42c352f2ba

+ 29 - 29
Source/Samples/39_CrowdNavigation/CrowdNavigation.cpp

@@ -91,7 +91,7 @@ void CrowdNavigation::CreateScene()
     // Also create a DebugRenderer component so that we can draw debug geometry
     scene_->CreateComponent<Octree>();
     scene_->CreateComponent<DebugRenderer>();
-	scene_->CreateComponent<PhysicsWorld>();
+    scene_->CreateComponent<PhysicsWorld>();
     
     // Create scene node & StaticModel component for showing a static plane
     Node* planeNode = scene_->CreateChild("Plane");
@@ -137,7 +137,7 @@ void CrowdNavigation::CreateScene()
 
     // Create a DynamicNavigationMesh component to the scene root
     DynamicNavigationMesh* navMesh = scene_->CreateComponent<DynamicNavigationMesh>();
-	navMesh->SetTileSize(64);
+    navMesh->SetTileSize(64);
     // Create a Navigable component to the scene root. This tags all of the geometry in the scene as being part of the
     // navigation mesh. By default this is recursive, but the recursion could be turned off from Navigable
     scene_->CreateComponent<Navigable>();
@@ -282,8 +282,8 @@ void CrowdNavigation::MoveCamera(float timeStep)
         
         // Redetermine which nodes are "jacks" and "mushrooms"
         jackNodes_.Clear();
-		PODVector<Node*> nodes;
-		scene_->GetChildrenWithComponent<CrowdAgent>(nodes, true);
+        PODVector<Node*> nodes;
+        scene_->GetChildrenWithComponent<CrowdAgent>(nodes, true);
         for (unsigned i = 0; i < nodes.Size(); ++i)
         {
             jackNodes_.Push(SharedPtr<Node>(nodes[i]));
@@ -319,21 +319,21 @@ void CrowdNavigation::SetPathPoint()
         else
         {
             // Set crowd agents to move to the target
-			for (unsigned i = 0; i < jackNodes_.Size(); ++i)
-			{
-				CrowdAgent* agent = jackNodes_[i]->GetComponent<CrowdAgent>();
-				// The first agent will always move to the exact position, all other agents will select a random point nearby
-				if (i == 0)
-				{
-					agent->SetMoveTarget(pathPos);
-				}
-				else
-				{
-					// Keep the random point somewhere on the navigation mesh
-					Vector3 targetPos = navMesh->FindNearestPoint(pathPos + Vector3(Random(7.0f), 0.0f, Random(7.0f)), Vector3(1.0f, 1.0f, 1.0f));
-					agent->SetMoveTarget(targetPos);
-				}
-            }            
+            for (unsigned i = 0; i < jackNodes_.Size(); ++i)
+            {
+                CrowdAgent* agent = jackNodes_[i]->GetComponent<CrowdAgent>();
+                // The first agent will always move to the exact position, all other agents will select a random point nearby
+                if (i == 0)
+                {
+                    agent->SetMoveTarget(pathPos);
+                }
+                else
+                {
+                    // Keep the random point somewhere on the navigation mesh
+                    Vector3 targetPos = navMesh->FindNearestPoint(pathPos + Vector3(Random(7.0f), 0.0f, Random(7.0f)), Vector3(1.0f, 1.0f, 1.0f));
+                    agent->SetMoveTarget(targetPos);
+                }
+            }
         }
     }
 }
@@ -361,15 +361,15 @@ void CrowdNavigation::AddOrRemoveObject()
 
 void CrowdNavigation::CreateJack(const Vector3& pos)
 {
-	ResourceCache* cache = GetSubsystem<ResourceCache>();
-	SharedPtr<Node> jackNode(scene_->CreateChild("Jack"));
+    ResourceCache* cache = GetSubsystem<ResourceCache>();
+    SharedPtr<Node> jackNode(scene_->CreateChild("Jack"));
     jackNode->SetPosition(pos);
     AnimatedModel* modelObject = jackNode->CreateComponent<AnimatedModel>();
     modelObject->SetModel(cache->GetResource<Model>("Models/Jack.mdl"));
     modelObject->SetMaterial(cache->GetResource<Material>("Materials/Jack.xml"));
     modelObject->SetCastShadows(true);
 
-	// Create the CrowdAgent
+    // Create the CrowdAgent
     CrowdAgent* agent = jackNode->CreateComponent<CrowdAgent>();
     jackNodes_.Push(jackNode);
 }
@@ -386,7 +386,7 @@ Node* CrowdNavigation::CreateMushroom(const Vector3& pos)
     mushroomObject->SetModel(cache->GetResource<Model>("Models/Mushroom.mdl"));
     mushroomObject->SetMaterial(cache->GetResource<Material>("Materials/Mushroom.xml"));
     mushroomObject->SetCastShadows(true);
-	// Create the navigation obstacle
+    // Create the navigation obstacle
     Obstacle* obstacle = mushroomNode->CreateComponent<Obstacle>();
     obstacle->SetRadius(2.0f);
     mushroomNodes_.Push(mushroomNode);
@@ -432,12 +432,12 @@ void CrowdNavigation::HandleUpdate(StringHash eventType, VariantMap& eventData)
     // Move the camera, scale movement with time step
     MoveCamera(timeStep);
 
-	for (unsigned i = 0; i < jackNodes_.Size(); ++i)
-	{
-		CrowdAgent* agent = jackNodes_[i]->GetComponent<CrowdAgent>();
-		Vector3 vel = agent->GetActualVelocity();
-		jackNodes_[i]->SetWorldDirection(vel);
-	}
+    for (unsigned i = 0; i < jackNodes_.Size(); ++i)
+    {
+        CrowdAgent* agent = jackNodes_[i]->GetComponent<CrowdAgent>();
+        Vector3 vel = agent->GetActualVelocity();
+        jackNodes_[i]->SetWorldDirection(vel);
+    }
 }
 
 void CrowdNavigation::HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData)

+ 15 - 15
Source/Urho3D/Graphics/DebugRenderer.cpp

@@ -243,21 +243,21 @@ void DebugRenderer::AddSphere(const Sphere& sphere, const Color& color, bool dep
 
 void DebugRenderer::AddCylinder(const Vector3& position, float radius, float height, const Color& color, bool depthTest)
 {
-	Sphere sphere(position, radius);
-	Vector3 heightVec(0, height, 0);
-	Vector3 offsetXVec(radius, 0, 0);
-	Vector3 offsetZVec(0, 0, radius);
-	for (unsigned i = 0; i < 360; i += 45)
-	{
-		Vector3 p1 = PointOnSphere(sphere, i, 90);
-		Vector3 p2 = PointOnSphere(sphere, i + 45, 90);
-		AddLine(p1, p2, color, depthTest);
-		AddLine(p1 + heightVec, p2 + heightVec, color, depthTest);
-	}
-	AddLine(position + offsetXVec, position + heightVec + offsetXVec, color, depthTest);
-	AddLine(position - offsetXVec, position + heightVec - offsetXVec, color, depthTest);
-	AddLine(position + offsetZVec, position + heightVec + offsetZVec, color, depthTest);
-	AddLine(position - offsetZVec, position + heightVec - offsetZVec, color, depthTest);
+    Sphere sphere(position, radius);
+    Vector3 heightVec(0, height, 0);
+    Vector3 offsetXVec(radius, 0, 0);
+    Vector3 offsetZVec(0, 0, radius);
+    for (unsigned i = 0; i < 360; i += 45)
+    {
+        Vector3 p1 = PointOnSphere(sphere, i, 90);
+        Vector3 p2 = PointOnSphere(sphere, i + 45, 90);
+        AddLine(p1, p2, color, depthTest);
+        AddLine(p1 + heightVec, p2 + heightVec, color, depthTest);
+    }
+    AddLine(position + offsetXVec, position + heightVec + offsetXVec, color, depthTest);
+    AddLine(position - offsetXVec, position + heightVec - offsetXVec, color, depthTest);
+    AddLine(position + offsetZVec, position + heightVec + offsetZVec, color, depthTest);
+    AddLine(position - offsetZVec, position + heightVec - offsetZVec, color, depthTest);
 }
 
 void DebugRenderer::AddSkeleton(const Skeleton& skeleton, const Color& color, bool depthTest)

+ 2 - 2
Source/Urho3D/Graphics/DebugRenderer.h

@@ -126,8 +126,8 @@ public:
     void AddPolyhedron(const Polyhedron& poly, const Color& color, bool depthTest = true);
     /// Add a sphere.
     void AddSphere(const Sphere& sphere, const Color& color, bool depthTest = true);
-	/// Add a cylinder
-	void AddCylinder(const Vector3& position, float radius, float height, const Color& color, bool depthTest = true);
+    /// Add a cylinder
+    void AddCylinder(const Vector3& position, float radius, float height, const Color& color, bool depthTest = true);
     /// Add a skeleton.
     void AddSkeleton(const Skeleton& skeleton, const Color& color, bool depthTest = true);
     /// Add a triangle mesh.

+ 14 - 0
Source/Urho3D/LuaScript/pkgs/Navigation/NavArea.pkg

@@ -0,0 +1,14 @@
+$#include "Navigation/NavArea.h"
+
+class NavArea : public Component
+{
+    unsigned GetAreaType() const;
+    void SetAreaType(unsigned);
+    BoundingBox GetBoundingBox();
+    void SetBoundingBox(const BoundingBox& bnds);
+    BoundingBox GetWorldBoundingBox() const;
+    
+    tolua_property__get_set unsigned areaType;
+    tolua_property__get_set BoundingBox boundingBox;
+    tolua_readonly tolua_property__get_set BoundingBox worldBoundingBox;
+};

+ 1 - 1
Source/Urho3D/Navigation/CrowdAgent.cpp

@@ -109,7 +109,7 @@ void CrowdAgent::OnNodeSet(Node* node)
         if (scene)
         {
             if (scene == node)
-                LOGERROR(GetTypeName() + " should not be created to the root scene node");		
+                LOGERROR(GetTypeName() + " should not be created to the root scene node");        
             crowdManager_ = scene->GetOrCreateComponent<DetourCrowdManager>();
             AddAgentToCrowd();
         }

+ 4 - 4
Source/Urho3D/Navigation/CrowdAgent.h

@@ -42,9 +42,9 @@ enum CrowdTargetState
 
 enum CrowdAgentState
 {
-    CROWD_AGENT_INVALID = 0,	///< The agent is not in a valid state.
-    CROWD_AGENT_READY,			///< The agent is traversing a normal navigation mesh polygon
-    CROWD_AGENT_TRAVERSINGLINK	///< The agent is traversing an off-mesh connection.
+    CROWD_AGENT_INVALID = 0,    ///< The agent is not in a valid state.
+    CROWD_AGENT_READY,            ///< The agent is traversing a normal navigation mesh polygon
+    CROWD_AGENT_TRAVERSINGLINK    ///< The agent is traversing an off-mesh connection.
 };
 
 /// DetourCrowd Agent, requires a DetourCrowdManager in the scene
@@ -111,7 +111,7 @@ public:
     /// Gets the agent's max velocity.
     float GetMaxSpeed() const { return maxSpeed_; }
     /// Gets the agent's max acceleration.
-    float GetMaxAccel()	const { return maxAccel_; }
+    float GetMaxAccel()    const { return maxAccel_; }
     /// Gets the agent's radius
     float GetRadius() const { return radius_; }
     /// Gets the agent's height

+ 1 - 1
Source/Urho3D/Navigation/DetourCrowdManager.cpp

@@ -445,7 +445,7 @@ void DetourCrowdManager::Update(float delta)
             dtCrowdAgent* agent = agentBuffer_[i];
             if (agent)
             {
-                CrowdAgent* crowdAgent = static_cast<CrowdAgent*>(agent->params.userData);	
+                CrowdAgent* crowdAgent = static_cast<CrowdAgent*>(agent->params.userData);    
                 if (crowdAgent)
                     crowdAgent->OnCrowdAgentReposition(Vector3(agent->npos), Vector3(agent->vel));
             }

+ 1 - 1
Source/Urho3D/Navigation/DetourCrowdManager.h

@@ -128,7 +128,7 @@ private:
     /// NavigationMesh for which the crowd was created
     WeakPtr<NavigationMesh> navigationMesh_;
     /// max agents for the crowd 
-    unsigned maxAgents_;	
+    unsigned maxAgents_;    
     /// internal debug information 
     dtCrowdAgentDebugInfo* agentDebug_;
     /// Container for fetching agents from DetourCrowd during update

+ 1 - 1
Source/Urho3D/Navigation/NavArea.cpp

@@ -66,7 +66,7 @@ namespace Urho3D
         MarkNetworkUpdate();
     }
 
-    BoundingBox NavArea::GetTransformedBounds() const
+    BoundingBox NavArea::GetWorldBoundingBox() const
     {
         Matrix3x4 mat;
         mat.SetTranslation(node_->GetWorldPosition());

+ 3 - 3
Source/Urho3D/Navigation/NavArea.h

@@ -48,12 +48,12 @@ namespace Urho3D
         void SetAreaType(unsigned);
 
         /// Gets the bounding box of this navigation area, in local space
-        BoundingBox GetBounds() const { return boundingBox_; }
+        BoundingBox GetBoundingBox() const { return boundingBox_; }
         /// Sets the bounding box of this area, in local space
-        void SetBounds(const BoundingBox& bnds) { boundingBox_ = bnds; }
+        void SetBoundingBox(const BoundingBox& bnds) { boundingBox_ = bnds; }
 
         /// Gets the bounds of this navigation area in world space
-        BoundingBox GetTransformedBounds() const;
+        BoundingBox GetWorldBoundingBox() const;
 
     private:
         /// Bounds of area to mark

+ 3 - 3
Source/Urho3D/Navigation/NavigationMesh.cpp

@@ -97,7 +97,7 @@ struct FindPathData
     Vector3 pathPoints_[MAX_POLYS];
     // Flags on the path.
     unsigned char pathFlags_[MAX_POLYS];
-    //	Arera Ids on the path
+    //    Arera Ids on the path
     unsigned char pathAreras_[MAX_POLYS];
 };
 
@@ -783,7 +783,7 @@ void NavigationMesh::CollectGeometries(Vector<NavigationGeometryInfo>& geometryL
         {
             NavigationGeometryInfo info;
             info.component_ = area;
-            info.boundingBox_ = area->GetTransformedBounds();
+            info.boundingBox_ = area->GetWorldBoundingBox();
             geometryList.Push(info);
         }
     }
@@ -894,7 +894,7 @@ void NavigationMesh::GetTileGeometry(NavBuildData* build, Vector<NavigationGeome
                 NavAreaStub stub;
                 //\todo is there an alternative to casting down? Attributes restricts area ID/type to being an unsigned int
                 stub.areaID_ = (unsigned char)area->GetAreaType();
-                stub.bounds_ = area->GetTransformedBounds();
+                stub.bounds_ = area->GetWorldBoundingBox();
                 build->navAreas_.Push(stub);
                 continue;
             }

+ 1 - 1
Source/Urho3D/Navigation/NavigationMesh.h

@@ -138,7 +138,7 @@ public:
     /// Sets the cost of an area
     void SetAreaTypeCost(unsigned areaType, float cost);
 
-    ///	Return the given name of this navigation mesh
+    ///    Return the given name of this navigation mesh
     String GetMeshName() const { return meshName_; }
     /// Set the name of this navigation mesh
     void SetMeshName(const String& newName);

+ 2 - 2
Source/Urho3D/Script/APITemplates.h

@@ -617,9 +617,9 @@ template <class T> void RegisterNode(asIScriptEngine* engine, const char* classN
 {
     RegisterAnimatable<T>(engine, className);
     RegisterSubclass<Node, T>(engine, "Node", className);
-	engine->RegisterObjectMethod(className, "void SetPosition2D(float, float)", asMETHODPR(T, SetPosition2D, (float, float), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod(className, "void SetPosition2D(float, float)", asMETHODPR(T, SetPosition2D, (float, float), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void SetScale(float)", asMETHODPR(T, SetScale, (float), void), asCALL_THISCALL);
-	engine->RegisterObjectMethod(className, "void SetScale2D(float, float)", asMETHODPR(T, SetScale2D, (float, float), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod(className, "void SetScale2D(float, float)", asMETHODPR(T, SetScale2D, (float, float), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void SetTransform(const Vector3&in, const Quaternion&in)", asMETHODPR(T, SetTransform, (const Vector3&, const Quaternion&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void SetTransform(const Vector3&in, const Quaternion&in, const Vector3&in)", asMETHODPR(T, SetTransform, (const Vector3&, const Quaternion&, const Vector3&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void SetTransform(const Vector3&in, const Quaternion&in, float)", asMETHODPR(T, SetTransform, (const Vector3&, const Quaternion&, float), void), asCALL_THISCALL);

+ 7 - 7
Source/Urho3D/Script/NavigationAPI.cpp

@@ -147,12 +147,12 @@ void RegisterObstacle(asIScriptEngine* engine)
 
 void RegisterNavArea(asIScriptEngine* engine)
 {
-    RegisterComponent<NavArea>(engine, "NavArea");
-    engine->RegisterObjectMethod("NavArea", "BoundingBox get_bounds() const", asMETHOD(NavArea, GetBounds), asCALL_THISCALL);
-    engine->RegisterObjectMethod("NavArea", "void set_bounds(const BoundingBox&in)", asMETHOD(NavArea, SetBounds), asCALL_THISCALL);
+    RegisterComponent<NavArea>(engine, "NavArea");
+    engine->RegisterObjectMethod("NavArea", "BoundingBox get_boundingBox() const", asMETHOD(NavArea, GetBoundingBox), asCALL_THISCALL);
+    engine->RegisterObjectMethod("NavArea", "void set_boundingBox(const BoundingBox&in)", asMETHOD(NavArea, SetBoundingBox), asCALL_THISCALL);
     engine->RegisterObjectMethod("NavArea", "uint get_areaType() const", asMETHOD(NavArea, GetAreaType), asCALL_THISCALL);
     engine->RegisterObjectMethod("NavArea", "void set_areaType(uint)", asMETHOD(NavArea, SetAreaType), asCALL_THISCALL);
-    engine->RegisterObjectMethod("NavArea", "BoundingBox get_transformedBounds() const", asMETHOD(NavArea, GetTransformedBounds), asCALL_THISCALL);
+    engine->RegisterObjectMethod("NavArea", "BoundingBox get_worldBoundingBox() const", asMETHOD(NavArea, GetWorldBoundingBox), asCALL_THISCALL);
 }
 
 void RegisterDetourCrowdManager(asIScriptEngine* engine)
@@ -194,7 +194,7 @@ void RegisterCrowdAgent(asIScriptEngine* engine)
     engine->RegisterEnumValue("NavigationPushiness", "PUSHINESS_LOW", PUSHINESS_LOW);
     engine->RegisterEnumValue("NavigationPushiness", "PUSHINESS_MEDIUM", PUSHINESS_MEDIUM);
     engine->RegisterEnumValue("NavigationPushiness", "PUSHINESS_HIGH", PUSHINESS_HIGH);
-
+
     RegisterComponent<CrowdAgent>(engine, "CrowdAgent");
     engine->RegisterObjectMethod("CrowdAgent", "void DrawDebugGeometry(bool)", asMETHODPR(CrowdAgent, DrawDebugGeometry, (bool), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("CrowdAgent", "uint get_navigationFilterType()", asMETHOD(CrowdAgent, GetNavigationFilterType), asCALL_THISCALL);
@@ -213,14 +213,14 @@ void RegisterCrowdAgent(asIScriptEngine* engine)
     engine->RegisterObjectMethod("CrowdAgent", "NavigationPushiness get_navigationPushiness()", asMETHOD(CrowdAgent, GetNavigationPushiness), asCALL_THISCALL);
     engine->RegisterObjectMethod("CrowdAgent", "Vector3 get_desiredVelocity() const", asMETHOD(CrowdAgent, GetDesiredVelocity), asCALL_THISCALL);
     engine->RegisterObjectMethod("CrowdAgent", "Vector3 get_actualVelocity() const", asMETHOD(CrowdAgent, GetActualVelocity), asCALL_THISCALL);
-    engine->RegisterObjectMethod("CrowdAgent", "Vector3 get_targetPosition() const", asMETHOD(CrowdAgent, GetTargetPosition), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CrowdAgent", "Vector3 get_targetPosition() const", asMETHOD(CrowdAgent, GetTargetPosition), asCALL_THISCALL);
     engine->RegisterObjectMethod("CrowdAgent", "CrowdAgentState get_agentState() const", asMETHOD(CrowdAgent, GetAgentState), asCALL_THISCALL);
     engine->RegisterObjectMethod("CrowdAgent", "CrowdTargetState get_targetState() const", asMETHOD(CrowdAgent, GetTargetState), asCALL_THISCALL);
     engine->RegisterObjectMethod("CrowdAgent", "Vector3 get_position() const", asMETHOD(CrowdAgent, GetPosition), asCALL_THISCALL);
     engine->RegisterObjectMethod("CrowdAgent", "void set_radius(float)", asMETHOD(CrowdAgent, SetRadius), asCALL_THISCALL);
     engine->RegisterObjectMethod("CrowdAgent", "float get_radius()", asMETHOD(CrowdAgent, GetRadius), asCALL_THISCALL);
     engine->RegisterObjectMethod("CrowdAgent", "void set_height(float)", asMETHOD(CrowdAgent, SetHeight), asCALL_THISCALL);
-    engine->RegisterObjectMethod("CrowdAgent", "float get_height()", asMETHOD(CrowdAgent, GetHeight), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CrowdAgent", "float get_height()", asMETHOD(CrowdAgent, GetHeight), asCALL_THISCALL);
 }
 
 void RegisterNavigationAPI(asIScriptEngine* engine)