Skip to content

AnimatedModelInstance

atresica edited this page Sep 2, 2017 · 10 revisions

An extension of ModelInstance. Aside from easily animating position, rotation and scale, this class also adds "lookAt" abilities, positioning objects relative to each other, and showing/hiding them by automatically adding/removing them from the render list in model management. It also enables optional interaction on objects.

@author Tom on the excellent and helpful advice of Xoppa

All widgets in GWTish ultimately extend this, but its also a useful to use for any dynamic objects in your scene. You should probably also look at the PosRotScale class, which simply stores position, rotation and scale separately rather then using a Matrix.


Selective method details copied from javadoc:

void attachThis(IsAnimatableModelInstance objectToAttach, PosRotScale displacement)

Lets you stick one object to another. The object stuck will then inherit rotation/position automatically as if physically attached.

Set getAllAttachments()

Gets all attachments and child attachments.

Quaternion getAngleTo(IsAnimatableModelInstance target)

Method to find the axis-angle between this AnimatableModelInstances and another relative to the xAxis (1,0,0).

Quaternion getAngleTo(IsAnimatableModelInstance target, com.badlogic.gdx.math.Vector3 Axis)

Method to find the axis-angle between this AnimatableModelInstances and another relative to the xAxis.

Quaternion getAngleTo(com.badlogic.gdx.math.Vector3 target, com.badlogic.gdx.math.Vector3 Axis) java.util.Set getAttachments()

Gets all the direct attachments.

PosRotScale getAttachmentsPoint(AnimatableModelInstance object) PosRotScale getAttachmentsPoint(IsAnimatableModelInstance object)

Returns the displacement specification of the specified object from this one (the posrotscale set during attach this).

getName() To help debugging you can optionally give objects a name

IsAnimatableModelInstance getParentObject() If this object has a parent, what is it?

void hide() Hides it by removing it from the render lists.

void hide(boolean setlocalVisibility) There should be a internal boolean to determine if this object "should be" visible. If there is no parent object, this object reflects if this object is visible or not. If there is a parent object, and "inherit visibility" is turned on, then both this localvisibility AND the parents' actual visibility have to be true in order for this object to display.

Thus normally when deliberately hiding/showing a object you also want to set the local visibility variable.

boolean isVisible() Determines if this object is visible or not.

void lookAt(IsAnimatableModelInstance target) Sets this model to "lookat" the target model's vector3 location by aligning this models xAxis(1,0,0) to point at the target's origin.

void lookAt(IsAnimatableModelInstance target, Vector3 Axis) Sets this model to lookat the target model's vector3 location

void lookAt(Vector3 target, Vector3 Axis) Sets this model to lookat the target vector3's location

Vector3 rayHits(com.badlogic.gdx.math.collision.Ray ray) Defaults to intersectRayBounds against bounding box, but you can override for more precision if needed.

void setAsHitable(boolean hitable) Adds it to the hitable list.

void setInheritedVisibility(boolean inheritVisibility) Sets the visibility to be inherited from any parent object.

void setToPosition(Vector3 vector3) Convenient to quickly set the position.

void setToRotation(Quaternion angle) Convenient to quickly set the rotation.

void setToScale(Vector3 scale) Sets the transform of this mesh object to a certain scale. It will also scale all things attached to this, if they have been set to inherit the scale, as well as scaling their relative displacement so they remain attached to the same place.

void setTransform(PosRotScale newState)

void show() Shows it by adding it to the render lists.

void show(boolean setlocalVisibility) There should be a internal boolean to determine if this object "should be" visible. If there is no parent object, this object reflects if this object is visible or not. If there is a parent object, and "inherit visibility" is turned on, then both this localvisibility AND the parents actual visibility have to be true in order for this object to display.

Thus normally when deliberately hiding/showing a object you also want to set the local visibility variable.

void sycnTransform() Should be called after ANY set of change to its transState before it will be reflected in the model visually.

This is done automatically whenever using

  • setToPosition
  • setToRotation
  • setToScale
  • setTransform