Browse Source

Cleanup and adding physics debugger

Panagiotis Christopoulos Charitos 11 years ago
parent
commit
9000e3bef5

+ 1 - 8
include/anki/Config.h.cmake

@@ -117,13 +117,6 @@
 
 #define ANKI_RENDERER_USE_MATERIAL_UBOS 0
 
-// Scene config
-#define ANKI_SCENE_OPTIMAL_SCENE_NODES_COUNT 1024
-
-#define ANKI_SCENE_ALLOCATOR_SIZE (1024 * 1024) 
-
-#define ANKI_SCENE_FRAME_ALLOCATOR_SIZE (1024 * 512)
-
 /// @{
 /// Used to optimize the initial vectors of VisibilityTestResults
 #define ANKI_FRUSTUMABLE_AVERAGE_VISIBLE_RENDERABLES_COUNT 16
@@ -137,7 +130,7 @@
 #define ANKI_GL_MAX_MIPMAPS 32
 #define ANKI_GL_MAX_TEXTURE_LAYERS 32
 #define ANKI_GL_MAX_SUB_DRAWCALLS 64
-#define ANKI_GL_MAX_INSTANCES 32
+#define ANKI_GL_MAX_INSTANCES 64
 
 //==============================================================================
 // Other                                                                       =

+ 52 - 0
include/anki/physics/PhysicsDrawer.h

@@ -0,0 +1,52 @@
+// Copyright (C) 2014, Panagiotis Christopoulos Charitos.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#ifndef ANKI_PHYSICS_PHYSICS_DRAWER_H
+#define ANKI_PHYSICS_PHYSICS_DRAWER_H
+
+#include "anki/physics/Common.h"
+#include "anki/util/Bitset.h"
+
+// Forward
+struct NewtonBody;
+
+namespace anki {
+
+/// @addtogroup physics
+/// @{
+
+/// Physics debug drawer interface.
+class PhysicsDrawer
+{
+public:
+	/// Draw a line.
+	virtual void drawLines(
+		const Vec3* lines,
+		const U32 linesCount,
+		const Vec4& color) = 0;
+
+	void drawWorld(const PhysicsWorld& world);
+
+	void setDrawAabbs(Bool draw)
+	{
+		m_drawAabbs = draw;
+	}
+
+	Bool getDrawAabbs() const
+	{
+		return m_drawAabbs;
+	}
+
+private:
+	Bool8 m_drawAabbs = true;
+
+	void drawAabb(const NewtonBody* body);
+};
+/// @}
+
+} // end namespace anki
+
+#endif
+

+ 2 - 2
include/anki/physics/PhysicsWorld.h

@@ -46,7 +46,7 @@ public:
 
 	/// @privatesection
 	/// @{
-	NewtonWorld* _getNewtonWorld()
+	NewtonWorld* _getNewtonWorld() const
 	{
 		ANKI_ASSERT(m_world);
 		return m_world;
@@ -61,7 +61,7 @@ private:
 	List<PhysicsBody*> m_bodies;
 	Array<AtomicU32, static_cast<U>(PhysicsObject::Type::COUNT)> 
 		m_forDeletionCount = {{{0}, {0}, {0}}};
-	NewtonWorld* m_world = nullptr;
+	mutable NewtonWorld* m_world = nullptr;
 
 	template<typename T, typename TContainer, typename... TArgs>
 	T* newObjectInternal(TContainer& cont, TArgs&&... args);

+ 2 - 1
include/anki/scene/SceneGraph.h

@@ -39,7 +39,8 @@ public:
 
 	ANKI_USE_RESULT Error create(
 		AllocAlignedCallback allocCb, 
-		void* allocCbData, 
+		void* allocCbData,
+		U32 frameAllocatorSize,
 		Threadpool* threadpool, 
 		ResourceManager* resources);
 

+ 2 - 1
src/core/App.cpp

@@ -261,7 +261,8 @@ Error App::createInternal(const ConfigSet& config_,
 	m_scene = m_heapAlloc.newInstance<SceneGraph>();
 	if(!m_scene) return ErrorCode::OUT_OF_MEMORY;
 
-	err = m_scene->create(m_allocCb, m_allocCbData, m_threadpool, m_resources);
+	err = m_scene->create(m_allocCb, m_allocCbData, 
+		config.get("sceneFrameAllocatorSize"), m_threadpool, m_resources);
 	if(err) return err;
 
 	// Script

+ 1 - 0
src/core/Config.cpp

@@ -73,6 +73,7 @@ Config::Config()
 	newOption("tilesXCount", 16);
 	newOption("tilesYCount", 16);
 	newOption("tessellation", true);
+	newOption("sceneFrameAllocatorSize", 1024 * 1024);
 
 	newOption("offscreen", false);
 

+ 67 - 0
src/physics/PhysicsDrawer.cpp

@@ -0,0 +1,67 @@
+// Copyright (C) 2014, Panagiotis Christopoulos Charitos.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#include "anki/physics/PhysicsDrawer.h"
+#include "anki/physics/PhysicsWorld.h"
+
+namespace anki {
+
+//==============================================================================
+void PhysicsDrawer::drawWorld(const PhysicsWorld& world)
+{
+	NewtonWorld* nworld = world._getNewtonWorld();
+	for(NewtonBody* body = NewtonWorldGetFirstBody(nworld); 
+		body != nullptr; 
+		body = NewtonWorldGetNextBody(nworld, body)) 
+	{
+		if(m_drawAabbs)
+		{
+			drawAabb(body);
+		}
+	}
+}
+
+//==============================================================================
+void PhysicsDrawer::drawAabb(const NewtonBody* body)
+{
+	Vec4 p0; 
+	Vec4 p1; 
+	Mat4 matrix;
+
+	NewtonCollision* collision = NewtonBodyGetCollision(body);
+	NewtonBodyGetMatrix(body, &matrix[0]);
+	NewtonCollisionCalculateAABB(collision, &matrix[0], &p0[0], &p1[0]);
+
+	Vec3 lines[] = {
+		Vec3(p0.x(), p0.y(), p0.z()),
+		Vec3(p1.x(), p0.y(), p0.z()),
+		Vec3(p0.x(), p1.y(), p0.z()),
+		Vec3(p1.x(), p1.y(), p0.z()),
+		Vec3(p0.x(), p1.y(), p1.z()),
+		Vec3(p1.x(), p1.y(), p1.z()),
+		Vec3(p0.x(), p0.y(), p1.z()),
+		Vec3(p1.x(), p0.y(), p1.z()),
+		Vec3(p0.x(), p0.y(), p0.z()),
+		Vec3(p0.x(), p1.y(), p0.z()),
+		Vec3(p1.x(), p0.y(), p0.z()),
+		Vec3(p1.x(), p1.y(), p0.z()),
+		Vec3(p0.x(), p0.y(), p1.z()),
+		Vec3(p0.x(), p1.y(), p1.z()),
+		Vec3(p1.x(), p0.y(), p1.z()),
+		Vec3(p1.x(), p1.y(), p1.z()),
+		Vec3(p0.x(), p0.y(), p0.z()),
+		Vec3(p0.x(), p0.y(), p1.z()),
+		Vec3(p1.x(), p0.y(), p0.z()),
+		Vec3(p1.x(), p0.y(), p1.z()),
+		Vec3(p0.x(), p1.y(), p0.z()),
+		Vec3(p0.x(), p1.y(), p1.z()),
+		Vec3(p1.x(), p1.y(), p0.z()),
+		Vec3(p1.x(), p1.y(), p1.z())};
+
+	drawLines(lines, sizeof(lines) / sizeof(Vec3), Vec4(0.0, 0.0, 1.0, 0.5));
+}
+
+} // end namespace anki
+

+ 2 - 1
src/scene/SceneGraph.cpp

@@ -100,6 +100,7 @@ SceneGraph::~SceneGraph()
 Error SceneGraph::create(
 	AllocAlignedCallback allocCb, 
 	void* allocCbData, 
+	U32 frameAllocatorSize,
 	Threadpool* threadpool, 
 	ResourceManager* resources)
 {
@@ -119,7 +120,7 @@ Error SceneGraph::create(
 		ChainMemoryPool::ChunkGrowMethod::FIXED,
 		0);
 	m_frameAlloc = SceneFrameAllocator<U8>(
-		allocCb, allocCbData, ANKI_SCENE_ALLOCATOR_SIZE);
+		allocCb, allocCbData, frameAllocatorSize);
 
 	err = m_events.create(this);
 

+ 1 - 1
thirdparty

@@ -1 +1 @@
-Subproject commit 823029c11b604fd9221391791d8efd177574a627
+Subproject commit 9a50350e0c10f413dd162fc5b62249f6568002b4