Last modified 26 September 2002 by jdavis@math.wisc.edu

SMKModel

Inherits from SMKShape : SMKResource : NSObject
Conforms to NSCoding

SMKModel augments SMKShape by assigning a normal vector and texture coordinates to each vertex. These let us apply lighting and texturing to the model. Note that SMKModel does not actually specify its texture; that is left to a client class such as SMKModelElement.

SMKModel overrides SMKShape's configureOpenGLForDrawing class method to activate texturing and the normal and texture coordinate arrays. Before drawing or selecting on an SMKModel, you need to invoke configureOpenGLForDrawing or configureOpenGLForSelection.

SMKShape and SMKModel offer a variety of methods to access the geometric data; here are SMKModel's additions:

- (float *)normal:(unsigned int)index;

Returns the normal vector for the indicated vertex; treat this pointer as an array of three floats. The pointer will be invalid after the array is resized with setNumberOfVertices:.

- (float *)textureCoordinates:(unsigned int)index;

Returns the texture coordinates for the indicated vertex; treat this pointer as an array of two floats. The pointer will be invalid after the array is resized with setNumberOfVertices:.

- (id)updateNormals;

Recomputes the normal vectors based on the underlying vertex information.

SMKModel overrides constructSphereOfRadius:slices:stacks: to assign normals and texture coordinates. On the other hand, it does not override deformByMatrix:, so you will probably want to update the model's normal vectors after using that method. There is no reason to update normals after using translateByVector: or scaleByFactor:.