Browse Source

Scene and sector

Panagiotis Christopoulos Charitos 13 years ago
parent
commit
82c4cf3b79

+ 3 - 3
include/anki/scene/Camera.h

@@ -192,7 +192,7 @@ public:
 		updateViewMatrix();
 		updateViewProjectionMatrix();
 		frustum.setTransform(getWorldTransform());
-		spatialMarkUpdated();
+		spatialMarkForUpdate();
 	}
 	/// @}
 
@@ -207,7 +207,7 @@ private:
 		projectionMat = frustum.calculateProjectionMatrix();
 		invProjectionMat = projectionMat.getInverse();
 		updateViewProjectionMatrix();
-		spatialMarkUpdated();
+		spatialMarkForUpdate();
 	}
 };
 
@@ -288,7 +288,7 @@ private:
 		projectionMat = frustum.calculateProjectionMatrix();
 		invProjectionMat = projectionMat.getInverse();
 		updateViewProjectionMatrix();
-		spatialMarkUpdated();
+		spatialMarkForUpdate();
 	}
 };
 /// @}

+ 4 - 4
include/anki/scene/Light.h

@@ -143,7 +143,7 @@ public:
 	void setRadius(const F32 x)
 	{
 		sphereW.setRadius(x);
-		spatialMarkUpdated();
+		spatialMarkForUpdate();
 	}
 
 	const Sphere& getSphere() const
@@ -161,7 +161,7 @@ public:
 	{
 		Movable::movableUpdate();
 		sphereW.setCenter(getWorldTransform().getOrigin());
-		spatialMarkUpdated();
+		spatialMarkForUpdate();
 	}
 	/// @}
 
@@ -256,7 +256,7 @@ public:
 		viewMat = Mat4(getWorldTransform().getInverse());
 		viewProjectionMat = projectionMat * viewMat;
 
-		spatialMarkUpdated();
+		spatialMarkForUpdate();
 	}
 	/// @}
 
@@ -286,7 +286,7 @@ private:
 		projectionMat = frustum.calculateProjectionMatrix();
 		viewProjectionMat = projectionMat * viewMat;
 
-		spatialMarkUpdated();
+		spatialMarkForUpdate();
 		frustumableMarkUpdated();
 	}
 };

+ 1 - 1
include/anki/scene/ModelNode.h

@@ -61,7 +61,7 @@ public:
 		Movable::movableUpdate();
 		obb = modelPatch->getBoundingShape().getTransformed(
 			getWorldTransform());
-		spatialMarkUpdated();
+		spatialMarkForUpdate();
 	}
 	/// @}
 

+ 12 - 12
include/anki/scene/Movable.h

@@ -52,22 +52,22 @@ public:
 	void setLocalTransform(const Transform& x)
 	{
 		lTrf = x;
-		movableMarkUpdated();
+		movableMarkForUpdate();
 	}
 	void setLocalTranslation(const Vec3& x)
 	{
 		lTrf.setOrigin(x);
-		movableMarkUpdated();
+		movableMarkForUpdate();
 	}
 	void setLocalRotation(const Mat3& x)
 	{
 		lTrf.setRotation(x);
-		movableMarkUpdated();
+		movableMarkForUpdate();
 	}
 	void setLocalScale(F32 x)
 	{
 		lTrf.setScale(x);
-		movableMarkUpdated();
+		movableMarkForUpdate();
 	}
 
 	const Transform& getWorldTransform() const
@@ -91,40 +91,40 @@ public:
 	void rotateLocalX(F32 angDegrees)
 	{
 		lTrf.getRotation().rotateXAxis(angDegrees);
-		movableMarkUpdated();
+		movableMarkForUpdate();
 	}
 	void rotateLocalY(F32 angDegrees)
 	{
 		lTrf.getRotation().rotateYAxis(angDegrees);
-		movableMarkUpdated();
+		movableMarkForUpdate();
 	}
 	void rotateLocalZ(F32 angDegrees)
 	{
 		lTrf.getRotation().rotateZAxis(angDegrees);
-		movableMarkUpdated();
+		movableMarkForUpdate();
 	}
 	void moveLocalX(F32 distance)
 	{
 		Vec3 x_axis = lTrf.getRotation().getColumn(0);
 		lTrf.getOrigin() += x_axis * distance;
-		movableMarkUpdated();
+		movableMarkForUpdate();
 	}
 	void moveLocalY(F32 distance)
 	{
 		Vec3 y_axis = lTrf.getRotation().getColumn(1);
 		lTrf.getOrigin() += y_axis * distance;
-		movableMarkUpdated();
+		movableMarkForUpdate();
 	}
 	void moveLocalZ(F32 distance)
 	{
 		Vec3 z_axis = lTrf.getRotation().getColumn(2);
 		lTrf.getOrigin() += z_axis * distance;
-		movableMarkUpdated();
+		movableMarkForUpdate();
 	}
 	void scale(F32 s)
 	{
 		lTrf.getScale() *= s;
-		movableMarkUpdated();
+		movableMarkForUpdate();
 	}
 	/// @}
 
@@ -158,7 +158,7 @@ protected:
 	/// is true. Then it moves to the children.
 	void updateWorldTransform();
 
-	void movableMarkUpdated()
+	void movableMarkForUpdate()
 	{
 		timestamp = Timestamp::getTimestamp();
 		enableFlags(MF_TRANSFORM_DIRTY);

+ 1 - 1
include/anki/scene/ParticleEmitter.h

@@ -238,7 +238,7 @@ public:
 private:
 	ParticleEmitterResourcePointer particleEmitterResource;
 	std::unique_ptr<btCollisionShape> collShape = nullptr;
-	Vector<ParticleBase*> particles;
+	SceneVector<ParticleBase*> particles;
 	F32 timeLeftForNextEmission;
 	/// The resource
 	Aabb aabb;

+ 1 - 1
include/anki/scene/Spatial.h

@@ -93,7 +93,7 @@ public:
 
 	/// The derived class has to manually set when the collision shape got
 	/// updated
-	void spatialMarkUpdated()
+	void spatialMarkForUpdate()
 	{
 		timestamp = Timestamp::getTimestamp();
 		spatialCs->toAabb(aabb);

+ 2 - 2
src/renderer/Dbg.cpp

@@ -67,9 +67,9 @@ void Dbg::run()
 	// Draw sectors
 	for(const Sector* sector : scene.getSectorGroup().getSectors())
 	{
-		if(sector->isVisible())
+		//if(sector->isVisible())
 		{
-			if(flagsEnabled(DF_SPATIAL))
+			if(flagsEnabled(DF_SECTOR))
 			{
 				sceneDrawer->draw(*sector);
 			}

+ 2 - 2
src/scene/Movable.cpp

@@ -13,7 +13,7 @@ Movable::Movable(U32 flags_, Movable* parent, PropertyMap& pmap,
 	pmap.addNewProperty(
 		new ReadPointerProperty<Transform>("worldTransform", &wTrf));
 
-	movableMarkUpdated();
+	movableMarkForUpdate();
 }
 
 //==============================================================================
@@ -67,7 +67,7 @@ void Movable::updateWorldTransform()
 		// If parent is dirty then make children dirty as well
 		if(dirty)
 		{
-			(*it)->movableMarkUpdated();
+			(*it)->movableMarkForUpdate();
 		}
 
 		(*it)->updateWorldTransform();

+ 0 - 1
src/scene/Octree.cpp

@@ -265,7 +265,6 @@ void Octree::doVisibilityTests(SceneNode& fsn, VisibilityTest test,
 	VisibilityTestResults& visibles)
 {
 	ANKI_ASSERT(fsn.getFrustumable());
-	ANKI_ASSERT(fsn.getFrustumable()->insideFrustum(root.getAabb()));
 	doVisibilityTestsInternal(fsn, test, visibles, root);
 }
 

+ 5 - 2
src/scene/ParticleEmitter.cpp

@@ -226,7 +226,8 @@ ParticleEmitter::ParticleEmitter(
 	:	SceneNode(name, scene),
 		Spatial(&aabb),
 		Movable(movableFlags, movParent, *this, getSceneAllocator()),
-		Renderable(getSceneAllocator())
+		Renderable(getSceneAllocator()),
+		particles(getSceneAllocator())
 {
 	// Load resource
 	particleEmitterResource.load(filename);
@@ -300,6 +301,8 @@ void ParticleEmitter::createParticlesSimulation(Scene* scene)
 	binit.group = PhysWorld::CG_PARTICLE;
 	binit.mask = PhysWorld::CG_MAP;
 
+	particles.reserve(maxNumOfParticles);
+
 	for(U i = 0; i < maxNumOfParticles; i++)
 	{
 		binit.mass = getRandom(particle.mass, particle.massDeviation);
@@ -403,7 +406,7 @@ void ParticleEmitter::frameUpdate(F32 prevUpdateTime, F32 crntTime, I frame)
 	{
 		aabb = Aabb(Vec3(0.0), Vec3(0.01));
 	}
-	spatialMarkUpdated();
+	spatialMarkForUpdate();
 
 	if(alphaRenderableVar)
 	{

+ 2 - 0
src/scene/Scene.cpp

@@ -68,6 +68,8 @@ void Scene::unregisterNode(SceneNode* node)
 //==============================================================================
 void Scene::update(F32 prevUpdateTime, F32 crntTime, Renderer& r)
 {
+	frameAlloc.reset();
+
 	physics.update(prevUpdateTime, crntTime);
 
 #if 0

+ 2 - 0
src/scene/Sector.cpp

@@ -155,6 +155,8 @@ Portal* SectorGroup::createNewPortal(Sector* a, Sector* b,
 	out->sectors[1] = b;
 	out->shape = collisionShape;
 
+	portals.push_back(out);
+
 	return out;
 }
 

+ 22 - 14
testapp/Main.cpp

@@ -195,7 +195,7 @@ void init()
 	spot->setShadowEnabled(true);
 #endif
 
-#if 1
+#if 0
 	// Vase point lights
 	F32 x = 8.5;
 	F32 y = 2.25;
@@ -251,16 +251,16 @@ void init()
 
 	(void)sponzaModel;
 
-	initPhysics();
+	//initPhysics();
 
 	// Sectors
 	SectorGroup& sgroup = scene.getSectorGroup();
 
-	Sector* sectorA = sgroup.createNewSector(Aabb(Vec3(-100), Vec3(100)));
-	Sector* sectorB = sgroup.createNewSector(Aabb(Vec3(-10), Vec3(10)));
+	Sector* sectorA = sgroup.createNewSector(Aabb(Vec3(-10), Vec3(10)));
+	Sector* sectorB = sgroup.createNewSector(Aabb(Vec3(-5), Vec3(5)));
 
-	sgroup.createNewPortal(sectorA, sectorB, Obb(Vec3(0.0), 
-		Mat3::getIdentity(), Vec3(2.0, 2.0, 0.0)));
+	sgroup.createNewPortal(sectorA, sectorB, Obb(Vec3(0.0, 1.0, 0.0),
+		Mat3::getIdentity(), Vec3(2.0, 2.0, 1.0)));
 }
 
 //==============================================================================
@@ -359,6 +359,16 @@ void mainLoopExtra()
 		MainRendererSingleton::get().getDbg().switchFlags(
 			Dbg::DF_PHYSICS);
 	}
+	if(in.getKey(KC_F4) == 1)
+	{
+		MainRendererSingleton::get().getDbg().switchFlags(
+			Dbg::DF_SECTOR);
+	}
+	if(in.getKey(KC_F5) == 1)
+	{
+		MainRendererSingleton::get().getDbg().switchFlags(
+			Dbg::DF_OCTREE);
+	}
 
 	if(in.getKey(KC_UP)) mover->rotateLocalX(ang);
 	if(in.getKey(KC_DOWN)) mover->rotateLocalX(-ang);
@@ -387,9 +397,12 @@ void mainLoopExtra()
 	}
 
 
-	mover->rotateLocalY(-ang * in.getMousePosition().x() * mouseSensivity * 
-		MainRendererSingleton::get().getAspectRatio());
-	mover->rotateLocalX(ang * in.getMousePosition().y() * mouseSensivity);
+	if(in.getMousePosition() != Vec2(0.0))
+	{
+		mover->rotateLocalY(-ang * in.getMousePosition().x() * mouseSensivity *
+			MainRendererSingleton::get().getAspectRatio());
+		mover->rotateLocalX(ang * in.getMousePosition().y() * mouseSensivity);
+	}
 
 	execStdinScpripts();
 }
@@ -404,11 +417,6 @@ void mainLoop()
 	HighRezTimer::Scalar prevUpdateTime = HighRezTimer::getCurrentTime();
 	HighRezTimer::Scalar crntTime = prevUpdateTime;
 
-	std::cout << sizeof(SpotLight) << " " << sizeof(Light) << " "
-		<< sizeof(Frustumable) << " " << sizeof(VisibilityInfo) << " "
-		<< sizeof(SceneNode) << " " << sizeof(Movable) << " "
-		<< sizeof(Spatial) << std::endl;
-
 	while(1)
 	{
 		HighRezTimer timer;