void cone::Read(Loader &input) { char token[MAX_INPUT_LENGTH]; bool moreTokens; do { input.PeekTokens(token, 1); moreTokens = true; if (strcmp(token, "base") == 0) { input.ReadToken(token); for (int i = 0; i < 3; i++) if (!input.ReadFloat(base[i])) input.Error("Not enough parameters for cone's base in cone '%s'", objectName); } else if (strcmp(token, "radius") == 0) { input.ReadToken(token); if (!input.ReadFloat(radius)) input.Error("Error reading radius in cone '%s'", objectName); } else if (strcmp(token, "height") == 0) { input.ReadToken(token); if (!input.ReadFloat(height)) input.Error("Error reading height in cone '%s'", objectName); } else if (strcmp(token, "axis") == 0) { input.ReadToken(token); if (!input.ReadInt(axis)) input.Error("Error reading axis number in cone '%s'", objectName); } else if (strcmp(token, "capped") == 0) { input.ReadToken(token); if (!input.ReadBool(capped)) input.Error("Error reading height in cone '%s'", objectName); } else if (strcmp(token, "resolution") == 0) { input.ReadToken(token); if (!input.ReadInt(resolution)) input.Error("Error reading resolution in cone '%s'", objectName); } else moreTokens = false; // If we don't recognize it jump out ... it is an attribute } while (moreTokens); SetupShape(); }
void sphere::Read(Loader &input) { char token[MAX_INPUT_LENGTH]; bool moreTokens; do { // We need to "peek" because if the token isn't giving us one // of the sphere properties, then it is a shape attribute like // color and if we've already read it out of the file, the shape // class would not be able to read the attribute afterwords. // So we "peek" at the token which does not remove it from the // file stream. For more information, see the "PeekTokens" // method defined in the Loader class input.PeekTokens(token, 1); moreTokens = true; if (strcmp(token, "center") == 0) { input.ReadToken(token); for (int i = 0; i < 3; i++) if (!input.ReadFloat(center[i])) input.Error("Not enough parameters for sphere's center in sphere '%s'", objectName); } else if (strcmp(token, "radius") == 0) { input.ReadToken(token); if (!input.ReadFloat(radius)) input.Error("Error reading radius in sphere '%s'", objectName); } else if (strcmp(token, "resolution") == 0) { input.ReadToken(token); if (!input.ReadInt(resolution)) input.Error("Error reading resolution in sphere '%s'", objectName); } else moreTokens = false; // If we don't recognize it jump out ... it is an attribute } while (moreTokens); SetupShape(); }