91 lines
1.6 KiB
JavaScript
Executable File
91 lines
1.6 KiB
JavaScript
Executable File
/*
|
|
* Copyright 2013, kaj dijkstra ,
|
|
* Author, Kaj Dijkstra.
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
import {matrix4, math} from './math.js';
|
|
|
|
class transform{
|
|
|
|
constructor() {
|
|
this.entity = false;
|
|
this.world = matrix4.identity();
|
|
this.local = matrix4.identity();
|
|
|
|
this.position = [0, 0, 0];
|
|
this.scale = [1, 1, 1];
|
|
this.rotation = [0, 0, 0];//Degrees
|
|
}
|
|
|
|
|
|
translate(x,y,z) {
|
|
this.position[0] += x;
|
|
this.position[1] += y;
|
|
this.position[2] += z;
|
|
}
|
|
|
|
translateTo(x,y,z) {
|
|
|
|
this.position = [x,y,z];
|
|
|
|
this.update();
|
|
}
|
|
|
|
update(x,y,z) {
|
|
this.local = matrix4.identity();
|
|
|
|
this.local = matrix4.translate(this.local, this.position);
|
|
|
|
this.local = matrix4.rotateZYX(this.local, [this.rotation[0] * ( Math.PI * 180), this.rotation[1]* ( Math.PI * 180), this.rotation[2]* ( Math.PI * 180)]);
|
|
|
|
this.local = matrix4.scale(this.local, this.scale);
|
|
|
|
//if(this.entity) {
|
|
//this.world = matrix4.mul( this.local, this.entity.parent.transform.world );
|
|
this.world = this.local;
|
|
//}
|
|
|
|
}
|
|
|
|
scaleXYZ(x,y,z) {
|
|
this.scale = [x,y,z];
|
|
this.update();
|
|
}
|
|
|
|
rotate(x,y,z) {
|
|
|
|
}
|
|
|
|
rotateTo(x,y,z) {
|
|
this.rotation = [x,y,z];
|
|
this.update();
|
|
}
|
|
|
|
rotateZ(x) {
|
|
this.world = matrix4.rotateZ( this.world, math.degToRad( x ) );
|
|
}
|
|
|
|
rotateX(x) {
|
|
this.world = matrix4.rotateX( this.world, math.degToRad( x ) );
|
|
}
|
|
rotateY(y) {
|
|
this.world = matrix4.rotateY( this.world, math.degToRad( y ) );
|
|
}
|
|
|
|
getWorldPosition(y) {
|
|
return [this.world[3][0], this.world[3][1], this.world[3][2]];
|
|
}
|
|
|
|
getUpdatedWorldMatrix() {
|
|
return this.world;
|
|
}
|
|
|
|
translateVec(v) {
|
|
this.world = matrix4.translate(this.world, v);
|
|
}
|
|
}
|
|
|
|
|
|
export {transform as default}; |