home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Samples / SampleCode / Unsupported Libraries / Text3D.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-12  |  7.4 KB  |  313 lines  |  [TEXT/MPS ]

  1. /******************************************************************************
  2.  **                                                                             **
  3.  **     Module:        Text3D.c                                                 **
  4.  **                                                                          **
  5.  **                                                                          **
  6.  **     Purpose:     Create a general polygon from character outlines          **
  7.  **                                                                          **
  8.  **                                                                          **
  9.  **                                                                          **
  10.  **     Copyright (C) 1992-1995 Apple Computer, Inc.  All rights reserved.     **
  11.  **                                                                          **
  12.  **                                                                          **
  13.  *****************************************************************************/
  14. #include "QD3D.h"
  15. #include "Text3D.h"
  16.  
  17. #if defined(NOGX) && NOGX
  18.  
  19. TQ3GroupObject ReadText(
  20.     void)
  21. {
  22.     return(NULL);
  23. }
  24.  
  25. TQ3GroupObject MakeText(
  26.     char    *str)
  27. {
  28.     return (NULL);
  29. }
  30.  
  31. #else /* !defined(NOGX) || !NOGX */
  32.  
  33. #include <stdlib.h>
  34. #include <stdio.h>
  35. #include <string.h>
  36.  
  37. #include <Dialogs.h>
  38. #include <Fonts.h>
  39. #include <Memory.h>
  40. #include <Menus.h>
  41. #include <OSUtils.h>
  42. #include <SegLoad.h>
  43. #include <TextEdit.h>
  44. #include <Files.h>
  45. #include <StandardFile.h>
  46.  
  47. #ifdef applec
  48. # include <Strings.h>
  49. #endif /* applec */
  50. #ifdef THINK_C
  51. # include <pascal.h>
  52. #endif /* THINK_C */
  53.  
  54. #include "QD3DShader.h"
  55. #include "QD3DTransform.h"
  56. #include "QD3DStyle.h"
  57. #include "QD3DView.h"
  58. #include "QD3DMath.h"
  59. #include "QD3DSet.h"
  60. #include "QD3DGroup.h"
  61. #include "QD3DGeometry.h"
  62.  
  63. #include "font library.h"
  64. #include "graphics libraries.h"
  65. #include "graphics routines.h"
  66. #include "graphics toolbox.h"
  67.  
  68. /* 
  69.  *  This needs to be after all Escher and toolbox includes 
  70.  */
  71. #include "math routines.h"
  72. #include "offscreen library.h"
  73. #include "storage library.h"
  74.  
  75. #include "layout types.h"
  76. #include "layout routines.h"
  77. #include "layout feature constants.h"
  78.  
  79.  
  80. /*===========================================================================*\
  81.  *
  82.  *    Routine:    ReadText()
  83.  *
  84.  *    Comments:    
  85.  *
  86. \*===========================================================================*/
  87.  
  88. TQ3GroupObject ReadText(
  89.     void)
  90. {
  91.     char     str[256];
  92.     
  93.     TextFont(symbol);
  94.     TextFace(italic);
  95.     TextSize(9);
  96.     TextMode(srcCopy);
  97.     
  98.     strcpy(str, "QuickDraw 3D");
  99.     return(MakeText(str));
  100. }
  101.  
  102.  
  103. /*===========================================================================*\
  104.  *
  105.  *    Routine:    MakeText()
  106.  *
  107.  *    Comments:    
  108.  *
  109. \*===========================================================================*/
  110.  
  111. TQ3GroupObject MakeText(
  112.     char    *str)
  113. {
  114.     gxPoint             strPosition;
  115.     gxShape             stringShape;
  116.     long                 size, numContours;
  117.     gxPolygons             *blog;
  118.     gxPolygon             *poly;
  119.     char                 *pp;
  120.     unsigned long         i, b, c;
  121.  
  122.     TQ3GroupObject     group;
  123.     TQ3ColorRGB             col;
  124.     gxRectangle            rect = {
  125.                                     IntToFixed(0.0), 
  126.                                     IntToFixed(0.0), 
  127.                                     IntToFixed(100.0), 
  128.                                     IntToFixed(-100.0)
  129.                                 };
  130.     gxRectangle         rect2 = {
  131.                                     IntToFixed(30.0), 
  132.                                     IntToFixed(-30.0), 
  133.                                     IntToFixed(60.0), 
  134.                                     IntToFixed(-60.0)};
  135.  
  136.  
  137.     TQ3GeneralPolygonData gp;
  138.     TQ3GeometryObject     generalPoly;
  139.     
  140.     gxRunFeature        features[1];
  141.     
  142.     strPosition.x = 0;
  143.     strPosition.y = 0;
  144.     stringShape = NewCString(str, &strPosition);
  145.     GXSetShapeFont(stringShape, FindCNameFont(gxFamilyFontName, "Apple Chancery"));
  146.     GXSetShapeTextSize(stringShape, IntToFixed(48));
  147.     GXSetShapeFill(stringShape, gxSolidFill);
  148.     
  149.     GXSetShapeType(stringShape, gxLayoutType);
  150.     features[0].featureType = designComplexityType;
  151.     features[0].featureSelector = designLevel3Selector;
  152.     GXSetShapeRunFeatures(stringShape, 1, features);
  153.     
  154.     GXSetStyleCurveError(GXGetShapeStyle(stringShape), FloatToFixed(1.5));    
  155.      GXSetShapeCurveError(stringShape, FloatToFixed(1.5));
  156.  
  157.     GXSetShapeType(stringShape, gxPolygonType);
  158.  
  159.     numContours = GXCountShapeContours(stringShape);
  160.     size = GXGetPolygons(stringShape, NULL);
  161.     if (!(blog = (gxPolygons *) malloc (size))) {
  162.         return(NULL);
  163.     }
  164.     GXGetPolygons(stringShape, blog);
  165.     GXDisposeShape(stringShape);
  166.  
  167.     group = Q3OrderedDisplayGroup_New();
  168.     Q3ColorRGB_Set(&col, 1.0, 0.0, 0.0);
  169.  
  170. #if 0
  171.     gp.numContours = blog->contours;
  172.     gp.generalPolygonAttributeSet = Q3AttributeSet_New();
  173.     
  174.     Q3AttributeSet_Add(
  175.         gp.generalPolygonAttributeSet, 
  176.         kQ3AttributeTypeDiffuseColor, 
  177.         (const void *) &col);
  178.  
  179.     if (!(gp.contours = 
  180.         (TQ3GeneralPolygonContourData *) malloc(gp.numContours * sizeof(TQ3GeneralPolygonContourData)))) {
  181.         return(NULL);
  182.     }
  183.  
  184.     pp = (char *)&blog->contour[0].vectors;
  185.     for (i = 0; i < blog->contours; i++) {
  186.         poly = (gxPolygon *)pp;
  187.         pp += sizeof(long);
  188.         gp.contours[i].numVertices = poly->vectors;
  189.  
  190.         if (!(gp.contours[i].vertices = (TQ3Vertex3D *)
  191.                         malloc(poly->vectors * sizeof(TQ3Vertex3D)))) {
  192.             return (NULL);
  193.         }
  194.  
  195.         for (b = 0, c = poly->vectors-1; b < poly->vectors; b++, c--) {
  196.             gp.contours[i].vertices[c].point.x = 
  197.                                 (float)FixedToFloat(poly->vector[b].x) / 20.0;
  198.             gp.contours[i].vertices[c].point.y = 
  199.                                 (float)-FixedToFloat(poly->vector[b].y) / 20.0;
  200.             gp.contours[i].vertices[c].point.z = 0.0;
  201.             gp.contours[i].vertices[c].attributeSet = NULL;
  202.             pp += sizeof(gxPoint);
  203.         }
  204.     }
  205.  
  206.     generalPoly = Q3GeneralPolygon_New(&gp);
  207.     Q3Group_AddObject(group, generalPoly);
  208.  
  209.     Q3Object_Dispose(gp.generalPolygonAttributeSet);
  210.     Q3Object_Dispose(generalPoly);
  211.  
  212.     for (i = 0; i < blog->contours; i++) {
  213.         free(gp.contours[i].vertices);
  214.     }
  215.     free(gp.contours);
  216. #else
  217.     {
  218.         TQ3MeshFace            frontSideFace = NULL, backSideFace = NULL;
  219.         TQ3MeshVertex        previousFront = NULL, previousBack = NULL;
  220.         long                numVertices = 0;
  221.         TQ3MeshVertex        *firstFrontVertex, *frontVertices, *firstBackVertex, *backVertices;
  222.         TQ3MeshVertex        sideFace[4] = {0, 0, 0, 0};
  223.         
  224.         pp = (char *)&blog->contour[0].vectors;
  225.  
  226.         /*
  227.         for (i = 0; i < blog->contours; i++) {
  228.             poly = (gxPolygon *)pp;
  229.             numVertices += poly->vectors;
  230.             pp += sizeof(long) + poly->vectors * 2 * sizeof(long);
  231.         }
  232.         */
  233.         
  234.         pp = (char *)&blog->contour[0].vectors;
  235.         
  236.         for (i = 0; i < blog->contours; i++) {
  237.             TQ3GeometryObject    textMesh = Q3Mesh_New();
  238.             
  239.             Q3Mesh_DelayUpdates(textMesh);
  240.     
  241.             poly = (gxPolygon *)pp;
  242.             pp += sizeof(long);
  243.     
  244.             if (!(frontVertices = (TQ3MeshVertex *)
  245.                             malloc(poly->vectors * sizeof(TQ3MeshVertex))) ) {
  246.                 return NULL;
  247.             }
  248.             
  249.             firstFrontVertex = frontVertices;
  250.             
  251.             if (!(backVertices = (TQ3MeshVertex *)
  252.                             malloc(poly->vectors * sizeof(TQ3MeshVertex))) ) {
  253.                 return NULL;
  254.             }
  255.         
  256.             firstBackVertex = backVertices;
  257.             
  258.             for (b = 0, c = poly->vectors-1; b < poly->vectors; b++, c--) {
  259.                 TQ3Vertex3D        vertex; 
  260.                 
  261.                 vertex.point.x = (float)FixedToFloat(poly->vector[b].x) / 20.0;
  262.                 vertex.point.y = (float)-FixedToFloat(poly->vector[b].y) / 20.0;
  263.                 vertex.point.z = 0.0;
  264.                 vertex.attributeSet = NULL;
  265.  
  266.                 *frontVertices = Q3Mesh_VertexNew(textMesh, &vertex);
  267.                 if( *frontVertices == NULL) {
  268.                     return NULL;
  269.                 }
  270.  
  271.                 vertex.point.z = 5.0;
  272.                 *backVertices = Q3Mesh_VertexNew(textMesh, &vertex);
  273.                 if( *backVertices == NULL) {
  274.                     return NULL;
  275.                 }
  276.                 
  277.                 if( sideFace[0] && sideFace[1]) {
  278.                     sideFace[2] = *backVertices;
  279.                     sideFace[3] = *frontVertices;
  280.                     Q3Mesh_FaceNew(textMesh, 4,sideFace,NULL);    
  281.                 }
  282.                 
  283.                 sideFace[0] = *frontVertices;
  284.                 sideFace[1] = *backVertices;
  285.  
  286.                 frontVertices++;
  287.                 backVertices++;
  288.  
  289.                 pp += sizeof(gxPoint);
  290.             }
  291.             Q3Mesh_FaceNew(textMesh, poly->vectors,firstFrontVertex,NULL);    
  292.             Q3Mesh_FaceNew(textMesh, poly->vectors,firstBackVertex,NULL);
  293.             
  294.             free(firstFrontVertex); free(firstBackVertex);
  295.             
  296.             Q3Group_AddObject(group, textMesh);
  297.         
  298.             Q3Object_Dispose(textMesh);
  299.         }
  300.     
  301.         /*
  302.         for (i = 0; i < blog->contours; i++) {
  303.             free(gp.contours[i].vertices);
  304.         }
  305.         free(gp.contours);
  306.         */
  307.     }
  308. #endif    
  309.     return(group);
  310. }
  311.  
  312. #endif /* defined(NOGX) && NOGX */
  313.