-
Notifications
You must be signed in to change notification settings - Fork 13
Vision system
The squid's ability to "see" and react to his environment is not based on simple proximity but on a simulated line-of-sight mechanic. This system is composed of two main parts: the View Cone, which is an attribute of the squid itself and represents his field of view, and the Vision Window (from vision.py), which is a debug tool that provides a first-person visualization of what the squid is currently perceiving.

The core of the vision system is the "View Cone." This is not a visual effect but an invisible geometric shape (specifically, a QPolygonF) that is mathematically projected from the squid's current position and orientation.
- Dynamic and Directional: The View Cone is not static. It is recalculated every frame to match the squid's state. When the squid moves, the cone moves with it. More importantly, when the squid turns to face left, right, or up, the cone rotates accordingly. This ensures the squid can only perceive objects that are genuinely in his line of sight.
- Object Detection via Intersection: The system determines what the squid "sees" by performing a continuous series of geometric intersection tests. The logic iterates through every object in the environment (decorations, food, poop, etc.) and checks if that object's bounding box intersects with the squid's View Cone polygon.
- Informing the Brain: If an intersection is detected, the object is officially considered "seen." This information is critical as it is fed directly into the squid's Decision Engine. For example, if "food" is seen, the desire to "eat" will likely increase. This allows the squid to make intelligent, context-aware decisions based on his immediate surroundings. The `has_food_visible` and `plant_proximity` inputs feed this system.

The Vision Window is a powerful debugging tool that renders the output of the View Cone, allowing you to see the world from the squid's perspective.
The update_vision() method is the heart of this window and performs the following steps on each refresh:
- Clear the Scene: It first clears its own display to ensure no leftover artifacts from the previous frame.
- Get the View Cone: It fetches the squid's current View Cone polygon from the main game logic.
- Draw the Cone: It draws a visual representation of the cone shape itself within its window, so you can see the precise boundaries of the squid's perception.
- Render Seen Objects: It then performs the same intersection logic as the main decision engine. For every object whose bounding box intersects with the View Cone, it creates a copy of that object's pixmap and draws it inside the Vision Window. It also draws the bounding box of the seen object for clarity.
🦑 Raise digital squids whose brains grow & rewire themselves through Hebbian learning and Neurogenesis