mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
some more renaming
This commit is contained in:
parent
9de3147406
commit
bd45f538c7
34 changed files with 0 additions and 0 deletions
50
app/Game/Client/View/CameraController.js
Executable file
50
app/Game/Client/View/CameraController.js
Executable file
|
|
@ -0,0 +1,50 @@
|
|||
define(['Vendor/Three', 'Chuck/Settings'], function(Three, Settings) {
|
||||
|
||||
function CameraController(isOrthographic) {
|
||||
|
||||
isOrthographic = typeof isOrthographic == 'undefined'
|
||||
? true
|
||||
: isOrthographic;
|
||||
|
||||
|
||||
if(isOrthographic) {
|
||||
|
||||
this.camera = new Three.OrthographicCamera(
|
||||
-Settings.STAGE_WIDTH/2,
|
||||
Settings.STAGE_WIDTH/2,
|
||||
Settings.STAGE_HEIGHT/2,
|
||||
-Settings.STAGE_HEIGHT/2,
|
||||
-2000,
|
||||
1000
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
this.camera = new Three.PerspectiveCamera(
|
||||
45,
|
||||
Settings.STAGE_WIDTH / Settings.STAGE_HEIGHT,
|
||||
-2000,
|
||||
1000
|
||||
);
|
||||
}
|
||||
|
||||
this.camera.position.z = 481;
|
||||
}
|
||||
|
||||
CameraController.prototype.getCamera = function(){
|
||||
return this.camera;
|
||||
}
|
||||
|
||||
CameraController.prototype.setPosition = function(x, y){
|
||||
this.camera.position.x = x;
|
||||
this.camera.position.y = y;
|
||||
}
|
||||
|
||||
|
||||
CameraController.prototype.setZoom = function(z){
|
||||
this.camera.position.z = z;
|
||||
}
|
||||
|
||||
return CameraController;
|
||||
|
||||
});
|
||||
53
app/Game/Client/View/DomController.js
Executable file
53
app/Game/Client/View/DomController.js
Executable file
|
|
@ -0,0 +1,53 @@
|
|||
define(['Chuck/Settings'], function(Settings) {
|
||||
|
||||
var Dom = {
|
||||
canvas: null,
|
||||
debugCanvas: null
|
||||
};
|
||||
|
||||
Dom.getCanvasContainer = function(){
|
||||
var container = document.getElementById(Settings.CANVAS_DOM_ID);
|
||||
|
||||
if(container) {
|
||||
return container;
|
||||
} else {
|
||||
throw 'Canvas Container missing: #' + Settings.CANVAS_DOM_ID;
|
||||
}
|
||||
}
|
||||
|
||||
Dom.getCanvas = function(){
|
||||
return Dom.canvas;
|
||||
}
|
||||
|
||||
Dom.setCanvas = function(canvas){
|
||||
|
||||
var container = Dom.getCanvasContainer();
|
||||
if(Dom.canvas){
|
||||
container.removeChild(Dom.canvas);
|
||||
}
|
||||
|
||||
Dom.canvas = canvas;
|
||||
container.appendChild(canvas);
|
||||
}
|
||||
|
||||
Dom.getDebugCanvas = function(){
|
||||
return Dom.debugCanvas;
|
||||
}
|
||||
|
||||
Dom.createDebugCanvas = function(){
|
||||
|
||||
var container = Dom.getCanvasContainer();
|
||||
if(Dom.debugCanvas){
|
||||
container.removeChild(Dom.debugCanvas);
|
||||
}
|
||||
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = Settings.STAGE_WIDTH;
|
||||
canvas.height = Settings.STAGE_HEIGHT;
|
||||
Dom.debugCanvas = canvas;
|
||||
container.appendChild(canvas);
|
||||
}
|
||||
|
||||
return Dom;
|
||||
|
||||
});
|
||||
106
app/Game/Client/View/ViewController.js
Executable file
106
app/Game/Client/View/ViewController.js
Executable file
|
|
@ -0,0 +1,106 @@
|
|||
define(["Client/Dom", "Vendor/Three", "Chuck/Settings", "Chuck/View/CameraController"], function(Dom, Three, Settings, CameraController){
|
||||
|
||||
function ViewController(){
|
||||
|
||||
this.mesh = null;
|
||||
this.scene = null;
|
||||
this.renderer = null;
|
||||
this.cameraController = new CameraController();
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
function isWebGlEnabled () {
|
||||
try {
|
||||
return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' );
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ViewController.prototype.init = function(){
|
||||
|
||||
var self = this;
|
||||
|
||||
var rendererOptions = {
|
||||
antialias: true,
|
||||
preserveDrawingBuffer: true
|
||||
};
|
||||
|
||||
if(isWebGlEnabled()) {
|
||||
this.renderer = new Three.WebGLRenderer(rendererOptions);
|
||||
} else {
|
||||
this.renderer = new Three.CanvasRenderer(rendererOptions);
|
||||
}
|
||||
|
||||
this.renderer.setClearColorHex(0x333333, 1);
|
||||
this.renderer.setSize(Settings.STAGE_WIDTH, Settings.STAGE_HEIGHT);
|
||||
|
||||
Dom.setCanvas(this.renderer.domElement);
|
||||
|
||||
if(Settings.DEBUG_MODE){
|
||||
Dom.createDebugCanvas();
|
||||
}
|
||||
|
||||
this.scene = new Three.Scene();
|
||||
this.scene.add(this.cameraController.getCamera());
|
||||
|
||||
|
||||
var ambientLight = new Three.AmbientLight(0xffffff);
|
||||
this.scene.add(ambientLight);
|
||||
|
||||
var directionalLight = new Three.DirectionalLight(0xffffff);
|
||||
directionalLight.position.set(1, 0, 10).normalize();
|
||||
this.scene.add(directionalLight);
|
||||
|
||||
|
||||
this.createMesh(100, 100, 100, 100, 'static/img/100.png', function(mesh){
|
||||
self.mesh = mesh;
|
||||
self.scene.add(mesh);
|
||||
});
|
||||
/*
|
||||
this.createMesh(50, 50, 200, 100, 'static/img/100.png', function(mesh){
|
||||
self.scene.add(mesh);
|
||||
});
|
||||
*/
|
||||
|
||||
//this.animate(this);
|
||||
}
|
||||
|
||||
ViewController.prototype.update = function() {
|
||||
|
||||
if(this.mesh) {
|
||||
this.mesh.rotation.z += .01;
|
||||
this.mesh.position.z += 1;
|
||||
this.mesh.position.x += .4;
|
||||
this.mesh.position.y += .4;
|
||||
}
|
||||
|
||||
this.render();
|
||||
}
|
||||
|
||||
ViewController.prototype.render = function() {
|
||||
|
||||
this.renderer.render(this.scene, this.cameraController.getCamera());
|
||||
}
|
||||
|
||||
ViewController.prototype.createMesh = function(width, height, x, y, imgPath, callback) {
|
||||
var textureImg = new Image();
|
||||
textureImg.onload = function(){
|
||||
var material = new Three.MeshLambertMaterial({
|
||||
map: Three.ImageUtils.loadTexture(imgPath)
|
||||
});
|
||||
|
||||
var mesh = new Three.Mesh(new Three.PlaneGeometry(width, height), material);
|
||||
mesh.overdraw = true;/*
|
||||
mesh.position.z = 0;
|
||||
mesh.position.x = x;
|
||||
mesh.position.y = y;
|
||||
*/
|
||||
callback(mesh);
|
||||
};
|
||||
textureImg.src = imgPath;
|
||||
}
|
||||
|
||||
return ViewController;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue