mirror of https://github.com/axmolengine/axmol.git
rename syncToNode and syncToPhysics
This commit is contained in:
parent
831ca47b13
commit
73d815b0ab
|
@ -147,7 +147,7 @@ void Physics3DComponent::preSimulate()
|
||||||
{
|
{
|
||||||
if (((int)_syncFlag & (int)Physics3DComponent::PhysicsSyncFlag::NODE_TO_PHYSICS) && _physics3DObj && _owner)
|
if (((int)_syncFlag & (int)Physics3DComponent::PhysicsSyncFlag::NODE_TO_PHYSICS) && _physics3DObj && _owner)
|
||||||
{
|
{
|
||||||
syncToNode();
|
syncNodeToPhysics();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ void Physics3DComponent::postSimulate()
|
||||||
{
|
{
|
||||||
if (((int)_syncFlag & (int)Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE) && _physics3DObj && _owner)
|
if (((int)_syncFlag & (int)Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE) && _physics3DObj && _owner)
|
||||||
{
|
{
|
||||||
syncToPhysics();
|
syncPhysicsToNode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ void Physics3DComponent::setSyncFlag(PhysicsSyncFlag syncFlag)
|
||||||
_syncFlag = syncFlag;
|
_syncFlag = syncFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physics3DComponent::syncToPhysics()
|
void Physics3DComponent::syncPhysicsToNode()
|
||||||
{
|
{
|
||||||
if (_physics3DObj->getObjType() == Physics3DObject::PhysicsObjType::RIGID_BODY)
|
if (_physics3DObj->getObjType() == Physics3DObject::PhysicsObjType::RIGID_BODY)
|
||||||
{
|
{
|
||||||
|
@ -207,7 +207,7 @@ void Physics3DComponent::syncToPhysics()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Physics3DComponent::syncToNode()
|
void Physics3DComponent::syncNodeToPhysics()
|
||||||
{
|
{
|
||||||
if (_physics3DObj->getObjType() == Physics3DObject::PhysicsObjType::RIGID_BODY)
|
if (_physics3DObj->getObjType() == Physics3DObject::PhysicsObjType::RIGID_BODY)
|
||||||
{
|
{
|
||||||
|
|
|
@ -110,14 +110,14 @@ public:
|
||||||
void setSyncFlag(PhysicsSyncFlag syncFlag);
|
void setSyncFlag(PhysicsSyncFlag syncFlag);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* align node and physics according to physics object
|
* synchronize node transformation to physics
|
||||||
*/
|
*/
|
||||||
void syncToPhysics();
|
void syncNodeToPhysics();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* align node and physics according to node
|
* synchronize physics transformation to node
|
||||||
*/
|
*/
|
||||||
void syncToNode();
|
void syncPhysicsToNode();
|
||||||
|
|
||||||
CC_CONSTRUCTOR_ACCESS:
|
CC_CONSTRUCTOR_ACCESS:
|
||||||
Physics3DComponent();
|
Physics3DComponent();
|
||||||
|
|
|
@ -57,16 +57,16 @@ void PhysicsSprite3D::setSyncFlag(Physics3DComponent::PhysicsSyncFlag syncFlag)
|
||||||
_physicsComponent->setSyncFlag(syncFlag);
|
_physicsComponent->setSyncFlag(syncFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsSprite3D::syncToPhysics()
|
void PhysicsSprite3D::syncNodeToPhysics()
|
||||||
{
|
{
|
||||||
if (_physicsComponent)
|
if (_physicsComponent)
|
||||||
_physicsComponent->syncToPhysics();
|
_physicsComponent->syncNodeToPhysics();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsSprite3D::syncToNode()
|
void PhysicsSprite3D::syncPhysicsToNode()
|
||||||
{
|
{
|
||||||
if (_physicsComponent)
|
if (_physicsComponent)
|
||||||
_physicsComponent->syncToNode();
|
_physicsComponent->syncPhysicsToNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
PhysicsSprite3D::PhysicsSprite3D()
|
PhysicsSprite3D::PhysicsSprite3D()
|
||||||
|
|
|
@ -56,11 +56,11 @@ public:
|
||||||
/** Set synchronization flag, see Physics3DComponent. */
|
/** Set synchronization flag, see Physics3DComponent. */
|
||||||
void setSyncFlag(Physics3DComponent::PhysicsSyncFlag syncFlag);
|
void setSyncFlag(Physics3DComponent::PhysicsSyncFlag syncFlag);
|
||||||
|
|
||||||
/** Physics synchronize rendering. */
|
/** synchronize node transformation to physics. */
|
||||||
void syncToPhysics();
|
void syncNodeToPhysics();
|
||||||
|
|
||||||
/** Rendering synchronize physics. */
|
/** synchronize physics transformation to node. */
|
||||||
void syncToNode();
|
void syncPhysicsToNode();
|
||||||
|
|
||||||
CC_CONSTRUCTOR_ACCESS:
|
CC_CONSTRUCTOR_ACCESS:
|
||||||
PhysicsSprite3D();
|
PhysicsSprite3D();
|
||||||
|
|
|
@ -210,7 +210,7 @@ void Physics3DTestDemo::shootBox( const cocos2d::Vec3 &des )
|
||||||
this->addChild(sprite);
|
this->addChild(sprite);
|
||||||
sprite->setPosition3D(_camera->getPosition3D());
|
sprite->setPosition3D(_camera->getPosition3D());
|
||||||
sprite->setScale(0.5f);
|
sprite->setScale(0.5f);
|
||||||
sprite->syncToNode();
|
sprite->syncNodeToPhysics();
|
||||||
|
|
||||||
//optimize, only sync node to physics
|
//optimize, only sync node to physics
|
||||||
sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); //sync node to physics
|
sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); //sync node to physics
|
||||||
|
@ -239,7 +239,7 @@ bool BasicPhysics3DDemo::init()
|
||||||
floor->setScaleZ(60);
|
floor->setScaleZ(60);
|
||||||
this->addChild(floor);
|
this->addChild(floor);
|
||||||
floor->setCameraMask((unsigned short)CameraFlag::USER1);
|
floor->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||||
floor->syncToNode();
|
floor->syncNodeToPhysics();
|
||||||
//static object sync is not needed
|
//static object sync is not needed
|
||||||
floor->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE);
|
floor->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE);
|
||||||
|
|
||||||
|
@ -263,7 +263,7 @@ bool BasicPhysics3DDemo::init()
|
||||||
auto sprite = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes);
|
auto sprite = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes);
|
||||||
sprite->setTexture("Images/CyanSquare.png");
|
sprite->setTexture("Images/CyanSquare.png");
|
||||||
sprite->setPosition3D(Vec3(x, y, z));
|
sprite->setPosition3D(Vec3(x, y, z));
|
||||||
sprite->syncToNode();
|
sprite->syncNodeToPhysics();
|
||||||
sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
|
sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
|
||||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||||
sprite->setScale(0.8f);
|
sprite->setScale(0.8f);
|
||||||
|
@ -303,7 +303,7 @@ bool Physics3DKinematicDemo::init()
|
||||||
floor->setPosition3D(Vec3(0.f, -1.f, 0.f));
|
floor->setPosition3D(Vec3(0.f, -1.f, 0.f));
|
||||||
this->addChild(floor);
|
this->addChild(floor);
|
||||||
floor->setCameraMask((unsigned short)CameraFlag::USER1);
|
floor->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||||
floor->syncToNode();
|
floor->syncNodeToPhysics();
|
||||||
//static object sync is not needed
|
//static object sync is not needed
|
||||||
floor->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE);
|
floor->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE);
|
||||||
|
|
||||||
|
@ -354,7 +354,7 @@ bool Physics3DKinematicDemo::init()
|
||||||
sprite->setScale(1.0f / sprite->getContentSize().width);
|
sprite->setScale(1.0f / sprite->getContentSize().width);
|
||||||
this->addChild(sprite);
|
this->addChild(sprite);
|
||||||
sprite->setPosition3D(Vec3(x, y, z));
|
sprite->setPosition3D(Vec3(x, y, z));
|
||||||
sprite->syncToNode();
|
sprite->syncNodeToPhysics();
|
||||||
|
|
||||||
sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
|
sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
|
||||||
}
|
}
|
||||||
|
@ -391,7 +391,7 @@ bool Physics3DConstraintDemo::init()
|
||||||
sprite->setScale(0.4f);
|
sprite->setScale(0.4f);
|
||||||
sprite->setPosition3D(Vec3(-20.f, 5.f, 0.f));
|
sprite->setPosition3D(Vec3(-20.f, 5.f, 0.f));
|
||||||
//sync node position to physics
|
//sync node position to physics
|
||||||
component->syncToNode();
|
component->syncNodeToPhysics();
|
||||||
//physics controlled, we will not set position for it, so we can skip sync node position to physics
|
//physics controlled, we will not set position for it, so we can skip sync node position to physics
|
||||||
component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
|
component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
|
||||||
|
|
||||||
|
@ -414,7 +414,7 @@ bool Physics3DConstraintDemo::init()
|
||||||
sprite->addComponent(component);
|
sprite->addComponent(component);
|
||||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||||
this->addChild(sprite);
|
this->addChild(sprite);
|
||||||
component->syncToNode();
|
component->syncNodeToPhysics();
|
||||||
rigidBody->setAngularVelocity(Vec3(0,3,0));
|
rigidBody->setAngularVelocity(Vec3(0,3,0));
|
||||||
constraint = Physics3DHingeConstraint::create(rigidBody, Vec3(4.f, 4.f, 0.5f), Vec3(0.f, 1.f, 0.f));
|
constraint = Physics3DHingeConstraint::create(rigidBody, Vec3(4.f, 4.f, 0.5f), Vec3(0.f, 1.f, 0.f));
|
||||||
physicsScene->getPhysics3DWorld()->addPhysics3DConstraint(constraint);
|
physicsScene->getPhysics3DWorld()->addPhysics3DConstraint(constraint);
|
||||||
|
@ -433,7 +433,7 @@ bool Physics3DConstraintDemo::init()
|
||||||
sprite->addComponent(component);
|
sprite->addComponent(component);
|
||||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||||
this->addChild(sprite);
|
this->addChild(sprite);
|
||||||
component->syncToNode();
|
component->syncNodeToPhysics();
|
||||||
rigidBody->setLinearVelocity(Vec3(0,3,0));
|
rigidBody->setLinearVelocity(Vec3(0,3,0));
|
||||||
|
|
||||||
rbDes.mass = 0.0f;
|
rbDes.mass = 0.0f;
|
||||||
|
@ -447,7 +447,7 @@ bool Physics3DConstraintDemo::init()
|
||||||
sprite->addComponent(component);
|
sprite->addComponent(component);
|
||||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||||
this->addChild(sprite);
|
this->addChild(sprite);
|
||||||
component->syncToNode();
|
component->syncNodeToPhysics();
|
||||||
|
|
||||||
Mat4 frameInA, frameInB;
|
Mat4 frameInA, frameInB;
|
||||||
Mat4::createRotationZ(CC_DEGREES_TO_RADIANS(90), &frameInA);
|
Mat4::createRotationZ(CC_DEGREES_TO_RADIANS(90), &frameInA);
|
||||||
|
@ -471,7 +471,7 @@ bool Physics3DConstraintDemo::init()
|
||||||
sprite->addComponent(component);
|
sprite->addComponent(component);
|
||||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||||
this->addChild(sprite);
|
this->addChild(sprite);
|
||||||
component->syncToNode();
|
component->syncNodeToPhysics();
|
||||||
|
|
||||||
Mat4::createRotationZ(CC_DEGREES_TO_RADIANS(90), &frameInA);
|
Mat4::createRotationZ(CC_DEGREES_TO_RADIANS(90), &frameInA);
|
||||||
frameInA.m[12] = 0.f;
|
frameInA.m[12] = 0.f;
|
||||||
|
@ -493,7 +493,7 @@ bool Physics3DConstraintDemo::init()
|
||||||
sprite->addComponent(component);
|
sprite->addComponent(component);
|
||||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||||
this->addChild(sprite);
|
this->addChild(sprite);
|
||||||
component->syncToNode();
|
component->syncNodeToPhysics();
|
||||||
frameInA.setIdentity();
|
frameInA.setIdentity();
|
||||||
constraint = Physics3D6DofConstraint::create(rigidBody, frameInA, false);
|
constraint = Physics3D6DofConstraint::create(rigidBody, frameInA, false);
|
||||||
physicsScene->getPhysics3DWorld()->addPhysics3DConstraint(constraint);
|
physicsScene->getPhysics3DWorld()->addPhysics3DConstraint(constraint);
|
||||||
|
@ -592,7 +592,7 @@ bool Physics3DTerrainDemo::init()
|
||||||
auto component = Physics3DComponent::create(rigidBody);
|
auto component = Physics3DComponent::create(rigidBody);
|
||||||
terrain->addComponent(component);
|
terrain->addComponent(component);
|
||||||
this->addChild(terrain);
|
this->addChild(terrain);
|
||||||
component->syncToNode();
|
component->syncNodeToPhysics();
|
||||||
component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE);
|
component->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE);
|
||||||
|
|
||||||
|
|
||||||
|
@ -619,7 +619,7 @@ bool Physics3DTerrainDemo::init()
|
||||||
sprite->setScale(1.0f / sprite->getContentSize().width);
|
sprite->setScale(1.0f / sprite->getContentSize().width);
|
||||||
sprite->setPosition3D(Vec3(x, y, z));
|
sprite->setPosition3D(Vec3(x, y, z));
|
||||||
this->addChild(sprite);
|
this->addChild(sprite);
|
||||||
sprite->syncToNode();
|
sprite->syncNodeToPhysics();
|
||||||
sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
|
sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue