How do game programmers define what 3D objects are?

456 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

There are systems programmed in the engine to handle each thing, lets simplify it to only rendering and physics.

The crate would have some data in a model file which would tell the renderer how to make the visual model of it using polygons (mostly triangles), with different locations, sizes and orientations. It doesn’t matter exactly how this is stored (vertices and indexes etc)

Using the positions and strengths of lights in the scene, and the angle between faces and light sources, the colour for each pixel on the screen is calculated in the graphics pipeline

The physics engine would use simple 3d geometry to have a collision box or hitbox which would be used to calculate when objects overlap and make an appropriate response to mimic the effect of solid objects

The most basic hitbox is a sphere, with position and radius, then there’s an axis aligned cuboid, with position, x y and z dimensions, and then more complex shapes like orientable boxes, capsules etc can be written

Physics objects have the same mass, velocities, forces that they do in real life (inverse mass is a thing but not important), and since we have known equations of motion (Force = Mass x Acceleration, Distance = Speed x Time etc) it is relatively straight forward to simulate motion like this, and then just update the positions of the objects so the renderer moves the visuals appropriately

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