For the sake of the question, imagine that I’m making a game engine from scratch by one of the popular programming languages and I would like to put an interactable crate in my game. How does the game know what a crate is? I’m thinking like they create a crate in one of the rendering software, but how do they translate that to a game? Do they do something like
`define “crate” crate.stl`
then refer to it only as “crate” to give it animation, physics and lighting properties by extra code, or does it work completely differently?
A follow up question, I want to give velocity to my crate when it’s propelled by the player. Let’s say I tell it moves on x axis by “5” when “interact” happens, how is x axis or velocity defined?
In: Technology
Essentially, there is a data structure that is used In many engines called a scene graph.
This is a way to structure various objects in a hierarchy that makes it easier to manipulate them.
For example your box could be a node in the scene graph that has various attributes applied to it (eg moving). If there are things in the box, they would be children of that box node, so when you apply a transformation (eg move 5 units in the X direction) that transform is applied to all the children of that node.
This structure also helps when you have groups of objects that move relatively to each other but also need to move together. For example if you have a character with a bird flying around him, you don’t need to worry about what global space coordinates it needs to orbit, you tell it to orbit the character and when the character moves that orbit is also moved without you needing to know where the center of that orbit is in the global coordinate space.
There are many tricks you can do to speed up things, for example your box textures or other data it has can be separated, so that of you have say 10 boxes, they reference that same data.
Obviously when you have very large and complex scenes, there are also other tricks that are used to reduce what is displayed etc. You can also have things like bounding boxes attached to various nodes for collision detection etc.
Modern game engines are insanely complicated and there are many tricks used to improve performance and memory utilisation, so this is a very basic description, but the main idea is that it provides a hierarchy for your in world objects that aims to optimize various typical operations you might want to do to them (moving, rotating, changing size, detecting collisions etc.)
Latest Answers