Class TWorld3D

Unit

Declaration

type TWorld3D = class(TObject)

Description

The world.

TWorld3D contains all objects, lights and the camera used to render a scene.

See also
TWorld3D.OwnsObjects
Should free the objects when they are removed.

Hierarchy

  • TObject
  • TWorld3D

Overview

Methods

Public CONSTRUCTOR Create;
Public DESTRUCTOR Destroy; OVERRIDE;
Public procedure SetAmbientLight (aValue: TColorDescription);
Public PROCEDURE SetFog ( CONST aColor: TColorDescription; CONST aDensity: GLfloat; CONST aHint: GLint = GL_DONT_CARE ); OVERLOAD;
Public PROCEDURE SetFog ( CONST aColor: TColorDescription; CONST aStart, aFinish: GLfloat; CONST aHint: GLint = GL_DONT_CARE ); OVERLOAD;
Public PROCEDURE SetOpenGLContext; VIRTUAL;
Public procedure DisableOpenGLContext;
Public PROCEDURE ClearObjects;
Public FUNCTION AddObject (CONST aObject: TObject3D): INTEGER;
Public PROCEDURE DeleteObject (CONST Ndx: INTEGER); OVERLOAD;
Public PROCEDURE DeleteObject (CONST aObject: TObject3D); OVERLOAD;
Public FUNCTION ExtractObject (CONST Ndx: INTEGER): TObject3D; OVERLOAD;
Public FUNCTION ExtractObject (CONST aObject: TObject3D): TObject3D; OVERLOAD;
Public PROCEDURE CheckCollisions;
Public function CheckSphereCollision ( const aCenter: TVector3D; const aRadius: Real; const aId: Integer=0 ): Boolean;
Public function CheckSphereCollisionWithTags ( const aCenter: TVector3D; const aRadius: Real; const aTag: Integer; const aAnd: Boolean=False ): Boolean;
Public PROCEDURE Render;

Properties

Public property Size: GLfloat READ fSize;
Public property RenderBounding: BOOLEAN READ fDrawBounding WRITE fDrawBounding;
Public property OwnsCamera: Boolean read fOwnsCamera write fOwnsCamera;
Public property Camera: TCamera READ fCamera WRITE SetCamera;
Public property OwnsSkybox: Boolean read fOwnsSkybox write fOwnsCamera;
Public property Skybox: TModel3D READ fSkyBox WRITE SetSkybox;
Public property Lights[Ndx:INTEGER]: TLight READ GetLight;
Public property UseFog: BOOLEAN READ fUseFog WRITE fUseFog;
Public property Heightmap: THeightmap read fHeightmap;
Public property OwnsObjects: Boolean read GetOwnsObjects write SetOwnsObjects;
Public property NumObjects: INTEGER READ GetNumObjects;
Public property Objects[Ndx:INTEGER]: TObject3D READ GetObject WRITE SetObject;
Public property Octree: TOctree READ fOctree;

Description

Methods

Public CONSTRUCTOR Create;

Create an empty world.

It creates an empty world with an octree of default size and depth.

See also
DefaultWorldSize
Default world size.
DefaultOctreeDepth
Default octree depth.
TWorld3D.Octree
Access to octree.
Public DESTRUCTOR Destroy; OVERRIDE;

Destructor.

If OwnsObjects is True it will destroy the Objects.

Public procedure SetAmbientLight (aValue: TColorDescription);

Set ambient light values.

Public PROCEDURE SetFog ( CONST aColor: TColorDescription; CONST aDensity: GLfloat; CONST aHint: GLint = GL_DONT_CARE ); OVERLOAD;

Defines the fog as exponential (GL_EXP).

Public PROCEDURE SetFog ( CONST aColor: TColorDescription; CONST aStart, aFinish: GLfloat; CONST aHint: GLint = GL_DONT_CARE ); OVERLOAD;

Defines the fog as linear (GL_LINEAR).

Parameters
aColor
Fog color.
aDensity
Fog density.
aStart
Where fog starts.
aFinish
Where fog ends.
aHint
OpenGL Hint. Can be GL_NICEST, GL_FASTEST or GL_DONT_CARE. Default is GL_DONT_CARE.
See also
TWorld3D.UseFog
Activates or deactivates the fog.
Public PROCEDURE SetOpenGLContext; VIRTUAL;

Enable OpenGL context, setting lighting, face culling, depth-buffer and 2D textures.

See also
TWorld3D.DisableOpenGLContext
Disable OpenGL context.
TWorld3D.UseFog
Activates or deactivates the fog.
Public procedure DisableOpenGLContext;

Disable OpenGL context.

You may need to disable the OpenGL contex when drawing the HUD or other overlays.

Remember to restore the OpenGL context before to render the world.

See also
TWorld3D.SetOpenGLContext
Enable OpenGL context, setting lighting, face culling, depth-buffer and 2D textures.
TWorld3D.UseFog
Activates or deactivates the fog.
Public PROCEDURE ClearObjects;

Remove all objects from the list.

It also frees all objects in the list if OwnsObjects is True.

Public FUNCTION AddObject (CONST aObject: TObject3D): INTEGER;

Adds a new object.

You should not add the same object twice to the list. Note that when OwnsObjects is True this will result in memory corruption when the object is freed (as it will be freed twice). The Add method does not check this, however

Parameters
aObject
Reference to the object.
Returns

The object index.

See also
TWorld3D.DeleteObject
Deletes and frees an object from the list.
TWorld3D.ExtractObject
Removes Item from the list, if it is present in the list.
Public PROCEDURE DeleteObject (CONST Ndx: INTEGER); OVERLOAD;

Deletes and frees an object from the list.

Public PROCEDURE DeleteObject (CONST aObject: TObject3D); OVERLOAD;

Deletes and frees an object from the list.

DeleteObject removes the object from the list. When OwnsObjects is True, the object is also freed.

See also
TWorld3D.ExtractObject
Removes Item from the list, if it is present in the list.
TWorld3D.OwnsObjects
Should free the objects when they are removed.
TWorld3D.AddObject
Adds a new object.
TWorld3D.ClearObjects
Remove all objects from the list.
Public FUNCTION ExtractObject (CONST Ndx: INTEGER): TObject3D; OVERLOAD;

Removes Item from the list, if it is present in the list.

Public FUNCTION ExtractObject (CONST aObject: TObject3D): TObject3D; OVERLOAD;

Removes Item from the list, if it is present in the list.

Note that the object is not freed, and that only the first found object is removed from the list.

Returns

the object if it is found, Nil if object is not present in the list.

See also
AddObject
Adds a new object.
DeleteObject
Deletes and frees an object from the list.
ClearObjects
Remove all objects from the list.
Public PROCEDURE CheckCollisions;

Check collisions and notify the objects when a collision is detected.

This method will check collisions of objects and the heightmap. The collision is notified using the TObject3D.OnCollision event passing the reference of the other object implied in the collision or Nil if the collision is with the heightmap.

Note it ignores the heigtmap if it isn't visible (i.e. its Visible property is False). To ignore collisions of objects set their Radius to zero or a negative value. This means it will check collisions of invisible objects too.

See also
TObject3D.Radius
Bounding sphere radius.
TObject3D.UseBoundingBox
To know if use the Bounding box for colission checking.
TObject3D.CheckCollision
Check if object collided with another object.
TObject3D.OnCollision
Event to notify collisions.
TWorld3D.CheckSphereCollision
Check if the sphere collides with objects in the world.
TWorld3D.CheckSphereCollisionWithTags
Check if the sphere collides with objects in the world with given tag.
Public function CheckSphereCollision ( const aCenter: TVector3D; const aRadius: Real; const aId: Integer=0 ): Boolean;

Check if the sphere collides with objects in the world.

If paramter aId is assinged and it is different to 0, then it will only check objects where its Id is the same value.

Parameters
aCenter
Center point coordinates of the sphere.
aRadius
Radius of the sphere.
aId
Filter objects by its Id.
See also
TWorld3D.CheckCollisions
Check collisions and notify the objects when a collision is detected.
TWorld3D.CheckSphereCollisionWithTags
Check if the sphere collides with objects in the world with given tag.
TObject3D.Id
Object identifier.
Public function CheckSphereCollisionWithTags ( const aCenter: TVector3D; const aRadius: Real; const aTag: Integer; const aAnd: Boolean=False ): Boolean;

Check if the sphere collides with objects in the world with given tag.

This will check collisions with objects which its Tag property is the same that the value pased as aTag parameter.

If aAnd parameter is assigned to True, then both tags will be combined using the AND operator and only those that retun a value different than 0 (zero) will be checked.

Parameters
aCenter
Center point coordinates of the sphere.
aRadius
Radius of the sphere.
aTag
The tag of the objects to check with.
aAnd
If True, it will use operator AND, if False, it will use operator = (equals).
See also
TWorld3D.CheckCollisions
Check collisions and notify the objects when a collision is detected.
TWorld3D.CheckSphereCollision
Check if the sphere collides with objects in the world.
TEntity3D.Tag
A tag value.
Public PROCEDURE Render;

Renders the world.

This method needs the viewport and OpenGL context to be set before.

See also
TWorld3D.Skybox
The skybox.
TWorld3D.Camera
Reference to the active camera.
TWorld3D.Heightmap
Heightmap.
TWorld3D.RenderBounding
If True it renders bounding boxes and/or spheres too.
TCamera.SetPerspectiveProjection
Change the camera projection matrix for perspective projection.
TCamera.SetOrthographicProjection
Change the camera projection matrix for orthographic (paralel) projection.
TWorld3D.SetOpenGLContext
Enable OpenGL context, setting lighting, face culling, depth-buffer and 2D textures.

Properties

Public property Size: GLfloat READ fSize;

Universe size.

Size is the size of the Octree's root node.

This is just informative and it doesn't have any effect in behavior of the game.

Public property RenderBounding: BOOLEAN READ fDrawBounding WRITE fDrawBounding;

If True it renders bounding boxes and/or spheres too.

Public property OwnsCamera: Boolean read fOwnsCamera write fOwnsCamera;

Should free the Camera when removed.

If you're using various cameras, this should be False.

Default is True.

Public property Camera: TCamera READ fCamera WRITE SetCamera;

Reference to the active camera.

See also
TWorld3D.OwnsCamera
Should free the Camera when removed.
Public property OwnsSkybox: Boolean read fOwnsSkybox write fOwnsCamera;

Should free the SkyBox when removed.

Default is True.

Public property Skybox: TModel3D READ fSkyBox WRITE SetSkybox;

The skybox.

If you don't use skybox just assign Nil.

See also
TWorld3D.OwnsSkybox
Should free the SkyBox when removed.
Public property Lights[Ndx:INTEGER]: TLight READ GetLight;

List of lights.

By default, all lights are disabled.

Public property UseFog: BOOLEAN READ fUseFog WRITE fUseFog;

Activates or deactivates the fog.

See also
SetFog
Defines the fog as linear (GL_LINEAR).
Public property Heightmap: THeightmap read fHeightmap;

Heightmap.

Public property OwnsObjects: Boolean read GetOwnsObjects write SetOwnsObjects;

Should free the objects when they are removed.

Public property NumObjects: INTEGER READ GetNumObjects;

The number of elements in the list. Note that this includes Nil elements.

Public property Objects[Ndx:INTEGER]: TObject3D READ GetObject WRITE SetObject;

Indexed access to the elements in the list.

The index Ndx is zero based, i.e., runs from 0 (zero) to NumObjects - 1.

See also
AddObject
Adds a new object.
TWorld3D.OwnsObjects
Should free the objects when they are removed.
Public property Octree: TOctree READ fOctree;

Access to octree.

You can use this method to change the octree properties such as size and Depth.


Generated by PasDoc 0.15.0. Generated on 2025-07-31 11:41:01.