From 113233b8df5d50fa671d09c87bc37a0a567f105f Mon Sep 17 00:00:00 2001 From: jianglong0156 Date: Thu, 30 Jul 2015 18:00:51 +0800 Subject: [PATCH] add Camera support constructor --- .../manual/3d/jsb_cocos2dx_3d_manual.h | 2 + .../js-bindings/script/3d/jsb_cocos2d_3d.js | 38 ++++++++++++++++++- .../src/BillBoardTest/BillBoardTest.js | 2 +- .../js-tests/src/Camera3DTest/Camera3DTest.js | 10 ++--- tests/js-tests/src/LightTest/LightTest.js | 2 +- tests/js-tests/src/NavMeshTest/NavMeshTest.js | 4 +- .../src/Particle3DTest/Particle3DTest.js | 4 +- .../src/Physics3DTest/Physics3DTest.js | 2 +- .../js-tests/src/Sprite3DTest/Sprite3DTest.js | 14 +++---- tests/js-tests/src/TerrainTest/TerrainTest.js | 6 +-- 10 files changed, 60 insertions(+), 24 deletions(-) diff --git a/cocos/scripting/js-bindings/manual/3d/jsb_cocos2dx_3d_manual.h b/cocos/scripting/js-bindings/manual/3d/jsb_cocos2dx_3d_manual.h index d496e1cd83..b65b866c4a 100644 --- a/cocos/scripting/js-bindings/manual/3d/jsb_cocos2dx_3d_manual.h +++ b/cocos/scripting/js-bindings/manual/3d/jsb_cocos2dx_3d_manual.h @@ -27,7 +27,9 @@ #define __jsb_cocos2dx_3d_manual_h__ #include "jsapi.h" +#include "3d/CCTerrain.h" void register_all_cocos2dx_3d_manual(JSContext *cx, JS::HandleObject global); +bool jsval_to_TerrainData(JSContext* cx, JS::HandleValue v, cocos2d::Terrain::TerrainData* ret); #endif \ No newline at end of file diff --git a/cocos/scripting/js-bindings/script/3d/jsb_cocos2d_3d.js b/cocos/scripting/js-bindings/script/3d/jsb_cocos2d_3d.js index cd0f30f6cf..9583c18d45 100644 --- a/cocos/scripting/js-bindings/script/3d/jsb_cocos2d_3d.js +++ b/cocos/scripting/js-bindings/script/3d/jsb_cocos2d_3d.js @@ -34,7 +34,11 @@ cc.CameraFlag = { USER7 : 1 << 7, USER8 : 1 << 8 }; - +cc.Camera.Mode = { + DEFAULT : 0, + PERSPECTIVE : 1, + ORTHOGRAPHIC : 2 +}; cc.LightType = { DIRECTIONAL : 0, POINT : 1, @@ -418,4 +422,34 @@ jsb.SpotLight.prototype._ctor = function(direction, position, color, innerAngle, else { throw new Error("jsb.SpotLight constructor: arguments error"); } -} \ No newline at end of file +} + +jsb.Terrain.prototype._ctor = function(parameter, fixedType = jsb.Terrain.INCREASE_LOWER){ + if (arguments.length === 2 || arguments.length === 1) { + this.init(parameter, fixedType); + } + else { + throw new Error("jsb.Terrain constructor: arguments error"); + } +} + +/** + * Camera* Camera::create() + * Camera* Camera::createPerspective(float fieldOfView, float aspectRatio, float nearPlane, float farPlane) + * Camera* Camera::createOrthographic(float zoomX, float zoomY, float nearPlane, float farPlane) + */ +cc.Camera.prototype._ctor = function(cameraMode, first, second, third, fourth){ + if (arguments.length === 1 && cameraMode == cc.Camera.Mode.DEFAULT) { + this.initDefault(); + this.setDepth(0); + } + else if (arguments.length === 5 && cameraMode == cc.Camera.Mode.PERSPECTIVE) { + this.initPerspective(first, second, third, fourth); + } + else if (arguments.length === 5 && cameraMode == cc.Camera.Mode.ORTHOGRAPHIC) { + this.initOrthographic(first, second, third, fourth); + } + else { + throw new Error("jsb.Camera constructor: arguments error"); + } +} diff --git a/tests/js-tests/src/BillBoardTest/BillBoardTest.js b/tests/js-tests/src/BillBoardTest/BillBoardTest.js index d81c74f1bc..1d67d1318a 100644 --- a/tests/js-tests/src/BillBoardTest/BillBoardTest.js +++ b/tests/js-tests/src/BillBoardTest/BillBoardTest.js @@ -178,7 +178,7 @@ var BillBoardTest = BillBoardTestDemo.extend({ var s = cc.winSize; if(!this._camera){ - this._camera = cc.Camera.createPerspective(60, s.width/s.height, 1, 500); + this._camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 60, s.width/s.height, 1, 500); this._camera.setCameraFlag(cc.CameraFlag.USER1); this._layerBillBorad.addChild(this._camera); } diff --git a/tests/js-tests/src/Camera3DTest/Camera3DTest.js b/tests/js-tests/src/Camera3DTest/Camera3DTest.js index 655c12fd28..09cbe32306 100644 --- a/tests/js-tests/src/Camera3DTest/Camera3DTest.js +++ b/tests/js-tests/src/Camera3DTest/Camera3DTest.js @@ -343,7 +343,7 @@ var Camera3DTest = (function(){ this.schedule(this.updateCamera, 0); if(this._camera == null){ - this._camera = cc.Camera.createPerspective(60, s.width/s.height, 1, 1000); + this._camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 60, s.width/s.height, 1, 1000); this._camera.setCameraFlag(cc.CameraFlag.USER1); layer3D.addChild(this._camera); } @@ -768,7 +768,7 @@ var CameraCullingDemo = Camera3DTestDemo.extend({ switchViewCallback:function(sender){ if(!this._cameraFirst){ - var camera = cc.Camera.createPerspective(30, cc.winSize.width/cc.winSize.height, 10, 200); + var camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 30, cc.winSize.width/cc.winSize.height, 10, 200); camera.setCameraFlag(cc.CameraFlag.USER8); camera.setPosition3D(cc.math.vec3(-100, 0, 0)); camera.lookAt(cc.math.vec3(1000, 0, 0)); @@ -782,7 +782,7 @@ var CameraCullingDemo = Camera3DTestDemo.extend({ } if(!this._cameraThird){ - var camera = cc.Camera.createPerspective(60, cc.winSize.width/ cc.winSize.height, 1, 1000); + var camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 60, cc.winSize.width/ cc.winSize.height, 1, 1000); camera.setCameraFlag(cc.CameraFlag.USER8); camera.setPosition3D(cc.math.vec3(0, 130, 130)); camera.lookAt(cc.math.vec3(0, 0, 0)); @@ -965,7 +965,7 @@ var CameraArcBallDemo = Camera3DTestDemo.extend({ this.addChild(layer3D); this._layer3D = layer3D; - this._camera = cc.Camera.createPerspective(60, cc.winSize.width/cc.winSize.height, 1, 1000); + this._camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 60, cc.winSize.width/cc.winSize.height, 1, 1000); this._camera.setCameraFlag(cc.CameraFlag.USER1); this._camera.setPosition3D(cc.math.vec3(0, 10, 50)); this._camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0)); @@ -1183,7 +1183,7 @@ var FogTestDemo = Camera3DTestDemo.extend({ this._sprite3D2.setScale(2); this._sprite3D2.setRotation3D(cc.math.vec3(-90, 180, 0)); - this._camera = cc.Camera.createPerspective(60, cc.winSize.width/cc.winSize.height, 1, 1000); + this._camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 60, cc.winSize.width/cc.winSize.height, 1, 1000); this._camera.setCameraFlag(cc.CameraFlag.USER1); this._camera.setPosition3D(cc.math.vec3(0, 30, 40)); this._camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0)); diff --git a/tests/js-tests/src/LightTest/LightTest.js b/tests/js-tests/src/LightTest/LightTest.js index 97554d5c0c..8e91ae8ba6 100644 --- a/tests/js-tests/src/LightTest/LightTest.js +++ b/tests/js-tests/src/LightTest/LightTest.js @@ -141,7 +141,7 @@ var LightTest = LightTestDemo.extend({ this.scheduleUpdate(); var s = cc.winSize; - var camera = cc.Camera.createPerspective(60, s.width/s.height, 1, 1000); + var camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 60, s.width/s.height, 1, 1000); camera.setCameraFlag(cc.CameraFlag.USER1); camera.setPosition3D(cc.math.vec3(0, 100, 100)); camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0)); diff --git a/tests/js-tests/src/NavMeshTest/NavMeshTest.js b/tests/js-tests/src/NavMeshTest/NavMeshTest.js index 026f1469d2..fbef9ecd53 100644 --- a/tests/js-tests/src/NavMeshTest/NavMeshTest.js +++ b/tests/js-tests/src/NavMeshTest/NavMeshTest.js @@ -53,7 +53,7 @@ var NavMeshBaseTestDemo = NavMeshTestScene.extend({ this._angle = 0.0; var size = cc.winSize; - this._camera = cc.Camera.createPerspective(30.0, size.width / size.height, 1.0, 1000.0); + this._camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 30.0, size.width / size.height, 1.0, 1000.0); this._camera.setPosition3D(cc.math.vec3(0, 50, 100)); this._camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0)); this._camera.setCameraFlag(cc.CameraFlag.USER1); @@ -396,4 +396,4 @@ var previousNavMeshTest = function () { }; var restartNavMeshTest = function () { return new arrayOfNavMeshTest[NavMeshTestIdx ](); -}; \ No newline at end of file +}; diff --git a/tests/js-tests/src/Particle3DTest/Particle3DTest.js b/tests/js-tests/src/Particle3DTest/Particle3DTest.js index ffc2796513..12896c078c 100644 --- a/tests/js-tests/src/Particle3DTest/Particle3DTest.js +++ b/tests/js-tests/src/Particle3DTest/Particle3DTest.js @@ -83,7 +83,7 @@ var Particle3DTestDemo = cc.Layer.extend({ this.addChild(menu, 102, BASE_TEST_MENU_TAG); var size = cc.winSize; - this._camera = cc.Camera.createPerspective(30.0, size.width / size.height, 1.0, 1000.0); + this._camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 30.0, size.width / size.height, 1.0, 1000.0); this._camera.setPosition3D(cc.math.vec3(0, 0, 100)); this._camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0)); this._camera.setCameraFlag(cc.CameraFlag.USER1); @@ -433,4 +433,4 @@ var restartParticle3DTest = function () { return new arrayOfParticle3DTest[Particle3DTestIdx ](); }; -})(); \ No newline at end of file +})(); diff --git a/tests/js-tests/src/Physics3DTest/Physics3DTest.js b/tests/js-tests/src/Physics3DTest/Physics3DTest.js index a11908b395..ffce859e38 100644 --- a/tests/js-tests/src/Physics3DTest/Physics3DTest.js +++ b/tests/js-tests/src/Physics3DTest/Physics3DTest.js @@ -47,7 +47,7 @@ var Physics3DTestDemo = cc.Layer.extend({ this._super(); var size = cc.winSize; - this._camera = cc.Camera.createPerspective(30.0, size.width / size.height, 1.0, 1000.0); + this._camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 30.0, size.width / size.height, 1.0, 1000.0); this._camera.setPosition3D(cc.math.vec3(0, 50, 100)); this._camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0)); this._camera.setCameraFlag(cc.CameraFlag.USER1); diff --git a/tests/js-tests/src/Sprite3DTest/Sprite3DTest.js b/tests/js-tests/src/Sprite3DTest/Sprite3DTest.js index 65d9b098bd..125cb1c819 100644 --- a/tests/js-tests/src/Sprite3DTest/Sprite3DTest.js +++ b/tests/js-tests/src/Sprite3DTest/Sprite3DTest.js @@ -929,7 +929,7 @@ var UseCaseSprite3D1 = Sprite3DTestDemo.extend({ var s = cc.winSize; //setup camera - var camera = cc.Camera.createPerspective(40, s.width/s.height, 0.01, 1000); + var camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 40, s.width/s.height, 0.01, 1000); camera.setCameraFlag(cc.CameraFlag.USER1); camera.setPosition3D(cc.math.vec3(0, 30, 100)); camera.lookAt(cc.math.vec3(0, 0, 0)); @@ -992,7 +992,7 @@ var UseCaseSprite3D2 = Sprite3DTestDemo.extend({ var s = cc.winSize; //setup camera - var camera = cc.Camera.createPerspective(40, s.width/s.height, 0.01, 1000); + var camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 40, s.width/s.height, 0.01, 1000); camera.setCameraFlag(cc.CameraFlag.USER1); camera.setPosition3D(cc.math.vec3(0, 30, 100)); camera.lookAt(cc.math.vec3(0, 0, 0)); @@ -1175,7 +1175,7 @@ var Sprite3DLightMapTest = Sprite3DTestDemo.extend({ //the assets are from the OpenVR demo //get the visible size. var visibleSize = cc.director.getVisibleSize(); - this._camera = cc.Camera.createPerspective(60, visibleSize.width/visibleSize.height, 0.1, 200); + this._camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 60, visibleSize.width/visibleSize.height, 0.1, 200); this._camera.setCameraFlag(cc.CameraFlag.USER1); this._camera.setPosition3D(cc.math.vec3(0, 25, 15)); this._camera.setRotation3D(cc.math.vec3(-35, 0, 0)); @@ -1239,7 +1239,7 @@ var Sprite3DUVAnimationTest = Sprite3DTestDemo.extend({ var visibleSize = cc.director.getVisibleSize(); //use custom camera - var camera = cc.Camera.createPerspective(60, visibleSize.width/visibleSize.height, 0.1, 200); + var camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 60, visibleSize.width/visibleSize.height, 0.1, 200); camera.setCameraFlag(cc.CameraFlag.USER1); this.addChild(camera); this.setCameraMask(2); @@ -1373,7 +1373,7 @@ var Sprite3DFakeShadowTest = Sprite3DTestDemo.extend({ state.setUniformTexture("u_shadowTexture", shadowTexture); state.setUniformVec3("u_target_pos", this._targetPos); - this._camera = cc.Camera.createPerspective(60, s.width/s.height, 1, 1000); + this._camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 60, s.width/s.height, 1, 1000); this._camera.setCameraFlag(cc.CameraFlag.USER1); this._camera.setPosition3D(cc.math.vec3(0, 20, 25)); this._camera.lookAt(cc.math.vec3(0, 0, 0)); @@ -1498,7 +1498,7 @@ var Sprite3DBasicToonShaderTest = Sprite3DTestDemo.extend({ ctor:function(){ this._super(); - var camera = cc.Camera.createPerspective(60, cc.winSize.width/cc.winSize.height, 1, 1000); + var camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 60, cc.winSize.width/cc.winSize.height, 1, 1000); camera.setCameraFlag(cc.CameraFlag.USER1); this.addChild(camera); this.setCameraMask(2); @@ -1541,7 +1541,7 @@ var Sprite3DCubeMapTest = Sprite3DTestDemo.extend({ this._super(); var visibleSize = cc.director.getVisibleSize(); - var camera = cc.Camera.createPerspective(60, visibleSize.width/visibleSize.height, 10, 1000); + var camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 60, visibleSize.width/visibleSize.height, 10, 1000); camera.setCameraFlag(cc.CameraFlag.USER1); camera.setPosition3D(cc.math.vec3(0, 0, 50)); diff --git a/tests/js-tests/src/TerrainTest/TerrainTest.js b/tests/js-tests/src/TerrainTest/TerrainTest.js index 61b2d7294e..8b36dfd835 100644 --- a/tests/js-tests/src/TerrainTest/TerrainTest.js +++ b/tests/js-tests/src/TerrainTest/TerrainTest.js @@ -133,7 +133,7 @@ var TerrainSimple = TerrainTestDemo.extend({ var visibleSize = cc.director.getVisibleSize(); //use custom camera - this._camera = cc.Camera.createPerspective(60,visibleSize.width/visibleSize.height,0.1,800); + this._camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 60,visibleSize.width/visibleSize.height,0.1,800); this._camera.setCameraFlag(cc.CameraFlag.USER1); this._camera.setPosition3D(cc.math.vec3(-1, 1.6, 4)); this.addChild(this._camera); @@ -302,7 +302,7 @@ var TerrainWalkThru = (function(){ }, this); var visibleSize = cc.director.getVisibleSize(); - this._camera = cc.Camera.createPerspective(60, visibleSize.width/visibleSize.height, 0.1, 200); + this._camera = new cc.Camera(cc.Camera.Mode.PERSPECTIVE, 60, visibleSize.width/visibleSize.height, 0.1, 200); this._camera.setCameraFlag(cc.CameraFlag.USER1); this.addChild(this._camera); @@ -423,4 +423,4 @@ var restartTerrainTest = function () { return new arrayOfTerrainTest[TerrainTestIdx ](); }; -})(); \ No newline at end of file +})();