add rotate function to node

This commit is contained in:
jerrywwl
2019-01-08 19:56:51 +08:00
parent d38733f6a4
commit b89c771290
6 changed files with 265 additions and 140 deletions
+85 -38
View File
@@ -24,7 +24,7 @@ export default class quat {
* @param w - Value assigned to w component.
* @return The newly created quaternion.
*/
public static create (x = 0, y = 0, z = 0, w = 1) {
public static create(x = 0, y = 0, z = 0, w = 1) {
return new quat(x, y, z, w);
}
@@ -34,7 +34,7 @@ export default class quat {
* @param a - Quaternion to clone.
* @return The newly created quaternion.
*/
public static clone (a: quat) {
public static clone(a: quat) {
return new quat(a.x, a.y, a.z, a.w);
}
@@ -45,7 +45,7 @@ export default class quat {
* @param a - The specified quaternion.
* @return out.
*/
public static copy<Out extends IQuatLike> (out: Out, a: quat) {
public static copy<Out extends IQuatLike>(out: Out, a: quat) {
return vec4.copy(out, a);
}
@@ -59,7 +59,7 @@ export default class quat {
* @param w - Value set to w component.
* @return out.
*/
public static set<Out extends IQuatLike> (out: Out, x: number, y: number, z: number, w: number) {
public static set<Out extends IQuatLike>(out: Out, x: number, y: number, z: number, w: number) {
out.x = x;
out.y = y;
out.z = z;
@@ -73,7 +73,7 @@ export default class quat {
* @param out - Quaternion to set.
* @return out.
*/
public static identity<Out extends IQuatLike> (out: Out) {
public static identity<Out extends IQuatLike>(out: Out) {
out.x = 0;
out.y = 0;
out.z = 0;
@@ -92,7 +92,7 @@ export default class quat {
* @param b - The destination vector.
* @return out.
*/
public static rotationTo<Out extends IQuatLike> (out: Out, a: vec3, b: vec3) {
public static rotationTo<Out extends IQuatLike>(out: Out, a: vec3, b: vec3) {
const dot = vec3.dot(a, b);
if (dot < -0.999999) {
vec3.cross(tmpVec3, tmpXUnitVec3, a);
@@ -131,7 +131,7 @@ export default class quat {
* @param {quat} q - Quaternion to be decomposed.
* @return - Angle, in radians, of the rotation.
*/
public static getAxisAngle<Out extends IVec3Like> (outAxis: Out, q: quat) {
public static getAxisAngle<Out extends IVec3Like>(outAxis: Out, q: quat) {
const rad = Math.acos(q.w) * 2.0;
const s = Math.sin(rad / 2.0);
if (s !== 0.0) {
@@ -155,7 +155,7 @@ export default class quat {
* @param b - The second operand.
* @return out.
*/
public static multiply<Out extends IQuatLike> (out: Out, a: quat, b: quat) {
public static multiply<Out extends IQuatLike>(out: Out, a: quat, b: quat) {
const { x: ax, y: ay, z: az, w: aw } = a;
const { x: bx, y: by, z: bz, w: bw } = b;
@@ -169,7 +169,7 @@ export default class quat {
/**
* Alias of {@link quat.multiply}.
*/
public static mul<Out extends IQuatLike> (out: Out, a: quat, b: quat) {
public static mul<Out extends IQuatLike>(out: Out, a: quat, b: quat) {
return quat.multiply(out, a, b);
}
@@ -181,7 +181,7 @@ export default class quat {
* @param b - The scale number.
* @return out.
*/
public static scale<Out extends IQuatLike> (out: Out, a: quat, b: number) {
public static scale<Out extends IQuatLike>(out: Out, a: quat, b: number) {
out.x = a.x * b;
out.y = a.y * b;
out.z = a.z * b;
@@ -197,7 +197,7 @@ export default class quat {
* @param rad - Angle (in radians) to rotate.
* @return out.
*/
public static rotateX<Out extends IQuatLike> (out: Out, a: quat, rad: number) {
public static rotateX<Out extends IQuatLike>(out: Out, a: quat, rad: number) {
rad *= 0.5;
const { x: ax, y: ay, z: az, w: aw } = a;
@@ -219,7 +219,7 @@ export default class quat {
* @param rad - Angle (in radians) to rotate.
* @return out.
*/
public static rotateY<Out extends IQuatLike> (out: Out, a: quat, rad: number) {
public static rotateY<Out extends IQuatLike>(out: Out, a: quat, rad: number) {
rad *= 0.5;
const { x: ax, y: ay, z: az, w: aw } = a;
@@ -241,7 +241,7 @@ export default class quat {
* @param rad - Angle (in radians) to rotate.
* @return out.
*/
public static rotateZ<Out extends IQuatLike> (out: Out, a: quat, rad: number) {
public static rotateZ<Out extends IQuatLike>(out: Out, a: quat, rad: number) {
rad *= 0.5;
const { x: ax, y: ay, z: az, w: aw } = a;
@@ -264,7 +264,7 @@ export default class quat {
* @param rad - Angle (in radians) to rotate.
* @return out.
*/
public static rotateAround<Out extends IQuatLike> (out: Out, rot: quat, axis: IVec3Like, rad: number) {
public static rotateAround<Out extends IQuatLike>(out: Out, rot: quat, axis: IVec3Like, rad: number) {
// get inv-axis (local to rot)
quat.invert(tmpQuat1, rot);
vec3.transformQuat(tmpVec3, axis, tmpQuat1);
@@ -283,7 +283,7 @@ export default class quat {
* @param rad - Angle (in radians) to rotate.
* @return out.
*/
public static rotateAroundLocal<Out extends IQuatLike> (out: Out, rot: quat, axis: IVec3Like, rad: number) {
public static rotateAroundLocal<Out extends IQuatLike>(out: Out, rot: quat, axis: IVec3Like, rad: number) {
quat.fromAxisAngle(tmpQuat1, axis, rad);
quat.mul(out, rot, tmpQuat1);
return out;
@@ -298,7 +298,7 @@ export default class quat {
* @param a - Quaternion to calculate W.
* @return out.
*/
public static calculateW<Out extends IQuatLike> (out: Out, a: quat) {
public static calculateW<Out extends IQuatLike>(out: Out, a: quat) {
const { x, y, z } = a;
out.x = x;
@@ -315,7 +315,7 @@ export default class quat {
* @param b - The second operand.
* @return - The dot product of a and b.
*/
public static dot (a: quat, b: quat) {
public static dot(a: quat, b: quat) {
return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
}
@@ -328,7 +328,7 @@ export default class quat {
* @param t - The interpolation coefficient.
* @return out.
*/
public static lerp<Out extends IQuatLike> (out: Out, a: quat, b: quat, t: number) {
public static lerp<Out extends IQuatLike>(out: Out, a: quat, b: quat, t: number) {
const { x: ax, y: ay, z: az, w: aw } = a;
out.x = ax + t * (b.x - ax);
out.y = ay + t * (b.y - ay);
@@ -346,7 +346,7 @@ export default class quat {
* @param t - The interpolation coefficient.
* @return out.
*/
public static slerp<Out extends IQuatLike> (out: Out, a: quat, b: quat, t: number) {
public static slerp<Out extends IQuatLike>(out: Out, a: quat, b: quat, t: number) {
// benchmarks:
// http://jsperf.com/quaternion-slerp-implementations
@@ -399,7 +399,7 @@ export default class quat {
* @param t - The interpolation coefficient.
* @return out
*/
public static sqlerp<Out extends IQuatLike> (out: Out, a: quat, b: quat, c: quat, d: quat, t: number) {
public static sqlerp<Out extends IQuatLike>(out: Out, a: quat, b: quat, c: quat, d: quat, t: number) {
quat.slerp(tmpQuat1, a, d, t);
quat.slerp(tmpQuat2, b, c, t);
quat.slerp(out, tmpQuat1, tmpQuat2, 2 * t * (1 - t));
@@ -413,7 +413,7 @@ export default class quat {
* @param a - Quaternion to calculate inverse of.
* @return out.
*/
public static invert<Out extends IQuatLike> (out: Out, a: quat) {
public static invert<Out extends IQuatLike>(out: Out, a: quat) {
const { x: a0, y: a1, z: a2, w: a3 } = a;
const dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;
const invDot = dot ? 1.0 / dot : 0;
@@ -435,7 +435,7 @@ export default class quat {
* @param a - Quaternion to calculate conjugate of.
* @return out.
*/
public static conjugate<Out extends IQuatLike> (out: Out, a: quat) {
public static conjugate<Out extends IQuatLike>(out: Out, a: quat) {
out.x = -a.x;
out.y = -a.y;
out.z = -a.z;
@@ -449,7 +449,7 @@ export default class quat {
* @param a - The quaternion.
* @return Length of the quaternion.
*/
public static magnitude (a: quat) {
public static magnitude(a: quat) {
const { x, y, z, w } = a;
return Math.sqrt(x * x + y * y + z * z + w * w);
}
@@ -457,7 +457,7 @@ export default class quat {
/**
* Alias of {@link quat.magnitude}.
*/
public static mag (a: quat) {
public static mag(a: quat) {
return quat.magnitude(a);
}
@@ -467,7 +467,7 @@ export default class quat {
* @param a - The quaternion.
* @return Squared length of the quaternion.
*/
public static squaredMagnitude (a: quat) {
public static squaredMagnitude(a: quat) {
const { x, y, z, w } = a;
return x * x + y * y + z * z + w * w;
}
@@ -475,7 +475,7 @@ export default class quat {
/**
* Alias of {@link quat.squaredMagnitude}
*/
public static sqrMag (a: quat) {
public static sqrMag(a: quat) {
return quat.squaredMagnitude(a);
}
@@ -487,7 +487,7 @@ export default class quat {
* @return out.
* @function
*/
public static normalize<Out extends IQuatLike> (out: Out, a: quat) {
public static normalize<Out extends IQuatLike>(out: Out, a: quat) {
const { x, y, z, w } = a;
let len = x * x + y * y + z * z + w * w;
if (len > 0) {
@@ -511,7 +511,7 @@ export default class quat {
* @param zAxis - Vector representing the viewing direction.
* @return out.
*/
public static fromAxes<Out extends IQuatLike> (out: Out, xAxis: IVec3Like, yAxis: IVec3Like, zAxis: IVec3Like) {
public static fromAxes<Out extends IQuatLike>(out: Out, xAxis: IVec3Like, yAxis: IVec3Like, zAxis: IVec3Like) {
mat3.set(tmpMat3,
xAxis.x, xAxis.y, xAxis.z,
yAxis.x, yAxis.y, yAxis.z,
@@ -529,7 +529,7 @@ export default class quat {
*
* @return out.
*/
public static fromViewUp<Out extends IQuatLike> (out: Out, view: IVec3Like, up: IVec3Like) {
public static fromViewUp<Out extends IQuatLike>(out: Out, view: IVec3Like, up: IVec3Like) {
mat3.fromViewUp(tmpMat3, view, up);
return quat.normalize(out, quat.fromMat3(out, tmpMat3));
}
@@ -543,7 +543,7 @@ export default class quat {
* @param rad - The angle in radians.
* @return out.
*/
public static fromAxisAngle<Out extends IQuatLike> (out: Out, axis: IVec3Like, rad: number) {
public static fromAxisAngle<Out extends IQuatLike>(out: Out, axis: IVec3Like, rad: number) {
rad = rad * 0.5;
const s = Math.sin(rad);
out.x = s * axis.x;
@@ -564,7 +564,7 @@ export default class quat {
* @return out.
* @function
*/
public static fromMat3<Out extends IQuatLike> (out: Out, m: IMat3Like) {
public static fromMat3<Out extends IQuatLike>(out: Out, m: IMat3Like) {
// http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
const {
@@ -621,7 +621,7 @@ export default class quat {
* @return out.
* @function
*/
public static fromEuler<Out extends IQuatLike> (out: Out, x: number, y: number, z: number) {
public static fromEuler<Out extends IQuatLike>(out: Out, x: number, y: number, z: number) {
x *= halfToRad;
y *= halfToRad;
z *= halfToRad;
@@ -641,6 +641,53 @@ export default class quat {
return out;
}
/**
* Returns the X orthonormal axis defining the quaternion.
*
* @param out - X axis.
* @param q - The quaternion.
* @function
*/
public static toAxisX(out: vec3, q: quat) {
let fy = 2.0 * q.y;
let fz = 2.0 * q.z;
out.x = 1.0 - fy * q.y - fz * q.z;
out.y = fy * q.x + fz * q.w;
out.z = fz * q.x + fy * q.w;
}
/**
* Returns the Y orthonormal axis defining the quaternion.
*
* @param out - Y axis.
* @param q - The quaternion.
* @function
*/
public static toAxisY(out: vec3, q: quat) {
let fx = 2.0 * q.x;
let fy = 2.0 * q.y;
let fz = 2.0 * q.z;
out.x = fy * q.x - fz * q.w;
out.y = 1.0 - fx * q.x - fz * q.z;
out.z = fz * q.y + fx * q.w;
}
/**
* Returns the Z orthonormal axis defining the quaternion.
*
* @param out - Z axis.
* @param q - The quaternion.
* @function
*/
public static toAxisZ(out: vec3, q: quat) {
let fx = 2.0 * q.x;
let fy = 2.0 * q.y;
let fz = 2.0 * q.z;
out.x = fz * q.x - fy * q.w;
out.y = fz * q.y - fx * q.w;
out.z = 1.0 - fx * q.x - fy * q.y;
}
/**
* Convert a quaternion back to euler angle (in degrees).
*
@@ -648,7 +695,7 @@ export default class quat {
* @param q - the quaternion to be converted
* @return out.
*/
public static toEuler<Out extends IQuatLike> (out: Out, q: quat) {
public static toEuler<Out extends IQuatLike>(out: Out, q: quat) {
const { x, y, z, w } = q;
let heading: number = 0;
let attitude: number = 0;
@@ -687,7 +734,7 @@ export default class quat {
* @param a - The quaternion.
* @return - String representation of this quaternion.
*/
public static str (a: quat) {
public static str(a: quat) {
return `quat(${a.x}, ${a.y}, ${a.z}, ${a.w})`;
}
@@ -698,7 +745,7 @@ export default class quat {
* @param q - The quaternion.
* @return out.
*/
public static array<Out extends IWritableArrayLike<number>> (out: Out, q: quat) {
public static array<Out extends IWritableArrayLike<number>>(out: Out, q: quat) {
out[0] = q.x;
out[1] = q.y;
out[2] = q.z;
@@ -714,7 +761,7 @@ export default class quat {
* @param b - The second quaternion.
* @return True if the quaternions are equal, false otherwise.
*/
public static exactEquals (a: quat, b: quat) {
public static exactEquals(a: quat, b: quat) {
return vec4.exactEquals(a, b);
}
@@ -725,7 +772,7 @@ export default class quat {
* @param b The second quaternion.
* @return True if the quaternions are approximately equal, false otherwise.
*/
public static equals (a: quat, b: quat) {
public static equals(a: quat, b: quat) {
return vec4.equals(a, b);
}
@@ -757,7 +804,7 @@ export default class quat {
* @param z - Value assigned to z component.
* @param w - Value assigned to w component.
*/
constructor (x = 0, y = 0, z = 0, w = 1) {
constructor(x = 0, y = 0, z = 0, w = 1) {
this.x = x;
this.y = y;
this.z = z;
+15 -15
View File
@@ -450,27 +450,27 @@ export interface GFXExtent {
}
export class GFXTextureSubres {
baseMipLevel: number = 0;
levelCount: number = 1;
baseArrayLayer: number = 0;
layerCount: number = 1;
public baseMipLevel: number = 0;
public levelCount: number = 1;
public baseArrayLayer: number = 0;
public layerCount: number = 1;
}
export class GFXTextureCopy {
srcSubres: GFXTextureSubres = new GFXTextureSubres;
srcOffset: GFXOffset = { x: 0, y: 0, z: 0 };
dstSubres: GFXTextureSubres = new GFXTextureSubres;
dstOffset: GFXOffset = { x: 0, y: 0, z: 0 };
extent: GFXExtent = { width: 0, height: 0, depth: 0 };
public srcSubres: GFXTextureSubres = new GFXTextureSubres;
public srcOffset: GFXOffset = { x: 0, y: 0, z: 0 };
public dstSubres: GFXTextureSubres = new GFXTextureSubres;
public dstOffset: GFXOffset = { x: 0, y: 0, z: 0 };
public extent: GFXExtent = { width: 0, height: 0, depth: 0 };
}
export class GFXBufferTextureCopy {
buffOffset: number = 0;
buffStride: number = 0;
buffTexHeight: number = 0;
texOffset: GFXOffset = { x: 0, y: 0, z: 0 };
texExtent: GFXExtent = { width: 0, height: 0, depth: 0 };
texSubres: GFXTextureSubres = new GFXTextureSubres;
public buffOffset: number = 0;
public buffStride: number = 0;
public buffTexHeight: number = 0;
public texOffset: GFXOffset = { x: 0, y: 0, z: 0 };
public texExtent: GFXExtent = { width: 0, height: 0, depth: 0 };
public texSubres: GFXTextureSubres = new GFXTextureSubres;
}
export interface GFXFormatInfo {
+70 -70
View File
@@ -1,136 +1,109 @@
import { GFXBindingLayout, GFXBindingLayoutInfo } from './binding-layout';
import { GFXBuffer, GFXBufferInfo } from './buffer';
import { GFXCommandAllocator, GFXCommandAllocatorInfo } from './command-allocator';
import { GFXCommandBuffer, GFXCommandBufferInfo } from './command-buffer';
import { GFXBufferTextureCopy, GFXFormat } from './define';
import { GFXFramebuffer, GFXFramebufferInfo } from './framebuffer';
import { GFXInputAssembler, GFXInputAssemblerInfo } from './input-assembler';
import { GFXPipelineLayout, GFXPipelineLayoutInfo } from './pipeline-layout';
import { GFXPipelineState, GFXPipelineStateInfo } from './pipeline-state';
import { GFXQueue, GFXQueueInfo } from './queue';
import { GFXRenderPass, GFXRenderPassInfo } from './render-pass';
import { GFXSampler, GFXSamplerInfo } from './sampler';
import { GFXShader, GFXShaderInfo } from './shader';
import { GFXTexture, GFXTextureInfo } from './texture';
import { GFXTextureViewInfo, GFXTextureView } from './texture-view';
import { GFXFramebufferInfo, GFXFramebuffer } from './framebuffer';
import { GFXRenderPassInfo, GFXRenderPass } from './render-pass';
import { GFXPipelineStateInfo, GFXPipelineState } from './pipeline-state';
import { GFXPipelineLayoutInfo, GFXPipelineLayout } from './pipeline-layout';
import { GFXSamplerInfo, GFXSampler } from './sampler';
import { GFXShaderInfo, GFXShader } from './shader';
import { GFXInputAssemblerInfo, GFXInputAssembler } from './input-assembler';
import { GFXCommandBufferInfo, GFXCommandBuffer } from './command-buffer';
import { GFXCommandAllocatorInfo, GFXCommandAllocator } from './command-allocator';
import { GFXWindowInfo, GFXWindow } from './window';
import { GFXBindingLayoutInfo, GFXBindingLayout } from './binding-layout';
import { GFXRect, GFXBufferTextureCopy, GFXFormat } from './define';
import { GFXTextureView, GFXTextureViewInfo } from './texture-view';
import { GFXWindow, GFXWindowInfo } from './window';
export enum GFXFeature {
};
}
export interface GFXDeviceInfo {
canvasElm: HTMLElement;
isAntialias?: boolean;
isPremultipliedAlpha?: boolean;
};
}
export abstract class GFXDevice {
public abstract initialize(info: GFXDeviceInfo): boolean;
public abstract destroy(): void;
public abstract createBuffer(info: GFXBufferInfo): GFXBuffer | null;
public abstract createTexture(info: GFXTextureInfo): GFXTexture | null;
public abstract createTextureView(info: GFXTextureViewInfo): GFXTextureView | null;
public abstract createSampler(info: GFXSamplerInfo): GFXSampler | null;
public abstract createBindingLayout(info: GFXBindingLayoutInfo): GFXBindingLayout | null;
public abstract createShader(info: GFXShaderInfo): GFXShader | null;
public abstract createInputAssembler(info: GFXInputAssemblerInfo): GFXInputAssembler | null;
public abstract createRenderPass(info: GFXRenderPassInfo): GFXRenderPass | null;
public abstract createFramebuffer(info: GFXFramebufferInfo): GFXFramebuffer | null;
public abstract createPipelineLayout(info: GFXPipelineLayoutInfo): GFXPipelineLayout | null;
public abstract createPipelineState(info: GFXPipelineStateInfo): GFXPipelineState | null;
public abstract createCommandAllocator(info: GFXCommandAllocatorInfo): GFXCommandAllocator | null;
public abstract createCommandBuffer(info: GFXCommandBufferInfo): GFXCommandBuffer | null;
public abstract createQueue(info: GFXQueueInfo): GFXQueue | null;
public abstract createWindow(info: GFXWindowInfo): GFXWindow | null;
public abstract present();
public abstract copyBufferToTexture(buffer: ArrayBuffer, texture: GFXTexture, regions: GFXBufferTextureCopy[]);
public abstract copyImageSourceToTexture(source: CanvasImageSource, texture: GFXTexture, regions: GFXBufferTextureCopy[]);
public abstract copyFramebufferToBuffer(srcFramebuffer: GFXFramebuffer, dstBuffer: ArrayBuffer, regions: GFXBufferTextureCopy[]);
public get canvas(): HTMLCanvasElement {
return <HTMLCanvasElement>this._canvas;
public get canvas (): HTMLCanvasElement {
return this._canvas as HTMLCanvasElement;
}
public get canvas2D(): HTMLCanvasElement {
return <HTMLCanvasElement>this._canvas2D;
public get canvas2D (): HTMLCanvasElement {
return this._canvas2D as HTMLCanvasElement;
}
public get queue(): GFXQueue {
return <GFXQueue>this._queue;
public get queue (): GFXQueue {
return this._queue as GFXQueue;
}
public get width(): number {
public get width (): number {
return this._width;
}
public get height(): number {
public get height (): number {
return this._height;
}
public get mainWindow(): GFXWindow {
return <GFXWindow>this._mainWindow;
public get mainWindow (): GFXWindow {
return this._mainWindow as GFXWindow;
}
public get commandAllocator(): GFXCommandAllocator {
return <GFXCommandAllocator>this._cmdAllocator;
public get commandAllocator (): GFXCommandAllocator {
return this._cmdAllocator as GFXCommandAllocator;
}
public get renderer(): string {
public get renderer (): string {
return this._renderer;
}
public get vendor(): string {
public get vendor (): string {
return this._vendor;
}
public get maxVertexAttributes(): number {
public get maxVertexAttributes (): number {
return this._maxVertexAttributes;
}
public get maxVertexUniformVectors(): number {
public get maxVertexUniformVectors (): number {
return this._maxVertexUniformVectors;
}
public get maxFragmentUniformVectors(): number {
public get maxFragmentUniformVectors (): number {
return this._maxFragmentUniformVectors;
}
public get maxTextureUnits(): number {
public get maxTextureUnits (): number {
return this._maxTextureUnits;
}
public get maxVertexTextureUnits(): number {
public get maxVertexTextureUnits (): number {
return this._maxVertexTextureUnits;
}
public get depthBits(): number {
public get depthBits (): number {
return this._depthBits;
}
public get stencilBits(): number {
public get stencilBits (): number {
return this._stencilBits;
}
public get colorFormat(): GFXFormat {
public get colorFormat (): GFXFormat {
return this._colorFmt;
}
public get depthStencilFormat(): GFXFormat {
public get depthStencilFormat (): GFXFormat {
return this._depthStencilFmt;
}
public genShaderId(): number {
return this._shaderIdGen++;
}
protected _canvas: HTMLCanvasElement | null = null;
protected _canvas2D: HTMLCanvasElement | null = null;
protected _deviceName: string = "";
protected _renderer: string = "";
protected _vendor: string = "";
protected _version: string = "";
protected _deviceName: string = '';
protected _renderer: string = '';
protected _vendor: string = '';
protected _version: string = '';
protected _queue: GFXQueue | null = null;
protected _width: number = 0;
protected _height: number = 0;
@@ -146,4 +119,31 @@ export abstract class GFXDevice {
protected _colorFmt: GFXFormat = GFXFormat.UNKNOWN;
protected _depthStencilFmt: GFXFormat = GFXFormat.UNKNOWN;
protected _shaderIdGen: number = 0;
};
public abstract initialize (info: GFXDeviceInfo): boolean;
public abstract destroy (): void;
public abstract createBuffer (info: GFXBufferInfo): GFXBuffer | null;
public abstract createTexture (info: GFXTextureInfo): GFXTexture | null;
public abstract createTextureView (info: GFXTextureViewInfo): GFXTextureView | null;
public abstract createSampler (info: GFXSamplerInfo): GFXSampler | null;
public abstract createBindingLayout (info: GFXBindingLayoutInfo): GFXBindingLayout | null;
public abstract createShader (info: GFXShaderInfo): GFXShader | null;
public abstract createInputAssembler (info: GFXInputAssemblerInfo): GFXInputAssembler | null;
public abstract createRenderPass (info: GFXRenderPassInfo): GFXRenderPass | null;
public abstract createFramebuffer (info: GFXFramebufferInfo): GFXFramebuffer | null;
public abstract createPipelineLayout (info: GFXPipelineLayoutInfo): GFXPipelineLayout | null;
public abstract createPipelineState (info: GFXPipelineStateInfo): GFXPipelineState | null;
public abstract createCommandAllocator (info: GFXCommandAllocatorInfo): GFXCommandAllocator | null;
public abstract createCommandBuffer (info: GFXCommandBufferInfo): GFXCommandBuffer | null;
public abstract createQueue (info: GFXQueueInfo): GFXQueue | null;
public abstract createWindow (info: GFXWindowInfo): GFXWindow | null;
public abstract present ();
public abstract copyBufferToTexture (buffer: ArrayBuffer, texture: GFXTexture, regions: GFXBufferTextureCopy[]);
public abstract copyImageSourceToTexture (source: CanvasImageSource, texture: GFXTexture, regions: GFXBufferTextureCopy[]);
public abstract copyFramebufferToBuffer (srcFramebuffer: GFXFramebuffer, dstBuffer: ArrayBuffer, regions: GFXBufferTextureCopy[]);
public genShaderId (): number {
return this._shaderIdGen++;
}
}
+33 -9
View File
@@ -126,13 +126,31 @@ export class Camera {
return this._position;
}
public rotate(axis: vec3, rad: number, ns?: NodeSpace) {
public rotate(rot: quat, ns?: NodeSpace) {
let space = (ns !== undefined? ns : NodeSpace.LOCAL);
if(space === NodeSpace.LOCAL || space === NodeSpace.PARENT) {
this._node.rotate(rot);
} else if (space === NodeSpace.WORLD) {
this._node.rotateWorld(rot);
}
}
public rotateFromAxisAngle(axis: vec3, rad: number, ns?: NodeSpace) {
quat.fromAxisAngle(this._rotation, axis, rad);
let space = (ns !== undefined? ns : NodeSpace.LOCAL);
if(space === NodeSpace.LOCAL || space === NodeSpace.PARENT) {
this._node.setRotation(this._rotation);
this._node.rotate(this._rotation);
} else if (space === NodeSpace.WORLD) {
this._node.setWorldRotation(this._rotation);
this._node.rotateWorld(this._rotation);
}
}
public setRotation(rot: quat, ns?: NodeSpace) {
let space = (ns !== undefined? ns : NodeSpace.LOCAL);
if(space === NodeSpace.LOCAL || space === NodeSpace.PARENT) {
this._node.setRotation(rot);
} else if (space === NodeSpace.WORLD) {
this._node.setWorldRotation(rot);
}
}
@@ -140,10 +158,12 @@ export class Camera {
let space = (ns !== undefined? ns : NodeSpace.LOCAL);
if(space === NodeSpace.LOCAL || space === NodeSpace.PARENT) {
this._node.getRotation(this._rotation);
this.rotate(this._rotation, rad, ns);
quat.toAxisX(this._direction, this._rotation);
this.rotateFromAxisAngle(this._direction, rad, ns);
} else if (space === NodeSpace.WORLD) {
this._node.getWorldRotation(this._rotation);
this.rotate(this._rotation, rad, ns);
quat.toAxisX(this._direction, this._rotation);
this.rotateFromAxisAngle(this._direction, rad, ns);
}
}
@@ -151,10 +171,12 @@ export class Camera {
let space = (ns !== undefined? ns : NodeSpace.LOCAL);
if(space === NodeSpace.LOCAL || space === NodeSpace.PARENT) {
this._node.getRotation(this._rotation);
this.rotate(this._rotation, rad, ns);
quat.toAxisY(this._direction, this._rotation);
this.rotateFromAxisAngle(this._direction, rad, ns);
} else if (space === NodeSpace.WORLD) {
this._node.getWorldRotation(this._rotation);
this.rotate(this._rotation, rad, ns);
quat.toAxisY(this._direction, this._rotation);
this.rotateFromAxisAngle(this._direction, rad, ns);
}
}
@@ -162,10 +184,12 @@ export class Camera {
let space = (ns !== undefined? ns : NodeSpace.LOCAL);
if(space === NodeSpace.LOCAL || space === NodeSpace.PARENT) {
this._node.getRotation(this._rotation);
this.rotate(this._rotation, rad, ns);
quat.toAxisZ(this._direction, this._rotation);
this.rotateFromAxisAngle(this._direction, rad, ns);
} else if (space === NodeSpace.WORLD) {
this._node.getWorldRotation(this._rotation);
this.rotate(this._rotation, rad, ns);
quat.toAxisZ(this._direction, this._rotation);
this.rotateFromAxisAngle(this._direction, rad, ns);
}
}
+1 -1
View File
@@ -151,7 +151,7 @@ export default class Model {
}
recordCommandBuffer(index: number) {
let pass = this._material.passes[index];
let pass = (<Material>this._material).passes[index];
let cmdBufferInfo = {
allocator: cc.director.root.device.commandAllocator,
type: GFXCommandBufferType.SECONDARY,
+61 -7
View File
@@ -7,6 +7,7 @@ import { ccclass, property, mixins } from '../core/data/class-decorator';
let v3_a = cc.v3();
let q_a = cc.quat();
let q_b = cc.quat();
let array_a = new Array(10);
let EventType = cc.Enum({
@@ -67,13 +68,13 @@ class Node extends BaseNode {
_eulerDirty = false;
// is node but not scene
static isNode (obj) {
static isNode(obj) {
return obj instanceof Node && (obj.constructor === Node || !(obj instanceof cc.Scene));
}
static EventType = EventType;
constructor (name) {
constructor(name) {
super(name);
EventTarget.call(this);
}
@@ -158,11 +159,11 @@ class Node extends BaseNode {
while (i) {
child = array_a[--i];
if (cur) {
vec3.mul(child._pos, child._lpos, cur._scale);
vec3.transformQuat(child._pos, child._pos, cur._rot);
vec3.add(child._pos, child._pos, cur._pos);
quat.mul(child._rot, cur._rot, child._lrot);
vec3.mul(child._scale, cur._scale, child._lscale);
vec3.mul(child._pos, child._lpos, cur._scale);
vec3.transformQuat(child._pos, child._pos, cur._rot);
vec3.add(child._pos, child._pos, cur._pos);
quat.mul(child._rot, cur._rot, child._lrot);
vec3.mul(child._scale, cur._scale, child._lscale);
}
child._matDirty = true; // further deferred eval
child._dirty = false;
@@ -211,6 +212,59 @@ class Node extends BaseNode {
}
}
/**
* rotate in local space
*
* @param {quat|number} val the new local rotation, or the x component of it
* @param {number} [y] the y component of the new local rotation
* @param {number} [z] the z component of the new local rotation
* @param {number} [w] the w component of the new local rotation
*/
rotate(val, y, z, w) {
if (arguments.length === 1) {
quat.normalize(q_a, val);
} else if (arguments.length === 4) {
quat.set(q_a, val, y, z, w);
quat.normalize(q_a, q_a);
}
quat.multiply(this._lrot, this._lrot, q_a);
this._eulerDirty = true;
this.invalidateChildren();
this.emit(EventType.TRANSFORM_CHANGED, EventType.ROTATION_PART);
}
/**
* rotate in world space
*
* @param {quat|number} val the new local rotation, or the x component of it
* @param {number} [y] the y component of the new local rotation
* @param {number} [z] the z component of the new local rotation
* @param {number} [w] the w component of the new local rotation
*/
rotateWorld(val, y, z, w) {
if (arguments.length === 1) {
quat.normalize(q_a, val);
} else if (arguments.length === 4) {
quat.set(q_a, val, y, z, w);
quat.normalize(q_a, q_a);
}
getWorldRotation(q_b);
quat.invert(q_b);
quat.multiply(q_a, q_a, q_b);
quat.multiply(this._lrot, this._lrot, q_a);
this._eulerDirty = true;
this.invalidateChildren();
this.emit(EventType.TRANSFORM_CHANGED, EventType.ROTATION_PART);
}
/**
* set local rotation
* @param {quat|number} val the new local rotation, or the x component of it