Skip to content

Commit

Permalink
better voxelMap + enabled cubemap
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromeetienne committed Jan 21, 2012
1 parent a58d4a3 commit d8e6ac5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
4 changes: 2 additions & 2 deletions js/gameLevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Marble.GameLevel = function()
this._player = new Marble.Player();
this._map = new Marble.Map();
this._camera = new Marble.Camera();
//this._skybox = new Marble.Skymap();
this._skybox = new Marble.Skymap();

// create all the balls
this._balls = [];
Expand Down Expand Up @@ -173,7 +173,7 @@ Marble.GameLevel.prototype._ballCtor = function(ballOpts)

Marble.GameLevel.prototype._ballBuild9Rack = function(){
var radius = Marble.tileSize;
var rack = new THREE.Vector3(0,0, -3 * radius);
var rack = new THREE.Vector3(0,0, -6 * radius);
var offset;
var addBall = function(arr, offset){
arr.forEach(function(ballDesc, index){
Expand Down
37 changes: 35 additions & 2 deletions js/lib/voxelMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,42 @@ Marble.VoxelMap.prototype.clone = function()
});
}

//////////////////////////////////////////////////////////////////////////////////
// transformation //
//////////////////////////////////////////////////////////////////////////////////

Marble.VoxelMap.prototype.translate = function(x, y, z)
{
this._map.forEach(function(voxel){
voxel.x += x;
voxel.y += y;
voxel.z += z;
})
return this;
}

Marble.VoxelMap.prototype.multiply = function(x, y, z)
{
this._map.forEach(function(voxel){
voxel.x *= x;
voxel.y *= y;
voxel.z *= z;
});
return this;
}

//////////////////////////////////////////////////////////////////////////////////
// getters //
//////////////////////////////////////////////////////////////////////////////////
Marble.VoxelMap.prototype.map = function(){ return this._map; }

Marble.VoxelMap.prototype.computeAll = function()
{
this._computeBoundingBox();
this._computeHeightMap();
return this;
}

Marble.VoxelMap.prototype._computeHeightMap = function()
{
var nbItems = this._size.x * this._size.z;
Expand Down Expand Up @@ -81,7 +112,7 @@ Marble.VoxelMap.prototype._computeBoundingBox = function()
this._size.z = Math.abs(this._max.z - this._min.z + 1);

// display to debug
//console.log('map bbmin', this._min, "bbMax", this._max, "size", this._size);
console.log('map bbmin', this._min, "bbMax", this._max, "size", this._size);
}

/**
Expand Down Expand Up @@ -121,7 +152,8 @@ Marble.VoxelMap.prototype._indexOf = function(x, y, z, t)

/**
* return true if all voxels of the box are of type t
* TODO rename to a better name
* - used for voxel clustering
* - not really optimized
*/
Marble.VoxelMap.prototype._checkBox = function(minX, minY, minZ, maxX, maxY, maxZ, t)
{
Expand All @@ -137,6 +169,7 @@ Marble.VoxelMap.prototype._checkBox = function(minX, minY, minZ, maxX, maxY, max

/**
* remove all voxels of the box from arr
* - used for voxel clustering
*/
Marble.VoxelMap.prototype._removeBox = function(minX, minY, minZ, maxX, maxY, maxZ, t)
{
Expand Down
Loading

0 comments on commit d8e6ac5

Please sign in to comment.