Merge pull request #8 from pandamicro/physics3d

Physics3d
This commit is contained in:
jianglong0156 2015-06-18 14:54:32 +08:00
commit 85c40b6580
16 changed files with 345 additions and 71 deletions

View File

@ -401,7 +401,7 @@ void Node::updateRotation3D()
float x = _rotationQuat.x, y = _rotationQuat.y, z = _rotationQuat.z, w = _rotationQuat.w;
_rotationX = atan2f(2.f * (w * x + y * z), 1.f - 2.f * (x * x + y * y));
_rotationY = asinf(2.f * (w * y - z * x));
_rotationZ_X = atanf(2.f * (w * z + x * y) / (1.f - 2.f * (y * y + z * z)));
_rotationZ_X = atan2f(2.f * (w * z + x * y), 1.f - 2.f * (y * y + z * z));
_rotationX = CC_RADIANS_TO_DEGREES(_rotationX);
_rotationY = CC_RADIANS_TO_DEGREES(_rotationY);

View File

@ -1836,8 +1836,10 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics3d\CCPhysicsSprite3D.h">
<Filter>physics3d</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\..\external\clipper\clipper.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\CCAutoPolygon.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\..\external\clipper\clipper.hpp">
<Filter>external\clipper</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\cocos2d.cpp">
@ -3501,8 +3503,10 @@
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\base\CCUserDefault-winrt.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\external\clipper\clipper.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\CCAutoPolygon.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\external\clipper\clipper.cpp">
<Filter>external\clipper</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="2d">

View File

@ -195,6 +195,7 @@
<ClCompile Include="..\..\..\extensions\Particle3D\PU\CCPUVortexAffectorTranslator.cpp" />
<ClCompile Include="..\..\..\extensions\physics-nodes\CCPhysicsDebugNode.cpp" />
<ClCompile Include="..\..\..\extensions\physics-nodes\CCPhysicsSprite.cpp" />
<ClCompile Include="..\..\..\external\clipper\clipper.cpp" />
<ClCompile Include="..\..\..\external\ConvertUTF\ConvertUTF.c">
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</CompileAsWinRT>
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</CompileAsWinRT>
@ -662,6 +663,7 @@
<ClCompile Include="..\CCAnimation.cpp" />
<ClCompile Include="..\CCAnimationCache.cpp" />
<ClCompile Include="..\CCAtlasNode.cpp" />
<ClCompile Include="..\CCAutoPolygon.cpp" />
<ClCompile Include="..\CCCamera.cpp" />
<ClCompile Include="..\CCClippingNode.cpp" />
<ClCompile Include="..\CCClippingRectangleNode.cpp" />
@ -715,9 +717,6 @@
<ClCompile Include="..\CCTransitionPageTurn.cpp" />
<ClCompile Include="..\CCTransitionProgress.cpp" />
<ClCompile Include="..\CCTweenFunction.cpp" />
<ClCompile Include="..\MarchingSquare.cpp" />
<ClCompile Include="..\SpritePolygon.cpp" />
<ClCompile Include="..\SpritePolygonCache.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\extensions\cocos-ext.h" />
@ -892,6 +891,7 @@
<ClInclude Include="..\..\..\extensions\Particle3D\PU\CCPUVortexAffectorTranslator.h" />
<ClInclude Include="..\..\..\extensions\physics-nodes\CCPhysicsDebugNode.h" />
<ClInclude Include="..\..\..\extensions\physics-nodes\CCPhysicsSprite.h" />
<ClInclude Include="..\..\..\external\clipper\clipper.hpp" />
<ClInclude Include="..\..\..\external\ConvertUTF\ConvertUTF.h" />
<ClInclude Include="..\..\..\external\edtaa3func\edtaa3func.h" />
<ClInclude Include="..\..\..\external\flatbuffers\flatbuffers.h" />
@ -1203,6 +1203,7 @@
<ClInclude Include="..\..\platform\winrt\WICImageLoader-winrt.h" />
<ClInclude Include="..\..\renderer\CCBatchCommand.h" />
<ClInclude Include="..\..\renderer\CCCustomCommand.h" />
<ClInclude Include="..\CCAutoPolygon.h" />
<ClInclude Include="..\renderer\CCFrameBuffer.h" />
<ClInclude Include="..\..\renderer\CCGLProgram.h" />
<ClInclude Include="..\..\renderer\CCGLProgramCache.h" />
@ -1328,9 +1329,6 @@
<ClInclude Include="..\CCTransitionPageTurn.h" />
<ClInclude Include="..\CCTransitionProgress.h" />
<ClInclude Include="..\CCTweenFunction.h" />
<ClInclude Include="..\MarchingSquare.h" />
<ClInclude Include="..\SpritePolygon.h" />
<ClInclude Include="..\SpritePolygonCache.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\base\CCController-iOS.mm" />

View File

@ -251,6 +251,9 @@
<Filter Include="navmesh">
<UniqueIdentifier>{cc4f6ca9-4231-479d-8e19-ede4dff3382e}</UniqueIdentifier>
</Filter>
<Filter Include="external\clipper">
<UniqueIdentifier>{e3a5fe25-a92e-4c98-9026-782b2b5b1388}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\cocos2d.cpp" />
@ -1797,15 +1800,6 @@
<ClCompile Include="..\..\platform\winrt\WICImageLoader-winrt.cpp">
<Filter>platform\winrt</Filter>
</ClCompile>
<ClCompile Include="..\MarchingSquare.cpp">
<Filter>2d</Filter>
</ClCompile>
<ClCompile Include="..\SpritePolygon.cpp">
<Filter>2d</Filter>
</ClCompile>
<ClCompile Include="..\SpritePolygonCache.cpp">
<Filter>2d</Filter>
</ClCompile>
<ClCompile Include="..\..\..\external\poly2tri\common\shapes.cc">
<Filter>external\poly2tri\common</Filter>
</ClCompile>
@ -1903,6 +1897,12 @@
<ClCompile Include="..\..\navmesh\CCNavMeshUtils.cpp">
<Filter>navmesh</Filter>
</ClCompile>
<ClCompile Include="..\CCAutoPolygon.cpp">
<Filter>2d</Filter>
</ClCompile>
<ClCompile Include="..\..\..\external\clipper\clipper.cpp">
<Filter>external\clipper</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\cocos2d.h" />
@ -3629,15 +3629,6 @@
<ClInclude Include="..\..\platform\winrt\WICImageLoader-winrt.h">
<Filter>platform\winrt</Filter>
</ClInclude>
<ClInclude Include="..\MarchingSquare.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="..\SpritePolygon.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="..\SpritePolygonCache.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="..\..\..\external\poly2tri\poly2tri.h">
<Filter>external\poly2tri</Filter>
</ClInclude>
@ -3734,6 +3725,12 @@
<ClInclude Include="..\..\navmesh\CCNavMeshUtils.h">
<Filter>navmesh</Filter>
</ClInclude>
<ClInclude Include="..\CCAutoPolygon.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="..\..\..\external\clipper\clipper.hpp">
<Filter>external\clipper</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\base\CCController-iOS.mm">

View File

@ -613,8 +613,9 @@ void Mesh::setLightUniforms(Pass* pass, Scene* scene, const Vec4& color, unsigne
if (hasAmbient)
{
ambient.x /= 255.f; ambient.y /= 255.f; ambient.z /= 255.f;
//override the uniform value of u_color using the calculated color
glProgramState->setUniformVec4("u_color", Vec4(color.x * ambient.x, color.y * ambient.y, color.z * ambient.z, color.w));
}
glProgramState->setUniformVec4("u_color", Vec4(color.x * ambient.x, color.y * ambient.y, color.z * ambient.z, color.w));
}
}

View File

@ -159,11 +159,9 @@ void Terrain::onDraw(const Mat4 &transform, uint32_t flags)
if(_isCameraViewChanged )
{
auto camPos = camera->getPosition3D();
auto camModelMat = camera->getNodeToWorldTransform();
camModelMat.transformPoint(&camPos);
auto m = camera->getNodeToWorldTransform();
//set lod
setChunksLOD(camPos);
setChunksLOD(Vec3(m.m[12], m.m[13], m.m[14]));
}
if(_isCameraViewChanged )
@ -265,7 +263,7 @@ void Terrain::setChunksLOD(Vec3 cameraPos)
{
AABB aabb = _chunkesArray[m][n]->_parent->_worldSpaceAABB;
auto center = aabb.getCenter();
float dist = Vec3(center.x,0,center.z).distance(Vec3(cameraPos.x,0,cameraPos.z));
float dist = Vec2(center.x, center.z).distance(Vec2(cameraPos.x, cameraPos.z));
_chunkesArray[m][n]->_currentLod = 3;
for(int i =0;i<3;i++)
{

View File

@ -3891,6 +3891,89 @@ bool js_cocos2dx_ccmat4MultiplyVec3(JSContext *cx, uint32_t argc, jsval *vp)
return false;
}
bool js_cocos2dx_ccmat4GetInversed(JSContext *cx, uint32_t argc, jsval *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
if(argc == 1)
{
cocos2d::Mat4 arg0;
bool ok = jsval_to_matrix(cx, args.get(0), &arg0);
JSB_PRECONDITION2(ok, cx, false, "Error processing arguments");
jsval jsret = matrix_to_jsval(cx, arg0.getInversed());
args.rval().set(jsret);
return true;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return false;
}
bool js_cocos2dx_ccmat4TransformVector(JSContext *cx, uint32_t argc, jsval *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
if(argc >= 2)
{
cocos2d::Mat4 arg0;
cocos2d::Vec4 arg1;
cocos2d::Vec4 ret;
bool ok = jsval_to_matrix(cx, args.get(0), &arg0);
ok &= jsval_to_vector4(cx, args.get(1), &arg1);
JSB_PRECONDITION2(ok, cx, false, "Error processing arguments");
arg0.transformVector(arg1, &ret);
jsval jsret = vector4_to_jsval(cx, ret);
args.rval().set(jsret);
return true;
}
else if (argc >= 5)
{
cocos2d::Mat4 arg0;
double arg1 = 0.0,arg2 = 0.0,arg3 = 0.0, arg4 = 0.0;
cocos2d::Vec3 ret;
bool ok = jsval_to_matrix(cx, args.get(0), &arg0) &&
JS::ToNumber(cx, args.get(1), &arg1) &&
JS::ToNumber(cx, args.get(2), &arg2) &&
JS::ToNumber(cx, args.get(3), &arg3) &&
JS::ToNumber(cx, args.get(4), &arg4);
JSB_PRECONDITION2(ok, cx, false, "Error processing arguments");
arg0.transformVector(arg1, arg2, arg3, arg4, &ret);
jsval jsret = vector3_to_jsval(cx, ret);
args.rval().set(jsret);
return true;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 3);
return false;
}
bool js_cocos2dx_ccmat4TransformPoint(JSContext *cx, uint32_t argc, jsval *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
if(argc >= 2)
{
cocos2d::Mat4 arg0;
cocos2d::Vec3 arg1;
cocos2d::Vec3 ret;
bool ok = jsval_to_matrix(cx, args.get(0), &arg0);
ok &= jsval_to_vector3(cx, args.get(1), &arg1);
JSB_PRECONDITION2(ok, cx, false, "Error processing arguments");
arg0.transformPoint(arg1, &ret);
jsval jsret = vector3_to_jsval(cx, ret);
args.rval().set(jsret);
return true;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 3);
return false;
}
bool js_cocos2dx_ccquatMultiply(JSContext *cx, uint32_t argc, jsval *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
@ -5167,15 +5250,15 @@ bool js_cocos2dx_Camera_unproject(JSContext *cx, uint32_t argc, jsval *vp)
js_proxy_t *proxy = jsb_get_js_proxy(obj);
cocos2d::Camera* cobj = (cocos2d::Camera *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Camera_unproject : Invalid Native Object");
if (argc == 2) {
if (argc >= 2) {
cocos2d::Size arg0;
cocos2d::Vec3 arg1;
cocos2d::Vec3 arg2;
cocos2d::Vec3 ret;
ok &= jsval_to_ccsize(cx, args.get(0), &arg0);
ok &= jsval_to_vector3(cx, args.get(1), &arg1);
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Camera_unproject : Error processing arguments");
cobj->unproject(arg0, &arg1, &arg2);
args.rval().set(vector3_to_jsval(cx, arg2));
cobj->unproject(arg0, &arg1, &ret);
args.rval().set(vector3_to_jsval(cx, ret));
return true;
}
else if (argc == 1)
@ -5187,7 +5270,7 @@ bool js_cocos2dx_Camera_unproject(JSContext *cx, uint32_t argc, jsval *vp)
args.rval().set(vector3_to_jsval(cx, ret));
return true;
}
JS_ReportError(cx, "js_cocos2dx_Camera_unproject : wrong number of arguments: %d, was expecting %d", argc, 2);
JS_ReportError(cx, "js_cocos2dx_Camera_unproject : wrong number of arguments: %d, was expecting %d", argc, 3);
return false;
}
@ -6237,6 +6320,9 @@ void register_cocos2dx_js_core(JSContext* cx, JS::HandleObject global)
JS_DefineFunction(cx, tmpObj, "mat4CreateRotation", js_cocos2dx_ccmat4CreateRotation, 1, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, tmpObj, "mat4Multiply", js_cocos2dx_ccmat4Multiply, 2, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, tmpObj, "mat4MultiplyVec3", js_cocos2dx_ccmat4MultiplyVec3, 2, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, tmpObj, "mat4GetInversed", js_cocos2dx_ccmat4GetInversed, 1, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, tmpObj, "mat4TransformVector", js_cocos2dx_ccmat4TransformVector, 3, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, tmpObj, "mat4TransformPoint", js_cocos2dx_ccmat4TransformPoint, 3, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, tmpObj, "quatMultiply", js_cocos2dx_ccquatMultiply, 2, JSPROP_READONLY | JSPROP_PERMANENT);
js_register_cocos2dx_EventKeyboard(cx, ccObj);

View File

@ -2717,6 +2717,22 @@ jsval vector3_to_jsval(JSContext *cx, const cocos2d::Vec3& v)
return JSVAL_NULL;
}
jsval vector4_to_jsval(JSContext *cx, const cocos2d::Vec4& v)
{
JS::RootedObject proto(cx);
JS::RootedObject parent(cx);
JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, proto, parent));
if (!tmp) return JSVAL_NULL;
bool ok = JS_DefineProperty(cx, tmp, "x", v.x, JSPROP_ENUMERATE | JSPROP_PERMANENT) &&
JS_DefineProperty(cx, tmp, "y", v.y, JSPROP_ENUMERATE | JSPROP_PERMANENT) &&
JS_DefineProperty(cx, tmp, "z", v.z, JSPROP_ENUMERATE | JSPROP_PERMANENT) &&
JS_DefineProperty(cx, tmp, "w", v.z, JSPROP_ENUMERATE | JSPROP_PERMANENT);
if (ok) {
return OBJECT_TO_JSVAL(tmp);
}
return JSVAL_NULL;
}
jsval blendfunc_to_jsval(JSContext *cx, const cocos2d::BlendFunc& v)
{
JS::RootedObject proto(cx);

View File

@ -337,6 +337,7 @@ jsval std_vector_float_to_jsval( JSContext *cx, const std::vector<float>& v);
jsval matrix_to_jsval(JSContext *cx, const cocos2d::Mat4& v);
jsval vector2_to_jsval(JSContext *cx, const cocos2d::Vec2& v);
jsval vector3_to_jsval(JSContext *cx, const cocos2d::Vec3& v);
jsval vector4_to_jsval(JSContext *cx, const cocos2d::Vec4& v);
jsval blendfunc_to_jsval(JSContext *cx, const cocos2d::BlendFunc& v);
jsval vector_vec2_to_jsval(JSContext *cx, const std::vector<cocos2d::Vec2>& v);

View File

@ -61,6 +61,10 @@ bool jsval_to_physics3DRigidBodyDes(JSContext* cx, JS::HandleValue v, Physics3DR
jsval_to_matrix(cx, tmp, &m4);
des->originalTransform = m4;
}
if(JS_GetProperty(cx, jsobj, "disableSleep", &tmp))
{
des->disableSleep = tmp.toBoolean();
}
return true;
}
@ -299,6 +303,90 @@ bool js_cocos2dx_physics3d_Physics3dShape_createHeightfield(JSContext *cx, uint3
return false;
}
bool jsval_to_Physics3DWorld_HitResult(JSContext *cx, JS::HandleValue v, cocos2d::Physics3DWorld::HitResult* ret)
{
JS::RootedObject tmp(cx);
JS::RootedValue jshitPosition(cx);
JS::RootedValue jshitNormal(cx);
JS::RootedValue jshitObject(cx);
bool ok = v.isObject() &&
JS_ValueToObject(cx, v, &tmp) &&
JS_GetProperty(cx, tmp, "hitPosition", &jshitPosition) &&
JS_GetProperty(cx, tmp, "hitNormal", &jshitNormal) &&
JS_GetProperty(cx, tmp, "hitObj", &jshitObject) &&
jsval_to_vector3(cx, jshitPosition, &(ret->hitPosition)) &&
jsval_to_vector3(cx, jshitNormal, &(ret->hitNormal));
JSB_PRECONDITION2(ok, cx, false, "jsval_to_Physics3DWorld_HitResult : Error processing arguments");
js_proxy_t *proxy = jsb_get_js_proxy(jshitObject.toObjectOrNull());
ret->hitObj = (cocos2d::Physics3DObject *)(proxy ? proxy->ptr : nullptr);
return true;
}
jsval Physics3DWorld_HitResult_to_jsval(JSContext *cx, const cocos2d::Physics3DWorld::HitResult& v)
{
JS::RootedObject proto(cx);
JS::RootedObject parent(cx);
JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, proto, parent));
if (!tmp) return JSVAL_NULL;
JS::RootedValue hitPosition(cx, vector3_to_jsval(cx, v.hitPosition));
JS::RootedValue hitNormal(cx, vector3_to_jsval(cx, v.hitNormal));
JS::RootedValue hitobject(cx);
if (v.hitObj)
{
js_proxy_t *jsProxy = js_get_or_create_proxy<cocos2d::Physics3DObject>(cx, (cocos2d::Physics3DObject*)v.hitObj);
hitobject.set(OBJECT_TO_JSVAL(jsProxy->obj));
}
bool ok = JS_DefineProperty(cx, tmp, "hitPosition", hitPosition, JSPROP_ENUMERATE | JSPROP_PERMANENT) &&
JS_DefineProperty(cx, tmp, "hitNormal", hitNormal, JSPROP_ENUMERATE | JSPROP_PERMANENT) &&
JS_DefineProperty(cx, tmp, "hitObj", hitobject, JSPROP_ENUMERATE | JSPROP_PERMANENT);
if (ok) {
return OBJECT_TO_JSVAL(tmp);
}
return JSVAL_NULL;
}
bool js_cocos2dx_physics3d_Physics3DWorld_rayCast(JSContext *cx, uint32_t argc, jsval *vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
bool ok = true;
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
js_proxy_t *proxy = jsb_get_js_proxy(obj);
cocos2d::Physics3DWorld* cobj = (cocos2d::Physics3DWorld *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_physics3d_Physics3DWorld_rayCast : Invalid Native Object");
if (argc >= 2) {
cocos2d::Vec3 arg0;
cocos2d::Vec3 arg1;
cocos2d::Physics3DWorld::HitResult ret;
ok &= jsval_to_vector3(cx, args.get(0), &arg0);
ok &= jsval_to_vector3(cx, args.get(1), &arg1);
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_physics3d_Physics3DWorld_rayCast : Error processing arguments");
bool succeed = cobj->rayCast(arg0, arg1, &ret);
if (succeed)
{
jsval jsret = JSVAL_NULL;
jsret = Physics3DWorld_HitResult_to_jsval(cx, ret);
args.rval().set(jsret);
}
else
{
args.rval().set(JSVAL_FALSE);
}
return true;
}
JS_ReportError(cx, "js_cocos2dx_physics3d_Physics3DWorld_rayCast : wrong number of arguments: %d, was expecting %d", argc, 3);
return false;
}
void register_all_cocos2dx_physics3d_manual(JSContext *cx, JS::HandleObject global)
{
JS::RootedObject ccObj(cx);
@ -319,6 +407,8 @@ void register_all_cocos2dx_physics3d_manual(JSContext *cx, JS::HandleObject glob
JS_DefineFunction(cx, tmpObj, "createHeightfield", js_cocos2dx_physics3d_Physics3dShape_createHeightfield, 8, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Physics3DObject_prototype), "setCollisionCallback", jsb_cocos2d_Physics3DObject_setCollisionCallback, 2, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(cx, JS::RootedObject(cx, jsb_cocos2d_Physics3DWorld_prototype), "rayCast", js_cocos2dx_physics3d_Physics3DWorld_rayCast, 2, JSPROP_READONLY | JSPROP_PERMANENT);
}
#endif //CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION

View File

@ -41,3 +41,18 @@ cc.Physics3DComponent.PhysicsSyncFlag = {
PHYSICS_TO_NODE : 2, // align physics transform to the node
NODE_AND_NODE : 1 | 2, //pre simulation, align the physics object to the node and align the node transform according to physics object after simulation
};
cc.HitResult = function(){
this.hitPosition = cc.math.vec3();
this.hitNormal = cc.math.vec3();
this.hitObj = null;
}
cc.hitResult = function(){
return new cc.HitResult();
};
cc.Physics3DObject.PhysicsObjType = {
UNKNOWN : 0,
RIGID_BODY : 1,
};

View File

@ -11,8 +11,8 @@
-- @return map_table#map_table ret (return value: map_table)
--------------------------------
-- brief remove animation data<br>
-- param id the id of the animation data
-- brief remove animation data<br>
-- param id the id of the animation data
-- @function [parent=#ArmatureDataManager] removeAnimationData
-- @param self
-- @param #string id
@ -53,8 +53,8 @@
-- @return map_table#map_table ret (return value: map_table)
--------------------------------
-- brief get texture data<br>
-- param id the id of the texture data you want to get<br>
-- brief get texture data<br>
-- param id the id of the texture data you want to get<br>
-- return TextureData *
-- @function [parent=#ArmatureDataManager] getTextureData
-- @param self
@ -62,17 +62,17 @@
-- @return TextureData#TextureData ret (return value: ccs.TextureData)
--------------------------------
-- brief get armature data<br>
-- param id the id of the armature data you want to get<br>
-- return ArmatureData *
-- brief get armature data<br>
-- param id the id of the armature data you want to get<br>
-- return ArmatureData *
-- @function [parent=#ArmatureDataManager] getArmatureData
-- @param self
-- @param #string id
-- @return ArmatureData#ArmatureData ret (return value: ccs.ArmatureData)
--------------------------------
-- brief get animation data from _animationDatas(Dictionary)<br>
-- param id the id of the animation data you want to get<br>
-- brief get animation data from _animationDatas(Dictionary)<br>
-- param id the id of the animation data you want to get<br>
-- return AnimationData *
-- @function [parent=#ArmatureDataManager] getAnimationData
-- @param self
@ -80,8 +80,8 @@
-- @return AnimationData#AnimationData ret (return value: ccs.AnimationData)
--------------------------------
-- brief add animation data<br>
-- param id the id of the animation data<br>
-- brief add animation data<br>
-- param id the id of the animation data<br>
-- return AnimationData *
-- @function [parent=#ArmatureDataManager] addAnimationData
-- @param self
@ -97,8 +97,8 @@
-- @return bool#bool ret (return value: bool)
--------------------------------
-- brief remove armature data<br>
-- param id the id of the armature data you want to get
-- brief remove armature data<br>
-- param id the id of the armature data you want to get
-- @function [parent=#ArmatureDataManager] removeArmatureData
-- @param self
-- @param #string id
@ -111,16 +111,16 @@
-- @return map_table#map_table ret (return value: map_table)
--------------------------------
-- brief remove texture data<br>
-- param id the id of the texture data you want to get
-- brief remove texture data<br>
-- param id the id of the texture data you want to get
-- @function [parent=#ArmatureDataManager] removeTextureData
-- @param self
-- @param #string id
-- @return ArmatureDataManager#ArmatureDataManager self (return value: ccs.ArmatureDataManager)
--------------------------------
-- brief add texture data<br>
-- param id the id of the texture data<br>
-- brief add texture data<br>
-- param id the id of the texture data<br>
-- return TextureData *
-- @function [parent=#ArmatureDataManager] addTextureData
-- @param self
@ -130,13 +130,13 @@
-- @return ArmatureDataManager#ArmatureDataManager self (return value: ccs.ArmatureDataManager)
--------------------------------
-- brief Juge whether or not need auto load sprite file
-- brief Juge whether or not need auto load sprite file
-- @function [parent=#ArmatureDataManager] isAutoLoadSpriteFile
-- @param self
-- @return bool#bool ret (return value: bool)
--------------------------------
-- brief Add sprite frame to CCSpriteFrameCache, it will save display name and it's relative image name
-- brief Add sprite frame to CCSpriteFrameCache, it will save display name and it's relative image name
-- @function [parent=#ArmatureDataManager] addSpriteFrameFromFile
-- @param self
-- @param #string plistPath

View File

@ -43,7 +43,7 @@
--------------------------------
-- Add a child to this bone, and it will let this child call setParent(Bone *parent) function to set self to it's parent<br>
-- param child the child you want to add
-- param child the child you want to add
-- @function [parent=#Bone] addChildBone
-- @param self
-- @param #ccs.Bone child
@ -193,7 +193,7 @@
--------------------------------
-- Removes a child Bone<br>
-- param bone the bone you want to remove
-- param bone the bone you want to remove
-- @function [parent=#Bone] removeChildBone
-- @param self
-- @param #ccs.Bone bone

View File

@ -41,6 +41,7 @@ var Physics3DTestDemo = cc.Layer.extend({
_camera:null,
_angle:0.0,
_needShootBox:false,
_listener: null,
ctor:function () {
this._super();
@ -52,7 +53,7 @@ var Physics3DTestDemo = cc.Layer.extend({
this._camera.setCameraFlag(cc.CameraFlag.USER1);
this.addChild(this._camera);
cc.eventManager.addListener({
this._listener = cc.eventManager.addListener({
event:cc.EventListener.TOUCH_ALL_AT_ONCE,
onTouchesBegan:this.onTouchesBegan.bind(this),
onTouchesMoved:this.onTouchesMoved.bind(this),
@ -285,10 +286,16 @@ var BasicPhysics3DDemo = Physics3DTestDemo.extend({
var Physics3DConstraintDemo = Physics3DTestDemo.extend({
_subtitle:"Physics3D Constraint",
_constraint: null,
_world: null,
ctor:function(){
this._super();
this._listener.onTouchesBegan = this.onTouchesBegan.bind(this);
this._listener.onTouchesMoved = this.onTouchesMoved.bind(this);
this._listener.onTouchesEnded = this.onTouchesEnded.bind(this);
//PhysicsSprite3d = Sprite3D + Physics3DComponent
var rbDes = cc.physics3DRigidBodyDes();
rbDes.disableSleep = true;
@ -309,10 +316,11 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({
component.setSyncFlag(cc.Physics3DComponent.PhysicsSyncFlag.PHYSICS_TO_NODE);
physicsScene.setPhysics3DDebugCamera(this._camera);
this._world = physicsScene.getPhysics3DWorld();
//create point to point constraint
var constraint = cc.Physics3DPointToPointConstraint.create(rigidBody, cc.math.vec3(2.5, 2.5, 2.5));
physicsScene.getPhysics3DWorld().addPhysics3DConstraint(constraint);
this._world.addPhysics3DConstraint(constraint);
//create hinge constraint
rbDes.mass = 1;
@ -322,7 +330,7 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({
sprite = new jsb.Sprite3D("Sprite3DTest/box.c3t");
sprite.setTexture("Sprite3DTest/plane.png");
sprite.setScaleX(8);
sprite.setScaleZ(8);
sprite.setScaleY(8);
sprite.setPosition3D(cc.math.vec3(5, 0, 0));
sprite.addComponent(component);
sprite.setCameraMask(cc.CameraFlag.USER1);
@ -330,7 +338,7 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({
component.syncNodeToPhysics();
rigidBody.setAngularVelocity(cc.math.vec3(0, 3, 0));
constraint = cc.Physics3DHingeConstraint.create(rigidBody, cc.math.vec3(4, 4, 0.5), cc.math.vec3(0, 1, 0));
physicsScene.getPhysics3DWorld().addPhysics3DConstraint(constraint);
this._world.addPhysics3DConstraint(constraint);
//create slider constraint
rbDes.mass = 1;
@ -361,10 +369,10 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({
this.addChild(sprite);
component.syncNodeToPhysics();
var frameInA = [-4.37114e-08, 1, 0, 0, -1, -4.37114e-08, 0, 0, 0, 0, 1, 0, 0, -5, 0, 1];
var frameInB = [-4.37114e-08, 1, 0, 0, -1, -4.37114e-08, 0, 0, 0, 0, 1, 0, 0, 5, 0, 1];
var frameInA = [-4.37114e-8, 1, 0, 0, -1, -4.37114e-8, 0, 0, 0, 0, 1, 0, 0, -5, 0, 1];
var frameInB = [-4.37114e-8, 1, 0, 0, -1, -4.37114e-8, 0, 0, 0, 0, 1, 0, 0, 5, 0, 1];
constraint = cc.Physics3DSliderConstraint.create(rigidBody, rigidBodyB, frameInA, frameInB, false);
physicsScene.getPhysics3DWorld().addPhysics3DConstraint(constraint);
this._world.addPhysics3DConstraint(constraint);
constraint.setLowerLinLimit(-5);
constraint.setUpperLinLimit(5);
@ -382,9 +390,9 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({
this.addChild(sprite);
component.syncNodeToPhysics();
frameInA = [-4.37114e-08, 1, 0, 0, -1, -4.37114e-08, 0, 0, 0, 0, 1, 0, 0, -10, 0, 1];
frameInA = [-4.37114e-8, 1, 0, 0, -1, -4.37114e-8, 0, 0, 0, 0, 1, 0, 0, -10, 0, 1];
constraint = cc.Physics3DConeTwistConstraint.create(rigidBody, frameInA);
physicsScene.getPhysics3DWorld().addPhysics3DConstraint(constraint, true);
this._world.addPhysics3DConstraint(constraint, true);
constraint.setLimit(cc.degreesToRadians(10), cc.degreesToRadians(10), cc.degreesToRadians(40));
//create 6 dof constraint
@ -403,11 +411,68 @@ var Physics3DConstraintDemo = Physics3DTestDemo.extend({
frameInA = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
constraint = cc.Physics3D6DofConstraint.create(rigidBody, frameInA, false);
physicsScene.getPhysics3DWorld().addPhysics3DConstraint(constraint);
this._world.addPhysics3DConstraint(constraint);
constraint.setAngularLowerLimit(cc.math.vec3(0, 0, 0));
constraint.setAngularUpperLimit(cc.math.vec3(0, 0, 0));
constraint.setLinearLowerLimit(cc.math.vec3(-10, 0, 0));
constraint.setLinearUpperLimit(cc.math.vec3(10, 0, 0));
},
onTouchesBegan:function(touches, event){
if(this._camera){
cc.log("STARTED " + touches.length);
var touch = touches[0];
var location = touch.getLocationInView();
var nearP = cc.math.vec3(location.x, location.y, 0);
var farP = cc.math.vec3(location.x, location.y, 1);
var size = director.getWinSize();
nearP = this._camera.unproject(size, nearP);
farP = this._camera.unproject(size, farP);
var result = this._world.rayCast(nearP, farP);
if(result !== false && result.hitObj.getObjType() == cc.Physics3DObject.PhysicsObjType.RIGID_BODY)
{
var mat = cc.math.mat4GetInversed(result.hitObj.getWorldTransform());
var position = cc.math.mat4TransformPoint(mat, result.hitPosition);
this._constraint = cc.Physics3DPointToPointConstraint.create(result.hitObj, position);
this._world.addPhysics3DConstraint(this._constraint, true);
this._pickingDistance = cc.math.vec3Length(cc.math.vec3Sub(result.hitPosition, nearP));
return;
}
}
Physics3DTestDemo.prototype.onTouchesBegan.call(this, touches, event);
this._needShootBox = false;
},
onTouchesMoved:function(touches, event){
if(this._constraint){
var touch = touches[0];
var location = touch.getLocationInView();
var nearP = cc.math.vec3(location.x, location.y, 0);
var farP = cc.math.vec3(location.x, location.y, 1);
var size = director.getWinSize();
nearP = this._camera.unproject(size, nearP);
farP = this._camera.unproject(size, farP);
var dir = cc.math.vec3Normalize(cc.math.vec3Sub(farP, nearP));
this._constraint.setPivotPointInB(cc.math.vec3Add(nearP, cc.math.vec3(dir.x * this._pickingDistance, dir.y * this._pickingDistance, dir.z * this._pickingDistance)));
return;
}
Physics3DTestDemo.prototype.onTouchesMoved.call(this, touches, event);
},
onTouchesEnded:function(touches, event){
if(this._constraint){
this._world.removePhysics3DConstraint(this._constraint);
this._constraint = null;
return;
}
Physics3DTestDemo.prototype.onTouchesEnded.call(this, touches, event);
}
});

View File

@ -391,7 +391,10 @@ function Physics3DConstraintDemo:extend()
component:syncNodeToPhysics()
local frameInA = cc.mat4.createRotationZ(cc.mat4.createIdentity(), math.pi / 2)
local frameInB = frameInA
local frameInB = {}
for i=1,16 do
frameInB[i] = frameInA[i]
end
frameInA[14] = -5.0
frameInB[14] = 5.0
constraint = cc.Physics3DSliderConstraint:create(rigidBody, rigidBodyB, frameInA, frameInB, false)

View File

@ -42,7 +42,7 @@ classes = Physics3DWorld Physics3DShape PhysicsSprite3D Physics3DObject Physics3
skip = Physics3DShape::[createCompoundShape createMesh createHeightfield],
Physics3DObject::[setCollisionCallback],
Physics3DWorld::[getPhysicsObjects],
Physics3DWorld::[getPhysicsObjects rayCast],
Physics3DConeTwistConstraint::[setMotorTarget setMotorTargetInConstraintSpace],
PhysicsSprite3D::[create],
Physics3DRigidBody::[create]