Source code for picogl.backend.gl.legacy.view

from __future__ import annotations

from dataclasses import dataclass, field

from picogl.backend.gl.enums.legacy.scale import gl_rotatef, gl_scalef, gl_translate_f


[docs] class LegacyGLTranslation: """Translation Parameters"""
[docs] x: float = 0.0
[docs] y: float = 0.0
[docs] z: float = 0.0
[docs] def apply(self): gl_translate_f(self.x, self.y, self.z)
[docs] def _apply_zoom(self, value: float = 0.01): gl_translate_f(self.x, self.y, value)
@dataclass
[docs] class LegacyGLZoom: """Zoom parameters.""" # translation: GLTranslation = None
[docs] value: float = -5.0
"""def apply(self): self.apply_translation_and_zoom(self.translation, self.value)"""
[docs] def apply_translation_and_zoom(self, translation, zoom): gl_translate_f(translation.x, translation.y, zoom)
[docs] def rescale(self): gl_scalef(self.value, self.value, self.value)
@dataclass
[docs] class LegacyGLRotation:
[docs] x: float = 0.0
[docs] y: float = 0.0
[docs] z: float = 0.0
[docs] def apply(self): gl_rotatef(self.x, 1.0, 0.0, 0.0) gl_rotatef(self.y, 0.0, 1.0, 0.0) gl_rotatef(self.z, 0.0, 0.0, 1.0)
[docs] def initialize(self): self.x = 0.0 self.y = 0.0 self.z = 0.0
@dataclass
[docs] class CameraPerspective: """ Represents parameters required to define a camera perspective. This class provides default values for the far clipping plane, near clipping plane, and field of view in the y-direction (fovy) for a perspective camera. These parameters can be used to set up a perspective projection for 3D rendering. """
[docs] far: float = 100.0
[docs] near: float = 0.1
[docs] fovy: float = 45.0
@dataclass
[docs] class LegacyGLViewTransform: """Encapsulates legacy OpenGL view rotation, translation, and zoom."""
[docs] rotation: LegacyGLRotation = field(default_factory=LegacyGLRotation)
[docs] translation: LegacyGLTranslation = field(default_factory=LegacyGLTranslation)
[docs] zoom: LegacyGLZoom = field(default_factory=lambda: LegacyGLZoom(value=1.0))
@property
[docs] def rotation_x(self) -> float: return self.rotation.x
@rotation_x.setter def rotation_x(self, value: float) -> None: self.rotation.x = value @property
[docs] def rotation_y(self) -> float: return self.rotation.y
@rotation_y.setter def rotation_y(self, value: float) -> None: self.rotation.y = value @property
[docs] def translation_x(self) -> float: return self.translation.x
@translation_x.setter def translation_x(self, value: float) -> None: self.translation.x = value @property
[docs] def translation_y(self) -> float: return self.translation.y
@translation_y.setter def translation_y(self, value: float) -> None: self.translation.y = value
[docs] def apply(self) -> None: """Apply the view transform using the legacy OpenGL matrix stack.""" self.translation.apply() self.rotation.apply()
[docs] def reset(self) -> None: """Reset view transformation to defaults.""" self.rotation = LegacyGLRotation() self.translation = LegacyGLTranslation() self.zoom = LegacyGLZoom(value=1.0)