fixed range recalculation on scrolling plot

This commit is contained in:
Lauchmelder 2021-12-27 22:49:06 +01:00
parent a45b47224a
commit 44affbe86c
4 changed files with 17 additions and 10 deletions

View file

@ -131,7 +131,7 @@ void Application::Init(int width, int height, const std::string& title)
camera = OrbitingCamera(glm::vec3(0.0f, 0.0f, 0.0f), 6.0f);
camera.SetPerspective(100.0f, aspectRatio, 0.01f, 100.0f);
pitch = 65.0f;
yaw = 265.0f;
yaw = 85.0f;
distance = 10.0f;
data.camera = &camera;

View file

@ -11,12 +11,13 @@ ScrollingPlot::ScrollingPlot(
Topology(manager, size, subdivision), domain(domain), dt(temporalResolution), func(func)
{
// Create initial texture for t = 0
for(unsigned int x = 0; x < subdivision.x; x++)
for (unsigned int x = 0; x < subdivision.x; x++)
{
CalculateStrip(x);
t += dt;
}
range = glm::vec2(-1.0f, 1.0f);
MakeTexture();
}

View file

@ -144,6 +144,19 @@ void Topology::PreRender(const lol::CameraBase& camera)
offset += 0.01f * scroll;
}
void Topology::CalculateRange()
{
float* pixels = GetTopology();
range = glm::vec2(pixels[0]);
unsigned int size = image.GetDimensions().x * image.GetDimensions().y;
for (unsigned int i = 1; i < size; i++)
{
range.x = std::min(pixels[i], range.x);
range.y = std::max(pixels[i], range.y);
}
}
void Topology::SetColormap(const Colormap& cm)
{
colormap = manager.Get<lol::Texture1D>(cm.id);
@ -174,14 +187,6 @@ void Topology::MakeTexture()
// Calculate range (min, max values) of topology
float* pixels = (float*)image.GetPixels();
range = glm::vec2(pixels[0]);
unsigned int size = image.GetDimensions().x * image.GetDimensions().y;
for (unsigned int i = 1; i < size; i++)
{
range.x = std::min(pixels[i], range.x);
range.y = std::max(pixels[i], range.y);
}
if (texture != nullptr)
delete texture;

View file

@ -23,6 +23,7 @@ public:
inline float* GetTopology() const { return (float*)image.GetPixels(); };
inline const glm::uvec2& GetSize() const { return image.GetDimensions(); };
void CalculateRange();
void SetColormap(const Colormap& cm);
void MakeTexture();