void Physics3DWorld::collisionChecking()
{
    int numManifolds = _dispatcher->getNumManifolds();
    for (int i = 0; i < numManifolds; ++i){
        btPersistentManifold * contactManifold = _dispatcher->getManifoldByIndexInternal(i);
        int numContacts = contactManifold->getNumContacts();
        if (0 < numContacts){
            const btCollisionObject* obA = static_cast<const btCollisionObject*>(contactManifold->getBody0());
            const btCollisionObject* obB = static_cast<const btCollisionObject*>(contactManifold->getBody1());
            Physics3DObject *poA = getPhysicsObject(obA);
            Physics3DObject *poB = getPhysicsObject(obB);
            if (poA->needCollisionCallback() || poB->needCollisionCallback()){
                Physics3DCollisionInfo ci;
                ci.objA = poA;
                ci.objB = poB;
                for (int c = 0; c < numContacts; ++c){
                    btManifoldPoint& pt = contactManifold->getContactPoint(c);
                    Physics3DCollisionInfo::CollisionPoint cp = {
                          convertbtVector3ToVec3(pt.m_localPointA), convertbtVector3ToVec3(pt.m_positionWorldOnA)
                        , convertbtVector3ToVec3(pt.m_localPointB), convertbtVector3ToVec3(pt.m_positionWorldOnB)
                        , convertbtVector3ToVec3(pt.m_normalWorldOnB)
                    };
                    ci.collisionPointList.push_back(cp);
                }

                if (poA->needCollisionCallback()){
                    poA->getCollisionCallback()(ci);
                }
                if (poB->needCollisionCallback()){
                    poB->getCollisionCallback()(ci);
                }
            }
        }
    }
}
Example #2
0
Magic3D::Tween* TweenInfo::getTween()
{
    Magic3D::PhysicsObject* physicsObject = getPhysicsObject();
    Magic3D::Tween* result = NULL;
    if (physicsObject)
    {
        result = physicsObject->getTween(tweenIndex);
    }

    return result;
}
Example #3
0
void TweenInfo::on_btnDelete_clicked()
{
    Magic3D::PhysicsObject* physicsObject = getPhysicsObject();
    if (physicsObject)
    {
        tweens->resetObject();
        physicsObject->removeTween(tweenIndex);
        mainWindow->setProjectChanged(true);
        mainWindow->update();
        tweens->update();
    }
}
Example #4
0
    ///this method is mainly for expert/internal use only.
    virtual void removeOverlappingObjectInternal(btBroadphaseProxy* otherProxy, btDispatcher* /*dispatcher*/, btBroadphaseProxy* thisProxy = nullptr) override
    {
        btCollisionObject* otherObject = (btCollisionObject*)otherProxy->m_clientObject;
        btAssert(otherObject);
        int index = m_overlappingObjects.findLinearSearch(otherObject);
        if (index < m_overlappingObjects.size())
        {
            m_overlappingObjects[index] = m_overlappingObjects[m_overlappingObjects.size() - 1];
            m_overlappingObjects.pop_back();

            if (_collider->onTriggerExit != nullptr && _collider->isTrigger())
                _collider->onTriggerExit(getPhysicsObject(otherObject));
        }
    }
Example #5
0
 ///this method is mainly for expert/internal use only.
 virtual void addOverlappingObjectInternal(btBroadphaseProxy* otherProxy, btBroadphaseProxy* thisProxy = nullptr) override
 {
     btCollisionObject* otherObject = (btCollisionObject*)otherProxy->m_clientObject;
     btAssert(otherObject);
     ///if this linearSearch becomes too slow (too many overlapping objects) we should add a more appropriate data structure
     int index = m_overlappingObjects.findLinearSearch(otherObject);
     if (index == m_overlappingObjects.size())
     {
         //not found
         m_overlappingObjects.push_back(otherObject);
         if (_collider->onTriggerEnter != nullptr && _collider->isTrigger())
             _collider->onTriggerEnter(getPhysicsObject(otherObject));
     }
 }
bool Physics3DWorld::rayCast(const cocos2d::Vec3& startPos, const cocos2d::Vec3& endPos, Physics3DWorld::HitResult* result)
{
    auto btStart = convertVec3TobtVector3(startPos);
    auto btEnd = convertVec3TobtVector3(endPos);
    btCollisionWorld::ClosestRayResultCallback btResult(btStart, btEnd);
    _btPhyiscsWorld->rayTest(btStart, btEnd, btResult);
    if (btResult.hasHit())
    {
        result->hitObj = getPhysicsObject(btResult.m_collisionObject);
        result->hitPosition = convertbtVector3ToVec3(btResult.m_hitPointWorld);
        result->hitNormal = convertbtVector3ToVec3(btResult.m_hitNormalWorld);
        return true;
    }
    result->hitObj = nullptr;
    return false;
}
bool Physics3DWorld::sweepShape(Physics3DShape* shape, const cocos2d::Mat4& startTransform, const cocos2d::Mat4& endTransform, Physics3DWorld::HitResult* result)
{
    CC_ASSERT(shape->getShapeType() != Physics3DShape::ShapeType::HEIGHT_FIELD && shape->getShapeType() != Physics3DShape::ShapeType::MESH);
    auto btStart = convertMat4TobtTransform(startTransform);
    auto btEnd = convertMat4TobtTransform(endTransform);
    btCollisionWorld::ClosestConvexResultCallback btResult(btStart.getOrigin(), btEnd.getOrigin());
    _btPhyiscsWorld->convexSweepTest((btConvexShape*)shape->getbtShape(), btStart, btEnd, btResult);
    if (btResult.hasHit())
    {
        result->hitObj = getPhysicsObject(btResult.m_hitCollisionObject);
        result->hitPosition = convertbtVector3ToVec3(btResult.m_hitPointWorld);
        result->hitNormal = convertbtVector3ToVec3(btResult.m_hitNormalWorld);
        return true;
    }
    result->hitObj = nullptr;
    return false;
}
Example #8
0
void Entity::CalculateForces( const NetData::Message_Input& Input )
{
	irr::core::matrix4 mat = Physics->getDrawMesh()->getAbsoluteTransformation();
	
	f32 dt = Game->getTimer()->getTickS();
	f32 mass = getPhysicsObject()->getLocalData().Mass;
	
	irr::core::vector3df linear_velocity = Physics->getBody()->getLinearVelocity();
	irr::core::vector3df angular_velocity = Physics->getBody()->getAngularVelocity();
	
	irr::core::vector3df new_lin_force ( 0, 0, Input.AXIS_Throttle ),
			rev_lin_force ( linear_velocity * -1.0f ),
			new_ang_force ( Input.AXIS_Pitch * 360, Input.AXIS_Yaw * 360, Input.AXIS_Roll * 360 ), // % of 360 rotation
			rev_ang_force ( angular_velocity * -1.0f );
	
	new_lin_force.setLength( max_lin_thrust );
	rev_lin_force.setLength( max_lin_thrust );
	
	new_ang_force.setLength( max_ang_thrust );
	rev_ang_force.setLength( max_ang_thrust );
	
	mat.rotateVect( new_lin_force );
	mat.rotateVect( new_ang_force );
	
	if( (new_lin_force / mass * dt + linear_velocity).getLengthSQ() >= max_lin_vel_sqr )
	{
		new_lin_force += rev_lin_force;
	}
	
	if( (new_ang_force / mass * dt + angular_velocity).getLengthSQ() >= max_ang_vel_sqr )
	{
		new_ang_force += rev_ang_force;
	}
	
	Physics->getBody()->applyCentralForce( new_lin_force );
	Physics->getBody()->applyTorque( new_ang_force );
}
Example #9
0
void TweenInfo::update()
{
    updating = true;
    Magic3D::PhysicsObject* physicsObject = getPhysicsObject();
    Magic3D::Tween* tween = getTween();

    if (physicsObject && tween)
    {
        ui->lblTitle->setText(tr("%0 - %1").arg(tweenIndex).arg(getTweenType(tween)));

        ui->chkPlayAtStart->setChecked(tween->isPlayingAtStart());
        ui->chkAllwaysUpdate->setChecked(tween->isAllwaysUpdated());
        ui->chkIgnoreTimeScale->setChecked(tween->isIgnoringTimeScale());
        ui->cmbUpdateType->setCurrentIndex(tween->getTweenUpdateType());

        if (!ui->txtRepeat->hasFocus())
        {
            ui->txtRepeat->setValue(tween->getRepeat());
        }

        if (!ui->txtStartValue->hasFocus())
        {
            ui->txtStartValue->setValue(tween->getStartValue());
        }

        if (!ui->txtSpeed->hasFocus())
        {
            ui->txtSpeed->setValue(tween->getSpeed());
        }

        if (!ui->txtDuration->hasFocus())
        {
            ui->txtDuration->setValue(tween->getDuration());
        }

        switch (tween->getType())
        {
            case Magic3D::eTWEEN_ALPHA:
            {
                if (!ui->txtX->hasFocus())
                {
                    ui->lblX->setText("Alpha:");
                    ui->txtX->setValue(static_cast<Magic3D::TweenAlpha*>(tween)->getAlpha());
                }
                break;
            }
            case Magic3D::eTWEEN_ROTATE:
            {
                ui->lblX->setText("Rotate x:");

                Magic3D::TweenRotate* rotate = static_cast<Magic3D::TweenRotate*>(tween);
                if (!ui->txtX->hasFocus())
                {
                    ui->txtX->setValue(rotate->getEuler().getX());
                }
                if (!ui->txtY->hasFocus())
                {
                    ui->txtY->setValue(rotate->getEuler().getY());
                }
                if (!ui->txtZ->hasFocus())
                {
                    ui->txtZ->setValue(rotate->getEuler().getZ());
                }
                break;
            }
            case Magic3D::eTWEEN_SCALE:
            {
                ui->lblX->setText("Scale x:");

                Magic3D::TweenScale* scale = static_cast<Magic3D::TweenScale*>(tween);
                if (!ui->txtX->hasFocus())
                {
                    ui->txtX->setValue(scale->getScale().getX());
                }
                if (!ui->txtY->hasFocus())
                {
                    ui->txtY->setValue(scale->getScale().getY());
                }
                if (!ui->txtZ->hasFocus())
                {
                    ui->txtZ->setValue(scale->getScale().getZ());
                }
                break;
            }
            case Magic3D::eTWEEN_TRANSLATE:
            {
                ui->lblX->setText("Translate x:");

                Magic3D::TweenTranslate* translate = static_cast<Magic3D::TweenTranslate*>(tween);
                if (!ui->txtX->hasFocus())
                {
                    ui->txtX->setValue(translate->getPosition().getX());
                }
                if (!ui->txtY->hasFocus())
                {
                    ui->txtY->setValue(translate->getPosition().getY());
                }
                if (!ui->txtZ->hasFocus())
                {
                    ui->txtZ->setValue(translate->getPosition().getZ());
                }
                break;
            }
            case Magic3D::eTWEEN_GOTO:
            {
                ui->lblX->setText("Position x:");

                Magic3D::TweenGoTo* goTo = static_cast<Magic3D::TweenGoTo*>(tween);
                if (!ui->txtX->hasFocus())
                {
                    ui->txtX->setValue(goTo->getPosition().getX());
                }
                if (!ui->txtY->hasFocus())
                {
                    ui->txtY->setValue(goTo->getPosition().getY());
                }
                if (!ui->txtZ->hasFocus())
                {
                    ui->txtZ->setValue(goTo->getPosition().getZ());
                }
                break;
            }
            case Magic3D::eTWEEN_LOOKAT:
            {
                ui->lblX->setText("Rotation x:");

                Magic3D::TweenLookAt* lookAt = static_cast<Magic3D::TweenLookAt*>(tween);
                if (!ui->txtX->hasFocus())
                {
                    ui->txtX->setValue(lookAt->getRotation().getX());
                }
                if (!ui->txtY->hasFocus())
                {
                    ui->txtY->setValue(lookAt->getRotation().getY());
                }
                if (!ui->txtZ->hasFocus())
                {
                    ui->txtZ->setValue(lookAt->getRotation().getZ());
                }
                break;
            }
            //case Magic3D::eTWEEN_DELAY: break;
            //case Magic3D::eTWEEN_CUSTOM: break;
            default: break;
        }
        bool visible = tween->getType() != Magic3D::eTWEEN_CUSTOM && tween->getType() != Magic3D::eTWEEN_DELAY;
        ui->lblX->setVisible(visible);
        ui->txtX->setVisible(visible);
        ui->lblY->setVisible(visible && tween->getType() != Magic3D::eTWEEN_ALPHA);
        ui->txtY->setVisible(visible && tween->getType() != Magic3D::eTWEEN_ALPHA);
        ui->lblZ->setVisible(visible && tween->getType() != Magic3D::eTWEEN_ALPHA);
        ui->txtZ->setVisible(visible && tween->getType() != Magic3D::eTWEEN_ALPHA);
        ui->spacerCustom->setVisible(visible && tween->getType() == Magic3D::eTWEEN_ALPHA);
        ui->spacerCustom2->setVisible(visible && tween->getType() == Magic3D::eTWEEN_ALPHA);

        ui->cmbNextTweenObject->clear();
        mainWindow->setComboList(tweens->getParentsList(), ui->cmbNextTweenObject);

        if (!tween->getNextTweenObject().empty())
        {
            ui->cmbNextTweenObject->setCurrentIndex(ui->cmbNextTweenObject->findText(QString::fromStdString(tween->getNextTweenObject())));
            if (!ui->txtNextIndex->hasFocus())
            {
                ui->txtNextIndex->setValue(tween->getNextTweenIndex());
            }
        }
        else
        {
            ui->cmbNextTweenObject->setCurrentIndex(ui->cmbNextTweenObject->findText(UTILS_NONE));
            ui->txtNextIndex->setValue(0);
        }

        ui->cmbNextTweenBone->setCurrentIndex(0);
        if (getModel(tween->getNextTweenObject()))
        {
            updateBoneCombo(ui->cmbNextTweenBone, tween->getNextTweenObject());
            ui->cmbNextTweenBone->setEnabled(true);
            if (!tween->getNextTweenBone().empty())
            {
                ui->cmbNextTweenBone->setCurrentIndex(ui->cmbNextTweenBone->findText(QString::fromStdString(tween->getNextTweenBone())));
            }
        }
        else
        {
            ui->cmbNextTweenBone->setEnabled(false);
        }
    }
    updating = false;
}