![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
The CubeWin Render FunctionsThe remaining CubeWin functions provide the demos Render menu support. These functions appear like this: void CubeWin::OnRenderWireframe() { if (mesh) mesh->SetGroupQuality( group, D3DRMRENDER_WIREFRAME ); } void CubeWin::OnRenderFlat() { if (mesh) mesh->SetGroupQuality( group, D3DRMRENDER_FLAT ); } void CubeWin::OnRenderGouraud() { if (mesh) mesh->SetGroupQuality( group, D3DRMRENDER_GOURAUD ); } void CubeWin::OnUpdateRenderWireframe(CCmdUI* pCmdUI) { if (mesh) { D3DRMRENDERQUALITY meshquality = mesh->GetGroupQuality( group ); pCmdUI->SetCheck( meshquality==D3DRMRENDER_WIREFRAME ); } } void CubeWin::OnUpdateRenderFlat(CCmdUI* pCmdUI) { if (mesh) { D3DRMRENDERQUALITY meshquality = mesh->GetGroupQuality( group ); pCmdUI->SetCheck( meshquality==D3DRMRENDER_FLAT ); } } void CubeWin::OnUpdateRenderGouraud(CCmdUI* pCmdUI) { if (mesh) { D3DRMRENDERQUALITY meshquality = mesh->GetGroupQuality( group ); pCmdUI->SetCheck( meshquality==D3DRMRENDER_GOURAUD ); } } Notice that the mesh group identifier group is used to set and retrieve the meshs rendering settings. You may also notice that when you use the demos Render menu, there is little or no difference between the flat and Gouraud settings. Typically, Gouraud rendering softens edges and corners. With the Cube demo, however, the edges of the mesh stay distinct in Gouraud mode. This is because the normals that we used to create the mesh are not calculated in the same way that the Direct3DRMMeshBuilder interface would have calculated the normals had it been used. The normals we use in the Cube demo are perpendicular to the face that the vertex is part of. Had the Direct3DRMMeshBuilder GenerateNormals() function been used, the normals would have been calculated based on all of the faces surrounding a vertex. Multiple Mesh GroupsIn the Cube demo, we create a mesh that has one group. All six of the cubes faces are part of the group and are modified as a single entity. Meshes support multiple groups. Each group must be added to the mesh with the Direct3DRMMesh AddGroup() function. The group can later be queried and modified using a group identifier that the AddGroup() function assigns. Using multiple groups in a mesh allows different colors, textures, and materials to be used simultaneously by a single mesh. The Cube2 DemoThe Cube2 demo has its name for two reasons. First, the demo is a direct adaptation from the Cube demo. Second, the Cube2 demo represents its cube using two mesh groups. The mesh in the Cube2 demo is animated in the same way as the cube in the Cube demo, but the color of the second group (three of the cubes faces) is animated. The Cube2 demo appears in Figure 8.2.
The Cube2 demo demonstrates the following techniques:
Well talk about each of these techniques as we walk through the Cube2 code. The Cube2Win ClassThe Cube2 demo provides its functionality with the Cube2Win class: class Cube2Win : public RMWin { public: Cube2Win(); BOOL CreateScene(); protected: //{{AFX_MSG(Cube2Win) afx_msg void OnRenderGroup1Flat(); afx_msg void OnRenderGroup1Wireframe(); afx_msg void OnRenderGroup1Gouraud(); afx_msg void OnRenderGroup2Wireframe(); afx_msg void OnRenderGroup2Flat(); afx_msg void OnRenderGroup2Gouraud(); afx_msg void OnUpdateRenderGroup1Wireframe(CCmdUI* pCmdUI); afx_msg void OnUpdateRenderGroup1Flat(CCmdUI* pCmdUI); afx_msg void OnUpdateRenderGroup1Gouraud(CCmdUI* pCmdUI); afx_msg void OnUpdateRenderGroup2Wireframe(CCmdUI* pCmdUI); afx_msg void OnUpdateRenderGroup2Flat(CCmdUI* pCmdUI); afx_msg void OnUpdateRenderGroup2Gouraud(CCmdUI* pCmdUI); //}}AFX_MSG DECLARE_MESSAGE_MAP() private: static void UpdateCube(LPDIRECT3DRMFRAME, void*, D3DVALUE); static void UpdateColors(LPDIRECT3DRMFRAME, void*, D3DVALUE); private: LPDIRECT3DRMMESH mesh; D3DRMGROUPINDEX group1, group2; }; Two public member functions are declared: a constructor and CreateScene(). The constructor initializes the classs data members. The CreateScene() function creates the demos mesh, light sources, and viewport.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |