Basic Rotating Cube
# Itroduction
This example demonstrates how to create a basic 3d application with ClayGL
# Main Code
x
1
var app = clay.application.create('#viewport', {
2
3
init: function (app) {
4
5
// Create a perspective camera.
6
// First parameter is the camera position. Which is in front of the cube.
7
// Second parameter is the camera lookAt target. Which is the origin of the world, and where the cube puts.
8
this._camera = app.createCamera([0, 2, 5], [0, 0, 0]);
9
10
// Create a sample cube
11
this._cube = app.createCube();
12
13
// Create a directional light. The direction is from top right to left bottom, away from camera.
14
this._mainLight = app.createDirectionalLight([-1, -1, -1]);
15
},
16
17
loop: function (app) {
18
// Simply rotating the cube every frame.
19
this._cube.rotation.rotateY(app.frameTime / 1000);
20
}
21
});