-
public class TransformManagerTransformManageris used to add transform components to entities.A transform component gives an entity a position and orientation in space in the coordinate space of its parent transform. The
Creation and destructionA transform component is created using create and destroyed by calling destroy.TransformManagertakes care of computing the world-space transform of each component (i.e. its transform relative to the root).Engine engine = Engine.create(); EntityManager entityManager = EntityManager().get(); int object = entityManager.create(); TransformManager tcm = engine.getTransformManager(); // create the transform component tcm.create(object); // set its transform float[] transform = ...; // transform to set EntityInstance i = tcm.getInstance(object); tcm.setTransform(i, transform)); // destroy the transform component tcm.destroy(object);
-
-
Method Summary
Modifier and Type Method Description booleanhasComponent(int entity)Returns whether a particular Entity is associated with a component of this TransformManagerintgetInstance(int entity)Gets an EntityInstance representing the transform component associated with thegiven Entity. voidsetAccurateTranslationsEnabled(boolean enable)Enables or disable the accurate translation mode. booleanisAccurateTranslationsEnabled()Returns whether the high precision translation mode is active. intcreate(int entity)Creates a transform component and associates it with the given entity. intcreate(int entity, int parent, @Nullable() @Size(min = 16) Array<float> localTransform)Creates a transform component with a parent and associates it with the given entity. intcreate(int entity, int parent, @Nullable() @Size(min = 16) Array<double> localTransform)Creates a transform component with a parent and associates it with the given entity. voiddestroy(int entity)Destroys this component from the given entity, children are orphaned. voidsetParent(int i, int newParent)Re-parents an entity to a new one. intgetParent(int i)Returns the actual parent entity of an EntityInstance originally definedby setParent. intgetChildCount(int i)Returns the number of children of an EntityInstance. Array<int>getChildren(int i, @Nullable() Array<int> outEntities)Gets a list of children for a transform component. voidsetTransform(int i, @NonNull() @Size(min = 16) Array<float> localTransform)Sets a local transform of a transform component. voidsetTransform(int i, @NonNull() @Size(min = 16) Array<double> localTransform)Sets a local transform of a transform component. Array<float>getTransform(int i, @Nullable() @Size(min = 16) Array<float> outLocalTransform)Returns the local transform of a transform component. Array<double>getTransform(int i, @Nullable() @Size(min = 16) Array<double> outLocalTransform)Returns the local transform of a transform component. Array<float>getWorldTransform(int i, @Nullable() @Size(min = 16) Array<float> outWorldTransform)Returns the world transform of a transform component. Array<double>getWorldTransform(int i, @Nullable() @Size(min = 16) Array<double> outWorldTransform)Returns the world transform of a transform component. voidopenLocalTransformTransaction()Opens a local transform transaction. voidcommitLocalTransformTransaction()Commits the currently open local transform transaction. longgetNativeObject()-
-
Method Detail
-
hasComponent
boolean hasComponent(int entity)
Returns whether a particular Entity is associated with a component of this
TransformManager- Parameters:
entity- an Entity
-
getInstance
int getInstance(int entity)
Gets an EntityInstance representing the transform component associated with thegiven Entity.
- Parameters:
entity- an Entity
-
setAccurateTranslationsEnabled
void setAccurateTranslationsEnabled(boolean enable)
Enables or disable the accurate translation mode. Disabled by default.When accurate translation mode is active, the translation component of all transforms ismaintained at double precision. This is only useful if the mat4 version of setTransform()is used, as well as getTransformAccurate().
- Parameters:
enable- true to enable the accurate translation mode, false to disable.
-
isAccurateTranslationsEnabled
boolean isAccurateTranslationsEnabled()
Returns whether the high precision translation mode is active.
-
create
int create(int entity)
Creates a transform component and associates it with the given entity. The component isinitialized with the identity transform.If this component already exists on the given entity, it is firstdestroyed as if destroy was called.
- Parameters:
entity- an Entity to associate a transform component to.
-
create
int create(int entity, int parent, @Nullable() @Size(min = 16) Array<float> localTransform)
Creates a transform component with a parent and associates it with the given entity.If this component already exists on the given entity, it is firstdestroyed as if destroy was called.
- Parameters:
entity- an Entity to associate a transform component to.parent- the EntityInstance of the parent transformlocalTransform- the transform, relative to the parent, to initialize the transformcomponent with.
-
create
int create(int entity, int parent, @Nullable() @Size(min = 16) Array<double> localTransform)
Creates a transform component with a parent and associates it with the given entity.If this component already exists on the given entity, it is firstdestroyed as if destroy was called.
- Parameters:
entity- an Entity to associate a transform component to.parent- the EntityInstance of the parent transformlocalTransform- the transform, relative to the parent, to initialize the transformcomponent with.
-
destroy
void destroy(int entity)
Destroys this component from the given entity, children are orphaned.
- Parameters:
entity- an Entity.If this transform had children, these are orphaned, which means their localtransform becomes a world transform.
-
setParent
void setParent(int i, int newParent)
Re-parents an entity to a new one.
- Parameters:
i- the EntityInstance of the transform component to re-parentnewParent- the EntityInstance of the new parent transform.It is an error to re-parent an entity to a descendant and will causeundefined behaviour.
-
getParent
int getParent(int i)
Returns the actual parent entity of an EntityInstance originally definedby setParent.
- Parameters:
i- the EntityInstance of the transform component to get the parent from.
-
getChildCount
int getChildCount(int i)
Returns the number of children of an EntityInstance.
- Parameters:
i- the EntityInstance of the transform component to query.
-
getChildren
@NonNull() Array<int> getChildren(int i, @Nullable() Array<int> outEntities)
Gets a list of children for a transform component.
- Parameters:
i- the EntityInstance of the transform component to get the childrenfrom.outEntities- array to receive the result sized to the maximum number of children toretrieve.
-
setTransform
void setTransform(int i, @NonNull() @Size(min = 16) Array<float> localTransform)
Sets a local transform of a transform component.
This operation can be slow if the hierarchy of transform is too deep, and thiswill be particularly bad when updating a lot of transforms. In that case,consider using openLocalTransformTransaction / commitLocalTransformTransaction.
- Parameters:
i- the EntityInstance of the transform component to set the localtransform to.localTransform- the local transform (i.e.
-
setTransform
void setTransform(int i, @NonNull() @Size(min = 16) Array<double> localTransform)
Sets a local transform of a transform component.
This operation can be slow if the hierarchy of transform is too deep, and thiswill be particularly bad when updating a lot of transforms. In that case,consider using openLocalTransformTransaction / commitLocalTransformTransaction.
- Parameters:
i- the EntityInstance of the transform component to set the localtransform to.localTransform- the local transform (i.e.
-
getTransform
@NonNull()@Size(min = 16) Array<float> getTransform(int i, @Nullable() @Size(min = 16) Array<float> outLocalTransform)
Returns the local transform of a transform component.
- Parameters:
i- the EntityInstance of the transform component to query thelocal transform from.outLocalTransform- a 16floatarray to receive the result.
-
getTransform
@NonNull()@Size(min = 16) Array<double> getTransform(int i, @Nullable() @Size(min = 16) Array<double> outLocalTransform)
Returns the local transform of a transform component.
- Parameters:
i- the EntityInstance of the transform component to query thelocal transform from.outLocalTransform- a 16floatarray to receive the result.
-
getWorldTransform
@NonNull()@Size(min = 16) Array<float> getWorldTransform(int i, @Nullable() @Size(min = 16) Array<float> outWorldTransform)
Returns the world transform of a transform component.
- Parameters:
i- the EntityInstance of the transform component to query theworld transform from.outWorldTransform- a 16floatarray to receive the result.
-
getWorldTransform
@NonNull()@Size(min = 16) Array<double> getWorldTransform(int i, @Nullable() @Size(min = 16) Array<double> outWorldTransform)
Returns the world transform of a transform component.
- Parameters:
i- the EntityInstance of the transform component to query theworld transform from.outWorldTransform- a 16floatarray to receive the result.
-
openLocalTransformTransaction
void openLocalTransformTransaction()
Opens a local transform transaction. During a transaction, getWorldTransform canreturn an invalid transform until commitLocalTransformTransaction is called.However, setTransform will perform significantly better and in constant time.
This is useful when updating many transforms and the transform hierarchy is deep (say morethan 4 or 5 levels).
If the local transform transaction is already open, this is a no-op.
-
commitLocalTransformTransaction
void commitLocalTransformTransaction()
Commits the currently open local transform transaction. When this returns, callsto getWorldTransform will return the proper value.
Failing to call this method when done updating the local transform will causea lot of rendering problems. The system never closes the transactionautomatically.
If the local transform transaction is not open, this is a no-op.
-
getNativeObject
long getNativeObject()
-
-
-
-