Panagiotis Christopoulos Charitos vor 15 Jahren
Ursprung
Commit
e7b6d1df1d

Datei-Diff unterdrückt, da er zu groß ist
+ 1 - 2
build/debug/Makefile


+ 0 - 1
src/Main.cpp

@@ -26,7 +26,6 @@
 #include "Renderer.h"
 #include "RendererInitializer.h"
 #include "MainRenderer.h"
-#include "DebugDrawer.h"
 #include "PhyCharacter.h"
 #include "RigidBody.h"
 #include "ScriptingEngine.h"

+ 1 - 1
src/Physics/Physics.cpp

@@ -19,7 +19,7 @@ Physics::Physics(Object* parent):
 	dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, sol, collisionConfiguration);
 	dynamicsWorld->setGravity(btVector3(0,-10, 0));
 
-	debugDrawer = new DebugDrawer;
+	debugDrawer = new PhyDbgDrawer;
 	dynamicsWorld->setDebugDrawer(debugDrawer);
 	dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe);
 }

+ 2 - 2
src/Physics/Physics.h

@@ -5,7 +5,7 @@
 #include <btBulletDynamicsCommon.h>
 #include "Object.h"
 #include "BtAndAnkiConvertors.h"
-#include "DebugDrawer.h"
+#include "PhyDbgDrawer.h"
 
 
 class PhyCharacter;
@@ -50,7 +50,7 @@ class Physics: public Object
 		btCollisionDispatcher* dispatcher;
 		btBroadphaseInterface* broadphase;
 		btSequentialImpulseConstraintSolver* sol;
-		DebugDrawer* debugDrawer;
+		PhyDbgDrawer* debugDrawer;
 		float defaultContactProcessingThreshold;
 		Vec<PhyCharacter*> characters;
 		float time; ///< Time of prev update

+ 28 - 24
src/Renderer/Dbg.cpp

@@ -5,7 +5,7 @@
 #include "Camera.h"
 #include "Light.h"
 #include "RendererInitializer.h"
-#include "DbgDrawer.h"
+#include "SceneDbgDrawer.h"
 #include "ParticleEmitter.h"
 
 
@@ -85,10 +85,8 @@ void Dbg::renderGrid()
 //======================================================================================================================
 // drawSphere                                                                                                        =
 //======================================================================================================================
-void Dbg::drawSphere(float radius, const Transform& trf, const Vec4& col, int complexity)
+void Dbg::drawSphere(float radius, int complexity)
 {
-	/*setColor(col);
-
 	const float twopi  = M::PI*2;
 	const float pidiv2 = M::PI/2;
 
@@ -104,9 +102,7 @@ void Dbg::drawSphere(float radius, const Transform& trf, const Vec4& col, int co
 	float py = 0.0;
 	float pz = 0.0;
 
-	Vec<Vec3> positions;
-	Vec<Vec3> normals;
-	Vec<Vec2> texCoodrs;
+	begin();
 
 	for(int i = 0; i < complexity/2; ++i)
 	{
@@ -132,9 +128,10 @@ void Dbg::drawSphere(float radius, const Transform& trf, const Vec4& col, int co
 			py = radius * ey;
 			pz = radius * ez;
 
-			positions.push_back(Vec3(px, py, pz));
-			normals.push_back(Vec3(ex, ey, ez));
-			texCoodrs.push_back(Vec2(-(j/(float)complexity), 2*(i+1)/(float)complexity));
+			pushBackVertex(Vec3(px, py, pz));
+			//positions.push_back(Vec3(px, py, pz));
+			//normals.push_back(Vec3(ex, ey, ez));
+			//texCoodrs.push_back(Vec2(-(j/(float)complexity), 2*(i+1)/(float)complexity));
 
 			ex = costheta1 * costheta3;
 			ey = sintheta1;
@@ -143,18 +140,25 @@ void Dbg::drawSphere(float radius, const Transform& trf, const Vec4& col, int co
 			py = radius * ey;
 			pz = radius * ez;
 
-			positions.push_back(Vec3(px, py, pz));
-			normals.push_back(Vec3(ex, ey, ez));
-			texCoodrs.push_back(Vec2(-(j/(float)complexity), 2*i/(float)complexity));
+			pushBackVertex(Vec3(px, py, pz));
+			//positions.push_back(Vec3(px, py, pz));
+			//normals.push_back(Vec3(ex, ey, ez));
+			//texCoodrs.push_back(Vec2(-(j/(float)complexity), 2*i/(float)complexity));
 		}
 	}
 
-	setModelMat(Mat4(trf));
+	positionsVbo->write(&positions[0], 0, sizeof(Vec3) * pointIndex);
+	colorsVbo->write(&colors[0], 0, sizeof(Vec3) * pointIndex);
+
+	Mat4 pmv = r.getViewProjectionMat() * modelMat;
+	sProg->findUniVar("modelViewProjectionMat")->setMat4(&pmv);
+
+	vao->bind();
+	glDrawArrays(GL_LINE_STRIP, 0, pointIndex);
+	vao->unbind();
 
-	glEnableVertexAttribArray(0);
-	glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, &(positions[0][0]));
-	glDrawArrays(GL_QUAD_STRIP, 0, positions.size());
-	glDisableVertexAttribArray(0);*/
+	// Cleanup
+	pointIndex = 0;
 }
 
 
@@ -240,7 +244,7 @@ void Dbg::init(const RendererInitializer& initializer)
 	ON_GL_FAIL_THROW_EXCEPTION();
 	modelMat.setIdentity();
 	crntCol = Vec3(1.0, 0.0, 0.0);
-	dbgDrawer = new DbgDrawer(*this, this);
+	sceneDbgDrawer = new SceneDbgDrawer(*this, this);
 }
 
 
@@ -262,8 +266,9 @@ void Dbg::run()
 	glEnable(GL_DEPTH_TEST);
 	glDisable(GL_BLEND);
 
+	setModelMat(Mat4::getIdentity());
 	renderGrid();
-	/// @todo Uncomment
+
 	Vec<SceneNode*>::const_iterator it = app->getScene().nodes.begin();
 	for(; it != app->getScene().nodes.end(); ++it)
 	{
@@ -272,13 +277,13 @@ void Dbg::run()
 		switch(node.type)
 		{
 			case SceneNode::SNT_CAMERA:
-				dbgDrawer->drawCamera(static_cast<const Camera&>(node));
+				sceneDbgDrawer->drawCamera(static_cast<const Camera&>(node));
 				break;
 			case SceneNode::SNT_LIGHT:
-				dbgDrawer->drawLight(static_cast<const Light&>(node));
+				sceneDbgDrawer->drawLight(static_cast<const Light&>(node));
 				break;
 			case SceneNode::SNT_PARTICLE_EMITTER:
-				dbgDrawer->drawParticleEmitter(static_cast<const ParticleEmitter&>(node));
+				sceneDbgDrawer->drawParticleEmitter(static_cast<const ParticleEmitter&>(node));
 				break;
 			default:
 				break;
@@ -352,7 +357,6 @@ void Dbg::end()
 
 	// Cleanup
 	pointIndex = 0;
-	sProg->findUniVar("modelViewProjectionMat")->setMat4(&Mat4::getIdentity());
 }
 
 

+ 3 - 3
src/Renderer/Dbg.h

@@ -11,7 +11,7 @@
 
 class Vbo;
 class Vao;
-class DbgDrawer;
+class SceneDbgDrawer;
 
 
 /// Debugging stage
@@ -23,7 +23,7 @@ class Dbg: public RenderingPass
 		void run();
 
 		void renderGrid();
-		void drawSphere(float radius, const Transform& trf, const Vec4& col, int complexity = 8);
+		void drawSphere(float radius, int complexity = 8);
 		void drawCube(float size = 1.0);
 		void drawLine(const Vec3& from, const Vec3& to, const Vec4& color);
 
@@ -63,7 +63,7 @@ class Dbg: public RenderingPass
 		Vbo* positionsVbo;
 		Vbo* colorsVbo;
 		Vao* vao;
-		DbgDrawer* dbgDrawer;
+		SceneDbgDrawer* sceneDbgDrawer;
 };
 
 

+ 11 - 9
src/Physics/DebugDrawer.cpp → src/Renderer/PhyDbgDrawer.cpp

@@ -1,4 +1,4 @@
-#include "DebugDrawer.h"
+#include "PhyDbgDrawer.h"
 #include "MainRenderer.h"
 #include "App.h"
 #include "BtAndAnkiConvertors.h"
@@ -8,7 +8,7 @@
 //======================================================================================================================
 // drawLine                                                                                                            =
 //======================================================================================================================
-void DebugDrawer::drawLine(const btVector3& from, const btVector3& to, const btVector3& color)
+void PhyDbgDrawer::drawLine(const btVector3& from, const btVector3& to, const btVector3& color)
 {
 	app->getMainRenderer().getDbg().drawLine(toAnki(from), toAnki(to), Vec4(toAnki(color), 1.0));
 }
@@ -17,16 +17,18 @@ void DebugDrawer::drawLine(const btVector3& from, const btVector3& to, const btV
 //======================================================================================================================
 // drawSphere                                                                                                          =
 //======================================================================================================================
-void DebugDrawer::drawSphere(btScalar radius, const btTransform& transform, const btVector3& color)
+void PhyDbgDrawer::drawSphere(btScalar radius, const btTransform& transform, const btVector3& color)
 {
-	app->getMainRenderer().getDbg().drawSphere(radius, Transform(toAnki(transform)), Vec4(toAnki(color), 1.0));
+	app->getMainRenderer().getDbg().setColor(toAnki(color));
+	app->getMainRenderer().getDbg().setModelMat(Mat4(toAnki(transform)));
+	app->getMainRenderer().getDbg().drawSphere(radius);
 }
 
 
 //======================================================================================================================
 // drawBox                                                                                                             =
 //======================================================================================================================
-void DebugDrawer::drawBox(const btVector3& min, const btVector3& max, const btVector3& color)
+void PhyDbgDrawer::drawBox(const btVector3& min, const btVector3& max, const btVector3& color)
 {
 	Mat4 trf(Mat4::getIdentity());
 	trf(0, 0) = max.getX() - min.getX();
@@ -44,7 +46,7 @@ void DebugDrawer::drawBox(const btVector3& min, const btVector3& max, const btVe
 //======================================================================================================================
 // drawBox                                                                                                             =
 //======================================================================================================================
-void DebugDrawer::drawBox(const btVector3& min, const btVector3& max, const btTransform& trans, const btVector3& color)
+void PhyDbgDrawer::drawBox(const btVector3& min, const btVector3& max, const btTransform& trans, const btVector3& color)
 {
 	Mat4 trf(Mat4::getIdentity());
 	trf(0, 0) = max.getX() - min.getX();
@@ -63,7 +65,7 @@ void DebugDrawer::drawBox(const btVector3& min, const btVector3& max, const btTr
 //======================================================================================================================
 // drawContactPoint                                                                                                    =
 //======================================================================================================================
-void DebugDrawer::drawContactPoint(const btVector3& /*pointOnB*/, const btVector3& /*normalOnB*/,
+void PhyDbgDrawer::drawContactPoint(const btVector3& /*pointOnB*/, const btVector3& /*normalOnB*/,
                                           btScalar /*distance*/, int /*lifeTime*/, const btVector3& /*color*/)
 {
 	//WARNING("Unimplemented");
@@ -73,7 +75,7 @@ void DebugDrawer::drawContactPoint(const btVector3& /*pointOnB*/, const btVector
 //======================================================================================================================
 // reportErrorWarning                                                                                                  =
 //======================================================================================================================
-void DebugDrawer::reportErrorWarning(const char* warningString)
+void PhyDbgDrawer::reportErrorWarning(const char* warningString)
 {
 	throw EXCEPTION(warningString);
 }
@@ -82,7 +84,7 @@ void DebugDrawer::reportErrorWarning(const char* warningString)
 //======================================================================================================================
 // draw3dText                                                                                                          =
 //======================================================================================================================
-void DebugDrawer::draw3dText(const btVector3& /*location*/, const char* /*textString*/)
+void PhyDbgDrawer::draw3dText(const btVector3& /*location*/, const char* /*textString*/)
 {
 	//WARNING("Unimplemented");
 }

+ 4 - 6
src/Physics/DebugDrawer.h → src/Renderer/PhyDbgDrawer.h

@@ -1,13 +1,11 @@
-#ifndef DEBUGDRAWER_H
-#define DEBUGDRAWER_H
+#ifndef PHY_DBG_DRAWER_H
+#define PHY_DBG_DRAWER_H
 
 #include <LinearMath/btIDebugDraw.h>
 
 
-/**
- * An implementation of btIDebugDraw used for debugging Bullet. See Bullet docs for details
- */
-class DebugDrawer: public btIDebugDraw
+/// An implementation of btIDebugDraw used for debugging Bullet. See Bullet docs for details
+class PhyDbgDrawer: public btIDebugDraw
 {
 	public:
 		void drawLine(const btVector3& from, const btVector3& to, const btVector3& color);

+ 7 - 5
src/Renderer/DbgDrawer.cpp → src/Renderer/SceneDbgDrawer.cpp

@@ -1,4 +1,4 @@
-#include "DbgDrawer.h"
+#include "SceneDbgDrawer.h"
 #include "Dbg.h"
 #include "Camera.h"
 #include "Light.h"
@@ -8,7 +8,7 @@
 //======================================================================================================================
 // drawCamera                                                                                                          =
 //======================================================================================================================
-void DbgDrawer::drawCamera(const Camera& cam) const
+void SceneDbgDrawer::drawCamera(const Camera& cam) const
 {
 	dbg.setColor(Vec4(1.0, 0.0, 1.0, 1.0));
 	dbg.setModelMat(Mat4(cam.getWorldTransform()));
@@ -39,16 +39,18 @@ void DbgDrawer::drawCamera(const Camera& cam) const
 //======================================================================================================================
 // drawLight                                                                                                           =
 //======================================================================================================================
-void DbgDrawer::drawLight(const Light& light) const
+void SceneDbgDrawer::drawLight(const Light& light) const
 {
-	dbg.drawSphere(0.1, light.getWorldTransform(), Vec4(light.getDiffuseCol(), 1.0));
+	dbg.setColor(light.getDiffuseCol());
+	dbg.setModelMat(Mat4(light.getWorldTransform()));
+	dbg.drawSphere(0.1);
 }
 
 
 //======================================================================================================================
 // drawParticleEmitter                                                                                                 =
 //======================================================================================================================
-void DbgDrawer::drawParticleEmitter(const ParticleEmitter& pe) const
+void SceneDbgDrawer::drawParticleEmitter(const ParticleEmitter& pe) const
 {
 	dbg.setColor(Vec4(1.0));
 	dbg.setModelMat(Mat4(pe.getWorldTransform()));

+ 5 - 5
src/Renderer/DbgDrawer.h → src/Renderer/SceneDbgDrawer.h

@@ -1,5 +1,5 @@
-#ifndef DBG_DRAWER_H
-#define DBG_DRAWER_H
+#ifndef SCENE_DBG_DRAWER_H
+#define SCENE_DBG_DRAWER_H
 
 #include "Object.h"
 
@@ -11,11 +11,11 @@ class ParticleEmitter;
 
 
 /// This is a drawer for some scene nodes that need debug
-class DbgDrawer: public Object
+class SceneDbgDrawer: public Object
 {
 	public:
 		/// Constructor
-		DbgDrawer(Dbg& dbg_, Object* parent);
+		SceneDbgDrawer(Dbg& dbg_, Object* parent);
 
 		/// Draw a Camera
 		virtual void drawCamera(const Camera& cam) const;
@@ -31,7 +31,7 @@ class DbgDrawer: public Object
 };
 
 
-inline DbgDrawer::DbgDrawer(Dbg& dbg_, Object* parent):
+inline SceneDbgDrawer::SceneDbgDrawer(Dbg& dbg_, Object* parent):
 	Object(parent),
 	dbg(dbg_)
 {}

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.