bool PlanetSprite::init() { if(!Sprite3D::init()) return false; //Loads the mesh from cache loadFromCache(PLANET_MESH_MARS); //Loads the texture setTexture(PLANET_TEXTURE_MARS); //Calculates a random rotation speed and Z axis inclination int rotationSpeed = RandomHelper::random_int(1, 3); unsigned int axisInclinitation = RandomHelper::random_int(-90, 90); //Calculates a random sacale float scale = RandomHelper::random_real(1.f, 3.f); //Calculates a irregular scale float scaleX = RandomHelper::random_real(1.0f, 1.25f) * scale; float scaleY = RandomHelper::random_real(1.0f, 1.25f) * scale; float scaleZ = RandomHelper::random_real(1.0f, 1.25f) * scale; setScaleX(scaleX); setScaleY(scaleY); setScaleZ(scaleZ); setRotation3D(Vec3(0, 0, axisInclinitation)); runAction(RepeatForever::create(RotateBy::create(rotationSpeed, Vec3(0, 360, 0)))); return true; }
Sprite3D* Sprite3D::createSprite3DNode(NodeData* nodedata,ModelData* modeldata,const MaterialDatas& materialdatas) { auto sprite = new (std::nothrow) Sprite3D(); if (sprite) { sprite->setName(nodedata->id); auto mesh = Mesh::create(nodedata->id, getMeshIndexData(modeldata->subMeshId)); if (modeldata->matrialId == "" && materialdatas.materials.size()) { const NTextureData* textureData = materialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse); if (!textureData->filename.empty()) mesh->setTexture(textureData->filename); } else { const NMaterialData* materialData=materialdatas.getMaterialData(modeldata->matrialId); if(materialData) { const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse); if(textureData && !textureData->filename.empty()) { auto tex = Director::getInstance()->getTextureCache()->addImage(textureData->filename); if(tex) { Texture2D::TexParams texParams; texParams.minFilter = GL_LINEAR; texParams.magFilter = GL_LINEAR; texParams.wrapS = textureData->wrapS; texParams.wrapT = textureData->wrapT; tex->setTexParameters(texParams); mesh->setTexture(tex); mesh->_isTransparent = (materialData->getTextureData(NTextureData::Usage::Transparency) != nullptr); } } } } // set locale transform Vec3 pos; Quaternion qua; Vec3 scale; nodedata->transform.decompose(&scale, &qua, &pos); sprite->setPosition3D(pos); sprite->setRotationQuat(qua); sprite->setScaleX(scale.x); sprite->setScaleY(scale.y); sprite->setScaleZ(scale.z); sprite->addMesh(mesh); sprite->autorelease(); sprite->genGLProgramState(); } return sprite; }
bool BasicPhysics3DDemo::init() { if (!Physics3DTestDemo::init()) return false; //create floor Physics3DRigidBodyDes rbDes; rbDes.mass = 0.0f; rbDes.shape = Physics3DShape::createBox(Vec3(60.0f, 1.0f, 60.0f)); auto floor = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes); floor->setTexture("Sprite3DTest/plane.png"); floor->setScaleX(60); floor->setScaleZ(60); this->addChild(floor); floor->setCameraMask((unsigned short)CameraFlag::USER1); floor->syncNodeToPhysics(); //static object sync is not needed floor->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE); //create several boxes using PhysicsSprite3D rbDes.mass = 1.f; rbDes.shape = Physics3DShape::createBox(Vec3(0.8f, 0.8f, 0.8f)); float start_x = START_POS_X - ARRAY_SIZE_X/2; float start_y = START_POS_Y; float start_z = START_POS_Z - ARRAY_SIZE_Z/2; for (int k=0;k<ARRAY_SIZE_Y;k++) { for (int i=0;i<ARRAY_SIZE_X;i++) { for(int j = 0;j<ARRAY_SIZE_Z;j++) { float x = 1.0*i + start_x; float y = 5.0+1.0*k + start_y; float z = 1.0*j + start_z; auto sprite = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes); sprite->setTexture("Images/CyanSquare.png"); sprite->setPosition3D(Vec3(x, y, z)); sprite->syncNodeToPhysics(); sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); sprite->setCameraMask((unsigned short)CameraFlag::USER1); sprite->setScale(0.8f); this->addChild(sprite); } } } physicsScene->setPhysics3DDebugCamera(_camera); return true; }
void Transform::applyAnimationValueScaleZ(float sz) { if ((_animationPropertyBitFlag & ANIMATION_SCALE_Z_BIT) != ANIMATION_SCALE_Z_BIT) { _animationPropertyBitFlag |= ANIMATION_SCALE_Z_BIT; setScaleZ(sz); } else { _scale.z += sz; dirty(); } }
void ModelDataModel::setScale(const Vector3f &scale) { setScaleX(scale[0]); setScaleY(scale[1]); setScaleZ(scale[2]); }
void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& materialdatas, bool singleSprite) { Node* node=nullptr; for(const auto& it : nodedata->modelNodeDatas) { if(it) { if(it->bones.size() > 0 || singleSprite) { if(singleSprite && root!=nullptr) root->setName(nodedata->id); auto mesh = Mesh::create(nodedata->id, getMeshIndexData(it->subMeshId)); if(mesh) { _meshes.pushBack(mesh); if (_skeleton && it->bones.size()) { auto skin = MeshSkin::create(_skeleton, it->bones, it->invBindPose); mesh->setSkin(skin); } mesh->_visibleChanged = std::bind(&Sprite3D::onAABBDirty, this); if (it->matrialId == "" && materialdatas.materials.size()) { const NTextureData* textureData = materialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse); mesh->setTexture(textureData->filename); } else { const NMaterialData* materialData=materialdatas.getMaterialData(it->matrialId); if(materialData) { const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse); if(textureData && !textureData->filename.empty()) { auto tex = Director::getInstance()->getTextureCache()->addImage(textureData->filename); if(tex) { Texture2D::TexParams texParams; texParams.minFilter = GL_LINEAR; texParams.magFilter = GL_LINEAR; texParams.wrapS = textureData->wrapS; texParams.wrapT = textureData->wrapT; tex->setTexParameters(texParams); mesh->setTexture(tex); mesh->_isTransparent = (materialData->getTextureData(NTextureData::Usage::Transparency) != nullptr); } } } } Vec3 pos; Quaternion qua; Vec3 scale; nodedata->transform.decompose(&scale, &qua, &pos); setPosition3D(pos); setRotationQuat(qua); setScaleX(scale.x); setScaleY(scale.y); setScaleZ(scale.z); } } else { auto sprite = createSprite3DNode(nodedata,it,materialdatas); if (sprite) { if(root) { root->addChild(sprite); } } node=sprite; } } } if(nodedata->modelNodeDatas.size() ==0 ) { node= Node::create(); if(node) { node->setName(nodedata->id); // set locale transform Vec3 pos; Quaternion qua; Vec3 scale; nodedata->transform.decompose(&scale, &qua, &pos); node->setPosition3D(pos); node->setRotationQuat(qua); node->setScaleX(scale.x); node->setScaleY(scale.y); node->setScaleZ(scale.z); if(root) { root->addChild(node); } } } for(const auto& it : nodedata->children) { createNode(it,node, materialdatas, nodedata->children.size() == 1); } }
void Transform::setAnimationPropertyValue(int propertyId, AnimationValue* value, float blendWeight) { GP_ASSERT(value); GP_ASSERT(blendWeight >= 0.0f && blendWeight <= 1.0f); switch (propertyId) { case ANIMATE_SCALE_UNIT: { float scale = Curve::lerp(blendWeight, _scale.x, value->getFloat(0)); setScale(scale); break; } case ANIMATE_SCALE: { setScale(Curve::lerp(blendWeight, _scale.x, value->getFloat(0)), Curve::lerp(blendWeight, _scale.y, value->getFloat(1)), Curve::lerp(blendWeight, _scale.z, value->getFloat(2))); break; } case ANIMATE_SCALE_X: { setScaleX(Curve::lerp(blendWeight, _scale.x, value->getFloat(0))); break; } case ANIMATE_SCALE_Y: { setScaleY(Curve::lerp(blendWeight, _scale.y, value->getFloat(0))); break; } case ANIMATE_SCALE_Z: { setScaleZ(Curve::lerp(blendWeight, _scale.z, value->getFloat(0))); break; } case ANIMATE_ROTATE: { applyAnimationValueRotation(value, 0, blendWeight); break; } case ANIMATE_TRANSLATE: { setTranslation(Curve::lerp(blendWeight, _translation.x, value->getFloat(0)), Curve::lerp(blendWeight, _translation.y, value->getFloat(1)), Curve::lerp(blendWeight, _translation.z, value->getFloat(2))); break; } case ANIMATE_TRANSLATE_X: { setTranslationX(Curve::lerp(blendWeight, _translation.x, value->getFloat(0))); break; } case ANIMATE_TRANSLATE_Y: { setTranslationY(Curve::lerp(blendWeight, _translation.y, value->getFloat(0))); break; } case ANIMATE_TRANSLATE_Z: { setTranslationZ(Curve::lerp(blendWeight, _translation.z, value->getFloat(0))); break; } case ANIMATE_ROTATE_TRANSLATE: { applyAnimationValueRotation(value, 0, blendWeight); setTranslation(Curve::lerp(blendWeight, _translation.x, value->getFloat(4)), Curve::lerp(blendWeight, _translation.y, value->getFloat(5)), Curve::lerp(blendWeight, _translation.z, value->getFloat(6))); break; } case ANIMATE_SCALE_ROTATE: { setScale(Curve::lerp(blendWeight, _scale.x, value->getFloat(0)), Curve::lerp(blendWeight, _scale.y, value->getFloat(1)), Curve::lerp(blendWeight, _scale.z, value->getFloat(2))); applyAnimationValueRotation(value, 3, blendWeight); break; } case ANIMATE_SCALE_TRANSLATE: { setScale(Curve::lerp(blendWeight, _scale.x, value->getFloat(0)), Curve::lerp(blendWeight, _scale.y, value->getFloat(1)), Curve::lerp(blendWeight, _scale.z, value->getFloat(2))); setTranslation(Curve::lerp(blendWeight, _translation.x, value->getFloat(3)), Curve::lerp(blendWeight, _translation.y, value->getFloat(4)), Curve::lerp(blendWeight, _translation.z, value->getFloat(5))); break; } case ANIMATE_SCALE_ROTATE_TRANSLATE: { setScale(Curve::lerp(blendWeight, _scale.x, value->getFloat(0)), Curve::lerp(blendWeight, _scale.y, value->getFloat(1)), Curve::lerp(blendWeight, _scale.z, value->getFloat(2))); applyAnimationValueRotation(value, 3, blendWeight); setTranslation(Curve::lerp(blendWeight, _translation.x, value->getFloat(7)), Curve::lerp(blendWeight, _translation.y, value->getFloat(8)), Curve::lerp(blendWeight, _translation.z, value->getFloat(9))); break; } default: break; } }
bool Physics3DConstraintDemo::init() { if (!Physics3DTestDemo::init()) return false; //PhysicsSprite3D = Sprite3D + Physics3DComponent Physics3DRigidBodyDes rbDes; rbDes.disableSleep = true; //create box auto sprite = Sprite3D::create("Sprite3DTest/orc.c3b"); rbDes.mass = 10.f; rbDes.shape = Physics3DShape::createBox(Vec3(5.0f, 5.0f, 5.0f)); auto rigidBody = Physics3DRigidBody::create(&rbDes); Quaternion quat; Quaternion::createFromAxisAngle(Vec3(0.f, 1.f, 0.f), CC_DEGREES_TO_RADIANS(180), &quat); auto component = Physics3DComponent::create(rigidBody, Vec3(0.f, -3.f, 0.f), quat); sprite->addComponent(component); addChild(sprite); sprite->setCameraMask((unsigned short)CameraFlag::USER1); sprite->setScale(0.4f); sprite->setPosition3D(Vec3(-20.f, 5.f, 0.f)); //sync node position to physics component->syncNodeToPhysics(); //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); physicsScene->setPhysics3DDebugCamera(_camera); //create point to point constraint Physics3DConstraint* constraint = Physics3DPointToPointConstraint::create(rigidBody, Vec3(2.5f, 2.5f, 2.5f)); physicsScene->getPhysics3DWorld()->addPhysics3DConstraint(constraint); //create hinge constraint rbDes.mass = 1.0f; rbDes.shape = Physics3DShape::createBox(Vec3(8.0f, 8.0f, 1.f)); rigidBody = Physics3DRigidBody::create(&rbDes); component = Physics3DComponent::create(rigidBody); sprite = Sprite3D::create("Sprite3DTest/box.c3t"); sprite->setTexture("Sprite3DTest/plane.png"); sprite->setScaleX(8.f); sprite->setScaleY(8.f); sprite->setPosition3D(Vec3(5.f, 0.f, 0.f)); sprite->addComponent(component); sprite->setCameraMask((unsigned short)CameraFlag::USER1); this->addChild(sprite); component->syncNodeToPhysics(); rigidBody->setAngularVelocity(Vec3(0,3,0)); constraint = Physics3DHingeConstraint::create(rigidBody, Vec3(4.f, 4.f, 0.5f), Vec3(0.f, 1.f, 0.f)); physicsScene->getPhysics3DWorld()->addPhysics3DConstraint(constraint); //create slider constraint rbDes.mass = 1.0f; rbDes.shape = Physics3DShape::createBox(Vec3(3.0f, 2.0f, 3.f)); rigidBody = Physics3DRigidBody::create(&rbDes); component = Physics3DComponent::create(rigidBody); sprite = Sprite3D::create("Sprite3DTest/box.c3t"); sprite->setTexture("Sprite3DTest/plane.png"); sprite->setScaleX(3.f); sprite->setScaleZ(3.f); sprite->setPosition3D(Vec3(30.f, 15.f, 0.f)); sprite->addComponent(component); sprite->setCameraMask((unsigned short)CameraFlag::USER1); this->addChild(sprite); component->syncNodeToPhysics(); rigidBody->setLinearVelocity(Vec3(0,3,0)); rbDes.mass = 0.0f; rbDes.shape = Physics3DShape::createBox(Vec3(3.0f, 3.0f, 3.f)); auto rigidBodyB = Physics3DRigidBody::create(&rbDes); component = Physics3DComponent::create(rigidBodyB); sprite = Sprite3D::create("Sprite3DTest/box.c3t"); sprite->setTexture("Sprite3DTest/plane.png"); sprite->setScale(3.f); sprite->setPosition3D(Vec3(30.f, 5.f, 0.f)); sprite->addComponent(component); sprite->setCameraMask((unsigned short)CameraFlag::USER1); this->addChild(sprite); component->syncNodeToPhysics(); Mat4 frameInA, frameInB; Mat4::createRotationZ(CC_DEGREES_TO_RADIANS(90), &frameInA); frameInB = frameInA; frameInA.m[13] = -5.f; frameInB.m[13] = 5.f; constraint = Physics3DSliderConstraint::create(rigidBody, rigidBodyB, frameInA, frameInB, false); physicsScene->getPhysics3DWorld()->addPhysics3DConstraint(constraint); ((Physics3DSliderConstraint*)constraint)->setLowerLinLimit(-5.f); ((Physics3DSliderConstraint*)constraint)->setUpperLinLimit(5.f); //create ConeTwist constraint rbDes.mass = 1.f; rbDes.shape = Physics3DShape::createBox(Vec3(3.f, 3.f, 3.f)); rigidBody = Physics3DRigidBody::create(&rbDes); component = Physics3DComponent::create(rigidBody); sprite = Sprite3D::create("Sprite3DTest/box.c3t"); sprite->setTexture("Sprite3DTest/plane.png"); sprite->setScale(3.f); sprite->setPosition3D(Vec3(-10.f, 5.f, 0.f)); sprite->addComponent(component); sprite->setCameraMask((unsigned short)CameraFlag::USER1); this->addChild(sprite); component->syncNodeToPhysics(); Mat4::createRotationZ(CC_DEGREES_TO_RADIANS(90), &frameInA); frameInA.m[12] = 0.f; frameInA.m[13] = -10.f; frameInA.m[14] = 0.f; constraint = Physics3DConeTwistConstraint::create(rigidBody, frameInA); physicsScene->getPhysics3DWorld()->addPhysics3DConstraint(constraint, true); ((Physics3DConeTwistConstraint*)constraint)->setLimit(CC_DEGREES_TO_RADIANS(10), CC_DEGREES_TO_RADIANS(10), CC_DEGREES_TO_RADIANS(40)); //create 6 dof constraint rbDes.mass = 1.0f; rbDes.shape = Physics3DShape::createBox(Vec3(3.0f, 3.0f, 3.f)); rigidBody = Physics3DRigidBody::create(&rbDes); component = Physics3DComponent::create(rigidBody); sprite = Sprite3D::create("Sprite3DTest/box.c3t"); sprite->setTexture("Sprite3DTest/plane.png"); sprite->setScale(3.f); sprite->setPosition3D(Vec3(30.f, -5.f, 0.f)); sprite->addComponent(component); sprite->setCameraMask((unsigned short)CameraFlag::USER1); this->addChild(sprite); component->syncNodeToPhysics(); frameInA.setIdentity(); constraint = Physics3D6DofConstraint::create(rigidBody, frameInA, false); physicsScene->getPhysics3DWorld()->addPhysics3DConstraint(constraint); ((Physics3D6DofConstraint*)constraint)->setAngularLowerLimit(Vec3(0,0,0)); ((Physics3D6DofConstraint*)constraint)->setAngularUpperLimit(Vec3(0,0,0)); ((Physics3D6DofConstraint*)constraint)->setLinearLowerLimit(Vec3(-10,0,0)); ((Physics3D6DofConstraint*)constraint)->setLinearUpperLimit(Vec3(10,0,0)); return true; }
bool Physics3DKinematicDemo::init() { if (!Physics3DTestDemo::init()) return false; //create floor Physics3DRigidBodyDes rbDes; rbDes.mass = 0.0f; rbDes.shape = Physics3DShape::createBox(Vec3(60.0f, 1.0f, 60.0f)); auto floor = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes); floor->setTexture("Sprite3DTest/plane.png"); floor->setScaleX(60); floor->setScaleZ(60); floor->setPosition3D(Vec3(0.f, -1.f, 0.f)); this->addChild(floor); floor->setCameraMask((unsigned short)CameraFlag::USER1); floor->syncNodeToPhysics(); //static object sync is not needed floor->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE); //create Kinematics for (unsigned int i = 0; i < 3; ++i) { rbDes.mass = 0.f; //kinematic objects. zero mass so that it can not be affected by other dynamic objects rbDes.shape = Physics3DShape::createBox(Vec3(2.0f, 2.0f, 2.0f)); auto sprite = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes); sprite->setTexture("Images/CyanSquare.png"); sprite->setCameraMask((unsigned short)CameraFlag::USER1); auto rigidBody = static_cast<Physics3DRigidBody*>(sprite->getPhysicsObj()); rigidBody->setKinematic(true); this->addChild(sprite); sprite->setScale(2.0f); sprite->setPosition3D(Vec3(-15.0f, 0.0f, 15.0f - 15.0f * i)); auto moveby = MoveBy::create(2.0f + i, Vec3(30.0f, 0.0f, 0.0f)); sprite->runAction(RepeatForever::create(Sequence::create(moveby, moveby->reverse(), nullptr))); } //create Dynamic { //create several spheres rbDes.mass = 1.f; rbDes.shape = Physics3DShape::createSphere(0.5f); float start_x = START_POS_X - ARRAY_SIZE_X/2; float start_y = START_POS_Y + 5.0f; float start_z = START_POS_Z - ARRAY_SIZE_Z/2; for (int k=0;k<ARRAY_SIZE_Y;k++) { for (int i=0;i<ARRAY_SIZE_X;i++) { for(int j = 0;j<ARRAY_SIZE_Z;j++) { float x = 1.0*i + start_x; float y = 5.0+1.0*k + start_y; float z = 1.0*j + start_z; rbDes.originalTransform.setIdentity(); rbDes.originalTransform.translate(x, y, z); auto sprite = PhysicsSprite3D::create("Sprite3DTest/sphere.c3b", &rbDes); sprite->setTexture("Sprite3DTest/plane.png"); sprite->setCameraMask((unsigned short)CameraFlag::USER1); sprite->setScale(1.0f / sprite->getContentSize().width); this->addChild(sprite); sprite->setPosition3D(Vec3(x, y, z)); sprite->syncNodeToPhysics(); sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); } } } } physicsScene->setPhysics3DDebugCamera(_camera); return true; }
//-------------------------------------------------------------- void LayerTransform::processOscCommand(const string& command, const ofxOscMessage& m) { if(isMatch(command,"position") || isMatch(command,"p")) { if(validateOscSignature("([if][if]?[if]?)|([s][if])", m)) { if(m.getArgType(0) == OFXOSC_TYPE_STRING) { char c = tolower(getArgAsStringUnchecked(m,0)[0]); if(c == 'x') { setPositionX(getArgAsFloatUnchecked(m,1)); } else if(c == 'y') { setPositionY(getArgAsFloatUnchecked(m,1)); } else if(c == 'z') { setPositionZ(getArgAsFloatUnchecked(m,1)); } else if(c == 'n') { setPositionNormalized(getArgAsBoolUnchecked(m,1)); } else { ofLogError("LayerTransform") << "invalid arg type: " << c << " " << command << "."; } } else { setPositionX(getArgAsFloatUnchecked(m,0)); if(m.getNumArgs() > 1) { setPositionY(getArgAsFloatUnchecked(m,1)); if(m.getNumArgs() > 2) { setPositionZ(getArgAsFloatUnchecked(m,2)); } } } } } else if(isMatch(command,"anchorpoint") || isMatch(command,"a")) { if(validateOscSignature("([if][if]?[if]?)|([s][if])", m)) { if(m.getArgType(0) == OFXOSC_TYPE_STRING) { char c = tolower(getArgAsStringUnchecked(m,0)[0]); if(c == 'x') { setAnchorPointX(getArgAsFloatUnchecked(m,1)); } else if(c == 'y') { setAnchorPointY(getArgAsFloatUnchecked(m,1)); } else if(c == 'z') { setAnchorPointZ(getArgAsFloatUnchecked(m,1)); } else if(c == 'n') { setAnchorPointNormalized(getArgAsBoolUnchecked(m,1)); } else { ofLog(OF_LOG_ERROR, "LayerTransform: invalid arg type: " + ofToString(c) + " " + command); } } else { setAnchorPointX(getArgAsFloatUnchecked(m,0)); if(m.getNumArgs() > 1) { setAnchorPointY(getArgAsFloatUnchecked(m,1)); if(m.getNumArgs() > 2) { setAnchorPointZ(getArgAsFloatUnchecked(m,2)); } } } } } else if(isMatch(command,"rotate") || isMatch(command,"r")) { if(validateOscSignature("([if][if]?[if]?)|([s][if][if]?[if]?)", m)) { if(m.getArgType(0) == OFXOSC_TYPE_STRING) { char c = tolower(getArgAsStringUnchecked(m,0)[0]); if(c == 'x') { setRotationX(getArgAsFloatUnchecked(m,1)); } else if(c == 'y') { setRotationY(getArgAsFloatUnchecked(m,1)); } else if(c == 'z') { setRotationZ(getArgAsFloatUnchecked(m,1)); } else if(c == 'd') { setRotation(getArgsAsPoint(m, 1)); } else if(c == 'n') { setRotationNormalized(getArgAsBoolUnchecked(m,1)); } else { ofLog(OF_LOG_ERROR, "LayerTransform: invalid arg type: " + ofToString(c) + " " + command); } } else { setRotationX(getArgAsFloatUnchecked(m,0)); if(m.getNumArgs() > 1) { setRotationY(getArgAsFloatUnchecked(m,1)); if(m.getNumArgs() > 2) { setRotationZ(getArgAsFloatUnchecked(m,2)); } } } } } else if(isMatch(command,"scale") || isMatch(command,"s")) { if(validateOscSignature("([f][f]?[f]?)|([s][f])", m)) { if(m.getArgType(0) == OFXOSC_TYPE_STRING) { char c = tolower(getArgAsStringUnchecked(m,0)[0]); float val = getArgAsFloatUnchecked(m,1); if(c == 'x') { setScaleX(val); } else if(c == 'y') { setScaleY(val); } else if(c == 'z') { setScaleZ(val); } else { ofLog(OF_LOG_ERROR, "LayerTransform: invalid arg type: " + ofToString(c) + " " + command); } } else { setScaleX(getArgAsFloatUnchecked(m,0)); if(m.getNumArgs() > 1) { setScaleY(getArgAsFloatUnchecked(m,1)); if(m.getNumArgs() > 2) { setScaleZ(getArgAsFloatUnchecked(m,2)); } } } } } else if(isMatch(command,"opacity") || isMatch(command,"o")) { if(validateOscSignature("[if]", m)) { setOpacity(getArgAsFloatUnchecked(m,0)); } } else if(isMatch(command,"opacityn") || isMatch(command,"on")) { if(validateOscSignature("[if]", m)) { setOpacityNormalized(getArgAsFloatUnchecked(m,0)); } } else if(isMatch(command,"size") || isMatch(command, "sz")) { if(validateOscSignature("[if][if]", m)) { setSize(getArgAsFloatUnchecked(m,0),getArgAsFloatUnchecked(m,1)); } } else if(isMatch(command,"width") || isMatch(command, "w")) { if(validateOscSignature("[if]", m)) { setWidth(getArgAsFloatUnchecked(m,0)); } } else if(isMatch(command,"height") || isMatch(command, "h")) { if(validateOscSignature("[if]", m)) { setHeight(getArgAsFloatUnchecked(m,0)); } } }
bool Physics3DColliderDemo::init() { if (!Physics3DTestDemo::init()) return false; Physics3DRigidBodyDes rbDes; rbDes.mass = 1.0f; rbDes.shape = Physics3DShape::createBox(Vec3(3.0f, 3.0f, 3.f)); auto playerBody = Physics3DRigidBody::create(&rbDes); auto component = Physics3DComponent::create(playerBody); playerBody->setKinematic(true); auto sprite = Sprite3D::create("Sprite3DTest/box.c3t"); sprite->setTexture("Sprite3DTest/plane.png"); sprite->setScale(3.f); sprite->setPosition3D(Vec3(0.0f, 0.f, 30.f)); sprite->addComponent(component); sprite->setCameraMask((unsigned short)CameraFlag::USER1); auto moveby = MoveBy::create(5.0f, Vec3(0.0f, 0.0f, -60.0f)); sprite->runAction(RepeatForever::create(Sequence::create(moveby, moveby->reverse(), nullptr))); this->addChild(sprite); { Physics3DColliderDes colliderDes; colliderDes.shape = Physics3DShape::createSphere(10.0f); colliderDes.isTrigger = true; auto collider = Physics3DCollider::create(&colliderDes); auto component = Physics3DComponent::create(collider); auto node = Node::create(); node->addComponent(component); node->setCameraMask((unsigned short)CameraFlag::USER1); this->addChild(node); Physics3DRigidBodyDes rbDes; rbDes.mass = 1.0f; rbDes.shape = Physics3DShape::createBox(Vec3(10.0f, 10.0f, 1.f)); auto rigidBody = Physics3DRigidBody::create(&rbDes); component = Physics3DComponent::create(rigidBody); rigidBody->setKinematic(true); auto doorLeft = Sprite3D::create("Sprite3DTest/box.c3t"); doorLeft->setTexture("Sprite3DTest/plane.png"); doorLeft->setScaleX(10.0f); doorLeft->setScaleY(10.0f); doorLeft->setScaleZ(1.0f); doorLeft->setPosition3D(Vec3(-5.0f, 0.0f, 0.0f)); doorLeft->addComponent(component); doorLeft->setCameraMask((unsigned short)CameraFlag::USER1); node->addChild(doorLeft); rbDes.mass = 1.0f; rbDes.shape = Physics3DShape::createBox(Vec3(10.0f, 10.0f, 1.f)); rigidBody = Physics3DRigidBody::create(&rbDes); component = Physics3DComponent::create(rigidBody); rigidBody->setKinematic(true); auto doorRight = Sprite3D::create("Sprite3DTest/box.c3t"); doorRight->setTexture("Sprite3DTest/plane.png"); doorRight->setScaleX(10.0f); doorRight->setScaleY(10.0f); doorRight->setScaleZ(1.0f); doorRight->setPosition3D(Vec3(5.0f, 0.0f, 0.0f)); doorRight->addComponent(component); doorRight->setCameraMask((unsigned short)CameraFlag::USER1); node->addChild(doorRight); collider->onTriggerEnter = [=](Physics3DObject *otherObject){ if (otherObject == playerBody){ auto moveby = MoveBy::create(1.0f, Vec3(-5.0f, 0.0f, 0.0f)); doorLeft->runAction(moveby); doorRight->runAction(moveby->reverse()); } }; collider->onTriggerExit = [=](Physics3DObject *otherObject){ if (otherObject == playerBody){ auto moveby = MoveBy::create(1.0f, Vec3(5.0f, 0.0f, 0.0f)); doorLeft->runAction(moveby); doorRight->runAction(moveby->reverse()); } }; } physicsScene->setPhysics3DDebugCamera(_camera); return true; }