home *** CD-ROM | disk | FTP | other *** search
- /****************************/
- /* MESH.C */
- /****************************/
-
-
- /****************************/
- /* EXTERNALS */
- /****************************/
-
- #include <qd3d.h>
- #include <QD3DGeometry.h>
- #include <QD3DSet.h>
- #include <QD3DView.h>
- #include <QD3DShader.h>
- #include <QD3DGroup.h>
- #include <QD3DRenderer.h>
- #include <QD3DAcceleration.h>
- #include <QD3DDrawContext.h>
-
- extern TQ3ViewObject gMyViewObject;
- extern TQ3StyleObject gMyStyleObject_Interpolation;
- extern TQ3StyleObject gMyStyleObject_Backfacing;
- extern TQ3StyleObject gMyStyleObject_Fillstyle;
- extern TQ3ShaderObject gMyShaderObject_IlluminationShader;
-
-
-
- /****************************/
- /* PROTOTYPES */
- /****************************/
-
- extern void DoFatalAlert(Str255 s);
-
- void DrawMyObjects(void);
- void CreateMyMesh(void);
-
-
- /****************************/
- /* CONSTANTS */
- /****************************/
-
-
- /*********************/
- /* VARIABLES */
- /*********************/
-
- TQ3GeometryObject gMyMeshObject;
-
-
- /****************** CREATE MY MESH ******************/
- //
- // Creates a mesh geometry object.
- //
- // INPUT : none
- // OUTPUT : none
- //
-
- void CreateMyMesh(void)
- {
- long i,faceNum,vertexNum;
- float ambient = 1.0;
- TQ3ColorRGB color;
- TQ3AttributeSet vertexAttribs;
- TQ3Vertex3D vertex;
- TQ3MeshFace face;
- TQ3MeshVertex meshVertexIDList[16];
- TQ3MeshVertex faceVerts[4];
- TQ3GeometryObject meshObj;
-
- TQ3Point3D meshVertexCoords[16] =
- {
- -10,0,-10, -5,0,-10, 5,0,-10, 10,0,-10,
- -10,0,-5, -5,0,-5, 5,0,-5, 10,0,-5,
- -10,0,5, -5,0,5, 5,0,5, 10,0,5,
- -10,0,10, -5,0,10, 5,0,10, 10,0,10
- };
-
- long meshFaceVertices[9*4] =
- {
- 0,4,5,1, 1,5,6,2, 2,6,7,3,
- 4,8,9,5, 5,9,10,6, 6,10,11,7,
- 8,12,13,9, 9,13,14,10, 10,14,15,11
- };
-
-
- /* CREATE NEW MESH OBJECT */
-
- meshObj = Q3Mesh_New();
- if (meshObj == nil)
- DoFatalAlert("\pError making new mesh!");
-
-
- /***********************************/
- /* CREATE THE VERTICES OF THE MESH */
- /***********************************/
-
- for (vertexNum = 0; vertexNum < 16; vertexNum++)
- {
- /* MAKE ATTRIBUTES FOR THIS VERTEX */
-
- vertexAttribs = Q3AttributeSet_New(); // make attribs
- if (vertexAttribs == nil)
- DoFatalAlert("\pError making new vertex attribs.");
-
- color.r = (float)1/((Random()&0xf)+1); // make random RGB color
- color.g = (float)1/((Random()&0xf)+1); // for each vertex
- color.b = (float)1/((Random()&0xf)+1);
-
- Q3AttributeSet_Add(vertexAttribs, // set color
- kQ3AttributeTypeDiffuseColor, &color);
-
- Q3AttributeSet_Add(vertexAttribs, // set ambient
- kQ3AttributeTypeAmbientCoefficient, &ambient);
-
-
- /* SET COORDS & ATTRIBS FOR VERTEX */
-
- vertex.point.x = meshVertexCoords[vertexNum].x; // copy x,y,z coords
- vertex.point.y = meshVertexCoords[vertexNum].y;
- vertex.point.z = meshVertexCoords[vertexNum].z;
- vertex.attributeSet = vertexAttribs; // attach attribs
-
-
- /* CREATE A NEW VERTEX & KEEP THE RETURNED VERTEX ID */
-
- meshVertexIDList[vertexNum] = Q3Mesh_VertexNew(meshObj, &vertex);
-
-
- /* DISPOSE OF OUR REFERENCE TO THE ATTRIBUTE SET */
-
- Q3Object_Dispose(vertexAttribs);
- }
-
- /*****************************/
- /* CREATE MESH POLYGON FACES */
- /*****************************/
-
- for (i = 0, faceNum=0; faceNum < 9; faceNum++)
- {
- /* GET VERTEX ID’S FROM TABLE */
-
- faceVerts[0] = meshVertexIDList[meshFaceVertices[i++]]; // copy vertex
- faceVerts[1] = meshVertexIDList[meshFaceVertices[i++]]; // ID’S into local
- faceVerts[2] = meshVertexIDList[meshFaceVertices[i++]]; // array for easy
- faceVerts[3] = meshVertexIDList[meshFaceVertices[i++]]; // use.
-
-
- /* MAKE FACE WITH NO ATTRIBUTES */
-
- face = Q3Mesh_FaceNew(meshObj,4,&faceVerts[0],nil); // make the face
- if (face == nil)
- DoFatalAlert("\pError adding face to mesh object!");
- }
-
- gMyMeshObject = meshObj;
- }
-
-
- /******************* DRAW MY OBJECTS *********************/
- //
- // Draws a frame of animation for the FlyThru window.
- //
-
- void DrawMyObjects(void)
- {
- TQ3Status myStatus;
- TQ3ViewStatus myViewStatus;
-
- /* START RENDERING */
-
- myStatus = Q3View_StartRendering(gMyViewObject); // start rendering
- if ( myStatus == kQ3Failure )
- DoFatalAlert("\p Q3View_StartRendering Failed!");
-
- do
- {
- /* SET INTERPOLATION STYLE */
-
- myStatus = Q3Style_Submit(gMyStyleObject_Interpolation,gMyViewObject);
- if ( myStatus == kQ3Failure )
- DoFatalAlert("\p Q3Style_Submit Failed!");
-
- /* SET BACKFACING STYLE */
-
- myStatus = Q3Style_Submit(gMyStyleObject_Backfacing,gMyViewObject);
- if ( myStatus == kQ3Failure )
- DoFatalAlert("\p Q3Style_Submit Failed!");
-
-
- /* SET FILL STYLE */
-
- myStatus = Q3Style_Submit(gMyStyleObject_Fillstyle, gMyViewObject);
- if ( myStatus == kQ3Failure )
- DoFatalAlert("\p Q3Style_Submit Failed!");
-
-
- /* SET SHADER TO USE */
-
- myStatus = Q3Shader_Submit(gMyShaderObject_IlluminationShader, gMyViewObject);
- if ( myStatus == kQ3Failure )
- DoFatalAlert("\p Q3Shader_Submit Failed!");
-
-
- /* DRAW THE MESH OBJECT */
-
- myStatus = Q3Geometry_Submit(gMyMeshObject,gMyViewObject);
- if ( myStatus == kQ3Failure )
- DoFatalAlert("\p Drawing Mesh Failed!");
-
-
- /* SEE IF DONE */
-
- myViewStatus = Q3View_EndRendering(gMyViewObject);
-
- } while ( myViewStatus == kQ3ViewStatusRetraverse );
- }
-
-
-
-