Knowledge Base » What's the root entity of the Untold Engine

Game characters, images, sprites, particles inherits their rendering, transformation and dynamic behaviors from parent classes.

For example, a 3D game character inherits its behaviors from:

  • Root Entity: Provides Transformation properties
  • Visible Entity: Provides Rendering properties
  • 3D Model Entity: Provides Attributes buffers
  • Static Model Entity: Enables Collision Behaviors
  • Dynamic Model Entity: Enables Physics Behaviors
Image

Fundamental Entity Classes

Root Entity

The Untold Engine's root entity is the U4DEntity class. All entities such as 3D models, buttons, particle systems, camera, etc inherit behaviors from the U4DEntity class.

The class is composed of dual quaternion objects that holds the local and absolute space of the entity. It also contains a U4DEngine::U4DTransformation object in charge of doing Linear Algebra operations such as Translation and Rotation

class U4DEntity{

    public:

    //entity local space
    U4DDualQuaternion localSpace;

    //entity absolute space
    U4DDualQuaternion absoluteSpace:

    //pointer to object in charge of the space coordinate transformation
    U4DTransformation *transformation;

    //Primary Method
    virtual void update(double dt);

}

Moreover, the class is capable of having children nodes, as in the case of a scenegraph data structure.

Visible Entity

The U4DVisibleEntity class represents all entities visible to the user. That is, entities that are rendered. This class provides a pointer to the U4DRenderManager class and loads the rendering information into the GPU. The class also provides a virtual render() method which renders the entity according to the subclasses configurations.

class U4DVisibleEntity:public U4DEntity{
    
    public:

    //Pointer to the render manager. The render manager is in charge of selecting the correct shader and loading attributes data into the GPU buffers
    U4DRenderManager *renderManager;

    //Primary Methods

    //Render the entity
    virtual void render(id<MTLRenderCommandEncoder> uRenderEncoder);

    //load attribute data into the allocated GPU buffers
    void loadRenderingInformation();

}

3D Model Entity

The U4DModel class represents a 3D model entity. It holds rendering information pertaining to the 3D model, such as vertices, normal vectors, UV coordinates, textures, material and armature (animation) information.

class U4DModel:public U4DVisibleEntity{

    public:

    //vertices, normal vectors, UV coordinates data
    U4DVertexData bodyCoordinates;

    //Diffuse, specular material data
    U4DMaterialData materialInformation;

    //texture data
    U4DTextureData textureInformation;

    //Bone armature data
    U4DArmatureData *armatureManager;

    //Faces, edges and vertex polygon information
    U4DPolygonData polygonInformation;

}

Static Model Entity

The U4DStaticModel class represents a static model. i.e., no moveable. It holds information pertaining to Collision, such as convex hull data, mass, moment of inertia, collision filters.

class U4DStaticModel:public U4DModel{

    public:

    //Contains Convex Hull data for the entity used for collision
    U4DBoundingVolume *convexHullBoundingVolume;

    //Contains Sphere Bounding Volume data for the entity used for collision
    U4DBoundingVolume *broadPhaseBoundingVolume;

    //Pointer to the Octree Mesh manager
    U4DMeshOctreeManager *meshOctreeManager; 

    //Mass properties i.e. moment of inertia, mass, center of mass
    MassProperties massProperties;

    //Contact collision points, normal force vector
    CollisionProperties collisionProperties;

    //Convex Hull vertices
    ConvexHullProperties convexHullProperties;

    //Primary Method

    //Computes the Convex Hull, Sphere Volume and enables the Collision Detection System to act on the entity
    void enableCollisionBehavior();
}

Dynamic Model Entity

The U4DDynamicModel inherits the collision properties from U4DEngine::U4DStaticModel and it adds dynamic properties such as velocity, acceleration, moment, force, drag, etc.

class U4DDynamicModel:public U4DStaticModel{

    public:

    //Entity Velocity
    U4DVector3n velocity;

    //Entity Acceleration
    U4DVector3n acceleration;

    //Entity accumulated forces
    U4DVector3n force;

    //Primary Method

    //Enables the Physics Engine to act on the entity
    void enableKineticsBehavior();

    //Adds forces acting on the entity
    void addForce(U4DVecto3n &uForce);

}

Game Object Entity

The U4DGameObject class represents a complete 3D game character with static and dynamic characteristics. i.e. able to collide and move in a game.

class U4DGameObject:public U4DDynamicModel{

    public:

    //Primary Method
    virtual void update(double dt);

    //Loads attribute data into the buffer
    bool loadModel(const char* uModelName, const char* uBlenderName);

    //loads animation data into the animation buffer
    bool loadAnimationToModel(U4DAnimation *uAnimation, const char *uAnimationName, const char *uBlenderName);
}

Creating a U4DGameObject

The steps to create a U4DGameObject are as follows:

//Line 1. The U4DMeshAssetLoader is in charge of loading the binary file containing the scene data
U4DEngine::U4DMeshAssetLoader *meshAssetLoader=U4DEngine::U4DMeshAssetLoader::sharedInstance();

//Line 1a.Load binary file with scene data
meshAssetLoader->loadSceneData("spaceAttributes.u4d");

//Line 1b. Load binary file with texture data
meshAssetLoader->loadTextureData("astronautTextures.u4d");

//Line 2. Create an instance of U4DGameObject type
U4DEngine::U4DGameObject *myAstronaut=new U4DEngine::U4DGameObject();

//Line 3. Load attribute (rendering information) into the game entity
if (myAstronaut->loadModel("astronaut")) {

    //Line 4. Load rendering information into the GPU
    myAstronaut->loadRenderingInformation();

    //Line 5. Add astronaut to the scenegraph
    addChild(myAstronaut);

}

When a U4DGameObject is created the following properties are initialized/allocated:

  • Local and Absolute Space (U4DEntity)
  • GPU Buffer (U4DVisibleEntity)
  • Data Buffers for Attributes (U4DModel)
  • Collision Behaviors (U4DStaticModel)
  • Physics Behaviors (U4DDynamicModel)

However, the creation of a U4DGameObject does not fill the buffers with data. It merely allocates memory for the U4DGameObject.

To fill the buffers with data, the user must call the loadModel() method (as shown in line 2)and provide a pointer to the file containing the attribute data for the 3D model. Upon successful execution of this function, the Attribute Buffers are filled with data.

Lastly, to send the attribute data to the GPU, the user must call the loadRenderingInformation() method. The U4DRenderManager provided by the U4DVisibleEntity loads the GPU Attribute buffers and initializes the correct shaders for rendering.