Changed bkcore.hexgl.RaceData format to array 2D, improving perf and fixing object cloning issue.
This commit is contained in:
+20
-38
@@ -22,18 +22,24 @@ bkcore.hexgl.RaceData = function(track, mode, shipControls)
|
||||
this.seek = 0;
|
||||
|
||||
this._p = new THREE.Vector3();
|
||||
this._pp = new THREE.Vector3();
|
||||
this._np = new THREE.Vector3();
|
||||
this._q = new THREE.Quaternion();
|
||||
this._pq = new THREE.Quaternion();
|
||||
this._nq = new THREE.Quaternion();
|
||||
}
|
||||
|
||||
bkcore.hexgl.RaceData.prototype.tick = function(time)
|
||||
{
|
||||
if(this.rateState == 1)
|
||||
{
|
||||
this.data.push(new bkcore.hexgl.RaceTick(
|
||||
var p = this.shipControls.getPosition();
|
||||
var q = this.shipControls.getQuaternion();
|
||||
this.data.push([
|
||||
time,
|
||||
this.shipControls.getPosition(),
|
||||
this.shipControls.getQuaternion()
|
||||
));
|
||||
p.x, p.y, p.z,
|
||||
q.x, q.y, q.z, q.w
|
||||
]);
|
||||
++this.last;
|
||||
}
|
||||
else if(this.rateState == this.rate)
|
||||
@@ -50,6 +56,8 @@ bkcore.hexgl.RaceData.prototype.applyInterpolated = function(time)
|
||||
++this.seek;
|
||||
|
||||
var prev = this.data[this.seek];
|
||||
this._pp.set(prev[1], prev[2], prev[3]);
|
||||
this._pq.set(prev[4], prev[5], prev[6], prev[7]);
|
||||
|
||||
if(this.seek < 0)
|
||||
{
|
||||
@@ -63,9 +71,12 @@ bkcore.hexgl.RaceData.prototype.applyInterpolated = function(time)
|
||||
|
||||
// interpolation
|
||||
var next = this.data[this.seek+1];
|
||||
var t = (time-prev.time) / (next.time-prev.time);
|
||||
this._p.copy(prev.position).lerpSelf(next.position, t);
|
||||
this._q.copy(prev.quaternion).slerpSelf(next.quaternion, t);
|
||||
this._np.set(next[1], next[2], next[3]);
|
||||
this._nq.set(next[4], next[5], next[6], next[7]);
|
||||
|
||||
var t = (time-prev[0]) / (next[0]-prev[0]);
|
||||
this._p.copy(this._pp).lerpSelf(this._np, t);
|
||||
this._q.copy(this._pq).slerpSelf(this._nq, t);
|
||||
|
||||
this.shipControls.teleport(this._p, this._q);
|
||||
}
|
||||
@@ -77,39 +88,10 @@ bkcore.hexgl.RaceData.prototype.reset = function()
|
||||
|
||||
bkcore.hexgl.RaceData.prototype.export = function()
|
||||
{
|
||||
var exp = [];
|
||||
for(var i = 0; i <= this.last; i++) exp.push(
|
||||
[this.data[i].time,
|
||||
this.data[i].position.x,
|
||||
this.data[i].position.y,
|
||||
this.data[i].position.z,
|
||||
this.data[i].quaternion.x,
|
||||
this.data[i].quaternion.y,
|
||||
this.data[i].quaternion.z,
|
||||
this.data[i].quaternion.w]
|
||||
);
|
||||
|
||||
return exp;
|
||||
return this.data;
|
||||
}
|
||||
|
||||
bkcore.hexgl.RaceData.prototype.import = function(imp)
|
||||
{
|
||||
this.data = [];
|
||||
for(var i = 0; i < imp.length; i++)
|
||||
{
|
||||
this.data.push(new bkcore.hexgl.RaceTick(
|
||||
imp[i][0],
|
||||
new THREE.Vector3(imp[i][1], imp[i][2], imp[i][3]),
|
||||
new THREE.Quaternion(imp[i][4], imp[i][5], imp[i][6], imp[i][7])
|
||||
));
|
||||
}
|
||||
|
||||
return exp;
|
||||
}
|
||||
|
||||
bkcore.hexgl.RaceTick = function(time, position, quaternion)
|
||||
{
|
||||
this.time = time;
|
||||
this.position = position;
|
||||
this.quaternion = quaternion;
|
||||
this.data = imp;
|
||||
}
|
||||
Reference in New Issue
Block a user