summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authoradmin <admin@optics-design.com>2025-08-15 20:53:56 +0200
committeradmin <admin@optics-design.com>2025-08-15 20:53:56 +0200
commit9acbbbfbca5e8049b200d344027ee1199db262c3 (patch)
tree2ede5dc4f04d04a8ea940544f07e42a8cb183f2c /include
parent91c024d42e54c3db70fa9693525c0dc2b5e775fc (diff)
various changesHEADmaster
Diffstat (limited to 'include')
-rw-r--r--include/glamac/graphics/glamac_view.h59
1 files changed, 51 insertions, 8 deletions
diff --git a/include/glamac/graphics/glamac_view.h b/include/glamac/graphics/glamac_view.h
index c7b00d9..9a556e2 100644
--- a/include/glamac/graphics/glamac_view.h
+++ b/include/glamac/graphics/glamac_view.h
@@ -43,6 +43,15 @@ struct TightCluster {
f32 centerVd; // Average vd of cluster
};
+// Cached coordinate transformation parameters
+typedef struct {
+ f32 scale_x, scale_y; // Scaling factors
+ f32 offset_x, offset_y; // Translation offsets
+ f32 abbe_range, ri_range; // Data ranges
+ i32 padding; // Current padding
+ b32 valid; // Whether cache is valid
+} CoordTransform;
+
// State for zooming and panning
typedef struct {
f32 zoomLevel;
@@ -61,6 +70,9 @@ typedef struct {
b32 viewDirty; // Flag to track if view needs re-rendering
u32 forceRenderFrames; // Number of additional frames to force rendering (for transitions)
+ // Coordinate transformation cache
+ CoordTransform transform_cache;
+
// Tight clustering data
TightCluster* tightClusters; // Array of tight clusters
u32 tightClusterCount; // Number of tight clusters
@@ -87,23 +99,53 @@ static inline i32 get_adaptive_padding_for_size(i32 windowWidth, i32 windowHeigh
return padding > MIN_PADDING ? padding : MIN_PADDING;
}
-// Convert glass data to screen coordinates with zoom and offset
+// Update coordinate transformation cache
+static inline void update_transform_cache(ViewState* view) {
+ CoordTransform* cache = &view->transform_cache;
+ const i32 padding = get_adaptive_padding(view);
+ const f32 abbe_range = view->maxAbbe - view->minAbbe;
+ const f32 ri_range = view->maxRI - view->minRI;
+
+ // Check if cache is valid (validate all relevant parameters)
+ if (cache->valid &&
+ cache->padding == padding &&
+ cache->abbe_range == abbe_range &&
+ cache->ri_range == ri_range &&
+ cache->scale_x != 0.0f && cache->scale_y != 0.0f) {
+ return; // Cache is still valid
+ }
+
+ // Update cache
+ cache->abbe_range = abbe_range;
+ cache->ri_range = ri_range;
+ cache->scale_x = (view->windowWidth - 2 * padding) * view->zoomLevel / abbe_range;
+ cache->scale_y = (view->windowHeight - 2 * padding) * view->zoomLevel / ri_range;
+ cache->offset_x = padding + (view->windowWidth - 2 * padding) * (0.5f + view->offsetX);
+ cache->offset_y = view->windowHeight - padding - (view->windowHeight - 2 * padding) * (0.5f + view->offsetY);
+ cache->padding = padding;
+ cache->valid = 1;
+}
+
+// Coordinate transformation (temporarily without cache to debug)
static inline void data_to_screen_coords(f32 abbeNumber, f32 refractiveIndex,
- const ViewState* view, i32 *x, i32 *y) {
+ ViewState* view, i32 *x, i32 *y) {
const i32 padding = get_adaptive_padding(view);
- // Apply zoom and offset transformation
+ // Calculate ranges
+ const f32 abbeRange = view->maxAbbe - view->minAbbe;
+ const f32 riRange = view->maxRI - view->minRI;
+
// FLIPPED: Use 1.0f - normalized to flip the Abbe number axis
- f32 normalizedX = 1.0f - (abbeNumber - view->minAbbe) / (view->maxAbbe - view->minAbbe);
- f32 normalizedY = (refractiveIndex - view->minRI) / (view->maxRI - view->minRI);
+ f32 normalizedX = 1.0f - (abbeNumber - view->minAbbe) / abbeRange;
+ f32 normalizedY = (refractiveIndex - view->minRI) / riRange;
- // Transform with zoom and offset
+ // Apply zoom and offset transformations
normalizedX = (normalizedX - 0.5f) * view->zoomLevel + 0.5f + view->offsetX;
normalizedY = (normalizedY - 0.5f) * view->zoomLevel + 0.5f + view->offsetY;
// Convert to screen coordinates
- *x = padding + (i32)(normalizedX * (view->windowWidth - 2 * padding));
- *y = view->windowHeight - padding - (i32)(normalizedY * (view->windowHeight - 2 * padding));
+ *x = (i32)(padding + normalizedX * (view->windowWidth - 2 * padding));
+ *y = (i32)(view->windowHeight - padding - normalizedY * (view->windowHeight - 2 * padding));
}
// Convert screen coordinates to data values
@@ -153,6 +195,7 @@ static inline b32 is_glass_visible(f32 abbeNumber, f32 refractiveIndex, const Vi
// Mark view as dirty (needs re-rendering)
static inline void mark_view_dirty(ViewState* view) {
view->viewDirty = 1;
+ view->transform_cache.valid = 0; // Invalidate coordinate cache
}
// Handle mouse wheel zoom
Back to https://optics-design.com