Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: e84232eac3
Fetching contributors…

Cannot retrieve contributors at this time

187 lines (160 sloc) 6.641 kb
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
overflow: hidden;
}
</style>
<script src="lib/jsmodplayer/src/modfile.js"></script>
<script src="lib/jsmodplayer/src/xmfile.js"></script>
<script src="lib/jsmodplayer/src/modplayer.js"></script>
<script src="lib/jsmodplayer/src/support.js"></script>
<script src="lib/cubicvr/CubicVR.js"></script>
<script src="lib/dsp.js"></script>
<script src="js/audio.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function (e) {
var canvas = document.createElement('canvas');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var gl = CubicVR.GLCore.init(canvas, 'lib/cubicvr/CubicVR_Core.vs', 'lib/cubicvr/CubicVR_Core.fs');
if (!gl) {
return;
}
var fft;
var audioBuffer;
var signal = new Float32Array(4096);
var audioEngine = new AudioEngine(function (data) {
fft.forward(data);
audioBuffer = data;
for (var i=0, l=4096; i<l; ++i) {
if (fft.spectrum[i] > signal[i]) {
signal[i] = fft.spectrum[i];
}
else {
signal[i]*=0.45;
} //if
} //for
});
audioEngine.playMod('mod.mod');
audioEngine.audioObject.volume = 1;
fft = new FFT(4096, 44100);
var logoMaterial = new CubicVR.Material({
textures: {
color: new CubicVR.Texture("img/logo.jpg"),
alpha: new CubicVR.Texture("img/logo-alpha.jpg"),
},
opacity: 0.99,
});
var logoMesh = CubicVR.primitives.plane({
size: 1.0,
material: logoMaterial,
uvmapper: {
projectionMode: CubicVR.enums.uv.projection.PLANAR,
projectionAxis: CubicVR.enums.uv.axis.Z,
scale: [1, 1, 1]
}
});
logoMesh.triangulateQuads().compile().clean();
var floorMaterial = new CubicVR.Material({
color: [.4, .4, .4],
opacity: 1,
});
var uvplanar = {
projectionMode: CubicVR.enums.uv.projection.PLANAR,
projectionAxis: CubicVR.enums.uv.axis.Y,
scale: [0.5, 0.5, 0.5]
};
function makeCylinderLathe(mesh, height, inner_radius, outer_radius, res, material, uvmapper) {
var pointList = new Array();
var thick = outer_radius-inner_radius;
var radius = inner_radius+(thick)/2.0;
var transform;
pointList.push([inner_radius, 0, 0]);
pointList.push([inner_radius+thick, 0, 0]);
pointList.push([inner_radius+thick, height, 0]);
pointList.push([inner_radius, height, 0]);
pointList.push([inner_radius, 0, 0]);
CubicVR.genLatheObject(mesh, pointList, res, material, transform, uvmapper);
}
var scene = new CubicVR.Scene(canvas.width, canvas.height, 80);
var SOUND_FLOOR_RINGS = 25,
SOUND_FLOOR_Y = -3,
SOUND_FLOOR_H = 2.0,
SOUND_FLOOR_SPACING = 0.35,
MAX_WIDTH = 15;
var soundFloorRings = [];
for (var i=0; i<SOUND_FLOOR_RINGS; ++i) {
var soundFloorMesh = new CubicVR.Mesh();
makeCylinderLathe(soundFloorMesh, SOUND_FLOOR_H, i*MAX_WIDTH/SOUND_FLOOR_RINGS, (i+1)*MAX_WIDTH/SOUND_FLOOR_RINGS-SOUND_FLOOR_SPACING, 3, floorMaterial, uvplanar);
soundFloorMesh.triangulateQuads().compile().clean();
var soundFloorObject = new CubicVR.SceneObject(soundFloorMesh);
scene.bindSceneObject(soundFloorObject);
soundFloorRings.push(soundFloorObject);
soundFloorObject.targetY = SOUND_FLOOR_Y;
soundFloorObject.rotation[1] = 3*i;
} //for
function updateSoundFloor(seconds) {
for (var i=0; i<SOUND_FLOOR_RINGS; ++i) {
var newY = SOUND_FLOOR_Y + fft.spectrum[2*(i)] * 10;
var ring = soundFloorRings[i];
if (ring.targetY < newY) {
ring.targetY = newY;
} //if
ring.position[1] -= (ring.position[1] - ring.targetY)*.25;
ring.targetY = Math.max(ring.targetY - 0.01, SOUND_FLOOR_Y);
//ring.rotation[1] -= (SOUND_FLOOR_RINGS - i) * 0.05;
ring.rotation[1] = Math.sin(seconds + (SOUND_FLOOR_RINGS-i)*0.1)*120;
} //for
}; //updateSoundFloor
var logoObject = new CubicVR.SceneObject(logoMesh);
// bind this last because of depth buffer quirks
scene.bindSceneObject(logoObject);
scene.camera.position = [1, 0.5, -1];
scene.camera.target = [0, 0, 0];
/*
planeObject.motion = new CubicVR.Motion();
planeObject.motion.setKey(CubicVR.enums.motion.ROT, 1, 0, 0);
planeObject.motion.setKey(CubicVR.enums.motion.ROT, 1, 2.5, -180).tension = 1;
planeObject.motion.setKey(CubicVR.enums.motion.ROT, 1, 5, 360).tension = 1;
planeObject.motion.setKey(CubicVR.enums.motion.ROT, 1, 6, 360);
planeObject.motion.setBehavior(CubicVR.enums.motion.ROT, 1, CubicVR.enums.envelope.behavior.CONSTANT, CubicVR.enums.envelope.behavior.OFFSET);
*/
var dirLight = new CubicVR.Light({
type: CubicVR.enums.light.type.DIRECTIONAL,
specular: [1,1,1],
direction: CubicVR.vec3.normalize([0.5,-1,0.5])
});
scene.bindLight(dirLight);
var pLight = new CubicVR.Light({
type: CubicVR.enums.light.type.POINT,
specular: [1, 1, 1],
intensity: 2,
distance: 20,
position: [0, 1.5, 0],
});
scene.bindLight(pLight);
CubicVR.MainLoop(function(timer, gl) {
var seconds = timer.getSeconds();
scene.render();
scene.evaluate(timer.getSeconds());
logoObject.rotation[1] = Math.sin(seconds)*180 + Math.sin(seconds/2)*540 + Math.sin(seconds/8)*1080;
pLight.position[0] = Math.sin(seconds/10)*10;
pLight.position[2] = Math.cos(seconds/10)*10;
scene.camera.position[0] = 2 * Math.sin(seconds/5) + Math.cos(seconds/2) * 1.5;
scene.camera.position[2] = 2 * Math.cos(seconds/5) + Math.cos(seconds/2) * 1.5;
updateSoundFloor(seconds);
});
document.body.appendChild(canvas);
//new CubicVR.MouseViewController(canvas, scene.camera);
}, false);
</script>
</head>
<body>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.