Hello again to the quick tip series. Today's quick tip will show you another way to render a turntable.
You can use this script below and customize it to your taste.
var currentFrame = 0;
var angle = 0;
var startPos = new DSMath.Vector3D();
var targetPos = new DSMath.Vector3D();
var radius = 15000;
beScript.onStart = function () {
startPos = this.actor.getPosition();
targetPos = this.target.getPosition();
radius = DSMath.Vector3D.sub(startPos,targetPos).norm();
console.log(radius);
};
beScript.onStop = function () {
//Will be called on experience stop.
};
beScript.execute = function (context) {
if(currentFrame > this.numberOfFrames) {
return;
}
angle = currentFrame * Math.PI*2/this.numberOfFrames;
/** @type {STU.Camera} */
var cam = this.actor;
cam.setPosition(new DSMath.Vector3D(targetPos.x + radius * Math.cos(angle), targetPos.y + radius * Math.sin(angle), startPos.z ) );
cam.lookAt(this.target);
/** @type {STU.Raytrace} */
var raytrace = this.actor.Raytrace;
if(this.render)
raytrace.capturePhoto();
currentFrame++;
}; 