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
Just to expand on what others are saying: the way a conventional game engine renders stuff on screen (I.e. rasterisation) fairly closely mimics the way you would draw something on paper.
First, you have the object you want to draw. Say, a figurine. As others have said, this figurine is defined as a set of triangles that, when slotted together, form the object. These triangles are defined as offsets from the “origin” of the model, for example the centre of the figurine’s base.
Next, you have to place the figurine in your 3D scene, on top of a desk for example. You translate those offsets to be relative to your scene, e.g. placing that collection of triangles on top of a table. This is the “model” or “world” matrix.
Then, you have to express where those triangles sit in relation to the camera or viewpoint. Is the figurine in the centre of the frame, off to one side in the background etc. This is the “view” matrix.
Finally, you have to translate those 3D coordinates in your world to 2D coordinates on a page. I.e. does the figurine appear on the top left of your page, the centre, does it take up most of the page or is it a tiny detail etc. This is the “projection” matrix.
You then combine all three into a “model view projection matrix” which is a matrix that when you take your figurine’s 3D triangles and multiply them by that matrix, you get a set of 2D coordinates where 0,0 is the centre of your “page”.
Now the renderer draws out the triangles and “colours them in” to draw a single frame of your game. Obviously there is a LOT that goes into the colouring in phase, but outside the scope of this example.
Latest Answers