-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource1.js
More file actions
66 lines (53 loc) · 1.92 KB
/
Source1.js
File metadata and controls
66 lines (53 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Returns the correct HTML5 rendering loop
window.requestAnimFrame = (function(){
return window.requestAnimationFrame || // IE 10 / Chrome
window.webkitRequestAnimationFrame || // Safari
window.mozRequestAnimationFrame // Firefox
})();
var canvas;
var device;
var mesh;
var meshes = [];
var camera;
function initExample1() {
// Clear device if it is already in use.
if (device !== undefined) {
device.clear();
}
// Create device
canvas = document.getElementById("frontBuffer");
device = new SoftEngineV1.Device(canvas);
// Create camera
camera = new SoftEngineV1.Camera();
// Set camera position
camera.Position = new BABYLON.Vector3(0, 0, 15);
camera.Target = new BABYLON.Vector3(0, 0, 0);
// Create 3d object
mesh = new SoftEngineV1.Mesh("Pyramid", 5);
meshes.push(mesh);
// Set mesh vertices
// Note: Coordinates start in the center of the object
mesh.Vertices[0] = new BABYLON.Vector3(0.5, 0.5, 1);
mesh.Vertices[1] = new BABYLON.Vector3(1, -1, -1);
mesh.Vertices[2] = new BABYLON.Vector3(-1, 1, -1);
mesh.Vertices[3] = new BABYLON.Vector3(-1, -1, -1);
mesh.Vertices[4] = new BABYLON.Vector3(1, 1, -1);
// Pass animation loop as function to call when it's time to update for the next repaint.
var requestID = requestAnimFrame(step);
console.log(requestID);
}
// Animation/Rendering loop handler
// Each tick (optimally every 16ms) a call is made to the handler registered to the rendering loop.
function step() {
// Clear the screen and set all pixes to black.
device.clear();
// Change the position and rotation values of meshes each frame
mesh.Rotation.x += 0.01;
mesh.Rotation.y += 0.01;
// Perform matrix operations and render them to the back buffer
device.render(camera, meshes);
// Display on screen by flushing from back buffer to the front buffer.
device.present();
// Shedule the next animation step
requestAnimFrame(step);
}