// create the teapot mesh and material
teapotmesh = mesh.teapot(device);
teapotmaterial = new material();
teapotmaterial.diffusecolor = new colorvalue(1.0f, 1.0f, 1.0f, 1.0f);
为了使茶壶更真实,还需要光照效果(这些会在本书的后面详细解释)。找到类中的onresedevice方法,将下面的代码添加到该方法的结尾处:
// setup lights
device.lights[0].diffusecolor = new colorvalue(1.0f, 1.0f, 1.0f, 1.0f);
device.lights[0].direction = new vector3(0,-1,0);
device.lights[0].type = lighttype.directional;
device.lights[0].enabled = true;
找到类中的onframerender方法并在beginscene后面添加如下代码:
device.transform.view = camera.viewmatrix;
device.transform.projection = camera.projectionmatrix;
device.transform.world = matrix.rotationx ((float)apptime);
device.material = teapotmaterial;
teapotmesh.drawsubset(0);
运行该应用程序,生成一个茶壶。在3d绘图世界中,茶壶有一段相当有名的历史。对于绘图来说,它是第一个可利用的“免费”模型。在那时,当前一些复杂的模型包都不存在,这是因为创建实际的3d模型非常复杂。任何免费的东西都会受欢迎。茶壶具有大量的属性,使它成为一个很好的测试模型:具有曲面表面,能够遮挡自己,并且很容易识别。
您创建的这个应用程序生成了茶壶,并慢慢地旋转,使得您能够看到各个角度,如图2-2所示。

