コード例 #1
0
ファイル: CubeMaps.cpp プロジェクト: bhlzlx/WildMagic
//----------------------------------------------------------------------------
void CubeMaps::CreateScene ()
{
	// Create the root of the scene.
	mScene = new0 Node();
	mWireState = new0 WireState();
	mRenderer->SetOverrideWireState(mWireState);

	// Create the walls of the cube room.  Each of the six texture images is
	// RGBA 64-by-64.
	Node* room = new0 Node();
	mScene->AttachChild(room);

	// Index buffer shared by the room walls.
	IndexBuffer* ibuffer = new0 IndexBuffer(6, sizeof(int));
	int* indices = (int*)ibuffer->GetData();
	indices[0] = 0;
	indices[1] = 1;
	indices[2] = 3;
	indices[3] = 0;
	indices[4] = 3;
	indices[5] = 2;

	// The vertex format shared by the room walls.
	VertexFormat* vformat = VertexFormat::Create(2,
	                        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
	                        VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0);
	int vstride = vformat->GetStride();
	VertexBufferAccessor vba;

	// The texture effect shared by the room walls.
	Texture2DEffect* effect = new0 Texture2DEffect(Shader::SF_LINEAR);

	VertexBuffer* vbuffer;
	TriMesh* wall;
	std::string textureName;

	// +x wall
	vbuffer = new0 VertexBuffer(4, vstride);
	vba.ApplyTo(vformat, vbuffer);
	vba.Position<Float3>(0) = Float3(+1.0f, -1.0f, -1.0f);
	vba.Position<Float3>(1) = Float3(+1.0f, -1.0f, +1.0f);
	vba.Position<Float3>(2) = Float3(+1.0f, +1.0f, -1.0f);
	vba.Position<Float3>(3) = Float3(+1.0f, +1.0f, +1.0f);
	vba.TCoord<Float2>(0, 0) = Float2(0.0f, 0.0f);
	vba.TCoord<Float2>(0, 1) = Float2(1.0f, 0.0f);
	vba.TCoord<Float2>(0, 2) = Float2(0.0f, 1.0f);
	vba.TCoord<Float2>(0, 3) = Float2(1.0f, 1.0f);
	wall = new0 TriMesh(vformat, vbuffer, ibuffer);
	room->AttachChild(wall);
	textureName = Environment::GetPathR("XpFace.wmtf");
	Texture2D* xpTexture = Texture2D::LoadWMTF(textureName);
	wall->SetEffectInstance(effect->CreateInstance(xpTexture));

	// -x wall
	vbuffer = new0 VertexBuffer(4, vstride);
	vba.ApplyTo(vformat, vbuffer);
	vba.Position<Float3>(0) = Float3(-1.0f, -1.0f, +1.0f);
	vba.Position<Float3>(1) = Float3(-1.0f, -1.0f, -1.0f);
	vba.Position<Float3>(2) = Float3(-1.0f, +1.0f, +1.0f);
	vba.Position<Float3>(3) = Float3(-1.0f, +1.0f, -1.0f);
	vba.TCoord<Float2>(0, 0) = Float2(0.0f, 0.0f);
	vba.TCoord<Float2>(0, 1) = Float2(1.0f, 0.0f);
	vba.TCoord<Float2>(0, 2) = Float2(0.0f, 1.0f);
	vba.TCoord<Float2>(0, 3) = Float2(1.0f, 1.0f);
	wall = new0 TriMesh(vformat, vbuffer, ibuffer);
	room->AttachChild(wall);
	textureName = Environment::GetPathR("XmFace.wmtf");
	Texture2D* xmTexture = Texture2D::LoadWMTF(textureName);
	wall->SetEffectInstance(effect->CreateInstance(xmTexture));

	// +y wall
	vbuffer = new0 VertexBuffer(4, vstride);
	vba.ApplyTo(vformat, vbuffer);
	vba.Position<Float3>(0) = Float3(+1.0f, +1.0f, +1.0f);
	vba.Position<Float3>(1) = Float3(-1.0f, +1.0f, +1.0f);
	vba.Position<Float3>(2) = Float3(+1.0f, +1.0f, -1.0f);
	vba.Position<Float3>(3) = Float3(-1.0f, +1.0f, -1.0f);
	vba.TCoord<Float2>(0, 0) = Float2(0.0f, 0.0f);
	vba.TCoord<Float2>(0, 1) = Float2(1.0f, 0.0f);
	vba.TCoord<Float2>(0, 2) = Float2(0.0f, 1.0f);
	vba.TCoord<Float2>(0, 3) = Float2(1.0f, 1.0f);
	wall = new0 TriMesh(vformat, vbuffer, ibuffer);
	room->AttachChild(wall);
	textureName = Environment::GetPathR("YpFace.wmtf");
	Texture2D* ypTexture = Texture2D::LoadWMTF(textureName);
	wall->SetEffectInstance(effect->CreateInstance(ypTexture));

	// -y wall
	vbuffer = new0 VertexBuffer(4, vstride);
	vba.ApplyTo(vformat, vbuffer);
	vba.Position<Float3>(0) = Float3(+1.0f, -1.0f, -1.0f);
	vba.Position<Float3>(1) = Float3(-1.0f, -1.0f, -1.0f);
	vba.Position<Float3>(2) = Float3(+1.0f, -1.0f, +1.0f);
	vba.Position<Float3>(3) = Float3(-1.0f, -1.0f, +1.0f);
	vba.TCoord<Float2>(0, 0) = Float2(0.0f, 0.0f);
	vba.TCoord<Float2>(0, 1) = Float2(1.0f, 0.0f);
	vba.TCoord<Float2>(0, 2) = Float2(0.0f, 1.0f);
	vba.TCoord<Float2>(0, 3) = Float2(1.0f, 1.0f);
	wall = new0 TriMesh(vformat, vbuffer, ibuffer);
	room->AttachChild(wall);
	textureName = Environment::GetPathR("YmFace.wmtf");
	Texture2D* ymTexture = Texture2D::LoadWMTF(textureName);
	wall->SetEffectInstance(effect->CreateInstance(ymTexture));

	// +z wall
	vbuffer = new0 VertexBuffer(4, vstride);
	vba.ApplyTo(vformat, vbuffer);
	vba.Position<Float3>(0) = Float3(+1.0f, -1.0f, +1.0f);
	vba.Position<Float3>(1) = Float3(-1.0f, -1.0f, +1.0f);
	vba.Position<Float3>(2) = Float3(+1.0f, +1.0f, +1.0f);
	vba.Position<Float3>(3) = Float3(-1.0f, +1.0f, +1.0f);
	vba.TCoord<Float2>(0, 0) = Float2(0.0f, 0.0f);
	vba.TCoord<Float2>(0, 1) = Float2(1.0f, 0.0f);
	vba.TCoord<Float2>(0, 2) = Float2(0.0f, 1.0f);
	vba.TCoord<Float2>(0, 3) = Float2(1.0f, 1.0f);
	wall = new0 TriMesh(vformat, vbuffer, ibuffer);
	room->AttachChild(wall);
	textureName = Environment::GetPathR("ZpFace.wmtf");
	Texture2D* zpTexture = Texture2D::LoadWMTF(textureName);
	wall->SetEffectInstance(effect->CreateInstance(zpTexture));

	// -z wall
	vbuffer = new0 VertexBuffer(4, vstride);
	vba.ApplyTo(vformat, vbuffer);
	vba.Position<Float3>(0) = Float3(-1.0f, -1.0f, -1.0f);
	vba.Position<Float3>(1) = Float3(+1.0f, -1.0f, -1.0f);
	vba.Position<Float3>(2) = Float3(-1.0f, +1.0f, -1.0f);
	vba.Position<Float3>(3) = Float3(+1.0f, +1.0f, -1.0f);
	vba.TCoord<Float2>(0, 0) = Float2(0.0f, 0.0f);
	vba.TCoord<Float2>(0, 1) = Float2(1.0f, 0.0f);
	vba.TCoord<Float2>(0, 2) = Float2(0.0f, 1.0f);
	vba.TCoord<Float2>(0, 3) = Float2(1.0f, 1.0f);
	wall = new0 TriMesh(vformat, vbuffer, ibuffer);
	room->AttachChild(wall);
	textureName = Environment::GetPathR("ZmFace.wmtf");
	Texture2D* zmTexture = Texture2D::LoadWMTF(textureName);
	wall->SetEffectInstance(effect->CreateInstance(zmTexture));

	// A sphere to reflect the environment via a cube map.  The colors will
	// be used to modulate the cube map texture.
	vformat = VertexFormat::Create(3,
	                               VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
	                               VertexFormat::AU_NORMAL, VertexFormat::AT_FLOAT3, 0,
	                               VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0);
	vstride = vformat->GetStride();

	mSphere = StandardMesh(vformat).Sphere(64, 64, 0.125f);
	room->AttachChild(mSphere);

	// Generate random vertex colors for the sphere.  The StandardMesh class
	// produces a sphere with duplicated vertices along a longitude line.
	// This allows texture coordinates to be assigned in a manner that treats
	// the sphere as if it were a rectangle mesh.  For vertex colors, we want
	// the duplicated vertices to have the same color, so a hash table is used
	// to look up vertex colors for the duplicates.
	vba.ApplyTo(mSphere);
	std::map<Float3,Float3> dataMap;
	for (int i = 0; i < vba.GetNumVertices(); ++i)
	{
		Float3& position = vba.Position<Float3>(i);
		Float3& color = vba.Color<Float3>(0, i);
		std::map<Float3,Float3>::iterator iter = dataMap.find(position);
		if (iter != dataMap.end())
		{
			color = iter->second;
		}
		else
		{
			color[0] = 0.0f;
			color[1] = Mathf::IntervalRandom(0.5f, 0.75f);
			color[2] = Mathf::IntervalRandom(0.75f, 1.0f);
			dataMap.insert(std::make_pair(position, color));
		}
	}

	// Create the cube map and attach it to the sphere.
	std::string effectFile = Environment::GetPathR("CubeMap.wmfx");
	CubeMapEffect* cubeMapEffect = new0 CubeMapEffect(effectFile);

	ShaderFloat* reflectivity = new0 ShaderFloat(1);
	(*reflectivity)[0] = 0.5f;

	std::string cubeName = Environment::GetPathR("CubeMap.wmtf");
	TextureCube* cubeTexture = TextureCube::LoadWMTF(cubeName);
	cubeTexture->GenerateMipmaps();
	mCubeMapInstance = cubeMapEffect->CreateInstance(cubeTexture,
	                   reflectivity, false);

	mSphere->SetEffectInstance(mCubeMapInstance);

	// Allow culling to be disabled on the sphere so when you move inside
	// the sphere, you can see the previously hidden facets and verify that
	// the cube image for those facets is correctly oriented.
	mSphereCullState = cubeMapEffect->GetCullState(0, 0);
}
コード例 #2
0
//----------------------------------------------------------------------------
void SwitchNodes::CreateScene ()
{
    mScene = new0 Node();
    mWireState = new0 WireState();
    mRenderer->SetOverrideWireState(mWireState);

    mSwitch = new0 SwitchNode();
    mScene->AttachChild(mSwitch);

    // Texture effect to be shared by all objects.
    Texture2DEffect* effect = new0 Texture2DEffect(Shader::SF_LINEAR);
    std::string path = Environment::GetPathR("Flower.wmtf");
    Texture2D* texture = Texture2D::LoadWMTF(path);

    // Create the children of the switch node.
    VertexFormat* vformat = VertexFormat::Create(2,
        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
        VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0);

    StandardMesh sm(vformat);

    // Create a rectangle mesh (child 0).
    TriMesh* mesh = sm.Rectangle(4, 4, 1.0f, 1.0f);
    mesh->SetEffectInstance(effect->CreateInstance(texture));
    mSwitch->AttachChild(mesh);

    // Create a disk mesh (child 1).
    mesh = sm.Disk(8,16,1.0f);
    mesh->SetEffectInstance(effect->CreateInstance(texture));
    mSwitch->AttachChild(mesh);

    // Create a box mesh (child 2).
    mesh = sm.Box(1.0f,0.5f,0.25f);
    mesh->SetEffectInstance(effect->CreateInstance(texture));
    mSwitch->AttachChild(mesh);

    // Create a closed cylinder mesh (child 3).
    mesh = sm.Cylinder(8,16,1.0f,2.0f,false);
    mesh->SetEffectInstance(effect->CreateInstance(texture));
    mSwitch->AttachChild(mesh);

    // Create a sphere mesh (child 4).
    mesh = sm.Sphere(32,16,1.0f);
    mesh->SetEffectInstance(effect->CreateInstance(texture));
    mSwitch->AttachChild(mesh);

    // Create a torus mesh (child 5).
    mesh = sm.Torus(16,16,1.0f,0.25f);
    mesh->SetEffectInstance(effect->CreateInstance(texture));
    mSwitch->AttachChild(mesh);

    // Create a tetrahedron (child 6).
    mesh = sm.Tetrahedron();
    mesh->SetEffectInstance(effect->CreateInstance(texture));
    mSwitch->AttachChild(mesh);

    // Create a hexahedron (child 7).
    mesh = sm.Hexahedron();
    mesh->SetEffectInstance(effect->CreateInstance(texture));
    mSwitch->AttachChild(mesh);

    // Create an octahedron (child 8).
    mesh = sm.Octahedron();
    mesh->SetEffectInstance(effect->CreateInstance(texture));
    mSwitch->AttachChild(mesh);

    // Create a dodecahedron (child 9).
    mesh = sm.Dodecahedron();
    mesh->SetEffectInstance(effect->CreateInstance(texture));
    mSwitch->AttachChild(mesh);

    // Create an icosahedron (child 10).
    mesh = sm.Icosahedron();
    mesh->SetEffectInstance(effect->CreateInstance(texture));
    mSwitch->AttachChild(mesh);

    // Set the active child (otherwise it is invalid).
    mSwitch->SetActiveChild(0);
}
コード例 #3
0
//----------------------------------------------------------------------------
void PlanarReflections::CreatePlanes ()
{
	VertexFormat* vformat = VertexFormat::Create(2,
	                        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
	                        VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0);
	int vstride = vformat->GetStride();

	// Create the floor mesh.
	VertexBuffer* vbuffer = new0 VertexBuffer(4, vstride);
	VertexBufferAccessor floor(vformat, vbuffer);

	float xValue = 128.0f;
	float yValue = 256.0f;
	float zValue = 0.0f;
	floor.Position<Float3>(0) = Float3(-xValue, -yValue, zValue);
	floor.Position<Float3>(1) = Float3(+xValue, -yValue, zValue);
	floor.Position<Float3>(2) = Float3(+xValue, +yValue, zValue);
	floor.Position<Float3>(3) = Float3(-xValue, +yValue, zValue);
	floor.TCoord<Float2>(0, 0) = Float2(0.0f, 0.0f);
	floor.TCoord<Float2>(0, 1) = Float2(1.0f, 0.0f);
	floor.TCoord<Float2>(0, 2) = Float2(1.0f, 1.0f);
	floor.TCoord<Float2>(0, 3) = Float2(0.0f, 1.0f);

	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;

	mPlane0 = new0 TriMesh(vformat, vbuffer, ibuffer);

	Texture2DEffect* effect = new0 Texture2DEffect(Shader::SF_LINEAR_LINEAR,
	                          Shader::SC_REPEAT, Shader::SC_REPEAT);
	std::string path = Environment::GetPathR("Sand.wmtf");
	Texture2D* texture = Texture2D::LoadWMTF(path);
	mPlane0->SetEffectInstance(effect->CreateInstance(texture));

	mScene->AttachChild(mPlane0);

	// Create the wall mesh.
	vbuffer = new0 VertexBuffer(4, vstride);
	VertexBufferAccessor wall(vformat, vbuffer);

	xValue = -128.0f;
	yValue = 256.0f;
	zValue = 128.0f;
	wall.Position<Float3>(0) = Float3(xValue, -yValue, 0.0f);
	wall.Position<Float3>(1) = Float3(xValue, +yValue, 0.0f);
	wall.Position<Float3>(2) = Float3(xValue, +yValue, zValue);
	wall.Position<Float3>(3) = Float3(xValue, -yValue, zValue);
	wall.TCoord<Float2>(0, 0) = Float2(0.0f, 0.0f);
	wall.TCoord<Float2>(0, 1) = Float2(1.0f, 0.0f);
	wall.TCoord<Float2>(0, 2) = Float2(1.0f, 1.0f);
	wall.TCoord<Float2>(0, 3) = Float2(0.0f, 1.0f);

	mPlane1 = new0 TriMesh(vformat, vbuffer, ibuffer);

	path = Environment::GetPathR("Stone.wmtf");
	texture = Texture2D::LoadWMTF(path);
	mPlane1->SetEffectInstance(effect->CreateInstance(texture));

	mScene->AttachChild(mPlane1);
}
コード例 #4
0
ファイル: BspNodes.cpp プロジェクト: bhlzlx/WildMagic
//----------------------------------------------------------------------------
void BspNodes::CreateScene ()
{
	// Create the scene graph.
	//
	// 1. The rectangles represent the BSP planes of the BSP tree.  They
	//    share a VertexColor3Effect.  You can see a plane from either side
	//    (backface culling disabled).  The planes do not interfere with view
	//    of the solid objects (wirestate enabled).
	//
	// 2. The sphere, tetrahedron, and cube share a TextureEffect.  These
	//    objects are convex.  The backfacing triangles are discarded
	//    (backface culling enabled).  The front facing triangles are drawn
	//    correctly by convexity, so depthbuffer reads are disabled and
	//    depthbuffer writes are enabled.  The BSP-based sorting of objects
	//    guarantees that front faces of convex objects in the foreground
	//    are drawn after the front faces of convex objects in the background,
	//    which allows us to set the depthbuffer state as we have.  That is,
	//    BSPNode sorts from back to front.
	//
	// 3. The torus has backface culling enabled and depth buffering enabled.
	//    This is necessary, because the torus is not convex.
	//
	// 4. Generally, if all objects are opaque, then you want to draw from
	//    front to back with depth buffering fully enabled.  You need to
	//    reverse-order the elements of the visible set before drawing.  If
	//    any of the objects are semitransparent, then drawing back to front
	//    is the correct order to handle transparency.  However, you do not
	//    get the benefit of early z-rejection for opaque objects.  A better
	//    BSP sorter needs to be built to produce a visible set with opaque
	//    objects listed first (front-to-back order) and semitransparent
	//    objects listed last (back-to-front order).
	//
	// scene
	//     ground
	//     bsp0
	//         bsp1
	//             bsp3
	//                 torus
	//                 rectangle3
	//                 sphere
	//             rectangle1
	//             tetrahedron
	//         rectangle0
	//         bsp2
	//             cube
	//             rectangle2
	//             octahedron

	mScene = new0 Node();

	// Create the ground.  It covers a square with vertices (1,1,0), (1,-1,0),
	// (-1,1,0), and (-1,-1,0).  Multiply the texture coordinates by a factor
	// to enhance the wrap-around.
	VertexFormat* vformat = VertexFormat::Create(2,
	                        VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
	                        VertexFormat::AU_TEXCOORD, VertexFormat::AT_FLOAT2, 0);

	StandardMesh sm(vformat);
	VertexBufferAccessor vba;

	TriMesh* ground = sm.Rectangle(2, 2, 16.0f, 16.0f);
	vba.ApplyTo(ground);
	for (int i = 0; i < vba.GetNumVertices(); ++i)
	{
		Float2& tcoord = vba.TCoord<Float2>(0, i);
		tcoord[0] *= 128.0f;
		tcoord[1] *= 128.0f;
	}

	std::string path = Environment::GetPathR("Horizontal.wmtf");
	Texture2D* texture = Texture2D::LoadWMTF(path);
	ground->SetEffectInstance(Texture2DEffect::CreateUniqueInstance(texture,
	                          Shader::SF_LINEAR_LINEAR, Shader::SC_REPEAT, Shader::SC_REPEAT));
	mScene->AttachChild(ground);

	// Partition the region above the ground into 5 convex pieces.  Each plane
	// is perpendicular to the ground (not required generally).
	VertexColor3Effect* vceffect = new0 VertexColor3Effect();
	vceffect->GetCullState(0, 0)->Enabled = false;
	vceffect->GetWireState(0, 0)->Enabled = true;

	Vector2f v0(-1.0f, 1.0f);
	Vector2f v1(1.0f, -1.0f);
	Vector2f v2(-0.25f, 0.25f);
	Vector2f v3(-1.0f, -1.0f);
	Vector2f v4(0.0f, 0.0f);
	Vector2f v5(1.0f, 0.5f);
	Vector2f v6(-0.75f, -7.0f/12.0f);
	Vector2f v7(-0.75f, 0.75f);
	Vector2f v8(1.0f, 1.0f);

	BspNode* bsp0 = CreateNode(v0, v1, vceffect, Float3(1.0f, 0.0f, 0.0f));
	BspNode* bsp1 = CreateNode(v2, v3, vceffect, Float3(0.0f, 0.5f, 0.0f));
	BspNode* bsp2 = CreateNode(v4, v5, vceffect, Float3(0.0f, 0.0f, 1.0f));
	BspNode* bsp3 = CreateNode(v6, v7, vceffect, Float3(0.0f, 0.0f, 0.0f));

	bsp0->AttachPositiveChild(bsp1);
	bsp0->AttachNegativeChild(bsp2);
	bsp1->AttachPositiveChild(bsp3);

	// Attach an object in each convex region.
	float height = 0.1f;
	Vector2f center;
	TriMesh* mesh;

	// The texture effect for the convex objects.
	Texture2DEffect* cvxeffect =
	    new0 Texture2DEffect(Shader::SF_LINEAR_LINEAR);
	cvxeffect->GetDepthState(0, 0)->Enabled = false;
	cvxeffect->GetDepthState(0, 0)->Writable = true;

	// The texture effect for the torus.
	Texture2DEffect* toreffect =
	    new0 Texture2DEffect(Shader::SF_LINEAR_LINEAR);

	// The texture image shared by the objects.
	path = Environment::GetPathR("Flower.wmtf");
	texture = Texture2D::LoadWMTF(path);

	// Region 0: Create a torus mesh.
	mesh = sm.Torus(16, 16, 1.0f, 0.25f);
	mesh->SetEffectInstance(toreffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v2 + v6 + v7)/3.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp3->AttachPositiveChild(mesh);

	// Region 1: Create a sphere mesh.
	mesh = sm.Sphere(32, 16, 1.0f);
	mesh->SetEffectInstance(cvxeffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v0 + v3 + v6 + v7)/4.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp3->AttachNegativeChild(mesh);

	// Region 2: Create a tetrahedron.
	mesh = sm.Tetrahedron();
	mesh->SetEffectInstance(cvxeffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v1 + v2 + v3)/3.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp1->AttachNegativeChild(mesh);

	// Region 3: Create a hexahedron (cube).
	mesh = sm.Hexahedron();
	mesh->SetEffectInstance(cvxeffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v1 + v4 + v5)/3.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp2->AttachPositiveChild(mesh);

	// Region 4: Create an octahedron.
	mesh = sm.Octahedron();
	mesh->SetEffectInstance(cvxeffect->CreateInstance(texture));
	mesh->LocalTransform.SetUniformScale(0.1f);
	center = (v0 + v4 + v5 + v8)/4.0f;
	mesh->LocalTransform.SetTranslate(APoint(center[0], center[1], height));
	bsp2->AttachNegativeChild(mesh);

	mScene->AttachChild(bsp0);
}
コード例 #5
0
ファイル: Castle.cpp プロジェクト: bhlzlx/WildMagic
//----------------------------------------------------------------------------
void Castle::CreateEffects ()
{
	std::string name = Environment::GetPathR("DLitMatTex.wmfx");
	mDLitMatTexEffect = new0 DLitMatTexEffect(name);
	mDLitMatTexAlphaEffect = new0 DLitMatTexEffect(name);
	mDLitMatTexAlphaEffect->GetAlphaState(0, 0)->BlendEnabled = true;

	mTexEffect = new0 Texture2DEffect(Shader::SF_LINEAR_LINEAR,
	                                  Shader::SC_REPEAT, Shader::SC_REPEAT);

	mMatEffect = new0 MaterialEffect();

	Material* common0 = new0 Material();
	common0->Emissive = Float4(0.0f, 0.0f, 0.0f, 1.0f);
	common0->Ambient = Float4(0.588235f, 0.588235f, 0.588235f, 1.0f);
	common0->Diffuse = Float4(0.0f, 0.0f, 0.0f, 1.0f);
	common0->Specular = Float4(0.0f, 0.0f, 0.0f, 2.0f);

	Material* common1 = new0 Material();
	common1->Emissive = Float4(0.0f, 0.0f, 0.0f, 1.0f);
	common1->Ambient = Float4(0.213070f, 0.183005f, 0.064052f, 1.0f);
	common1->Diffuse = Float4(0.0f, 0.0f, 0.0f, 1.0f);
	common1->Specular = Float4(0.045f, 0.045f, 0.045f, 5.656854f);

	Material* water = new0 Material();
	water->Emissive = Float4(0.0f, 0.0f, 0.0f, 1.0f);
	water->Ambient = Float4(0.088888f, 0.064052f, 0.181698f, 1.0f);
	water->Diffuse = Float4(0.0f, 0.0f, 0.0f, 1.0f);
	water->Specular = Float4(0.045f, 0.045f, 0.045f, 5.656854f);

	Material* roofsteps = new0 Material();
	roofsteps->Emissive = Float4(0.0f, 0.0f, 0.0f, 1.0f);
	roofsteps->Ambient = Float4(0.1f, 0.1f, 0.1f, 1.0f);
	roofsteps->Diffuse = Float4(0.0f, 0.0f, 0.0f, 1.0f);
	roofsteps->Specular = Float4(0.045f, 0.045f, 0.045f, 5.656854f);

	// diffuse channel is outwall03.wmtf
	mOutWallMaterial = common1;

	// diffuse channel is stone01.wmtf
	mStoneMaterial = common1;

	// diffuse channel is river01.wmtf (has alpha)
	mRiverMaterial = water;

	// emissive channel is walllightmap.wmtf
	// diffuse channel is wall02.wmtf
	mWallMaterial = common1;

	// emissive channel is walllightmap.wmtf
	// diffuse channel is steps.wmtf
	mStairsMaterial = roofsteps;

	// diffuse channel is outwall03.wmtf
	mInteriorMaterial = common1;

	// emissive channel is walllightmap.wmtf
	// diffuse channel is door.wmtf
	mDoorMaterial = common0;

	// emissive channel is walllightmap.wmtf
	// diffuse channel is floor02.wmtf
	mFloorMaterial = common0;

	// emissive channel is walllightmap.wmtf
	// diffuse channel is woodceiling.wmtf
	mWoodCeilingMaterial = common0;

	// diffuse channel is keystone.wmtf
	mKeystoneMaterial = common1;

	// diffuse channel is tileplanks.wmtf
	mDrawBridgeMaterial = common1;

	// diffuse channel is rooftemp.wmtf
	mRoofMaterial = roofsteps;

	// diffuse channel is ramp03.wmtf
	mRampMaterial = common1;

	// diffuse channel is shield01.wmtf
	mWoodShieldMaterial = common1;

	// diffuse channel is metal01.wmtf
	mTorchHolderMaterial = new0 Material();
	mTorchHolderMaterial->Emissive = Float4(0.0f, 0.0f, 0.0f, 1.0f);
	mTorchHolderMaterial->Ambient = Float4(0.213070f, 0.183005f, 0.064052f, 1.0f);
	mTorchHolderMaterial->Diffuse = Float4(0.0f, 0.0f, 0.0f, 1.0f);
	mTorchHolderMaterial->Specular = Float4(0.216f, 0.216f, 0.216f, 11.313708f);

	// diffuse channel is torchwood.wmtf
	mTorchWoodMaterial = common1;

	// emissive channel is torchhead.tga (same as .wmtf ???)
	// diffuse channel is torchhead.wmtf
	mTorchHeadMaterial = common0;

	// diffuse channel is barrelbase.wmtf
	mBarrelBaseMaterial = common0;

	// diffuse channel is barrelbase.wmtf
	mBarrelMaterial = common0;

	// emissive channel is walllightmap.wmtf
	// diffuse channel is doorframe.wmtf
	mDoorFrameMaterial = common1;

	// diffuse channel is bunkwood.wmtf
	mBunkMaterial = common1;

	// diffuse channel is blanket.wmtf
	mBlanketMaterial = common0;

	// diffuse channel is bunkwood.wmtf
	mBenchMaterial = common0;

	// diffuse channel is bunkwood.wmtf
	mTableMaterial = common0;

	mBarrelRackMaterial = mDrawBridgeMaterial;

	// diffuse channel is chest01.wmtf
	mChestMaterial = common1;

	// diffuse channel is tileplanks.wmtf
	mLightwoodMaterial = common1;

	// part of ceiling lights
	mMaterial26 = new0 Material();
	mMaterial26->Emissive = Float4(0.0f, 0.0f, 0.0f, 1.0f);
	mMaterial26->Ambient = Float4(0.588235f, 0.588235f, 0.588235f, 1.0f);
	mMaterial26->Diffuse = Float4(0.588235f, 0.588235f, 0.588235f, 1.0f);
	mMaterial26->Specular = Float4(0.0f, 0.0f, 0.0f, 2.0f);

	// diffuse channel is rope.wmtf
	mRopeMaterial = common0;

	// diffuse channel is rope.wmtf
	mSquareTableMaterial = common0;

	mSimpleChairMaterial = mDrawBridgeMaterial;

	// diffuse channel is mug.wmtf
	mMugMaterial = common0;

	// diffuse channel is port.wmtf
	mPortMaterial = common1;

	// diffuse channel is skyline.wmtf
	mSkyMaterial = common0;

	// diffuse channel is river02.wmtf (has alpha)
	mWaterMaterial = water;

	// TERRAIN
	// diffuse channel is gravel01.wmtf
	mGravel1Material = common1;

	// diffuse channel is gravel02.wmtf
	mGravel2Material = common1;

	// diffuse channel is gravel_corner_ne.wmtf
	mGravelCornerNEMaterial = common1;

	// diffuse channel is gravel_corner_nw.wmtf
	mGravelCornerNWMaterial = common1;

	// diffuse channel is gravel_corner_se.wmtf
	mGravelCornerSEMaterial = common1;

	// diffuse channel is gravel_corner_sw.wmtf
	mGravelCornerSWMaterial = common1;

	// diffuse channel is gravel_cap_ne.wmtf
	mGravelCapNEMaterial = common1;

	// diffuse channel is gravel_cap_nw.wmtf
	mGravelCapNWMaterial = common1;

	// diffuse channel is gravel_side_n.wmtf
	mGravelSideNMaterial = common1;

	// diffuse channel is gravel_side_s.wmtf
	mGravelSideSMaterial = common1;

	// diffuse channel is gravel_side_w.wmtf
	mGravelSideWMaterial = common1;

	// diffuse channel is stone01.wmtf
	mStone1Material = common1;

	// diffuse channel is stone02.wmtf
	mStone2Material = common1;

	// diffuse channel is stone03.wmtf
	mStone3Material = common1;

	// diffuse channel is largestone01.wmtf
	mLargeStone1Material = common1;

	// diffuse channel is largerstone01.wmtf
	mLargerStone1Material = common1;

	// diffuse channel is largerstone02.wmtf
	mLargerStone2Material = common1;

	// diffuse channel is largeststone01.wmtf
	mLargestStone1Material = common1;

	// diffuse channel is largeststone02.wmtf
	mLargestStone2Material = common1;

	// diffuse channel is hugestone01.wmtf
	mHugeStone1Material = common1;

	// diffuse channel is hugestone02.wmtf
	mHugeStone2Material = common1;
}