Transform
Type | Name | Interface Description |
---|---|---|
Variables | localPosition: Vector3f | • Function: Defines the local position of an object. |
Variables | localScale: Vector3f | • Function: Defines the local scaling of an object. |
Variables | localRotation: Quaternionf | • Function: Defines the local rotation of an object. |
Examples
localPosition: Vector3f
trans.localPosition = new APJS.Vector3f(1,0,0);
localScale: Vector3f
trans.localScale = new APJS.Vector3f(2,2,2);
localRotation: Quaternionf
trans.localRotation = APJS.Quaternionf.makeFromAngleAxis(
0.2, new APJS.Vector3f(0, 1, 0));
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Cube');
let trans = child?.getTransform();
if(!trans) return;
this.time += deltaTime;
var radius = 10;
trans.localPosition = new APJS.Vector3f(
radius * Math.cos(this.time),
radius * Math.sin(this.time),
0);
trans.localRotation = APJS.Quaternionf.makeFromAngleAxis(
this.time, new APJS.Vector3f(0, 1, 0));
var scale = 0.5 + (Math.sin(this.time) + 1) * 0.5;
trans.localScale = new APJS.Vector3f(scale, scale, scale);
}
}
Type | Name | Interface Description |
---|---|---|
Functions | localMatrix: Matrix4x4f | • Function: Obtain the world transformation matrix of an object, which is used to convert local coordinates to world coordinates. |
Example
trans.localMatrix = APJS.Matrix4x4f.makeFromRotation(rot);
Type | Name | Interface Description | Example |
---|---|---|---|
Functions | setWorldMatrix(matrix: Matrix4x4f): void | • Function: Sets the world position of the object. | Code block 1 trans.setWorldMatrix([ 2 API.Matrix4x4f.makeTransform( 3 position: { }; |
Example
trans.setWorldMatrix( APJS.Matrix4x4f.makeFromRotation(rot) );
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Cube');
let trans = child?.getTransform();
if(!trans) return;
this.time += deltaTime;
var radius = 10;
const rot = APJS.Quaternionf.makeFromAngleAxis(
this.time, new APJS.Vector3f(0, 1, 0));
trans.setWorldMatrix( APJS.Matrix4x4f.makeFromRotation(rot) );
}
}
Type | Name | Interface Description |
---|---|---|
Functions | getWorldMatrix(): Matrix4x4f | • Function: Get the world position of the object. |
Example
let worldMatrix = transform.getWorldMatrix();
Type | Name | Interface Description | Example |
---|---|---|---|
Functions | setWorldPosition(pos: Vector3f): void | • Function: Sets the world position of the object. | Code block 1 trans.setWorldPosition(new 2 API.Vector3f(1,0,0)); |
Functions | getWorldPosition(): Vector3f | • Function: Get the world rotation of the object. | Code block 1 let worldPosition = 2 transform.getWorldPosition(); |
Functions | setWorldRotation(rotation: Quaternionf): void | • Function: Sets the world scale of the object. | Code block 1 transform.setWorldRotation(ne 2 w Quaternionf(0, 0, 0, 1)); |
Functions | getWorldRotation(): Quaternionf | • Function: Get the world scale of the object. | Code block 1 let worldRotation = 2 transform.getWorldRotation(); |
Functions | setWorldScale(scale: Vector3f): void | • Function: Sets the world scale of the object. | Code block 1 transform.setWorldScale(new 2 Vector3f(2, 2, 2)); |
Functions | getWorldScale(): Vector3f | • Function: Get the world scale of the object. | Code block 1 let worldScale = 2 transform.getWorldScale(); |
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
private firstFrame = true;
private time = 0.0;
onStart() {
}
onUpdate(deltaTime: number) {
if (this.firstFrame) {
this.firstFrame = false;
}
let child = this.getSceneObject().getChild('Cube');
let trans = child?.getTransform();
if(!trans) return;
this.time += deltaTime;
var radius = 10;
trans.setWorldPosition(new APJS.Vector3f(
radius * Math.cos(this.time),
radius * Math.sin(this.time),
0));
trans.setWorldRotation(APJS.Quaternionf.makeFromAngleAxis(
this.time, new APJS.Vector3f(0, 1, 0)));
var scale = 0.5 + (Math.sin(this.time) + 1) * 0.5;
trans.setWorldScale(new APJS.Vector3f(scale, scale, scale));
}
}
Scenario Example
Achieve object rotation by modifying rotation
let rotation = sceneObject.getTransform().localRotation;
let r = new APJS.Quaternionf();
r.x = 0;
r.y = Math.sin(5);
r.z = 0;
r.w = Math.cos(5);
rotation = rotation.multiply(r);
sceneObject.getTransform().localRotation = rotation;