r3-legacy/bak/r3-d3-api-follow.js

99 lines
2.4 KiB
JavaScript

/**
* Follow Component
* @param id
* @param name
* @param currentComponent R3.Component
* @param targetComponent R3.Component
* @param targetPositionOffset R3.API.Vector3
* @param minDistance
* @param moveSpeed
* @param parentEntity
* @constructor
*/
R3.D3.API.Follow = function (
id,
name,
currentComponent,
targetComponent,
targetPositionOffset,
minDistance,
moveSpeed,
parentEntity
) {
R3.Component.call(
this,
R3.Component.COMPONENT_FOLLOW,
{
'currentComponent': R3.Component,
'targetComponent': R3.Component
},
parentEntity
);
if (R3.Utils.UndefinedOrNull(id)) {
id = R3.Utils.RandomId();
}
this.id = id;
if (R3.Utils.UndefinedOrNull(name)) {
name = this.constructor.name;
}
this.name = name;
if (R3.Utils.UndefinedOrNull(currentComponent)) {
currentComponent = null;
}
this.currentComponent = currentComponent;
if (R3.Utils.UndefinedOrNull(targetComponent)) {
targetComponent = null;
}
this.targetComponent = targetComponent;
if(R3.Utils.UndefinedOrNull(targetPositionOffset)) {
targetPositionOffset = new R3.API.Vector3(0, 0, 0);
}
this.targetPositionOffset = targetPositionOffset;
if (R3.Utils.UndefinedOrNull(minDistance)) {
minDistance = 2;
}
this.minDistance = minDistance;
if (R3.Utils.UndefinedOrNull(moveSpeed)) {
moveSpeed = 12.5;
}
this.moveSpeed = moveSpeed;
this.target = new R3.API.Vector3(0, 0, 0);
this.targetToParent = new R3.API.Vector3(0, 0, 0);
this.rotatedTargetOffset = new R3.API.Vector3(0, 0, 0);
this.rotated = new R3.API.Quaternion();
};
R3.D3.API.Follow.prototype = Object.create(R3.Component.prototype);
R3.D3.API.Follow.prototype.constructor = R3.D3.API.Follow;
/**
* Object to R3.D3.API.Follow
* @param objectComponent
* @returns {R3.D3.API.Follow}
* @constructor
*/
R3.D3.API.Follow.FromObject = function(objectComponent) {
return new R3.D3.API.Follow(
objectComponent.id,
objectComponent.name,
objectComponent.currentComponent,
objectComponent.targetComponent,
R3.API.Vector3.FromObject(objectComponent.targetPositionOffset),
objectComponent.minDistance,
objectComponent.moveSpeed,
objectComponent.parentEntity
);
};