home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-27 | 2.6 KB | 89 lines | [TEXT/CWIE] |
- //
- // CClub.cp
- //
- // class CClub
- // A juggling club.
- // Implimented as a Tri-Grid.
- //
- // by James Jennings
- // Started November 23, 1995
- //
-
- #include "CClubMaker.h"
- #include "QD3D Debug Macros.h"
- #include "StQ3Disposer.h"
-
- #include "ObjectHandle.h" // to dispose of an array of stuff
-
- const short lathNumber = 13; // number of "lath faces" + 1
- const short numberOfClubPoints = 11;
- static const float club[numberOfClubPoints][2] = {
- // { z-coord, x or y-coord}, measured in cm
- { 0.0, 0.0 }, // bottom face (black)
- { 0.0, 3.3/2 }, // knob (black)
- { 2.2, 3.2/2 },
- { 2.2, 1.9/2 }, // handle (silver)
- { 23.0, 3.1/2 }, // throat (blue)
- { 32.5, 6.0/2 }, // body (white)
- { 37.0, 7.5/2 },
- { 40.5, 7.6/2 },
- { 44.0, 7.0/2 }, // cap (silver)
- { 52.0, 4.2/2 }, // end
- { 52.0, 0.0 } // top face (black)
- };
- static const TQ3Point3D centerOfGravity = { 0.0, 0.0, 28.0};
- static const float scale = 0.01 * 5; // convert to meters, and blow up a bit
-
- void
- CClubMaker::Make()
- {
- TQ3TriGridData data;
-
- data.numRows = numberOfClubPoints;
- data.numColumns = lathNumber;
- data.facetAttributeSet = nil;
- data.triGridAttributeSet = ::Q3AttributeSet_New();
- ThrowIfNil_(data.triGridAttributeSet);
- StQ3Disposer tgColor(data.triGridAttributeSet);
- TQ3ColorRGB color = { 1, 0, 0};
- ::Q3AttributeSet_Add(data.triGridAttributeSet, kQ3AttributeTypeDiffuseColor, &color);
-
- // Allocate the vertices as a self-disposing handle.
- StHandleBlock verts( data.numRows *data.numColumns * sizeof(TQ3Vertex3D) );
- StHandleLocker locker(verts);
- data.vertices = (TQ3Vertex3D*)*Handle(verts);
-
- // an array of attribute objects that disposes itself.
- ObjectArrayHandle<StQ3Disposer> oah(data.numRows * data.numColumns);
-
- int i=0;
- for (int r=0; r<data.numRows; r++) {
- float z = club[r][0]*scale; // convert to meters
- float rho = club[r][1]*scale;
- for (int c=0; c<data.numColumns; c++, i++) {
- float angle = c * kQ32Pi/(data.numColumns-1);
- TQ3Vertex3D *v = &(data.vertices[i]);
- ::Q3Point3D_Set(&(v->point), rho*cos(angle), rho*sin(angle), z);
- // Add a parameterization.
- v->attributeSet = ::Q3AttributeSet_New();
- ThrowIfNil_(v->attributeSet);
- oah[i] = v->attributeSet; // put it in the self disposing array
- TQ3Param2D p;
- p.u = z/(club[numberOfClubPoints-1][0]*scale);
- p.v = (float)c/(data.numColumns-1);
- ::Q3AttributeSet_Add(v->attributeSet, kQ3AttributeTypeShadingUV, &p);
- }
- }
-
- mObject = ::Q3TriGrid_New(&data);
- ThrowIfNil_(mObject);
- }
-
- void
- CClubMaker::GetCenterOfGravity(TQ3Point3D &com)
- {
- ::Q3Point3D_Set(&com, centerOfGravity.x * scale,
- centerOfGravity.y * scale,
- centerOfGravity.z * scale);
- }
-