Files
cocos4/cocos/renderer/scene/directional-light.ts
T
ChiaNing 4bc2739786 Vmath (#4987)
* Vmath (#4895)

* vmath refactor

* value-type API change

* vmath change update

* conflict fix

* value types change

* translate modify (#4917)

* value types bug fixed (#4940)

* playground update (#4946)

* bug fixed

* bug fixed

* bug fixed

* bug fix

* util modify

* create remove & ccenum rename

* export by cc.math

* Rename value-types to math

* util funtion deprecated warn

* value-types change

* color test fix

* color API change
2019-07-29 11:50:51 +08:00

45 lines
1.1 KiB
TypeScript

import { Quat, Vec3 } from '../../core/math';
import { Light, LightType } from './light';
import { RenderScene } from './render-scene';
import { INode } from '../../core/utils/interfaces';
const _forward = new Vec3(0, 0, -1);
const _v3 = new Vec3();
const _qt = new Quat();
export class DirectionalLight extends Light {
protected _dir: Vec3 = new Vec3(1.0, -1.0, -1.0);
protected _illum: number = 65000.0;
set direction (dir: Vec3) {
this._dir = dir;
Vec3.normalize(this._dir, this._dir);
}
get direction (): Vec3 {
return this._dir;
}
// in Lux(lx)
set illuminance (illum: number) {
this._illum = illum;
}
get illuminance (): number {
return this._illum;
}
constructor (scene: RenderScene, name: string, node: INode) {
super(scene, name, node);
this._type = LightType.DIRECTIONAL;
}
public update () {
if (this._node) {
this._dir = Vec3.transformQuat(_v3, _forward, this._node.getWorldRotation(_qt));
Vec3.normalize(this._dir, this._dir);
}
}
}