OpenSAGE / OpenSAGE

OpenSAGE is a free, open source re-implementation of SAGE, the 3D real time strategy (RTS) engine used in Command & Conquer: Generals and other RTS titles from EA Pacific. Written in C#. Not affiliated with EA.
https://opensage.github.io
Other
1.39k stars 131 forks source link

Generals: Object selection seems to use rudimentary bounding box #697

Open charliefoxtwo opened 2 years ago

charliefoxtwo commented 2 years ago

In OpenSAGE, the logic for determining whether an item has been selected seems to use the axis-aligned bounding box a single bounding sphere instead of the model geometry itself. This means that, especially for objects with varying geometry like the command center, the cursor can be nowhere near the model itself but still allow for selection. Generals/Zero Hour seem to use the model geometry or something similar.

charliefoxtwo commented 2 years ago

Correction - it seems to be a single geometry object which encompasses the entire object

https://github.com/OpenSAGE/OpenSAGE/blob/9c832e89c7370f326b17c217c16657768fe1d839/src/OpenSage.Game/Logic/Object/Colliders.cs#L53-L70

charliefoxtwo commented 2 years ago

For structures in Generals, GameObject.Colliders contains a single collider that encompasses the entire object. This is great for a rough pass, but it seems like we'll need a more precise way for determining if the ray actually intersects the object or not. I wonder if there's a way to do this with the model itself?

https://github.com/OpenSAGE/OpenSAGE/blob/9c832e89c7370f326b17c217c16657768fe1d839/src/OpenSage.Game/Logic/SelectionSystem.cs#L188-L220

charliefoxtwo commented 4 months ago

Looked at this a little bit more, and basically Colliders is set from the ObjectDefinition Geometry. Some objects may have multiple geometries via the AdditionalGeometry property, but this doesn't seem to apply to any objects in Generals, so they all just get the one geometry.

Perhaps we need to use the geometry of the active W3DModelDraws defined by the ModelConditionState? This also means we'll need to update the quadtree when the state changes as well.