Exemple #1
0
void Snake::spawn()
{
    nextDirection = DIRECTION_RIGHT;
    prevDirection = DIRECTION_RIGHT;

    position = sf::Vector2i(3, 1);
    addBodyPart(2, 1);
    addBodyPart(1, 1);

    lengthToGrow = 0;
    speedLevel = 0;

    prevMovement = sf::milliseconds(0);
    movementDelay = sf::milliseconds(initialMovementDelay.asMilliseconds());
}
void PhysicsRagdoll::initProperties(const vec3& position, const RagdollDesc& desc, const PhysicsMaterial& material, 
                                    uint32 collisionGroup, uint32 collisionGroupAgainst )
{
    m_StartPosition = position;

    m_Aggregate = PHYSICS->getSDK()->createAggregate(20, false);

    addBodyPart(&m_pArmL1, desc.armL1, material, collisionGroup, collisionGroupAgainst);
    addBodyPart(&m_pArmL2, desc.armL2, material, collisionGroup, collisionGroupAgainst);
    addBodyPart(&m_pHandL, desc.handL, material, collisionGroup, collisionGroupAgainst);

    addBodyPart(&m_pArmR1, desc.armR1, material, collisionGroup, collisionGroupAgainst);
    addBodyPart(&m_pArmR2, desc.armR2, material, collisionGroup, collisionGroupAgainst);
    addBodyPart(&m_pHandR, desc.handR, material, collisionGroup, collisionGroupAgainst);

    addBodyPart(&m_pHead, desc.head, material, collisionGroup, collisionGroupAgainst);
    addBodyPart(&m_pNeck, desc.neck, material, collisionGroup, collisionGroupAgainst);

    addBodyPart(&m_pShoulderL, desc.shoulderL, material, collisionGroup, collisionGroupAgainst);
    addBodyPart(&m_pShoulderR, desc.shoulderR, material, collisionGroup, collisionGroupAgainst);

    addBodyPart(&m_pSpine1, desc.spine1, material, collisionGroup, collisionGroupAgainst);
    addBodyPart(&m_pSpine2, desc.spine2, material, collisionGroup, collisionGroupAgainst);
    addBodyPart(&m_pSpine3, desc.spine3, material, collisionGroup, collisionGroupAgainst);
    addBodyPart(&m_pPelvis, desc.pelvis, material, collisionGroup, collisionGroupAgainst);

    addBodyPart(&m_pLegL1, desc.legL1, material, collisionGroup, collisionGroupAgainst);
    addBodyPart(&m_pLegL2, desc.legL2, material, collisionGroup, collisionGroupAgainst);
    addBodyPart(&m_pFootL, desc.footL, material, collisionGroup, collisionGroupAgainst);

    addBodyPart(&m_pLegR1, desc.legR1, material, collisionGroup, collisionGroupAgainst);
    addBodyPart(&m_pLegR2, desc.legR2, material, collisionGroup, collisionGroupAgainst);
    addBodyPart(&m_pFootR, desc.footR, material, collisionGroup, collisionGroupAgainst);


    //Spine
    addJoint(&m_pPelvisSpine3Joint, m_pPelvis, m_pSpine3, desc.pelvis, desc.spine3,  
              physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED,
              -pi / 16.0f, pi / 16.0f, pi / 8.0f, pi / 8.0f);
    addJoint(&m_pSpine3Spine2Joint, m_pSpine3, m_pSpine2, desc.spine3, desc.spine2,  
        physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED,
        -pi / 8.0f, pi / 8.0f, pi / 8.0f, pi / 8.0f);
    addJoint(&m_pSpine2Spine1Joint, m_pSpine2, m_pSpine1, desc.spine2, desc.spine1,  
        physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED,
        -pi / 8.0f, pi / 8.0f, pi / 8.0f, pi / 8.0f);

    //Shoulders
    addJoint(&m_pSpine1ShoulderLJoint, m_pSpine1, m_pShoulderL, desc.spine1, desc.shoulderL,  
        physx::PxD6Motion::eLOCKED, physx::PxD6Motion::eLOCKED, physx::PxD6Motion::eLOCKED,
        0, 0, pi / 6.0f, pi / 9.0f);
    addJoint(&m_pSpine1ShoulderRJoint, m_pSpine1, m_pShoulderR, desc.spine1, desc.shoulderR,  
        physx::PxD6Motion::eLOCKED, physx::PxD6Motion::eLOCKED, physx::PxD6Motion::eLOCKED,
        0, 0, pi / 6.0f, pi / 9.0f);

    //Neck/Head
    addJoint(&m_pSpine1NeckJoint, m_pSpine1, m_pNeck, desc.spine1, desc.neck,
        physx::PxD6Motion::eLOCKED, physx::PxD6Motion::eLOCKED, physx::PxD6Motion::eLOCKED,
        0, 0, pi/6, pi/6);
    addJoint(&m_pNeckHeadJoint, m_pNeck, m_pHead, desc.neck, desc.head,
        physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED,
        -pi/6, pi/6, pi/6, pi/6);
    
    //Arms
    addJoint(&m_pShouldersArmL1Joint, m_pShoulderL, m_pArmL1, desc.shoulderL, desc.armL1,  
        physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED,
        -pi / 8.0f, pi / 8.0f, pi / 6, pi / 6);
    addJoint(&m_pShouldersArmR1Joint, m_pShoulderR, m_pArmR1, desc.shoulderR, desc.armR1,  
        physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED,
        -pi / 8.0f, pi / 8.0f, pi / 6, pi / 6);

    addJoint(&m_pArmL1ArmL2Joint, m_pArmL1, m_pArmL2, desc.armL1, desc.armL2,  
        physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLOCKED,
        -pi / 8.0f, pi / 8.0f, pi / 6, pi / 6);
    addJoint(&m_pArmR1ArmR2Joint, m_pArmR1, m_pArmR2, desc.armR1, desc.armR2,  
        physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLOCKED,
        -pi / 8.0f, pi / 8.0f, pi / 6, pi / 6);

    addJoint(&m_pArmL2HandJoint, m_pArmL2, m_pHandL, desc.armL2, desc.handL,  
        physx::PxD6Motion::eLOCKED, physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED,
        0, 0, piOverFour, piOverTwo);
    addJoint(&m_pArmR2HandJoint, m_pArmR2, m_pHandR, desc.armR2, desc.handR,  
        physx::PxD6Motion::eLOCKED, physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED,
        0, 0, piOverFour, piOverTwo);

    //Legs
    addJoint(&m_pPelvisLegL1Joint, m_pPelvis, m_pLegL1, desc.pelvis, desc.legL1,  
        physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED,
        -pi / 6.0f, pi / 6.0f, piOverTwo, piOverTwo);
    addJoint(&m_pPelvisLegR1Joint, m_pPelvis, m_pLegR1, desc.pelvis, desc.legR1,  
        physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED,
        -pi / 6.0f, pi / 6.0f, piOverTwo, piOverTwo);

    addJoint(&m_pLegL1LegL2Joint, m_pLegL1, m_pLegL2, desc.legL1, desc.legL2,  
        physx::PxD6Motion::eLOCKED, physx::PxD6Motion::eLOCKED, physx::PxD6Motion::eLIMITED,
        0, 0, pi / 3, pi / 3);
    addJoint(&m_pLegR1LegR2Joint, m_pLegR1, m_pLegR2, desc.legR1, desc.legR2,  
        physx::PxD6Motion::eLOCKED, physx::PxD6Motion::eLOCKED, physx::PxD6Motion::eLIMITED,
        0, 0, pi / 3, pi / 3);

    addJoint(&m_pLegL2FootJoint, m_pLegL2, m_pFootL, desc.legL2, desc.footL,  
        physx::PxD6Motion::eLOCKED, physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED,
        0, 0, piOverFour, piOverFour);
    addJoint(&m_pLegR2FootJoint, m_pLegR2, m_pFootR, desc.legR2, desc.footR,  
        physx::PxD6Motion::eLOCKED, physx::PxD6Motion::eLIMITED, physx::PxD6Motion::eLIMITED,
        0, 0, piOverFour, piOverFour);

    PHYSICS->getScene()->addAggregate(*m_Aggregate);
}