apply axis and angle to vectors
parent
6f9dc88a78
commit
c572393a54
|
@ -291,7 +291,16 @@ GameLib.Component.prototype.clone = function() {
|
|||
|
||||
apiObject.id = GameLib.Utils.RandomId();
|
||||
|
||||
apiObject.name = apiObject.name + ' (Clone)';
|
||||
var matches = apiObject.name.match(/Clone \((\d+)\)/);
|
||||
|
||||
if (matches && matches.length > 1) {
|
||||
if (matches.length === 2) {
|
||||
var number = Number(matches[1]);
|
||||
apiObject.name = apiObject.name.replace(/Clone \(\d*\)/, 'Clone (' + (number+1) + ')');
|
||||
}
|
||||
} else {
|
||||
apiObject.name = apiObject.name + ' Clone (1)'
|
||||
}
|
||||
|
||||
var runtimeObject = null;
|
||||
|
||||
|
|
|
@ -935,6 +935,22 @@ GameLib.D3.Mesh.prototype.centerAroundOrigin = function() {
|
|||
this.position.z = -position.z;
|
||||
|
||||
this.updateInstancePosition();
|
||||
|
||||
return position;
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.prototype.applyAxisAngleToPosition = function(axis, angle) {
|
||||
this.position.applyAxisAngle(this.quaternion.axis, this.quaternion.angle);
|
||||
this.updateInstancePosition();
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.prototype.translate = function(vector3) {
|
||||
|
||||
this.position.x += vector3.x;
|
||||
this.position.y += vector3.y;
|
||||
this.position.z += vector3.z;
|
||||
|
||||
this.updateInstancePosition();
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.prototype.getDistanceFromCenter = function() {
|
||||
|
@ -958,20 +974,46 @@ GameLib.D3.Mesh.prototype.applyPositionRotationScale = function() {
|
|||
|
||||
this.instance.geometry.applyMatrix(this.instance.matrix);
|
||||
|
||||
/**
|
||||
* Reset position
|
||||
* @type {number}
|
||||
*/
|
||||
this.position.x = 0;
|
||||
this.position.y = 0;
|
||||
this.position.z = 0;
|
||||
this.updateInstancePosition();
|
||||
|
||||
/**
|
||||
* Reset scale
|
||||
* @type {number}
|
||||
*/
|
||||
this.scale.x = 1;
|
||||
this.scale.y = 1;
|
||||
this.scale.z = 1;
|
||||
this.instance.scale.set(1,1,1);
|
||||
|
||||
/**
|
||||
* Reset rotation
|
||||
* @type {number}
|
||||
*/
|
||||
this.quaternion.x = 0;
|
||||
this.quaternion.y = 0;
|
||||
this.quaternion.z = 0;
|
||||
this.quaternion.w = 1;
|
||||
this.quaternion.axis.x = 0;
|
||||
this.quaternion.axis.y = 0;
|
||||
this.quaternion.axis.z = 0;
|
||||
this.quaternion.angle = 0;
|
||||
this.updateInstanceRotationFromAxisAngle();
|
||||
|
||||
/**
|
||||
* Update our instance matrix
|
||||
*/
|
||||
this.instance.updateMatrix();
|
||||
|
||||
/**
|
||||
* Let this reflect back to our vertices
|
||||
*/
|
||||
this.updateVerticesFromGeometryInstance(this.instance.geometry);
|
||||
};
|
||||
|
||||
|
@ -997,10 +1039,15 @@ GameLib.D3.Mesh.prototype.updateInstanceRotationFromAxisAngle = function(axis, a
|
|||
};
|
||||
|
||||
GameLib.D3.Mesh.prototype.updateInstancePosition = function() {
|
||||
this.position.instance.x = this.position.x;
|
||||
this.position.instance.y = this.position.y;
|
||||
this.position.instance.z = this.position.z;
|
||||
|
||||
this.position.instance.set(
|
||||
this.position.x,
|
||||
this.position.y,
|
||||
this.position.z
|
||||
);
|
||||
|
||||
this.instance.position.copy(this.position.instance);
|
||||
|
||||
if (this.helper) {
|
||||
this.removeHelper();
|
||||
this.createHelper();
|
||||
|
|
|
@ -126,6 +126,44 @@ GameLib.Vector3.prototype.copy = function() {
|
|||
)
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a negative version of this vector
|
||||
* @returns {GameLib.Vector3}
|
||||
*/
|
||||
GameLib.Vector3.prototype.negativeCopy = function() {
|
||||
return new GameLib.Vector3(
|
||||
this.implementation,
|
||||
new GameLib.API.Vector3(
|
||||
-this.x,
|
||||
-this.y,
|
||||
-this.z
|
||||
),
|
||||
this.parentObject,
|
||||
this.grain
|
||||
)
|
||||
};
|
||||
|
||||
/**
|
||||
* Applies rotation specified by axis / angle to this vector - its a wrapper for three..
|
||||
* @param axis
|
||||
* @param angle
|
||||
*/
|
||||
GameLib.Vector3.prototype.applyAxisAngle = function(axis, angle) {
|
||||
|
||||
this.instance.applyAxisAngle(
|
||||
new THREE.Vector3(
|
||||
axis.x,
|
||||
axis.y,
|
||||
axis.z
|
||||
),
|
||||
angle
|
||||
);
|
||||
|
||||
this.x = this.instance.x;
|
||||
this.y = this.instance.y;
|
||||
this.z = this.instance.z;
|
||||
};
|
||||
|
||||
GameLib.Vector3.prototype.setFrom = function(vector3) {
|
||||
this.x = vector3.x;
|
||||
this.y = vector3.y;
|
||||
|
|
Loading…
Reference in New Issue