backup
parent
9c90cb81ac
commit
b91f0b57ea
|
@ -14,6 +14,7 @@ GameLib.D3.ComponentPathFollowing = function ComponentPathFollowing(
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
splineCurve3,
|
splineCurve3,
|
||||||
|
normalSplineCurve3,
|
||||||
accel,
|
accel,
|
||||||
maxSpeed,
|
maxSpeed,
|
||||||
baseOffset,
|
baseOffset,
|
||||||
|
@ -30,6 +31,7 @@ GameLib.D3.ComponentPathFollowing = function ComponentPathFollowing(
|
||||||
this.parentEntity = null;
|
this.parentEntity = null;
|
||||||
|
|
||||||
this.splineCurve3 = splineCurve3;
|
this.splineCurve3 = splineCurve3;
|
||||||
|
this.normalSplineCurve3 = normalSplineCurve3;
|
||||||
|
|
||||||
this.maxSpeed = maxSpeed || 10.0;
|
this.maxSpeed = maxSpeed || 10.0;
|
||||||
this.accel = accel || 2.0;
|
this.accel = accel || 2.0;
|
||||||
|
@ -57,7 +59,7 @@ GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function(
|
||||||
parentEntity
|
parentEntity
|
||||||
) {
|
) {
|
||||||
|
|
||||||
if(this.splineCurve3) {
|
if(this.splineCurve3 && this.normalSplineCurve3) {
|
||||||
|
|
||||||
if(this.currentPathValue >= 1 || this.currentPathValue < 0) {
|
if(this.currentPathValue >= 1 || this.currentPathValue < 0) {
|
||||||
this.currentPathValue = 0;
|
this.currentPathValue = 0;
|
||||||
|
@ -67,19 +69,16 @@ GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function(
|
||||||
//http://stackoverflow.com/questions/18400667/three-js-object-following-a-spline-path-rotation-tanget-issues-constant-sp
|
//http://stackoverflow.com/questions/18400667/three-js-object-following-a-spline-path-rotation-tanget-issues-constant-sp
|
||||||
var position = this.splineCurve3.getPointAt(this.currentPathValue);
|
var position = this.splineCurve3.getPointAt(this.currentPathValue);
|
||||||
|
|
||||||
|
var nextIndex = this.currentPathValue + 0.005;
|
||||||
|
if(nextIndex > 1.0) {
|
||||||
|
nextIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// var nextPosition = this.splineCurve3.getPointAt(this.currentPathValue + 0.01);
|
var nextPoint = this.splineCurve3.getPointAt(nextIndex);
|
||||||
|
var normal = this.normalSplineCurve3.getPointAt(this.currentPathValue).normalize();
|
||||||
|
|
||||||
var rotation = this.splineCurve3.getTangentAt(this.currentPathValue).normalize();
|
var matrix = new THREE.Matrix4().lookAt(position, nextPoint, normal);
|
||||||
//var tangent = this.splineCurve3.getTangentAt(this.currentPathValue).normalize();
|
var quaternion = new THREE.Quaternion().setFromRotationMatrix(matrix);
|
||||||
//var rotation = position.clone().normalize().cross( tangent );
|
|
||||||
|
|
||||||
// extract rotation
|
|
||||||
var forward = new THREE.Vector3(-1, 0, 0);
|
|
||||||
var axis = new THREE.Vector3();
|
|
||||||
axis.crossVectors(forward, rotation).normalize();
|
|
||||||
var radians = Math.acos(forward.dot(rotation));
|
|
||||||
var quaternion = new THREE.Quaternion().setFromAxisAngle(axis, radians);
|
|
||||||
|
|
||||||
{ // update current speed
|
{ // update current speed
|
||||||
var t = deltaTime * this.accel;
|
var t = deltaTime * this.accel;
|
||||||
|
|
Loading…
Reference in New Issue