Documentation/Programming Articles/Map System
From NeoAxis Engine Wiki
| Language: | Status: | Approved |
Contents |
Description
Map System is a substructure of the Game Object System that enables object positioning in 3D space, working with physical models etc. The system consists of numerous game classes used for map and map object implementation.
In this article you will find the description of the basic map system classes such as: (Map) and (MapObject) that build upon game classes of the Entity System thereby making functionality of maps and map objects.
We would recommend you to read the Tutorial in creating a simple game object first.
Game classes and basic types
The list of map system game classes and game types (based on these classes) includes:
| Class | Base type | Description |
|---|---|---|
| MapGeneralObject | Base class for all map objects. This one is used as a CHILD by many game classes. ????потомка????. | |
| MapObject | Base class for map objects. Unlike MapGeneralObject it has a map position (set in Position, Rotation, Scale properties). It can also be a subject to physical interactions, since it has a physical model. This one is used as a basic class for many game classes. | |
| StaticMesh | StaticMesh.type | An object used for the creation of a static geometry on the map. |
| CameraAttachedObject | An auxiliary class used for the implementation of camera-following objects. This object may control models, particle systems and billboards and can be used for the creation of advanced (or high-quality) sky or rain. | |
| CubemapZone | CubemapZone.type | This type is used for cubic texture calculation. |
| Fog | Fog.type | Fog. |
| Light | Light.type | Light source. |
| MapCamera | MapCamera.type | This type is used for arranging cameras on the map. |
| MapCameraCurve | MapCameraCurve.type | This type is used for setting camera curve. |
| MapCurve | MapCurve.type | This type is used for setting map curve from point to point. |
| Occluder | Occluder.type | This type is used for portal switch off (it is a component of the portal system). |
| Portal | Portal.type | Portal (a component of the portal system as well) |
| Region | Region.type | Map region. |
| SkyBox | SkyBox.type | Skies implemented as a cubemap. |
| SkyDome | SkyDome.type | Skies implemented as a hemisphere. |
| StaticLightingManager | StaticLightingManager.type | Static light manager (used for creation of precalculated static light). |
| StaticSound | StaticSound.type | Static sound source. |
| Zone | Zone.type | Zone (component of the portal system). |
Object’s map position
Description
In order to set object’s map position the following three parameters are used: Position, Rotation and Scale.
Previous Position
The tick frequency of the game world is not so high (by default it is set to 30 ticks per second). Thus, objects are updated only 30 times per second.
However, the frame rate may be higher than 30 FPS. Therefore, it is necessary to interpolate object position while rendering to make its movement look smooth. For this purpose the information on position from the previous tick is used. The engine is using the information on the previous and the next position of the object to interpolate its position while rendering.
API
MapObject class
| Name | Description | |
|---|---|---|
| |
Vec3 Position | Returns or sets object position. |
| |
Quat Rotation | Returns or sets object rotation. |
| |
Vec3 Scale | Returns or sets object scale. |
| |
Void SetTransform( Vec3 pos, Quat rot, Vec3 scl ) | Sets object position . Use this one if you need to set several parameters. |
| |
Void OnSetTransform( ref Vec3 pos, ref Quat rot, ref Vec3 scl ) | A method called on object position change. |
| |
Vec3 OldPosition | Returns or sets the previous object position. |
| |
Quat OldRotation | Returns or sets the previous object rotation. |
| |
Vec3 OldScale | Returns or sets the previous object scale. |
| |
Void SetOldTransform( Vec3 pos, Quat rot, Vec3 scl ) | Returns the previous object position. |
| |
Vec3 GetInterpolatedPosition() | Returns an interpolated object position. |
| |
Quat GetInterpolatedRotation() | Returns an interpolated object rotation. |
| |
Vec3 GetInterpolatedScale() | Returns an interpolated object scale. |
| |
Void GetInterpolatedTransform( out Vec3 pos, out Quat rot, out Vec3 scl ) | Returns an interpolated object position. |
Working with Attached Objects
Description
Any object of the game world has some physical properties. This can be a 3D model, effects or sound.
This is implemented the following way: any MapObject has its list of attached objects. Thus, various resources can be attached to the game object including:
- 3D models
- Particle systems
- Billboards
- Ленты траекторий
- Light sources
- In-game UI
- Sounds
- Game objects. You can attach any game object to another game object (this can be used for the creation of complex dynamic constructions). For example, you can attach a machine gun to a helicopter (keeping the machine gun functionality). You can also use this system to attach arms and armor to characters.
There is a number of ways how an object can be attached: relative to game object’s position, directly to object’s physical model or to the skeleton bones of a 3D model.
Resource Editor
You can adjust attached objects in the Game Objects Editor. For work with attached objects the AttachedObjects property is used.
You can learn more about working with attached objects in the Resource Editor here.
Run-time
You can not only attach game objects in the game type but also do this during simulation (e.g. attach a gun to the character when he picks it up).
Below you can see a list of classes that can be attached:
- Game objects - MapObjectAttachedMapObject
- 3D models - MapObjectAttachedMesh
- Particle systems - MapObjectAttachedParticle
- Billboards - MapObjectAttachedBillboard
- Ленты траекторий - MapObjectAttachedRibbonTrail
- Light sources - MapObjectAttachedLight
- In-game UI - MapObjectAttachedGui
- Sounds - MapObjectAttachedSound
- Helper objects - MapObjectAttachedHelper
Example
Attaching a particle system:
MapObject obj = ...; MapObjectAttachedParticle attachedParticle = new MapObjectAttachedParticle(); attachedParticle.SetParticleSystem( "SmokeParticle" ); obj.Attach( attachedParticle );
API
MapObject class
| Name | Description | |
|---|---|---|
| |
void Attach( MapObjectAttachedObject attachedObject ) | Object attachment. |
| |
void Detach( MapObjectAttachedObject attachedObject ) | Object detachment. |
| |
void OnAttach( MapObjectAttachedObject attachedObject ) | A method called on object attachment. |
| |
void OnDetach( MapObjectAttachedObject attachedObject ) | A method called on object detachment. |
| |
MapObjectAttachedObject[] AttachedObjects | Displays the list of attached objects. |
| |
MapObject AttachedMapObjectParent | Ruturns the object to which the given object is attached (if there is one). |
| |
MapObjectAttachedObject GetAttachedObjectByAlias( String alias ) | Returns the attached object by its alias. |
Object sampling
Description
It is often necessary to make a list of object located in a certain region. To do this you can go over all objects selecting those you need. However, with a large number of objects on the map this can take a long time, so there is a function for selecting certain objects in an area.
The Map class contains methods for object sampling in regions of various forms????:
- Sampling by size
- Sampling by sphere
- Sampling by parallelepiped
- Sampling by ray
- Sampling by camera frustum
- Sampling by list of clip planes
- Sampling by screen rectangle
Sampling is performed by object dimensions (the MapBounds property). This property is automatically calculated taking into account the size of object's 3D and physical model etc.
The engine supports object creation and removal during sampling.
Sampling by groups is also available and enables even greater increase of performance.
Example
Sampling by size.
Bounds bounds = new Bounds( new Vec3( 10, 10, 10 ), new Vec3( 20, 20, 20 ) ); Map.Instance.GetObjects( bounds, delegate( MapObject obj ) { ... //Some work with "obj" } );
API
Map class