How do game programmers define what 3D objects are?

450 viewsOtherTechnology

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

9 Answers

Anonymous 0 Comments

It’s basically just a list of 3D coordinates that defines the geometry of the crate, along with a list of integers that tells you in which order you need to connect the 3D coordinates. A 1x1x1 box would just look like:

(0,0,0),(1,0,0),(1,1,0),(0,1,0),(0,0,1),(1,0,1),(1,1,1),(0,1,1)

and then the indices of those coordinates that tells the computer which points to connect. The most basic style is to give the computer a list of triangles to render. For example, to render one side of the box, you’d need to render two triangles, and each would use 3 of the 4 coordinates for the corners of the box:

0,1,2 (first triangle) 1,2,3 (second triangle).

To add textures or colors to the box, you’d include more coordinates (0,0,0,0) instead of (0,0,0) where the additional coordinate tells you what part of the texture image aligns with that corner of the box.

You are viewing 1 out of 9 answers, click here to view all answers.