Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Commit

Permalink
fixed camera issue #8
Browse files Browse the repository at this point in the history
  • Loading branch information
codeiain committed Apr 20, 2017
1 parent 710ce98 commit 664d231
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/providers/GameService/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ export class Player {
cam.ellipsoid = new BABYLON.Vector3(2, this._height, 2);
cam.checkCollisions = true;
cam.applyGravity = true;
cam.speed = this._speed;
cam.inertia = this._inertia;
cam.angularSensibility = this._angularSensibility;
//cam.speed = this._speed;
//cam.inertia = this._inertia;
//cam.angularSensibility = this._angularSensibility;
this._controller = new Controller(cam);
this._controller.setKeyboardControls(this._game.settings)
//cam.angularInertia = this._angularInertia;
cam.angularSensibility = this._angularSensibility;
//cam.angularSensibility = this._angularSensibility;
cam.layerMask = 2;

return cam;
Expand Down
22 changes: 15 additions & 7 deletions src/providers/GameService/Terrain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export class Terrain {
private game: Game
private GB: any;
private mat: BABYLON.StandardMaterial;

private mesh :any;
time = 0;
constructor(game: Game) {
this.game = game;
Expand Down Expand Up @@ -62,9 +64,15 @@ export class Terrain {
return ns;
}

getHeight(x:number, z:number):number{
this.mesh
var pickInfo = this.mesh.pick(x, z);
return pickInfo.pickedPoint.y;
}

update() {
var mesh = this.geo1({ seg: 20, size: 1000, x: -500, y: -500 }).toMesh(this.game.scene);
mesh.material = this.mat;
this.mesh = this.geo1({ seg: 200, size: 1000, x: -500, y: -500 }).toMesh(this.game.scene);
this.mesh.material = this.mat;
var lastPos = { x: 0, z: 0 };
var _self = this;
this.game.scene.registerBeforeRender(() => {
Expand All @@ -77,21 +85,21 @@ export class Terrain {
lastPos.x = camera.position.x;
lastPos.z = camera.position.z;

mesh.dispose();
mesh = _self.geo1({ seg: 200, size: 1000, x: -500 + camera.position.x, y: -500 + camera.position.z, }).toMesh(_self.game.scene);
mesh.material = _self.mat;
_self.mesh.dispose();
_self.mesh = _self.geo1({ seg: 200, size: 1000, x: -500 + camera.position.x, y: -500 + camera.position.z, }).toMesh(_self.game.scene);
_self.mesh.material = _self.mat;
}

new BABYLONX.ShaderMaterialHelper().SetUniforms(
_self.game.scene.meshes,
camera.position,
camera._currentTarget,
camera.Target,
{ x: 0, y: 0 },
{ x: 100, y: 100 },
_self.time++);


camera.position.y = 5. + _self.height_Map(camera.position);
camera.position.y = 2 + _self.height_Map(camera.position);
})

}
Expand Down
30 changes: 18 additions & 12 deletions www/build/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59204,13 +59204,13 @@ var Player = (function () {
cam.ellipsoid = new __WEBPACK_IMPORTED_MODULE_0_babylonjs___default.a.Vector3(2, this._height, 2);
cam.checkCollisions = true;
cam.applyGravity = true;
cam.speed = this._speed;
cam.inertia = this._inertia;
cam.angularSensibility = this._angularSensibility;
//cam.speed = this._speed;
//cam.inertia = this._inertia;
//cam.angularSensibility = this._angularSensibility;
this._controller = new __WEBPACK_IMPORTED_MODULE_4__Controller__["a" /* Controller */](cam);
this._controller.setKeyboardControls(this._game.settings);
//cam.angularInertia = this._angularInertia;
cam.angularSensibility = this._angularSensibility;
//cam.angularSensibility = this._angularSensibility;
cam.layerMask = 2;
return cam;
};
Expand All @@ -59222,9 +59222,10 @@ var Player = (function () {
}());
Player = __decorate([
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__angular_core__["l" /* Injectable */])(),
__metadata("design:paramtypes", [__WEBPACK_IMPORTED_MODULE_1__Game__["a" /* Game */], __WEBPACK_IMPORTED_MODULE_0_babylonjs___default.a.Vector3])
__metadata("design:paramtypes", [typeof (_a = typeof __WEBPACK_IMPORTED_MODULE_1__Game__["a" /* Game */] !== "undefined" && __WEBPACK_IMPORTED_MODULE_1__Game__["a" /* Game */]) === "function" && _a || Object, typeof (_b = (typeof __WEBPACK_IMPORTED_MODULE_0_babylonjs___default.a !== "undefined" && __WEBPACK_IMPORTED_MODULE_0_babylonjs___default.a).Vector3) === "function" && _b || Object])
], Player);

var _a, _b;
//# sourceMappingURL=Player.js.map

/***/ }),
Expand Down Expand Up @@ -108670,9 +108671,14 @@ var Terrain = (function () {
ns = -50. + Math.pow(ns - 29., 1.13);
return ns;
};
Terrain.prototype.getHeight = function (x, z) {
this.mesh;
var pickInfo = this.mesh.pick(x, z);
return pickInfo.pickedPoint.y;
};
Terrain.prototype.update = function () {
var mesh = this.geo1({ seg: 20, size: 1000, x: -500, y: -500 }).toMesh(this.game.scene);
mesh.material = this.mat;
this.mesh = this.geo1({ seg: 200, size: 1000, x: -500, y: -500 }).toMesh(this.game.scene);
this.mesh.material = this.mat;
var lastPos = { x: 0, z: 0 };
var _self = this;
this.game.scene.registerBeforeRender(function () {
Expand All @@ -108682,12 +108688,12 @@ var Terrain = (function () {
if (dis > 300.) {
lastPos.x = camera.position.x;
lastPos.z = camera.position.z;
mesh.dispose();
mesh = _self.geo1({ seg: 200, size: 1000, x: -500 + camera.position.x, y: -500 + camera.position.z, }).toMesh(_self.game.scene);
mesh.material = _self.mat;
_self.mesh.dispose();
_self.mesh = _self.geo1({ seg: 200, size: 1000, x: -500 + camera.position.x, y: -500 + camera.position.z, }).toMesh(_self.game.scene);
_self.mesh.material = _self.mat;
}
new BABYLONX.ShaderMaterialHelper().SetUniforms(_self.game.scene.meshes, camera.position, camera._currentTarget, { x: 0, y: 0 }, { x: 100, y: 100 }, _self.time++);
camera.position.y = 5. + _self.height_Map(camera.position);
new BABYLONX.ShaderMaterialHelper().SetUniforms(_self.game.scene.meshes, camera.position, camera.Target, { x: 0, y: 0 }, { x: 100, y: 100 }, _self.time++);
camera.position.y = 2 + _self.height_Map(camera.position);
});
};
return Terrain;
Expand Down
2 changes: 1 addition & 1 deletion www/build/main.js.map

Large diffs are not rendered by default.

0 comments on commit 664d231

Please sign in to comment.