Merge pull request #35 from YunHsiao/gfx

camera component test scene
This commit is contained in:
Weiliang Wang
2019-01-10 21:15:55 +08:00
committed by GitHub
4 changed files with 24 additions and 22 deletions
+1 -1
View File
@@ -328,7 +328,7 @@ export abstract class RenderPipeline {
mat4.array(_mat4Array, camera.matViewProjInv);
this._uboGlobal.view.set(_mat4Array, UBOGlobal.MAT_VIEW_PROJ_INV_OFFSET);
vec3.array(_vec4Array, camera.position);
vec3.array(_vec4Array, camera.node && camera.node.getPosition());
_vec4Array[3] = 1.0;
this._uboGlobal.view.set(_vec4Array, UBOGlobal.CAMERA_POS_OFFSET);
+2 -3
View File
@@ -223,7 +223,6 @@ export class Camera {
*/
public screenPointToRay (x: number, y: number, out: ray): ray {
out = out || ray.create();
this.update();
const cx = this._viewport.x * this._width;
const cy = this._viewport.y * this._height;
@@ -236,7 +235,7 @@ export class Camera {
if (this._proj === CameraProjection.PERSPECTIVE) {
// camera origin
this._node.getWorldPosition(v_b);
if (this._node) { this._node.getWorldPosition(v_b); }
} else {
// near plane intersection
vec3.set(v_b, (x - cx) / cw * 2 - 1, (y - cy) / ch * 2 - 1, -1);
@@ -267,7 +266,7 @@ export class Camera {
vec3.transformMat4(out, out, this._matViewProjInv);
// lerp to depth z
this._node.getWorldPosition(v_a);
if (this._node) { this._node.getWorldPosition(v_a); }
vec3.lerp(out, v_a, out, lerp(this._nearClip / this._farClip, 1, screenPos.z));
} else {
+9 -9
View File
@@ -297,7 +297,7 @@ class Node extends BaseNode {
* @param out the receiving vector
* @returns the resulting vector
*/
public getPosition (out: Vec3): Vec3 {
public getPosition (out?: Vec3): Vec3 {
if (out) {
return vec3.set(out, this._lpos.x, this._lpos.y, this._lpos.z);
} else {
@@ -346,7 +346,7 @@ class Node extends BaseNode {
* @param out - the receiving quaternion
* @returns the resulting quaternion
*/
public getRotation (out: Quat): Quat {
public getRotation (out?: Quat): Quat {
if (out) {
return quat.set(out, this._lrot.x, this._lrot.y, this._lrot.z, this._lrot.w);
} else {
@@ -377,7 +377,7 @@ class Node extends BaseNode {
* @param out - the receiving vector
* @returns the resulting vector
*/
public getScale (out: Vec3): Vec3 {
public getScale (out?: Vec3): Vec3 {
if (out) {
return vec3.set(out, this._lscale.x, this._lscale.y, this._lscale.z);
} else {
@@ -417,7 +417,7 @@ class Node extends BaseNode {
* @param out - the receiving vector
* @returns the resulting vector
*/
public getWorldPosition (out: Vec3): Vec3 {
public getWorldPosition (out?: Vec3): Vec3 {
this.updateWorldTransform();
if (out) {
return vec3.copy(out, this._pos);
@@ -477,7 +477,7 @@ class Node extends BaseNode {
* @param out - the receiving quaternion
* @returns the resulting quaternion
*/
public getWorldRotation (out: Quat): Quat {
public getWorldRotation (out?: Quat): Quat {
this.updateWorldTransform();
if (out) {
return quat.copy(out, this._rot);
@@ -514,7 +514,7 @@ class Node extends BaseNode {
* @param out - the receiving vector
* @returns the resulting vector
*/
public getWorldScale (out: Vec3): Vec3 {
public getWorldScale (out?: Vec3): Vec3 {
this.updateWorldTransform();
if (out) {
return vec3.copy(out, this._scale);
@@ -528,7 +528,7 @@ class Node extends BaseNode {
* @param out - the receiving matrix
* @returns the - resulting matrix
*/
public getWorldMatrix (out: Mat4): Mat4 {
public getWorldMatrix (out?: Mat4): Mat4 {
this.updateWorldTransformFull();
if (out) {
return mat4.copy(out, this._mat);
@@ -542,7 +542,7 @@ class Node extends BaseNode {
* @param out - the receiving matrix
* @returns the - resulting matrix
*/
public getWorldRS (out: Mat4): Mat4 {
public getWorldRS (out?: Mat4): Mat4 {
this.updateWorldTransformFull();
if (out) {
mat4.copy(out, this._mat);
@@ -558,7 +558,7 @@ class Node extends BaseNode {
* @param out - the receiving matrix
* @returns the - resulting matrix
*/
public getWorldRT (out: Mat4): Mat4 {
public getWorldRT (out?: Mat4): Mat4 {
this.updateWorldTransform();
if (!out) {
out = new Mat4();
+12 -9
View File
@@ -55,11 +55,13 @@
*/
let root = cc.director.root;
let scene = root.createScene({
name: "testScene",
});
let scene = new cc.Scene();
let cameraNode = new cc.Node();
cameraNode.parent = scene;
let camComp = cameraNode.addComponent(cc.CameraComponent);
let mainWindow = root.mainWindow;
cc.director.runSceneImmediate(scene);
let view = root.createView({
name: "defaultView",
@@ -69,12 +71,14 @@
width: mainWindow.width,
height: mainWindow.height,
});
view.attach(scene.mainCamera);
view.attach(camComp._camera);
let camera = scene.mainCamera;
camera.position = { x: 0.0, y: 0.0, z: 3.0 };
camera.direction = { x: 0.0, y: 0.0, z: -1.0 };
camera.update();
// let camera = scene.mainCamera;
// camera.position = { x: 0.0, y: 0.0, z: 3.0 };
// camera.direction = { x: 0.0, y: 0.0, z: -1.0 };
// camera.update();
//todo initialization
/*
@@ -106,7 +110,6 @@
mtl.setProperty('emissive', color);
/**/
// model.material = mtl;
//cc.director.runSceneImmediate(scene);
}
cc.game.run({ id: 'canvas' }, onStart);
</script>