welcome to linkAR technical documentation

next

previous

Transformations

You can apply these transformations to any Bone object. As explained here, Bones are parts of the model that you can move, rotate and scale.

8.1- Rotation

The rotation is applied to the objects considering each object axis orientation. This means that the axis do not usually correspond to the world axis, but each object has a different axis orientation.
We can set the model initial rotation offset:

/** Set Model initial rotation offset*/
gl3DEngine.setModelRotationOffset(MainModelRootID,90, 0, 0);	


Other samples of rotation:

float fAngleSky = 0.0f;
float[] tempArray = new float[3] ;
 
float head_rotation_angle=0;
boolean head_rotation_b=true;
final double HEAD_MAX_ROTATION=360/10;
private static final int HEAD_STEP_ROTATION = 360/200;

Applies the sky rotation inside the onRenderFrame() function:

if (fAngleSky > 3600.0f)
   fAngleSky = 0.0f;
fAngleSky += 0.75f;
 
tempArray[0] = 0.0f;
tempArray[1] = -fAngleSky/10.0f;
tempArray[2] = 0.0f;
 
/** Set model rotation (applied to 3 axes)*/
gl3DEngine.setModelRotation(skyModelID, tempArray);

Applies the head rotation inside the onRenderFrame() function:

if(head_rotation_b){
   head_rotation_angle+=HEAD_STEP_ROTATION;
   if(head_rotation_angle>HEAD_MAX_ROTATION)
      head_rotation_b=!head_rotation_b;
}else{
   head_rotation_angle-=HEAD_STEP_ROTATION;
   if(head_rotation_angle<-HEAD_MAX_ROTATION)
      head_rotation_b=!head_rotation_b;
}
tempArray[0] = 0.0f;
tempArray[1] = 0.0f;
tempArray[2] = head_rotation_angle;
 
/** Set model rotation (applied to 3 axes)*/
gl3DEngine.setModelRotation(HeadModelID, tempArray);

Additional graphic:

8.2- Scale

To scale an object you will need to give each axis a separate scale factor. Consider the following:

  • 0 < k < 1: The object size is reduced.
  • k > 1: The object size is incremented.
  • k < 0: The object is inverted.
float[] modelScale = new float[] {2.0f,2.0f,2.0f};
/** Set Model initial scale*/
gl3DEngine.setModelScale(MainModelRootID, modelScale);

8.3- Translation

To translate an object you will need to give each axis a separate position value.

float fAngle = 0.0f;

Applies the model movement around its position (FLOATING EFFECT) inside the onRenderFrame() function.

//function
if (fAngle > 360.0f)
   fAngle = 0.0f;
fAngle += 0.75f;
 
float s = (float) Math.sin(fAngle/8.0f),
c = (float) Math.cos(fAngle/8.0f);
 
tempArray[0] = c+s + 10;
tempArray[1] = s + c -5;
tempArray[2] = s+c + 10;
 
/** Set model positing (Move model to other value*/
gl3DEngine.setModelPosition(MainModelRootID, tempArray);

8.4- Model matrix

If you calculate the matrix to apply to an object, you can apply it directly (note that this will affect the rotate/scale/translate values).

In this case we will use the SensorDataManager provided inside the library to get the device orientation matrix. Using that matrix will move the girl model according to the device orientation.

// Sensor manager instance variable
private SensorDataManager sensorDataManager; 
/** Initiate sensor manager in onCreate() function */
sensorDataManager = new SensorDataManager(this, false);

These functions are necessary for the class to work properly.

@Override protected void onPause() {
   super.onPause();
   sensorDataManager.stopSensorReading();
}
 
@Override protected void onResume() {
   super.onResume();
   sensorDataManager.startSensorReading();
}

Finally set the class calculated matrix to the model. In this case we want the whole girl scene to be moved altogether, so we apply it to the MainModelRoot world.

/** Apply rotation matrix to the model (The model gets the ability to move)*/
gl3DEngine.setModelMatrix(MainModelRootID, sensorDataManager.getCurrentRotationMatrix());

Quaternion vector:

Additional Information

next

previous