Cube and colors

This documentation was generated with the assistance of AI. Please report any inaccuracies.

Size, position and rotation

The cube is defined in world coordinates, where the y axis points upwards (OpenGL convention). Its size, position and rotation can be changed at any time, before or after the surface is created:

import com.irurueta.geometry.InhomogeneousPoint3D
import com.irurueta.geometry.Quaternion

// Size of the cube edges (default is CubeRenderer.DEFAULT_CUBE_SIZE = 1.0)
cubeView.cubeSize = 0.5f

// Cube center. By default it is placed 2 units in front of the camera
// (0.0, 0.0, CubeRenderer.DEFAULT_CUBE_DISTANCE)
cubeView.cubePosition = InhomogeneousPoint3D(0.0, 0.0, 3.0)

// Cube rotation: any Rotation3D (Quaternion, MatrixRotation3D, AxisRotation3D...)
val rotation = Quaternion()
rotation.setFromEulerAngles(Math.toRadians(30.0), Math.toRadians(45.0), 0.0)
cubeView.cubeRotation = rotation
Property Default Description

cubeSize

CubeRenderer.DEFAULT_CUBE_SIZE (1.0f)

Length of the cube edges. Must be zero or positive, otherwise IllegalArgumentException is thrown.

cubePosition

(0.0, 0.0, CubeRenderer.DEFAULT_CUBE_DISTANCE) = (0, 0, 2)

Position of the cube center, as a Point3D.

cubeRotation

Identity (Rotation3D.create())

Orientation of the cube, as any Rotation3D (Quaternion, MatrixRotation3D, AxisRotation3D…​).

Rotations are applied by reference. If you reuse the same Quaternion instance, assign it again to cubeRotation after modifying it so that a new frame is requested.

Colors

Each vertex of the cube has a fixed color (green, orange, red, yellow, blue, light blue and magenta) and the faces are filled by interpolating them.

import android.graphics.Color

// Default is Color.TRANSPARENT: views behind the cube remain visible
cubeView.clearColor = Color.argb(128, 0, 0, 0) // translucent black background

// Diffuse lighting color (only used when normals are available)
cubeView.diffuseColor = Color.rgb(200, 200, 200)
Property Default Description

clearColor

Color.TRANSPARENT

ARGB color used to clear the scene before drawing the cube. Keep it transparent (or translucent) to compose the cube with the views behind it.

diffuseColor

Color.rgb(127, 127, 127)

Diffuse color used for lighting. Only taken into account when vertex normals are used.

Composing with other views

Because CubeTextureView is a TextureView, it can be animated and transformed like any other view, for instance with alpha, translationX, scaleX or rotation, and it respects the drawing order of its parent. This is not possible with a GLSurfaceView, which is drawn in a separate window.

cubeView.alpha = 0.5f
cubeView.animate().translationX(200f).setDuration(1000L).start()

Next: Camera.