add Camera support constructor

This commit is contained in:
jianglong0156 2015-07-30 18:00:51 +08:00
parent b016b642ce
commit 113233b8df
10 changed files with 60 additions and 24 deletions

View File

@ -27,7 +27,9 @@
#define __jsb_cocos2dx_3d_manual_h__ #define __jsb_cocos2dx_3d_manual_h__
#include "jsapi.h" #include "jsapi.h"
#include "3d/CCTerrain.h"
void register_all_cocos2dx_3d_manual(JSContext *cx, JS::HandleObject global); 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 #endif

View File

@ -34,7 +34,11 @@ cc.CameraFlag = {
USER7 : 1 << 7, USER7 : 1 << 7,
USER8 : 1 << 8 USER8 : 1 << 8
}; };
cc.Camera.Mode = {
DEFAULT : 0,
PERSPECTIVE : 1,
ORTHOGRAPHIC : 2
};
cc.LightType = { cc.LightType = {
DIRECTIONAL : 0, DIRECTIONAL : 0,
POINT : 1, POINT : 1,
@ -419,3 +423,33 @@ jsb.SpotLight.prototype._ctor = function(direction, position, color, innerAngle,
throw new Error("jsb.SpotLight constructor: arguments error"); throw new Error("jsb.SpotLight constructor: arguments error");
} }
} }
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");
}
}

View File

@ -178,7 +178,7 @@ var BillBoardTest = BillBoardTestDemo.extend({
var s = cc.winSize; var s = cc.winSize;
if(!this._camera){ 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._camera.setCameraFlag(cc.CameraFlag.USER1);
this._layerBillBorad.addChild(this._camera); this._layerBillBorad.addChild(this._camera);
} }

View File

@ -343,7 +343,7 @@ var Camera3DTest = (function(){
this.schedule(this.updateCamera, 0); this.schedule(this.updateCamera, 0);
if(this._camera == null){ 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); this._camera.setCameraFlag(cc.CameraFlag.USER1);
layer3D.addChild(this._camera); layer3D.addChild(this._camera);
} }
@ -768,7 +768,7 @@ var CameraCullingDemo = Camera3DTestDemo.extend({
switchViewCallback:function(sender){ switchViewCallback:function(sender){
if(!this._cameraFirst){ 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.setCameraFlag(cc.CameraFlag.USER8);
camera.setPosition3D(cc.math.vec3(-100, 0, 0)); camera.setPosition3D(cc.math.vec3(-100, 0, 0));
camera.lookAt(cc.math.vec3(1000, 0, 0)); camera.lookAt(cc.math.vec3(1000, 0, 0));
@ -782,7 +782,7 @@ var CameraCullingDemo = Camera3DTestDemo.extend({
} }
if(!this._cameraThird){ 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.setCameraFlag(cc.CameraFlag.USER8);
camera.setPosition3D(cc.math.vec3(0, 130, 130)); camera.setPosition3D(cc.math.vec3(0, 130, 130));
camera.lookAt(cc.math.vec3(0, 0, 0)); camera.lookAt(cc.math.vec3(0, 0, 0));
@ -965,7 +965,7 @@ var CameraArcBallDemo = Camera3DTestDemo.extend({
this.addChild(layer3D); this.addChild(layer3D);
this._layer3D = 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.setCameraFlag(cc.CameraFlag.USER1);
this._camera.setPosition3D(cc.math.vec3(0, 10, 50)); this._camera.setPosition3D(cc.math.vec3(0, 10, 50));
this._camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0)); 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.setScale(2);
this._sprite3D2.setRotation3D(cc.math.vec3(-90, 180, 0)); 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.setCameraFlag(cc.CameraFlag.USER1);
this._camera.setPosition3D(cc.math.vec3(0, 30, 40)); this._camera.setPosition3D(cc.math.vec3(0, 30, 40));
this._camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0)); this._camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0));

View File

@ -141,7 +141,7 @@ var LightTest = LightTestDemo.extend({
this.scheduleUpdate(); this.scheduleUpdate();
var s = cc.winSize; 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.setCameraFlag(cc.CameraFlag.USER1);
camera.setPosition3D(cc.math.vec3(0, 100, 100)); camera.setPosition3D(cc.math.vec3(0, 100, 100));
camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0)); camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0));

View File

@ -53,7 +53,7 @@ var NavMeshBaseTestDemo = NavMeshTestScene.extend({
this._angle = 0.0; this._angle = 0.0;
var size = cc.winSize; 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.setPosition3D(cc.math.vec3(0, 50, 100));
this._camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0)); this._camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0));
this._camera.setCameraFlag(cc.CameraFlag.USER1); this._camera.setCameraFlag(cc.CameraFlag.USER1);

View File

@ -83,7 +83,7 @@ var Particle3DTestDemo = cc.Layer.extend({
this.addChild(menu, 102, BASE_TEST_MENU_TAG); this.addChild(menu, 102, BASE_TEST_MENU_TAG);
var size = cc.winSize; 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.setPosition3D(cc.math.vec3(0, 0, 100));
this._camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0)); this._camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0));
this._camera.setCameraFlag(cc.CameraFlag.USER1); this._camera.setCameraFlag(cc.CameraFlag.USER1);

View File

@ -47,7 +47,7 @@ var Physics3DTestDemo = cc.Layer.extend({
this._super(); this._super();
var size = cc.winSize; 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.setPosition3D(cc.math.vec3(0, 50, 100));
this._camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0)); this._camera.lookAt(cc.math.vec3(0, 0, 0), cc.math.vec3(0, 1, 0));
this._camera.setCameraFlag(cc.CameraFlag.USER1); this._camera.setCameraFlag(cc.CameraFlag.USER1);

View File

@ -929,7 +929,7 @@ var UseCaseSprite3D1 = Sprite3DTestDemo.extend({
var s = cc.winSize; var s = cc.winSize;
//setup camera //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.setCameraFlag(cc.CameraFlag.USER1);
camera.setPosition3D(cc.math.vec3(0, 30, 100)); camera.setPosition3D(cc.math.vec3(0, 30, 100));
camera.lookAt(cc.math.vec3(0, 0, 0)); camera.lookAt(cc.math.vec3(0, 0, 0));
@ -992,7 +992,7 @@ var UseCaseSprite3D2 = Sprite3DTestDemo.extend({
var s = cc.winSize; var s = cc.winSize;
//setup camera //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.setCameraFlag(cc.CameraFlag.USER1);
camera.setPosition3D(cc.math.vec3(0, 30, 100)); camera.setPosition3D(cc.math.vec3(0, 30, 100));
camera.lookAt(cc.math.vec3(0, 0, 0)); camera.lookAt(cc.math.vec3(0, 0, 0));
@ -1175,7 +1175,7 @@ var Sprite3DLightMapTest = Sprite3DTestDemo.extend({
//the assets are from the OpenVR demo //the assets are from the OpenVR demo
//get the visible size. //get the visible size.
var visibleSize = cc.director.getVisibleSize(); 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.setCameraFlag(cc.CameraFlag.USER1);
this._camera.setPosition3D(cc.math.vec3(0, 25, 15)); this._camera.setPosition3D(cc.math.vec3(0, 25, 15));
this._camera.setRotation3D(cc.math.vec3(-35, 0, 0)); this._camera.setRotation3D(cc.math.vec3(-35, 0, 0));
@ -1239,7 +1239,7 @@ var Sprite3DUVAnimationTest = Sprite3DTestDemo.extend({
var visibleSize = cc.director.getVisibleSize(); var visibleSize = cc.director.getVisibleSize();
//use custom camera //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); camera.setCameraFlag(cc.CameraFlag.USER1);
this.addChild(camera); this.addChild(camera);
this.setCameraMask(2); this.setCameraMask(2);
@ -1373,7 +1373,7 @@ var Sprite3DFakeShadowTest = Sprite3DTestDemo.extend({
state.setUniformTexture("u_shadowTexture", shadowTexture); state.setUniformTexture("u_shadowTexture", shadowTexture);
state.setUniformVec3("u_target_pos", this._targetPos); 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.setCameraFlag(cc.CameraFlag.USER1);
this._camera.setPosition3D(cc.math.vec3(0, 20, 25)); this._camera.setPosition3D(cc.math.vec3(0, 20, 25));
this._camera.lookAt(cc.math.vec3(0, 0, 0)); this._camera.lookAt(cc.math.vec3(0, 0, 0));
@ -1498,7 +1498,7 @@ var Sprite3DBasicToonShaderTest = Sprite3DTestDemo.extend({
ctor:function(){ ctor:function(){
this._super(); 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); camera.setCameraFlag(cc.CameraFlag.USER1);
this.addChild(camera); this.addChild(camera);
this.setCameraMask(2); this.setCameraMask(2);
@ -1541,7 +1541,7 @@ var Sprite3DCubeMapTest = Sprite3DTestDemo.extend({
this._super(); this._super();
var visibleSize = cc.director.getVisibleSize(); 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.setCameraFlag(cc.CameraFlag.USER1);
camera.setPosition3D(cc.math.vec3(0, 0, 50)); camera.setPosition3D(cc.math.vec3(0, 0, 50));

View File

@ -133,7 +133,7 @@ var TerrainSimple = TerrainTestDemo.extend({
var visibleSize = cc.director.getVisibleSize(); var visibleSize = cc.director.getVisibleSize();
//use custom camera //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.setCameraFlag(cc.CameraFlag.USER1);
this._camera.setPosition3D(cc.math.vec3(-1, 1.6, 4)); this._camera.setPosition3D(cc.math.vec3(-1, 1.6, 4));
this.addChild(this._camera); this.addChild(this._camera);
@ -302,7 +302,7 @@ var TerrainWalkThru = (function(){
}, this); }, this);
var visibleSize = cc.director.getVisibleSize(); 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.setCameraFlag(cc.CameraFlag.USER1);
this.addChild(this._camera); this.addChild(this._camera);