当前位置: 首页>>代码示例>>C++>>正文


C++ TriMesh::SetEffectInstance方法代码示例

本文整理汇总了C++中TriMesh::SetEffectInstance方法的典型用法代码示例。如果您正苦于以下问题:C++ TriMesh::SetEffectInstance方法的具体用法?C++ TriMesh::SetEffectInstance怎么用?C++ TriMesh::SetEffectInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TriMesh的用法示例。


在下文中一共展示了TriMesh::SetEffectInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ModifyBoxes

//----------------------------------------------------------------------------
void IntersectingBoxes::ModifyBoxes ()
{
    const int numBoxes = (int)mBoxes.size();
    int i;
    for (i = 0; i < numBoxes; ++i)
    {
        AxisAlignedBox3f box = mBoxes[i];

        float dx = Mathf::IntervalRandom(-4.0f, 4.0f);
        if (-mSize <= box.Min[0] + dx && box.Max[0] + dx <= mSize)
        {
            box.Min[0] += dx;
            box.Max[0] += dx;
        }

        float dy = Mathf::IntervalRandom(-4.0f, 4.0f);
        if (-mSize <= box.Min[1] + dy && box.Max[1] + dy <= mSize)
        {
            box.Min[1] += dy;
            box.Max[1] += dy;
        }

        float dz = Mathf::IntervalRandom(-4.0f, 4.0f);
        if (-mSize <= box.Min[2] + dz && box.Max[2] + dz <= mSize)
        {
            box.Min[2] += dz;
            box.Max[2] += dz;
        }

        mManager->SetBox(i, box);
        ModifyMesh(i);
    }

    mManager->Update();
    mScene->Update();

    // Switch material to red for any box that overlaps another.
    TriMesh* mesh;
    for (i = 0; i < numBoxes; ++i)
    {
        // Reset all boxes to blue.
        mesh = StaticCast<TriMesh>(mScene->GetChild(i));
        mesh->SetEffectInstance(mNoIntersectEffect);
    }

    const std::set<EdgeKey>& overlap = mManager->GetOverlap();
    std::set<EdgeKey>::const_iterator iter = overlap.begin();
    std::set<EdgeKey>::const_iterator end = overlap.end();
    for (/**/; iter != end; ++iter)
    {
        // Set intersecting boxes to red.
        i = iter->V[0];
        mesh = StaticCast<TriMesh>(mScene->GetChild(i));
        mesh->SetEffectInstance(mIntersectEffect);
        i = iter->V[1];
        mesh = StaticCast<TriMesh>(mScene->GetChild(i));
        mesh->SetEffectInstance(mIntersectEffect);
    }
}
开发者ID:vijaynerella,项目名称:GeometricTools,代码行数:60,代码来源:IntersectingBoxes.cpp

示例2: CreatePlane

//----------------------------------------------------------------------------
TriMesh* PolyhedronDistance::CreatePlane ()
{
    VertexFormat* vformat = VertexFormat::Create(2,
        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
        VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0);
    int vstride = vformat->GetStride();

    VertexBuffer* vbuffer = new0 VertexBuffer(4, vstride);
    VertexBufferAccessor vba(vformat, vbuffer);

    float size = 16.0f;
    vba.Position<Float3>(0) = Float3(-size, -size, -0.1f);
    vba.Position<Float3>(1) = Float3(+size, -size, -0.1f);
    vba.Position<Float3>(2) = Float3(+size, +size, -0.1f);
    vba.Position<Float3>(3) = Float3(-size, +size, -0.1f);
    vba.Color<Float3>(0, 0) = Float3(0.0f, 0.50f, 0.00f);
    vba.Color<Float3>(0, 1) = Float3(0.0f, 0.25f, 0.00f);
    vba.Color<Float3>(0, 2) = Float3(0.0f, 0.75f, 0.00f);
    vba.Color<Float3>(0, 3) = Float3(0.0f, 1.00f, 0.00f);

    IndexBuffer* ibuffer = new0 IndexBuffer(6, sizeof(int));
    int* indices = (int*)ibuffer->GetData();
    indices[0] = 0; indices[1] = 1; indices[2] = 2;
    indices[3] = 0; indices[4] = 2; indices[5] = 3;

    TriMesh* mesh = new0 TriMesh(vformat, vbuffer, ibuffer);
    mesh->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance());

    return mesh;
}
开发者ID:rasslingcats,项目名称:calico,代码行数:31,代码来源:PolyhedronDistance.cpp

示例3: CreateScene

//----------------------------------------------------------------------------
void PointInPolyhedron::CreateScene ()
{
    mScene = new0 Node();
    mWireState = new0 WireState();
    mRenderer->SetOverrideWireState(mWireState);

    // Create a semitransparent sphere mesh.
    VertexFormat* vformatMesh = VertexFormat::Create(1,
        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0);
    TriMesh* mesh = StandardMesh(vformatMesh).Sphere(16, 16, 1.0f);
    Material* material = new0 Material();
    material->Diffuse = Float4(1.0f, 0.0f, 0.0f, 0.25f);
    VisualEffectInstance* instance = MaterialEffect::CreateUniqueInstance(
        material);
    instance->GetEffect()->GetAlphaState(0, 0)->BlendEnabled = true;
    mesh->SetEffectInstance(instance);

    // Create the data structures for the polyhedron that represents the
    // sphere mesh.
    CreateQuery(mesh);

    // Create a set of random points.  Points inside the polyhedron are
    // colored white.  Points outside the polyhedron are colored blue.
    VertexFormat* vformat = VertexFormat::Create(2,
        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
        VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0);
    int vstride = vformat->GetStride();

    VertexBuffer* vbuffer = new0 VertexBuffer(1024, vstride);
    VertexBufferAccessor vba(vformat, vbuffer);
    Float3 white(1.0f, 1.0f, 1.0f);
    Float3 blue(0.0f, 0.0f, 1.0f);
    for (int i = 0; i < vba.GetNumVertices(); ++i)
    {
        Vector3f random(Mathf::SymmetricRandom(),
            Mathf::SymmetricRandom(), Mathf::SymmetricRandom());

        vba.Position<Vector3f>(i) = random;

        if (mQuery->Contains(random))
        {
            vba.Color<Float3>(0, i) = white;
        }
        else
        {
            vba.Color<Float3>(0, i) = blue;
        }
    }

    DeleteQuery();

    mPoints = new0 Polypoint(vformat, vbuffer);
    mPoints->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance());

    mScene->AttachChild(mPoints);
    mScene->AttachChild(mesh);
}
开发者ID:rasslingcats,项目名称:calico,代码行数:58,代码来源:PointInPolyhedron.cpp

示例4: StandardMesh

//----------------------------------------------------------------------------
TriMesh* Delaunay3D::CreateSphere () const
{
    VertexFormat* vformat = VertexFormat::Create(2,
        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
        VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0);

    TriMesh* mesh = StandardMesh(vformat).Sphere(8, 8, 0.01f);
    mesh->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance());
    mesh->Culling = Spatial::CULL_ALWAYS;
    return mesh;
}
开发者ID:rasslingcats,项目名称:calico,代码行数:12,代码来源:Delaunay3D.cpp

示例5: CreateScene

//----------------------------------------------------------------------------
void ProjectedTextures::CreateScene ()
{
    mScene = new0 Node();
    mTrnNode = new0 Node();
    mScene->AttachChild(mTrnNode);

    // Load the face model.
#ifdef WM5_LITTLE_ENDIAN
    std::string path = Environment::GetPathR("FacePN.wmof");
#else
    std::string path = Environment::GetPathR("FacePN.be.wmof");
#endif
    InStream inStream;
    inStream.Load(path);
    TriMesh* mesh = StaticCast<TriMesh>(inStream.GetObjectAt(0));

    // Create a camera to project the texture.
    Projector* projector = new0 Projector(Camera::PM_DEPTH_ZERO_TO_ONE);
    projector->SetFrustum(1.0f, 10.0f, -0.4125f, 0.4125f, -0.55f, 0.55f);
    AVector proDVector(0.0f, 1.0f, 0.0f);
    AVector proUVector(0.0f, 0.0f, 1.0f);
    AVector proRVector = proDVector.Cross(proUVector);
    APoint proPosition = APoint::ORIGIN - 303.0f*proDVector;
    projector->SetFrame(proPosition, proDVector, proUVector, proRVector);

    // Create a directional light for the face.
    Light* light = new0 Light(Light::LT_DIRECTIONAL);
    light->Ambient = Float4(0.25f, 0.25f, 0.25f, 1.0f);
    light->Diffuse = Float4(1.0f, 1.0f, 1.0f, 1.0f);
    light->Specular = Float4(0.0f, 0.0f, 0.0f, 1.0f);
    light->DVector = AVector::UNIT_Y;  // scene-camera direction

    // Create a material for the face.
    Material* material = new0 Material();
    material->Emissive = Float4(0.0f, 0.0f, 0.0f, 1.0f);
    material->Ambient = Float4(0.5f, 0.5f, 0.5f, 1.0f);
    material->Diffuse = Float4(0.99607f, 0.83920f, 0.67059f, 1.0f);
    material->Specular = Float4(0.8f, 0.8f, 0.8f, 0.0f);

    // Create the effect.
    std::string effectFile = Environment::GetPathR("ProjectedTexture.wmfx");
    ProjectedTextureEffect* effect = new0 ProjectedTextureEffect(effectFile);

    std::string projectedName = Environment::GetPathR("Magician.wmtf");
    Texture2D* projectedTexture = Texture2D::LoadWMTF(projectedName);
    mesh->SetEffectInstance(effect->CreateInstance(projector, light,
        material, projectedTexture));

    mTrnNode->AttachChild(mesh);
}
开发者ID:,项目名称:,代码行数:51,代码来源:

示例6: CreateFloor

//----------------------------------------------------------------------------
TriMesh* FoucaultPendulum::CreateFloor ()
{
    VertexFormat* vformat = VertexFormat::Create(2,
        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
        VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0);

    TriMesh* floor = StandardMesh(vformat).Rectangle(2, 2, 32.0f, 32.0f);
    std::string path = Environment::GetPathR("Wood.wmtf");
    Texture2D* texture = Texture2D::LoadWMTF(path);
    floor->SetEffectInstance(Texture2DEffect::CreateUniqueInstance(texture,
        Shader::SF_LINEAR, Shader::SC_CLAMP_EDGE, Shader::SC_CLAMP_EDGE));

    return floor;
}
开发者ID:vijaynerella,项目名称:GeometricTools,代码行数:15,代码来源:FoucaultPendulum.cpp

示例7:

//----------------------------------------------------------------------------
void Smoke2D::Initialize ()
{
    TriMesh* square = mIP->GetRectangle();
    RenderTarget* target0 = mIP->GetTarget(0);
    RenderTarget* target1 = mIP->GetTarget(1);
    RenderTarget* target2 = mIP->GetTarget(2);
    RenderTarget* target3 = mIP->GetTarget(3);

    mBoundaryNeumannInstance->SetPixelTexture(0, "StateSampler",
        target0->GetColorTexture(0));

    mBoundaryDirichletInstance->SetPixelTexture(0, "StateSampler",
        target3->GetColorTexture(0));

    if (mRenderer->PreDraw())
    {
        mRenderer->SetCamera(mIP->GetCamera());

        // Set the initial data.
        mCopyStateInstance->SetPixelTexture(0, "StateSampler",
            mInitialTexture);
        square->SetEffectInstance(mCopyStateInstance);
        mRenderer->Enable(target2);
        mRenderer->Draw(square);  // in: InitialTexture
        mRenderer->Disable(target2);  // out: Target2
        mCopyStateInstance->SetPixelTexture(0, "StateSampler",
            target1->GetColorTexture(0));

        // Set the mixed boundary conditions.
        square->SetEffectInstance(mBoundaryMixedInstance);
        mRenderer->Enable(target1);
        mRenderer->Draw(square);  // in: Target2, MaskMixed, OffsetMixed
        mRenderer->Disable(target1);  // out: Target1

        mRenderer->PostDraw();
    }
}
开发者ID:rasslingcats,项目名称:calico,代码行数:38,代码来源:Smoke2D.cpp

示例8: CreateVisualConvexPolyhedron

//----------------------------------------------------------------------------
Node* ExtremalQuery::CreateVisualConvexPolyhedron ()
{
    const Vector3f* vertices = mConvexPolyhedron->GetVertices();
    int numTriangles = mConvexPolyhedron->GetNumTriangles();
    int numIndices = 3*numTriangles;
    const int* polyIndices = mConvexPolyhedron->GetIndices();

    // Visualize the convex polyhedron as a collection of face-colored
    // triangles.
    VertexFormat* vformat = VertexFormat::Create(2,
        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
        VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0);
    int vstride = vformat->GetStride();

    VertexBuffer* vbuffer = new0 VertexBuffer(numIndices, vstride);
    VertexBufferAccessor vba(vformat, vbuffer);

    IndexBuffer* ibuffer = new0 IndexBuffer(numIndices, sizeof(int));
    int* indices = (int*)ibuffer->GetData();

    int i;
    for (i = 0; i < numIndices; ++i)
    {
        vba.Position<Vector3f>(i) = vertices[polyIndices[i]];
        indices[i] = i;
    }

    TriMesh* mesh = new0 TriMesh(vformat, vbuffer, ibuffer);

    // Use randomly generated vertex colors.
    for (i = 0; i < numTriangles; ++i)
    {
        Float3 color;
        for (int j = 0; j < 3; ++j)
        {
            color[j] = Mathf::UnitRandom();
        }

        vba.Color<Float3>(0, 3*i  ) = color;
        vba.Color<Float3>(0, 3*i+1) = color;
        vba.Color<Float3>(0, 3*i+2) = color;
    }

    mesh->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance());

    Node* root = new0 Node();
    root->AttachChild(mesh);
    return root;
}
开发者ID:rasslingcats,项目名称:calico,代码行数:50,代码来源:ExtremalQuery.cpp

示例9: CreateBox

//----------------------------------------------------------------------------
void GelatinCube::CreateBox ()
{
    // Create a quadratic spline using the interior particles as control
    // points.
    int numSlices = mModule->GetNumSlices() - 2;
    int numRows = mModule->GetNumRows() - 2;
    int numCols = mModule->GetNumCols() - 2;
    mSpline = new0 BSplineVolumef(numCols, numRows, numSlices, 2, 2, 2);

    for (int s = 0; s < numSlices; ++s)
    {
        for (int r = 0; r < numRows; ++r)
        {
            for (int c = 0; c < numCols; ++c)
            {
                mSpline->SetControlPoint(c, r, s,
                    mModule->Position(s + 1, r + 1, c + 1));
            }
        }
    }

    // Generate the box.
    VertexFormat* vformat = VertexFormat::Create(2,
        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
        VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0);

    VertexFormat* vformats[6] =
        { vformat, vformat, vformat, vformat, vformat, vformat };

    mBox = new0 BoxSurface(mSpline, 8, 8, 8, vformats);

    // The texture effect for the box faces.
    std::string path = Environment::GetPathR("WaterWithAlpha.wmtf");
    Texture2D* texture = Texture2D::LoadWMTF(path);
    VisualEffectInstance* instance = Texture2DEffect::CreateUniqueInstance(
        texture, Shader::SF_LINEAR, Shader::SC_REPEAT, Shader::SC_REPEAT);
    for (int i = 0; i < 6; ++i)
    {
        TriMesh* mesh = StaticCast<TriMesh>(mBox->GetChild(i));
        mesh->SetEffectInstance(instance);
    }

    // The texture has an alpha channel of 1/2 for all texels.
    instance->GetEffect()->GetAlphaState(0, 0)->BlendEnabled = true;

    mBox->EnableSorting();
    mTrnNode->AttachChild(mBox);
}
开发者ID:vijaynerella,项目名称:GeometricTools,代码行数:49,代码来源:GelatinCube.cpp

示例10: CreateTetra

//----------------------------------------------------------------------------
TriMesh* PolyhedronDistance::CreateTetra (float size, bool isBlack)
{
    VertexFormat* vformat = VertexFormat::Create(2,
        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
        VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0);
    int vstride = vformat->GetStride();

    VertexBuffer* vbuffer = new0 VertexBuffer(4, vstride);
    VertexBufferAccessor vba(vformat, vbuffer);

    vba.Position<Vector3f>(0) = -(size/3.0f)*Vector3f(1.0f, 1.0f, 1.0f);
    vba.Position<Vector3f>(1) = Vector3f(size, 0.0f, 0.0f);
    vba.Position<Vector3f>(2) = Vector3f(0.0f, size, 0.0f);
    vba.Position<Vector3f>(3) = Vector3f(0.0f, 0.0f, size);

    if (isBlack)
    {
        // Black tetrahedra for the small ones used as points.
        Float3 black(0.0f, 0.0f, 0.0f);
        vba.Color<Float3>(0, 0) = black;
        vba.Color<Float3>(0, 1) = black;
        vba.Color<Float3>(0, 2) = black;
        vba.Color<Float3>(0, 3) = black;
    }
    else
    {
        // Colorful colors for the tetrahedra under study.
        vba.Color<Float3>(0, 0) = Float3(0.0f, 0.0f, 1.0f);
        vba.Color<Float3>(0, 1) = Float3(0.0f, 1.0f, 0.0f);
        vba.Color<Float3>(0, 2) = Float3(1.0f, 0.0f, 0.0f);
        vba.Color<Float3>(0, 3) = Float3(1.0f, 1.0f, 1.0f);
    }

    IndexBuffer* ibuffer = new0 IndexBuffer(12, sizeof(int));
    int* indices = (int*)ibuffer->GetData();
    indices[ 0] = 0; indices[ 1] = 2; indices[ 2] = 1;
    indices[ 3] = 0; indices[ 4] = 3; indices[ 5] = 2;
    indices[ 6] = 0; indices[ 7] = 1; indices[ 8] = 3;
    indices[ 9] = 1; indices[10] = 2; indices[11] = 3;

    TriMesh* mesh = new0 TriMesh(vformat, vbuffer, ibuffer);
    mesh->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance());

    return mesh;
}
开发者ID:rasslingcats,项目名称:calico,代码行数:46,代码来源:PolyhedronDistance.cpp

示例11: CreateRamp

//----------------------------------------------------------------------------
TriMesh* RoughPlaneSolidBox::CreateRamp ()
{
    float x = 8.0f;
    float y = 8.0f;
    float z = y*Mathf::Tan((float)mModule.Angle);

    VertexFormat* vformat = VertexFormat::Create(2,
        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
        VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0);
    int vstride = vformat->GetStride();

    VertexBuffer* vbuffer = new0 VertexBuffer(6, vstride);
    VertexBufferAccessor vba(vformat, vbuffer);

    vba.Position<Float3>(0) = Float3(-x, 0.0f, 0.0f);
    vba.Position<Float3>(1) = Float3(+x, 0.0f, 0.0f);
    vba.Position<Float3>(2) = Float3(-x, y, 0.0f);
    vba.Position<Float3>(3) = Float3(+x, y, 0.0f);
    vba.Position<Float3>(4) = Float3(-x, y, z);
    vba.Position<Float3>(5) = Float3(+x, y, z);
    vba.TCoord<Float2>(0, 0) = Float2(0.25f, 0.0f);
    vba.TCoord<Float2>(0, 1) = Float2(0.75f, 0.0f);
    vba.TCoord<Float2>(0, 2) = Float2(0.0f, 1.0f);
    vba.TCoord<Float2>(0, 3) = Float2(1.0f, 1.0f);
    vba.TCoord<Float2>(0, 4) = Float2(0.25f, 1.0f);
    vba.TCoord<Float2>(0, 5) = Float2(0.75f, 1.0f);

    IndexBuffer* ibuffer = new0 IndexBuffer(18, sizeof(int));
    int* indices = (int*)ibuffer->GetData();
    indices[ 0] = 0;  indices[ 1] = 1;  indices[ 2] = 4;
    indices[ 3] = 1;  indices[ 4] = 5;  indices[ 5] = 4;
    indices[ 6] = 0;  indices[ 7] = 4;  indices[ 8] = 2;
    indices[ 9] = 1;  indices[10] = 3;  indices[11] = 5;
    indices[12] = 3;  indices[13] = 2;  indices[14] = 4;
    indices[15] = 3;  indices[16] = 4;  indices[17] = 5;

    TriMesh* ramp = new0 TriMesh(vformat, vbuffer, ibuffer);

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

    return ramp;
}
开发者ID:2asoft,项目名称:GeometricTools,代码行数:46,代码来源:RoughPlaneSolidBox.cpp

示例12: white

//----------------------------------------------------------------------------
TriMesh* ConvexHull3D::CreateSphere ()
{
    VertexFormat* vformat = VertexFormat::Create(2,
        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
        VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0);

    Float3 white(1.0f, 1.0f, 1.0f);
    float radius = 0.01f;
    TriMesh* sphere = StandardMesh(vformat).Sphere(8, 8, radius);
    VertexBufferAccessor vba(sphere);
    for (int i = 0; i < vba.GetNumVertices(); ++i)
    {
        vba.Color<Float3>(0, i) = white;
    }

    sphere->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance());
    return sphere;
}
开发者ID:,项目名称:,代码行数:19,代码来源:

示例13: CreateScene

//----------------------------------------------------------------------------
void SphereMaps::CreateScene ()
{
    mScene = new0 Node();
    mTrnNode = new0 Node();
    mScene->AttachChild(mTrnNode);

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

    TriMesh* mesh = StandardMesh(vformat).Torus(64, 64, 1.0f, 0.5f);
    mTrnNode->AttachChild(mesh);

    std::string effectFile = Environment::GetPathR("SphereMap.wmfx");
    SphereMapEffect* effect = new0 SphereMapEffect(effectFile);
    std::string environmentName = Environment::GetPathR("SphereMap.wmtf");
    Texture2D* environmentTexture = Texture2D::LoadWMTF(environmentName);
    mesh->SetEffectInstance(effect->CreateInstance(environmentTexture));
}
开发者ID:rasslingcats,项目名称:calico,代码行数:20,代码来源:SphereMaps.cpp

示例14: CreateNode

//----------------------------------------------------------------------------
BspNode* BspNodes::CreateNode (const Vector2f& v0, const Vector2f& v1,
                               VertexColor3Effect* effect, const Float3& color)
{
	// Create the model-space separating plane.
	Vector2f dir = v1 - v0;
	AVector normal(dir[1], -dir[0], 0.0f);
	normal.Normalize();
	float constant = normal[0]*v0[0] + normal[1]*v0[1];
	HPlane modelPlane(normal, constant);

	// Create the BSP node.
	BspNode* bsp = new0 BspNode(modelPlane);

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

	// Create the rectangle representation of the model plane and set the
	// vertex colors to the specified color.
	float xExtent = 0.5f*dir.Length();
	float yExtent = 0.125f;
	TriMesh* rect = StandardMesh(vformat).Rectangle(2, 2, xExtent, yExtent);
	VertexBufferAccessor vba(rect);
	for (int i = 0; i < 4; ++i)
	{
		vba.Color<Float3>(0, i) = color;
	}
	rect->SetEffectInstance(effect->CreateInstance());

	// Set the position and orientation for the world-space plane.
	APoint trn(0.5f*(v0[0] + v1[0]), 0.5f*(v0[1] + v1[1]), yExtent + 0.001f);
	HMatrix zRotate(AVector::UNIT_Z, Mathf::ATan2(dir.Y(),dir.X()));
	HMatrix xRotate(AVector::UNIT_X, Mathf::HALF_PI);
	HMatrix rotate = zRotate*xRotate;
	rect->LocalTransform.SetTranslate(trn);
	rect->LocalTransform.SetRotate(rotate);

	bsp->AttachCoplanarChild(rect);
	return bsp;
}
开发者ID:bhlzlx,项目名称:WildMagic,代码行数:41,代码来源:BspNodes.cpp

示例15: Node

//----------------------------------------------------------------------------
void ConvexHull3D::CreateScene ()
{
    mScene = new0 Node();
    mTrnNode = new0 Node();
    mScene->AttachChild(mTrnNode);
    mWireState = new0 WireState();
    mRenderer->SetOverrideWireState(mWireState);
    mCullState = new0 CullState();
    mCullState->Enabled = false;
    mRenderer->SetOverrideCullState(mCullState);

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

    TriMesh* sphere = StandardMesh(vformat).Sphere(8, 8, 0.01f);
    sphere->SetEffectInstance(VertexColor3Effect::CreateUniqueInstance());
    mTrnNode->SetChild(1, sphere);

    // The current file is "Data/data01.txt".
    LoadData();
}
开发者ID:,项目名称:,代码行数:23,代码来源:


注:本文中的TriMesh::SetEffectInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。