Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
74 lines (60 sloc) 2.24 KB
<!DOCTYPE html>
<html>
<head>
<title>
CubicVR.js: Lathe test - Torus /w Scene and MouseViewController
</title>
<script src="../../CubicVR.js" type="text/javascript">
</script>
<script type='text/javascript'>
// Simple torus using lathe
function makeTorus(radius, thick, lat) {
var pointList = new Array();
var M_TWO_PI = Math.PI * 2.0;
// generate a circle on the right side (radius) of the X/Y axis, circle radius of (thick)
for (var i = 0; i <= M_TWO_PI; i += (M_TWO_PI / lat)) {
pointList.push([radius + Math.cos(i) * thick, Math.sin(i) * thick, 0]);
}
var torusMesh = new CubicVR.Mesh({
primitive: {
type: "lathe",
divisions: lat,
points: pointList,
material: {
textures: {
color: new CubicVR.Texture("../images/2062-diffuse.jpg")
}
},
uv: {
projectionMode: "planar",
projectionAxis: "y",
scale: [0.5, 0.5, 0.5]
}
},
compile: true
});
return torusMesh;
}
function webGLStart(gl,canvas) {
// New scene with our canvas dimensions and default camera with FOV 80
var scene = new CubicVR.Scene(canvas.width, canvas.height, 80);
// SceneObject container for the mesh
var sceneObj = new CubicVR.SceneObject(makeTorus(0.75, 0.3, 24));
// Add SceneObject containing the mesh to the scene
scene.bind(sceneObj);
// set initial camera position and target
scene.camera.position = [1, 1, 1];
scene.camera.target = [0, 0, 0];
// Add our scene to the window resize list
CubicVR.addResizeable(scene);
// Start our main drawing loop, it provides a timer and the gl context as parameters
CubicVR.MainLoop(function(timer, gl) {
scene.render();
});
// initialize a mouse view controller
mvc = new CubicVR.MouseViewController(canvas, scene.camera);
}
</script>
</head>
<body onLoad="CubicVR.start('auto',webGLStart);"></body>
</html>