How to Circle
by Admiral Potato
HTML
<script src="http://admiralpotato.github.io/js/npos3d/build/npos3d.js"></script>
JavaScript
var n = NPos3d;
var scene = new n.Scene({backgroundColor:'rgba(0,0,0,0.4)'});
var s = scene;
var c = s.c;
var q = s.rQ;
var scroll = 0;
window.onmousewheel = function(e){scroll=e.wheelDelta;}; //Chrome
window.addEventListener('DOMMouseScroll',function(e){scroll=e.detail;},false); //FireFox. Wut. You. Smokin.
var userControl = {
pos:[0,0,0],
rot:[0,0,0],
update:function(){
//this.rot[0] += deg*1;
this.rot[1] = tau * s.mpos.x / s.w;
this.rot[0] = -tau * s.mpos.y / s.w;
scene.camera.pos[2] += (scroll/8);
scroll = 0;
//this.pos[0] = s.mpos.x;
//this.pos[1] = s.mpos.y;
}
};
s.add(userControl);
s.camera.pos[2] = 800;
s.camera.update = function(){};
var myCircleGeom = new n.Geom.Circle({
radius:200,
segments:3,
offset:0
});
var myLabel = new n.VText({
string: '3'
});
var myOb = new n.Ob3D({
shape: myCircleGeom,
pos:userControl.pos,
rot:userControl.rot,
scale:[1,1,1]
});
myOb.counter = 0;
myOb.update = function(){
var t = this;
t.counter += 1;
if(t.counter > 60){
t.counter = 0;
t.shape.segments += 1;
if(t.shape.segments > 16){t.shape.segments = 3;}
myLabel.string = t.shape.segments.toString();
t.shape.formCircle();
t.lastGlobalCompositeMatrixString = false;
}
}
s.add(myOb);
myOb.add(myLabel);