Hi all,
I've been having some issues with a program I've been writing on-and-off over the last year or so, and was hoping to get some input. I keep running into major hurdles in development that I think are caused largely by my unfamiliarity with graphics/game engine design. It's a little convoluted, so I'll give some context:
The basic concept is a generalized 3D visualization program for the results of a simulator program that I've developed earlier. I'm using a mix of nalgebra and glium (yes I know it's deprecated) to make it, but I'm constantly running into issues with the design, which has involved a few refactors. What it should do is take position data, either generated by the program itself (for a demo) or by another computer providing data (eventually), and render it on the local computer. I've got the rendering and some basic orbiting camera behavior, but my issue primarily arises when trying to actually _move_the objects within the world.
My basic structure is as follows:
- The 'world' is comprised of a
Scene
struct, which is basically just a struct with a vector of entities.- Each
Entity
has anid
,position
,rotation
,model
s, et.c., like you'd expect. They also have a placeholderBehavior
list because I'd like to be able to make them more dynamic but I'm not there yet.
- Each
- The world is rendered via
Viewport
s, a box on the screen that renders as a camera. Show above are two small viewports and one large one. Each contains anArc
reference to theScene
to read the data and render it. Each needs only a read-only reference.- Eventually, there should be multiple viewports displaying different views: one could be static in reference to a map, with another window locked on to a moving entity, with another showing some telemetry data. Hence the multiple views rather than a single large window.
- The primary event loop does event handling (mostly camera control), creates a blank frame, updates the graphical elements, and then iterates over every viewport and draws each entity.
Now that I have a working camera, I've tried to start moving some of the objects around. Nothing big yet, just moving one in a circle. However, even though everything's been declared mutable, I can't modify any of the entities within the Scene
anymore. I can't modify the original struct because it's been moved into the Arc
, and I can't modify through an Arc
de-reference because I can't seem to implement the trait DerefMut
.
Any ideas? I'm open to alternative structures for the program. Is there a way to allow the struct to be changed in its current form? Is there another type of reference I can use that will allow the Scene
to be read by multiple viewports and still be written to?