示例#1
0
//----------------------------------------------------------------------------
void Rope::CreateRope ()
{
    // Create a quadratic spline using particles as control points.
    int numCtrlPoints = mModule->GetNumParticles();
    Vector3f* ctrlPoints = mModule->Positions();
    const int degree = 2;
    mSpline = new0 BSplineCurve3f(numCtrlPoints, ctrlPoints, degree, false,
        true);

    // Generate a tube surface whose medial axis is the spline.
    VertexFormat* vformat = VertexFormat::Create(2,
        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
        VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0);

    Float2 tcoordMin(0.0f, 0.0f), tcoordMax(1.0f, 1.0f);

    mRope = new0 TubeSurface(mSpline, Radial, false, Vector3f::UNIT_Z, 64, 8,
        false, false, &tcoordMin, &tcoordMax, vformat);

    // Attach a texture for the rope.
    std::string path = Environment::GetPathR("Rope.wmtf");
    Texture2D* texture = Texture2D::LoadWMTF(path);
    mRope->SetEffectInstance(Texture2DEffect::CreateUniqueInstance(texture,
        Shader::SF_LINEAR_LINEAR, Shader::SC_REPEAT, Shader::SC_REPEAT));

    mTrnNode->AttachChild(mRope);
}
示例#2
0
//----------------------------------------------------------------------------
void WrigglingSnake::CreateSnakeBody ()
{
    // Create the B-spline curve for the snake body.
    Vector3f* ctrlPoints = new1<Vector3f>(mNumCtrlPoints);
    int i;
    for (i = 0; i < mNumCtrlPoints; ++i)
    {
        // Control points for a snake.
        float ratio = ((float)i)/(float)(mNumCtrlPoints - 1);
        float x = -1.0f + 2.0f*ratio;
        float xMod = 10.0f*x - 4.0f;
        ctrlPoints[i].X() = x;
        ctrlPoints[i].Y() = msRadius*(1.5f + Mathf::ATan(xMod)/Mathf::PI);
        ctrlPoints[i].Z() = 0.0f;

        // Sinusoidal motion for snake.
        mAmplitudes[i] = 0.1f + ratio*Mathf::Exp(-ratio);
        mPhases[i] = 1.5f*ratio*Mathf::TWO_PI;
    }

    // The control points are copied by the curve objects.
    mCenter = new0 BSplineCurve3f(mNumCtrlPoints, ctrlPoints, mDegree, false,
        true);
    delete1(ctrlPoints);

    // Generate a tube surface.
    VertexFormat* vformat = VertexFormat::Create(2,
        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
        VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0);

    Float2 tcoordMin(0.0f, 0.0f), tcoordMax(1.0f, 16.0f);

    mSnakeBody = new0 TubeSurface(mCenter, Radial, false, Vector3f::UNIT_Y,
        128, 32, false, false, &tcoordMin, &tcoordMax, vformat);

    // Attach a texture to the snake body.
    std::string path = Environment::GetPathR("Snake.wmtf");
    Texture2D* texture = Texture2D::LoadWMTF(path);
    mSnakeBody->SetEffectInstance(Texture2DEffect::CreateUniqueInstance(
        texture, Shader::SF_LINEAR_LINEAR, Shader::SC_REPEAT,
        Shader::SC_REPEAT));

    mSnakeRoot->AttachChild(mSnakeBody);
}
//----------------------------------------------------------------------------
void HelixTubeSurface::CreateScene ()
{
    mScene = new0 Node();
    mWireState = new0 WireState();
    mRenderer->SetOverrideWireState(mWireState);

    VertexFormat* vformat = VertexFormat::Create(2,
        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
        VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0);

    mCurve = CreateCurve();
    Float2 tcoordMin(0.0f, 0.0f), tcoordMax(1.0f, 32.0f);
    TubeSurface* tube = new TubeSurface(mCurve, Radial, false,
        Vector3f::UNIT_Z, 256, 32, false, true, &tcoordMin, &tcoordMax,
        vformat);

    std::string path = Environment::GetPathR("Grating.wmtf");
    Texture2D* texture = Texture2D::LoadWMTF(path);
    tube->SetEffectInstance(Texture2DEffect::CreateUniqueInstance(texture,
        Shader::SF_LINEAR, Shader::SC_REPEAT, Shader::SC_REPEAT));

    mScene->AttachChild(tube);
}