Void EngineTests::_CreateWorld()
{
    // Floor
    RigidBody * pFloorBody = PhysicsFn->CreateRigidBody( true, m_pFloorShape, 1.0f, Vertex3(0.0f,0.0f,-10.0f) );
    pFloorBody->SetRestitution( 0.0f );
    pFloorBody->SetFriction( 0.0f );
    pFloorBody->SetRollingFriction( 0.0f );
    pFloorBody->SetCollisionGroup( 0x01 );
    pFloorBody->SetCollisionMask( 0x7f );

    m_pFloor = WorldFn->CreateLeaf( TEXT("Floor") );
    m_pFloor->SetMesh( m_pFloorGeometry );
    m_pFloor->SetEffectInstance( m_pEffectInstanceFloor );
    m_pFloor->SetBody( pFloorBody );
    WorldFn->AddChild( m_pFloor );

    // Character
    Vertex3 vInitialPosition( 0.0f, 0.0f, 2.0f );

    KinematicBody * pCharacterBody = PhysicsFn->CreateKinematicBody( false, m_pCharacterShape, 1.0f );
    pCharacterBody->SetRestitution( 0.0f );
    pCharacterBody->SetFriction( 0.0f );
    pCharacterBody->SetRollingFriction( 0.0f );
    pCharacterBody->SetCollisionGroup( 0x01 );
    pCharacterBody->SetCollisionMask( 0x07 );

    m_pCharacterController = PhysicsFn->CreateCharacterController( TEXT("CharacterController"), vInitialPosition, Quaternion::Identity, Vector3::Null, Vector3::Null );
    m_pCharacterController->Enabled = true;
    m_pCharacterController->EnableForces( false );
    m_pCharacterController->SetMovementSpeed( 5.0f );
    pCharacterBody->AttachController( m_pCharacterController );

    m_pCharacter = WorldFn->CreateLeaf( TEXT("Character") );
    m_pCharacter->SetMesh( m_pCharacterGeometry );
    m_pCharacter->SetEffectInstance( m_pEffectInstanceCharacter );
    m_pCharacter->SetBody( pCharacterBody );
    WorldFn->AddChild( m_pCharacter );

    // Sphere/Box stack
    Vertex3 vBallStackPosition( -10.0f, 10.0f, 0.0f );
    Vertex3 vBoxStackPosition( -10.0f, -10.0f, 0.0f );
    GChar strName[64];

    for( UInt i = 0; i < ENGINE_TEST_STACK_SIZE; ++i ) {
        vBallStackPosition.Z = 5.0f * (Scalar)(i+1);
        vBoxStackPosition.Z = 5.0f * (Scalar)(i+1);

        //StringFn->Format( strName, TEXT("Ball_%d"), i );

        //RigidBody * pBallBody = PhysicsFn->CreateRigidBody( false, m_pSphereShape, 1.0f, vBallStackPosition );
        //pBallBody->SetRestitution( 0.0f );
        //pBallBody->SetFriction( 0.0f );
        //pBallBody->SetRollingFriction( 0.0f );

        //m_arrBallStack[i] = WorldFn->CreateLeaf( strName );
        //m_arrBallStack[i]->SetMesh( m_pSphereGeometry );
        //m_arrBallStack[i]->SetEffectInstance( m_pEffectInstanceA );
        //m_arrBallStack[i]->SetBody( pBallBody );
        //WorldFn->AddChild( m_arrBallStack[i] );

        StringFn->Format( strName, TEXT("Box_%d"), i );

        RigidBody * pBoxBody = PhysicsFn->CreateRigidBody( false, m_pBoxShape, 1.0f, vBoxStackPosition );
        pBoxBody->SetRestitution( 0.0f );
        pBoxBody->SetFriction( 0.0f );
        pBoxBody->SetRollingFriction( 0.0f );

        m_arrBoxStack[i] = WorldFn->CreateLeaf( strName );
        m_arrBoxStack[i]->SetMesh( m_pBoxGeometry );
        m_arrBoxStack[i]->SetEffectInstance( m_pEffectInstanceA );
        m_arrBoxStack[i]->SetBody( pBoxBody );
        WorldFn->AddChild( m_arrBoxStack[i] );
    }

    // Joint systems
    //Matrix3 matRotation;
    //matRotation.MakeRotate( 0.0f, SCALAR_PI_4, SCALAR_PI_4, EULER_ANGLES_XYZ );

    //Vertex3 vFixedObjectPosition( 10.0f, 10.0f, 10.0f );
    //Vertex3 vObjectAPosition( 12.0f, 10.0f, 10.0f );
    //Quaternion qObjectAOrientation( matRotation );
    //Vertex3 vObjectBPosition( 7.0f, 10.0f, 10.0f );

    //RigidBody * pFixedBody = PhysicsFn->CreateRigidBody( true, m_pSphereShape, 1.0f, vFixedObjectPosition );
    //pFixedBody->SetRestitution( 0.0f );
    //pFixedBody->SetFriction( 0.0f );
    //pFixedBody->SetRollingFriction( 0.0f );
    //pFixedBody->SetCollisionGroup( 0x80 );
    //pFixedBody->SetCollisionMask( 0 );

    //m_pFixedObject = WorldFn->CreateLeaf( TEXT("FixedObject") );
    //m_pFixedObject->SetMesh( m_pSphereGeometry );
    //m_pFixedObject->SetEffectInstance( m_pEffectInstanceC );
    //m_pFixedObject->SetBody( pFixedBody );
    //WorldFn->AddChild( m_pFixedObject );

    //RigidBody * pObjectABody = PhysicsFn->CreateRigidBody( false, m_pBoxShape, 1.0f, vObjectAPosition ); //, qObjectAOrientation );
    //pObjectABody->SetRestitution( 0.0f );
    //pObjectABody->SetFriction( 0.0f );
    //pObjectABody->SetRollingFriction( 0.0f );
    //pObjectABody->SetCollisionGroup( 0x02 );
    //pObjectABody->SetCollisionMask( 0x03 );

    //m_pObjectA = WorldFn->CreateLeaf( TEXT("ObjectA") );
    //m_pObjectA->SetMesh( m_pBoxGeometry );
    //m_pObjectA->SetEffectInstance( m_pEffectInstanceA );
    //m_pObjectA->SetBody( pObjectABody );
    //WorldFn->AddChild( m_pObjectA );

    //RigidBody * pObjectBBody = PhysicsFn->CreateRigidBody( false, m_pBoxShape, 1.0f, vObjectBPosition );
    //pObjectBBody->SetRestitution( 0.0f );
    //pObjectBBody->SetFriction( 0.0f );
    //pObjectBBody->SetRollingFriction( 0.0f );
    //pObjectBBody->SetCollisionGroup( 0x04 );
    //pObjectBBody->SetCollisionMask( 0x05 );

    //m_pObjectB = WorldFn->CreateLeaf( TEXT("ObjectB") );
    //m_pObjectB->SetMesh( m_pBoxGeometry );
    //m_pObjectB->SetEffectInstance( m_pEffectInstanceB );
    //m_pObjectB->SetBody( pObjectBBody );
    //WorldFn->AddChild( m_pObjectB );

    //Transform3 vJointFrame;

    //Matrix3 matJointFrame;
    //matJointFrame.SetColumn( 0, Vector3::eJ );
    //matJointFrame.SetColumn( 1, Vector3::eK );
    //matJointFrame.SetColumn( 2, Vector3::eI );
    //vJointFrame.SetRotate( matJointFrame );
    //vJointFrame.SetTranslate( Vector3(11.0f, 10.0f, 10.0f) );

    //m_pJointAF = PhysicsFn->CreateJoint( JOINT_CONETWIST, pObjectABody, pFixedBody, vJointFrame );
    //( (JointConeTwist*)(m_pJointAF->GetJoint()) )->EnableTwistLimits( -SCALAR_PI_4, SCALAR_PI_4 );
    //( (JointHinge*)(m_pJointAF->GetJoint()) )->EnableSpring( 0.5f, SCALAR_PI_4 );

    //vJointFrame.SetTranslate( Vector3(9.0f, 10.0f, 10.0f) );

    //m_pJointBF = PhysicsFn->CreateJoint( JOINT_SLIDER, pObjectBBody, pFixedBody, vJointFrame );
    //( (JointSlider*)(m_pJointBF->GetJoint()) )->EnableLimits( -2.0f, +2.0f );
    //( (JointSlider*)(m_pJointBF->GetJoint()) )->EnableSpring( 0.5f, -1.0f );

    // World camera
    m_pRenderCamera = New Camera( true );
    m_pWorldCamera = New WorldCamera3rdPerson( m_pRenderCamera, m_pCharacter, NULL, 3.0f );
    WorldFn->SetWorldCamera( m_pWorldCamera );
}
Example #2
0
//-------------------
//-------------------
void VaniaDebugEnv::Setup(SharedPtr<Scene> scene, SharedPtr<Node> cameraNode)
{

	scene_ = scene;
	cameraNode_ = cameraNode;

	ResourceCache* cache = GetSubsystem<ResourceCache>();

    // Create scene node & StaticModel component for showing a static plane
    /*Node* planeNode = scene_->CreateChild("Plane");
    planeNode->SetScale(Vector3(100.0f, 1.0f, 100.0f));
    StaticModel* planeObject = planeNode->CreateComponent<StaticModel>();
    planeObject->SetModel(cache->GetResource<Model>("Models/Plane.mdl"));
    planeObject->SetMaterial(cache->GetResource<Material>("Materials/StoneTiled.xml"));*/

    // Create a Zone component for ambient lighting & fog control
    Node* zoneNode = scene_->CreateChild("Zone");
    Zone* zone = zoneNode->CreateComponent<Zone>();
    zone->SetBoundingBox(BoundingBox(-1000.0f, 1000.0f));
    zone->SetAmbientColor(Color(0.15f, 0.15f, 0.15f));
    zone->SetFogColor(Color(0.5f, 0.5f, 0.7f));
    zone->SetFogStart(100.0f);
    zone->SetFogEnd(300.0f);

    // Create a directional light to the world. Enable cascaded shadows on it
    Node* lightNode = scene_->CreateChild("DirectionalLight");
    lightNode->SetDirection(Vector3(0.6f, -1.0f, 0.8f));
    Light* light = lightNode->CreateComponent<Light>();
    light->SetLightType(LIGHT_DIRECTIONAL);
    light->SetCastShadows(true);
    light->SetShadowBias(BiasParameters(0.00025f, 0.5f));
    // Set cascade splits at 10, 50 and 200 world units, fade shadows out at 80% of maximum shadow distance
    light->SetShadowCascade(CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f));

    // Create animated models
    /*const unsigned NUM_MODELS = 100;
    const float MODEL_MOVE_SPEED = 2.0f;
    const float MODEL_ROTATE_SPEED = 100.0f;
    const BoundingBox bounds(Vector3(-47.0f, 0.0f, -47.0f), Vector3(47.0f, 0.0f, 47.0f));

    for (unsigned i = 0; i < NUM_MODELS; ++i)
    {
        Node* modelNode = scene_->CreateChild("Jack");
        modelNode->SetPosition(Vector3(Random(90.0f) - 45.0f, 0.0f, Random(90.0f) - 45.0f));
        modelNode->SetRotation(Quaternion(0.0f, Random(360.0f), 0.0f));
        AnimatedModel* modelObject = modelNode->CreateComponent<AnimatedModel>();
        modelObject->SetModel(cache->GetResource<Model>("Models/Jack.mdl"));
        modelObject->SetMaterial(cache->GetResource<Material>("Materials/Jack.xml"));
        modelObject->SetCastShadows(true);

        // Create an AnimationState for a walk animation. Its time position will need to be manually updated to advance the
        // animation, The alternative would be to use an AnimationController component which updates the animation automatically,
        // but we need to update the model's position manually in any case
        Animation* walkAnimation = cache->GetResource<Animation>("Models/Jack_Walk.ani");
        AnimationState* state = modelObject->AddAnimationState(walkAnimation);
        // The state would fail to create (return null) if the animation was not found
        if (state)
        {
            // Enable full blending weight and looping
            state->SetWeight(1.0f);
            state->SetLooped(true);
        }

        // Create our custom Mover component that will move & animate the model during each frame's update
        //Mover* mover = modelNode->CreateComponent<Mover>();
        //mover->SetParameters(MODEL_MOVE_SPEED, MODEL_ROTATE_SPEED, bounds);
    }*/
    {

        Node* floorNode = scene_->CreateChild("Floor");
        floorNode->SetPosition(Vector3(0.0f, -1.0f, 0.0f));
        floorNode->SetScale(Vector3(1000.0f, 1.0f, 1000.0f));
        StaticModel* floorObject = floorNode->CreateComponent<StaticModel>();
        floorObject->SetModel(cache->GetResource<Model>("Models/Box.mdl"));
        floorObject->SetMaterial(cache->GetResource<Material>("Materials/StoneTiled.xml"));
        
        // Make the floor physical by adding RigidBody and CollisionShape components. The RigidBody's default
        // parameters make the object static (zero mass.) Note that a CollisionShape by itself will not participate
        // in the physics simulation
        RigidBody* body = floorNode->CreateComponent<RigidBody>();
        CollisionShape* shape = floorNode->CreateComponent<CollisionShape>();
        body->SetCollisionLayer(32);
        body->SetCollisionMask(63);
        // Set a box shape of size 1 x 1 x 1 for collision. The shape will be scaled with the scene node scale, so the
        // rendering and physics representation sizes should match (the box model is also 1 x 1 x 1.)
        shape->SetBox(Vector3::ONE);
    }

   
    /*Node* stateNode = scene_->CreateChild("state");
    stateNode->SetPosition(positions_[0]);
    StaticModel* stateModel = stateNode->CreateComponent<StaticModel>();
    stateModel->SetModel( cache->GetResource<Model>(String("Models/States/")+states_[0]) );*/

    // Create the camera. Limit far clip distance to match the fog
    //cameraNode_ = scene_->CreateChild("Camera");
    //Camera* camera = cameraNode_->CreateComponent<Camera>();
    //camera->SetFarClip(300.0f);

    // Set an initial position for the camera scene node above the plane
    cameraNode_->SetPosition(Vector3(0.0f, 5.0f, 0.0f));

    //give the camera the logic I want
    //CameraLogic* cameralogic = cameraNode_->CreateComponent<CameraLogic>();
}