2015-11-25 22:15:58 +00:00
|
|
|
#include "BaseTestCase.h"
|
|
|
|
#include "OpenGLVegetationLayer.h"
|
|
|
|
|
|
|
|
#include "VegetationLayerDefinition.h"
|
|
|
|
#include "VegetationModelDefinition.h"
|
|
|
|
#include "VegetationInstance.h"
|
|
|
|
#include "OpenGLVegetationInstance.h"
|
|
|
|
#include "CameraDefinition.h"
|
|
|
|
|
|
|
|
class FakeLayerRenderer : public OpenGLVegetationLayer {
|
|
|
|
public:
|
|
|
|
FakeLayerRenderer(VegetationLayerDefinition *definition) : OpenGLVegetationLayer(NULL, definition, false) {
|
|
|
|
}
|
|
|
|
virtual ~FakeLayerRenderer() {
|
|
|
|
for (auto instance : static_instances) {
|
|
|
|
delete instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virtual void produceInstancesInArea(double xmin, double xmax, double zmin, double zmax,
|
2015-12-13 16:16:26 +00:00
|
|
|
vector<OpenGLVegetationInstance *> *instances) const override {
|
2015-11-25 22:15:58 +00:00
|
|
|
for (auto instance : static_instances) {
|
|
|
|
Vector3 location = instance->getBase();
|
|
|
|
if (location.x >= xmin and location.z >= zmin and location.x < xmax and location.z < zmax) {
|
|
|
|
instances->push_back(instance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-13 16:16:26 +00:00
|
|
|
vector<OpenGLVegetationInstance *> static_instances;
|
2015-11-25 22:15:58 +00:00
|
|
|
};
|
|
|
|
|
2015-12-13 16:47:22 +00:00
|
|
|
TEST(OpenGLVegetationLayer, updateInstances) {
|
2015-11-25 22:15:58 +00:00
|
|
|
CameraDefinition camera;
|
|
|
|
VegetationLayerDefinition definition(NULL, "test");
|
|
|
|
FakeLayerRenderer rendering(&definition);
|
|
|
|
VegetationModelDefinition model(NULL);
|
|
|
|
|
|
|
|
EXPECT_EQ(0, rendering.getInstanceCount());
|
|
|
|
|
2015-12-13 16:47:22 +00:00
|
|
|
rendering.updateInstances();
|
2015-11-25 22:15:58 +00:00
|
|
|
EXPECT_EQ(0, rendering.getInstanceCount());
|
|
|
|
|
|
|
|
rendering.static_instances.push_back(
|
|
|
|
new OpenGLVegetationInstance(VegetationInstance(model, Vector3(0.0, 0.0, 0.0))));
|
|
|
|
rendering.reset();
|
2015-12-13 16:47:22 +00:00
|
|
|
rendering.updateInstances();
|
2015-11-25 22:15:58 +00:00
|
|
|
EXPECT_EQ(1, rendering.getInstanceCount());
|
|
|
|
|
|
|
|
camera.setLocation(Vector3(-5.0, 0.0, 0.0));
|
|
|
|
rendering.setCamera(&camera);
|
2015-12-13 16:47:22 +00:00
|
|
|
rendering.updateInstances();
|
2015-11-25 22:15:58 +00:00
|
|
|
EXPECT_EQ(1, rendering.getInstanceCount());
|
|
|
|
|
|
|
|
camera.setLocation(Vector3(-11.0, 0.0, 0.0));
|
|
|
|
rendering.setCamera(&camera);
|
2015-12-13 16:47:22 +00:00
|
|
|
rendering.updateInstances();
|
2015-11-25 22:15:58 +00:00
|
|
|
EXPECT_EQ(0, rendering.getInstanceCount());
|
|
|
|
|
|
|
|
camera.setLocation(Vector3(0.0, 0.0, 5.0));
|
|
|
|
rendering.setCamera(&camera);
|
2015-12-13 16:47:22 +00:00
|
|
|
rendering.updateInstances();
|
2015-11-25 22:15:58 +00:00
|
|
|
EXPECT_EQ(1, rendering.getInstanceCount());
|
|
|
|
|
|
|
|
camera.setLocation(Vector3(0.0, 0.0, 15.0));
|
|
|
|
rendering.setCamera(&camera);
|
2015-12-13 16:47:22 +00:00
|
|
|
rendering.updateInstances();
|
2015-11-25 22:15:58 +00:00
|
|
|
EXPECT_EQ(0, rendering.getInstanceCount());
|
|
|
|
}
|