Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
Source/Process.c
/****************************/ |
/* PROCESS.C */ |
/* By Brian Greenstone */ |
/****************************/ |
/****************************/ |
/* EXTERNALS */ |
/****************************/ |
#include <MacWindows.h> |
#include <StandardFile.h> |
#include <QD3D.h> |
#include <QD3DGeometry.h> |
#include <QD3DGroup.h> |
#include <QD3DMath.h> |
#include <QD3DViewer.h> |
#include <QD3DGroup.h> |
#include "myglobals.h" |
#include "misc.h" |
#include "process.h" |
/****************************/ |
/* PROTOTYPES */ |
/****************************/ |
static void InitModelWindow(void); |
static void BuildTestModel(void); |
/****************************/ |
/* CONSTANTS */ |
/****************************/ |
#define MODEL_WIND_ID 400 |
#define MY_HITHER 10 |
#define MY_YON 120 |
/*********************/ |
/* VARIABLES */ |
/*********************/ |
WindowPtr gModelWindow = nil; |
TQ3Object gModelGroup = nil; |
TQ3ViewerObject gViewer = nil; |
#pragma mark ========INITIALIZATION STUFF========= |
/******************** INIT TEST ************************/ |
void InitTest(void) |
{ |
Rect r; |
TQ3ColorARGB color; |
/* CREATE THE WINDOW */ |
gModelWindow = GetNewCWindow(MODEL_WIND_ID, nil,MOVE_TO_FRONT); |
if (gModelWindow == nil) |
DoFatalAlert("\pWhere did the window go?"); |
SetPort((GrafPtr)gModelWindow); |
/* CREATE THE TEST MODEL */ |
BuildTestModel(); |
/* CREATE VIEWER IN THE WINDOW */ |
r.left = gModelWindow->portRect.left + 20; |
r.right = r.left+300; |
r.top = gModelWindow->portRect.top + 20; |
r.bottom = r.top+300; |
gViewer = Q3ViewerNew((CGrafPtr)gModelWindow, &r, kQ3ViewerActive|kQ3ViewerControllerVisible| |
kQ3ViewerButtonOptions|kQ3ViewerButtonCamera| |
kQ3ViewerButtonTruck|kQ3ViewerButtonOrbit| |
kQ3ViewerButtonDolly|kQ3ViewerButtonReset); |
if (gViewer == nil) |
DoFatalAlert("\pQ3ViewerNew failed!"); |
color.a = 1.0; |
color.r = 1.0; |
color.g = .5; |
color.b = .5; |
Q3ViewerSetBackgroundColor(gViewer, &color); |
/* ASSIGN GEOMETRY TO VIEWER */ |
if (Q3ViewerUseGroup(gViewer, gModelGroup)) |
DoFatalAlert("\pQ3ViewerUseGroup failed!"); |
/* DRAW IT */ |
Q3ViewerDraw(gViewer); |
} |
/********************* BUILD TEST MODEL **************************/ |
static void BuildTestModel(void) |
{ |
TQ3TriMeshData myTriMeshData; |
TQ3TriMeshAttributeData faceAttribs; |
TQ3Object tmObj; |
TQ3Point3D points[3] = |
{ |
0,35,0, |
-35,-35,0, |
35,-35,0 |
}; |
TQ3Vector3D vertexNormals[3] = |
{ |
0,0,1, |
0,0,1, |
0,0,1 |
}; |
TQ3Vector3D faceNormals[1] = |
{ |
0,0,1 |
}; |
TQ3TriMeshTriangleData triangles[1] = |
{ |
0,1,2 |
}; |
/* BUILD MAIN TRIMESH DATA STRUCTURE */ |
myTriMeshData.triMeshAttributeSet = nil; |
myTriMeshData.numTriangles = 1; |
myTriMeshData.triangles = &triangles[0]; |
myTriMeshData.numTriangleAttributeTypes = 1; |
myTriMeshData.triangleAttributeTypes = &faceAttribs; |
myTriMeshData.numEdges = 0; |
myTriMeshData.edges = nil; |
myTriMeshData.numEdgeAttributeTypes = 0; |
myTriMeshData.edgeAttributeTypes = nil; |
myTriMeshData.numPoints = 3; |
myTriMeshData.points = &points[0]; |
myTriMeshData.numVertexAttributeTypes = 0; |
myTriMeshData.vertexAttributeTypes = nil; |
/* CALCULATE BOUNDING BOX */ |
Q3BoundingBox_SetFromPoints3D(&myTriMeshData.bBox, &points[0], 3, sizeof(TQ3Point3D)); |
/* CREATE FACE ATTRIBUTES */ |
faceAttribs.attributeType = kQ3AttributeTypeNormal; |
faceAttribs.data = &faceNormals[0]; |
faceAttribs.attributeUseArray = nil; |
/* MAKE THE TRIMESH GEOMETRY OBJECT */ |
tmObj = Q3TriMesh_New(&myTriMeshData); |
if (tmObj == nil) |
DoFatalAlert("\pQ3TriMesh_New failed!"); |
gModelGroup = Q3DisplayGroup_New(); |
Q3Group_AddObject(gModelGroup, tmObj); |
Q3Object_Dispose(tmObj); |
} |
#pragma mark =========UPDATING============ |
/*************** DO MODEL WINDOW NULL EVENT **********************/ |
void DoModelWindowNullEvent(void) |
{ |
} |
#pragma mark ======= PICT STUFF ============= |
/******************** SAVE VIEWER PICT **********************/ |
void SaveViewerPICT(void) |
{ |
SFReply reply; |
Point myPoint; |
Str255 prompt = "\pSave Map View PICT As:"; |
Str255 name = "\pMapView.pict"; |
OSErr iErr; |
long numBytes; |
FInfo fndrInfo; |
PicHandle thePic; |
Ptr blankPtr; |
short fRefNum; |
/* GET PICT FROM VIEWER */ |
thePic = Q3ViewerGetPict(gViewer); |
/* GET FILENAME TO SAVE TO */ |
myPoint.h = -1; |
myPoint.v = -1; |
SFPutFile(myPoint,prompt,name,nil,&reply); |
if (!reply.good) // see if cancelled |
return; |
/* SEE IF FILE ALREADY EXISTS, THEN DELETE */ |
iErr = GetFInfo(reply.fName,reply.vRefNum,&fndrInfo); |
if (iErr != noErr) |
iErr = FSDelete(reply.fName,reply.vRefNum); |
/* CREATE THE FILE */ |
Create(reply.fName,reply.vRefNum,'ttxt','PICT'); |
iErr = SetVol(0,reply.vRefNum); |
if (iErr != noErr) // set default volume |
DoFatalAlert("\pCant seem to set Volume?!"); |
/* OPEN THE FILE */ |
iErr = FSOpen(reply.fName,reply.vRefNum,&fRefNum); |
if (iErr != noErr) |
DoFatalAlert("\pCouldnt Open File."); |
/**********************************/ |
/* WRITE PICT DATA INTO RESOURCES */ |
/**********************************/ |
blankPtr = NewPtr(512); |
numBytes = 512; // write 512 header |
FSWrite(fRefNum,&numBytes,blankPtr); |
DisposePtr(blankPtr); |
numBytes = GetHandleSize((Handle)thePic); |
FSWrite(fRefNum,&numBytes,(Ptr)*thePic); // write PICT data |
FSClose(fRefNum); |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14