8:00 – 4:30 SR
- A tad nippy today
- Updating monthly reports and adding an FY15 truancy report. Done.
- Spent the rest of the day building TypeScript versions of WebGLCanvas and WebGLComponent
- Wrote up detailed notes here.
8:00 – 4:30 SR
8:00 – 4:00 SR
glElement:HTMLCanvasElement; overlayElement:HTMLCanvasElement; overlayContext:CanvasRenderingContext2D;
.glContainer {
position: absolute;
z-index: 0;
}
.overlayContainer {
position: absolute;
z-index: 1;
}
this.renderer = new THREE.WebGLRenderer({antialias: true});
this.renderer.setClearColor(this.blackColor, 1);
this.renderer.setSize(this.contW, this.contH);
// element is provided by the angular directive
this.renderer.domElement.setAttribute("class", "glContainer");
this.glElement = this.myElements[0].appendChild(this.renderer.domElement);
//this.overlayNode = angular.element(divString);
this.overlayElement = document.createElement("canvas");
this.overlayElement.setAttribute("class", "overlayContainer");
this.myElements[0].appendChild(this.overlayElement);
this.overlayContext = this.overlayElement.getContext("2d");
draw2D = (ctx:CanvasRenderingContext2D):void =>{
var canvas:HTMLCanvasElement = ctx.canvas;
canvas.width = this.contW;
canvas.height = this.contH;
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.font = '12px "Times New Roman"';
ctx.fillStyle = 'rgba( 255, 255, 255, 1)'; // Set the letter color
ctx.fillText("Hello, framecount: "+this.frameCount, 10, 20);
};
render = ():void=> {
// do the 3D rendering
this.camera.lookAt(this.scene.position);
this.renderer.render(this.scene, this.camera);
this.frameCount++;
this.draw2D(this.overlayContext);
};
7:00 – 4:00 SR
module WGLA1_dirtv {
// The base class for the webGL 'canvas' has the scene, root object, basic lights and a camera
class webGLBase {
myScope:any;
myElements:any;
myAttrs:any;
frameCount:number;
mouseX:number;
mouseY:number;
contW:number;
contH:number;
windowHalfX:number;
windowHalfY:number;
camera:THREE.PerspectiveCamera;
scene:THREE.Scene;
sphere:THREE.Mesh;
light:THREE.DirectionalLight;
renderer:THREE.WebGLRenderer;
redColor:THREE.Color;
whiteColor:THREE.Color;
greyColor:THREE.Color;
constructor(scope:any, element:any, attrs:any) {
this.myScope = scope;
this.myElements = element;
this.myAttrs = attrs;
this.frameCount = 0;
this.mouseX = 0;
this.mouseY = 0;
this.contW = scope.width;
this.contH = scope.height;
this.windowHalfX = this.contW / 2;
this.windowHalfY = this.contH / 2;
}
public init = ():void => {
this.myElements[0].addEventListener('mousemove', this.onDocumentMouseMove, false);
this.redColor = new THREE.Color(0xff0000);
this.whiteColor = new THREE.Color(0xffffff);
this.greyColor = new THREE.Color(0x080808);
// Scene
this.scene = new THREE.Scene();
// camera
this.camera = new THREE.PerspectiveCamera(45, this.contW / this.contH, 0.1, 10000);
// Position is -20 along the Z axis and look at the origin
this.camera.position = new THREE.Vector3(0, 0, 10);
this.camera.lookAt(new THREE.Vector3(0, 0, 0));
var sphereGeometry = new THREE.SphereGeometry(5, 20, 20);
// This time we create a Phong shader material and provide a texture.
var sphereMaterial = new THREE.MeshPhongMaterial(
{
map: THREE.ImageUtils.loadTexture("assets/earth-day.jpg")
}
);
// Now make a THREE.Mesh using the geometry and a shader
this.sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
// And put it at the origin
this.sphere.position = new THREE.Vector3(0, 0, 0);
// Add it to the scene and render the scene using the Scene and Camera objects
this.scene.add(this.sphere);
// Lighting
this.light = new THREE.DirectionalLight(0xffffff);
this.light.position.set(10, 10, 10);
this.scene.add(this.light);
this.scene.add(new THREE.AmbientLight(this.greyColor.getHex()));
/****/
this.renderer = new THREE.WebGLRenderer({antialias: true});
this.renderer.setClearColor(this.whiteColor, 1);
this.renderer.setSize(this.contW, this.contH);
// element is provided by the angular directive
this.myElements[0].appendChild(this.renderer.domElement);
this.renderer.clear();
};
onDocumentMouseMove = (event:MouseEvent):void => {
this.mouseX = ( event.clientX - this.windowHalfX );
this.mouseY = ( event.clientY - this.windowHalfY );
};
render = ():void=> {
//camera.position.x = ( mouseX - camera.position.x ) * 0.05;
//camera.position.y = ( - mouseY - camera.position.y ) * 0.05;
this.camera.lookAt(this.scene.position);
this.renderer.render(this.scene, this.camera);
this.frameCount++;
//console.log("frameCount = "+frameCount);
};
animate = () => {
this.sphere.rotation.y = this.frameCount * 0.01;
requestAnimationFrame(this.animate);
this.render();
};
}
// The webGL directive. Instantiates a webGlBase-derived class for each scope
export class ngWebgl {
private myDirective:ng.IDirective;
constructor() {
this.myDirective = null;
}
private linkFn = (scope:any, element:any, attrs:any) => {
scope.webGlBase = new webGLBase(scope, element, attrs);
scope.webGlBase.init();
scope.webGlBase.animate();
};
public ctor = ():ng.IDirective => {
if (!this.myDirective) {
this.myDirective = {
restrict: 'A',
scope: {
'width': '=',
'height': '=',
'fillcontainer': '=',
'scale': '=',
'materialType': '='
},
link: this.linkFn
}
}
return this.myDirective;
}
}
}
8:00 – 4:00 SR
then( ():void => {
scope.isValid = this.loginObj.response;
if (this.loginObj.response) {
scope.speak('new password for ' + this.loginObj.name + ' accepted');
} else {
scope.speak('new password for ' + this.loginObj.name + ' rejected');
}
}, this.errorResponse);
.glWindow{
position: absolute;
box-sizing: border-box;
top: 5vh;
left: 5vw;
width: 90vw;
height: 90vh;
background-color: red;
}
Phil 8:00 – 6:30 SR
8:00 – 2:30 SR
this (e.g. self) to a variable that could be closed over. Arrow functions capture the this value of the enclosing context, so the following code works as expected.function Person(){
this.age = 0;
setInterval(() => {
this.age++; // |this| properly refers to the person object
}, 1000);
}
var p = new Person();
new AngularMain().doCreate(angular, new InheritApp.TestFactory().ctor,...);
8:00 – 4:00 SR
this.querySpeech.onend = (event:Event) => {
this.queryService.submit(this.query, this.goodUserQuery, this.errorResponse);
};
this.querySpeech.onend = function (event) {
_this.queryService.submit(_this.query, _this.goodUserQuery, _this.errorResponse);
};
public runQuery(query:string){
this.query = query;
this.submit();
};
public runQuery = (query:string) => {
this.query = query;
this.submit();
};
QueryController.prototype.runQuery = function (query) {
this.query = query;
this.submit();
};
this.runQuery = function (query) {
_this.query = query;
_this.submit();
};
You must be logged in to post a comment.