mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
added zoom for OrthographicCamera, tried to decouple gl rendering and box2d updates, didn't work yet
This commit is contained in:
parent
1f55cdff2d
commit
ffb7db528a
5 changed files with 50 additions and 44 deletions
|
|
@ -1,33 +1,19 @@
|
|||
define(['Lib/Vendor/Three', 'Game/Config/Settings'], function (Three, Settings) {
|
||||
|
||||
function CameraController (isOrthographic) {
|
||||
function CameraController () {
|
||||
this.zoom = 1;
|
||||
|
||||
isOrthographic = typeof isOrthographic == 'undefined'
|
||||
? true
|
||||
: isOrthographic;
|
||||
this.camera = new Three.OrthographicCamera(
|
||||
-Settings.STAGE_WIDTH/2,
|
||||
Settings.STAGE_WIDTH/2,
|
||||
Settings.STAGE_HEIGHT/2,
|
||||
-Settings.STAGE_HEIGHT/2,
|
||||
0,
|
||||
1000
|
||||
);
|
||||
|
||||
if(!isOrthographic) {
|
||||
|
||||
this.camera = new Three.OrthographicCamera(
|
||||
-Settings.STAGE_WIDTH/2,
|
||||
Settings.STAGE_WIDTH/2,
|
||||
Settings.STAGE_HEIGHT/2,
|
||||
-Settings.STAGE_HEIGHT/2,
|
||||
1,
|
||||
1000
|
||||
);
|
||||
this.camera.position.z = 1;
|
||||
|
||||
} else {
|
||||
|
||||
this.camera = new Three.PerspectiveCamera(
|
||||
45,
|
||||
Settings.STAGE_WIDTH / Settings.STAGE_HEIGHT,
|
||||
1,
|
||||
-500
|
||||
);
|
||||
}
|
||||
|
||||
this.camera.position.z = 270; // 481
|
||||
this.setPosition(Settings.STAGE_WIDTH / 2, -Settings.STAGE_HEIGHT / 2);
|
||||
|
||||
this.initWheel();
|
||||
|
|
@ -46,7 +32,9 @@ define(['Lib/Vendor/Three', 'Game/Config/Settings'], function (Three, Settings)
|
|||
if(!event) event = window.event; // IE
|
||||
if(event.wheelDelta) delta = event.wheelDelta/120;
|
||||
else if(event.detail) delta = -event.detail/3;
|
||||
if(delta) this.camera.position.z -= delta * 10;
|
||||
if(delta) {
|
||||
this.setZoom(this.zoom + (delta / 30));
|
||||
}
|
||||
if(event.preventDefault) event.preventDefault();
|
||||
event.returnValue = false;
|
||||
};
|
||||
|
|
@ -62,7 +50,14 @@ define(['Lib/Vendor/Three', 'Game/Config/Settings'], function (Three, Settings)
|
|||
|
||||
|
||||
CameraController.prototype.setZoom = function (z) {
|
||||
this.camera.position.z = z;
|
||||
this.zoom = z;
|
||||
z *= 2;
|
||||
console.log(this.zoom)
|
||||
this.camera.left = - Settings.STAGE_WIDTH / z;
|
||||
this.camera.right = Settings.STAGE_WIDTH / z;
|
||||
this.camera.top = Settings.STAGE_HEIGHT / z;
|
||||
this.camera.bottom = - Settings.STAGE_HEIGHT / z;
|
||||
this.camera.updateProjectionMatrix();
|
||||
}
|
||||
|
||||
return CameraController;
|
||||
|
|
|
|||
|
|
@ -102,13 +102,10 @@ define(requires, function (DomController, Three, Settings, CameraController) {
|
|||
return false;
|
||||
};
|
||||
|
||||
ViewController.prototype.update = function () {
|
||||
this.render();
|
||||
}
|
||||
|
||||
ViewController.prototype.render = function () {
|
||||
if(this.mainPlayer) {
|
||||
var pos = this.mainPlayer.getDoll().getBody().GetPosition();
|
||||
|
||||
if(this.me) {
|
||||
var pos = this.me.getDoll().getBody().GetPosition();
|
||||
this.cameraController.setPosition(pos.x * Settings.RATIO, -(pos.y * Settings.RATIO));
|
||||
}
|
||||
|
||||
|
|
@ -135,14 +132,13 @@ define(requires, function (DomController, Three, Settings, CameraController) {
|
|||
mesh.overdraw = true;
|
||||
mesh.position.x = x;
|
||||
mesh.position.y = y;
|
||||
//mesh.position.z = 1;
|
||||
}
|
||||
|
||||
ViewController.prototype.setMainPlayer = function(player) {
|
||||
this.mainPlayer = player;
|
||||
ViewController.prototype.setMe = function(player) {
|
||||
this.me = player;
|
||||
};
|
||||
|
||||
ViewController.prototype.addMovablePlayer = function(player) {
|
||||
ViewController.prototype.addPlayer = function(player) {
|
||||
var self = this;
|
||||
var mesh = null;
|
||||
var pos = player.getDoll().getBody().GetPosition();
|
||||
|
|
@ -155,7 +151,15 @@ define(requires, function (DomController, Three, Settings, CameraController) {
|
|||
});
|
||||
}
|
||||
this.createMesh(size.w, size.h, pos.x, pos.y, "static/img/Characters/Chuck/chuck.png", callback);
|
||||
};
|
||||
|
||||
ViewController.prototype.removPlayer = function(player) {
|
||||
for (var i = 0; i < this.movableObjects.length; i++) {
|
||||
var o = this.movableObjects[i];
|
||||
if(o.player == player) {
|
||||
this.scene.remove(o.mesh);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
return ViewController;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue