You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WebCAD/src/Geometry/CoordinateSystem.ts

69 lines
1.7 KiB

import { Matrix4, Vector3 } from 'three';
/**
* .
*/
7 years ago
export class CoordinateSystem
{
Postion: Vector3;
XAxis: Vector3;
YAxis: Vector3;
ZAxis: Vector3;
7 years ago
constructor(postion?: Vector3, xAxis?: Vector3, yAxis?: Vector3, zAxis?: Vector3)
7 years ago
{
this.Postion = postion || new Vector3(0, 0, 0);
this.XAxis = xAxis || new Vector3(1, 0, 0);
this.YAxis = yAxis || new Vector3(0, 1, 0);
this.ZAxis = zAxis || new Vector3(0, 0, 1);
7 years ago
}
applyMatrix4(mat4: Matrix4)
7 years ago
{
this.Postion.applyMatrix4(mat4);
let roMat = mat4.clone().setPosition(new Vector3());
this.XAxis.applyMatrix4(roMat);
this.YAxis.applyMatrix4(roMat);
this.ZAxis.applyMatrix4(roMat);
return this;
7 years ago
}
getMatrix4(): Matrix4
7 years ago
{
let m = new Matrix4()
m.makeBasis(this.XAxis, this.YAxis, this.ZAxis)
m.setPosition(this.Postion)
7 years ago
return m;
}
CopyForm(mat4: Matrix4)
7 years ago
{
this.Postion.setFromMatrixPosition(mat4);
mat4.extractBasis(this.XAxis, this.YAxis, this.ZAxis);
return this;
7 years ago
}
extractBasis(xAxisA: Vector3, yAxisA: Vector3, zAxisA: Vector3)
7 years ago
{
xAxisA.copy(this.XAxis);
yAxisA.copy(this.YAxis);
zAxisA.copy(this.ZAxis);
7 years ago
}
copy(cs: CoordinateSystem): CoordinateSystem
{
this.Postion.copy(cs.Postion);
this.XAxis.copy(cs.XAxis);
this.YAxis.copy(cs.YAxis);
this.ZAxis.copy(cs.ZAxis);
7 years ago
return this;
}
clone()
{
let r = new CoordinateSystem();
r.Postion = this.Postion.clone();
r.XAxis = this.XAxis.clone();
r.YAxis = this.YAxis.clone();
r.ZAxis = this.ZAxis.clone();
return r;
7 years ago
}
}