TweetFollow Us on Twitter

Nov 99 Challenge

Volume Number: 15 (1999)
Issue Number: 11
Column Tag: Programmer's Challenge

Programmer's Challenge

by Bob Boonstra, Westford, MA

Putting Green

I'll confess. While I'm as much of a sports fan as the next guy, I've never been able to get excited about golf. Not playing it, except maybe a round of miniature golf while on vacation each summer. Not watching it, which is the closest thing to watching grass grow that I can imagine. In fact, I have a hard time even thinking of golf as a sport. Real sports involve perspiration. Real sports involve being exhausted. Golf doesn't have either, as near as I have been able to tell, and therefore couldn't be worth getting involved in. Or so I thought.

Feeling this way, I didn't pay very much attention to the news that the 1999 Ryder Cup was going to be held relatively close by. And, when a ticket to the first day of matches came my way, I thought about passing it on to someone else. For a few days, that is. Until I started reading some of the growing volume of newspaper coverage and got an appreciation for what a really big deal people were making of this. It seemed even bigger than the baseball All Star game, also held in Boston this year. Baseball, also not the most intense sport, involves some amount of running and perspiration. So if the Ryder Cup was as big as the All Star game, it must be worth watching. So I decided to attend.

What, you must be asking, does any of this have to do with the Programmer's Challenge? Did someone substitute an issue of Sports Illustrated under the cover? No, it's just that the Ryder Cup provided the inspiration for this month's Challenge. Watching Tiger Woods make a birdie putt on the 10th, watching three teams miss essentially the same putt on the 14th, my mind turned to - why, physics, of course. How did they read (or misread) those breaks? Your Challenge will be to figure it out.

The Challenge this month is going to be to put some simulated balls into simulated holes on simulated greens. The greens will be provided to you as an array of three dimensional points, divided into an array of adjoining triangles. You will "putt" the ball by imparting a velocity. The ball will move according to a black box propagation model that incorporates the effects of gravity and drag. How are you supposed to know how the ball will move if you don't have the propagation code? The same way Tiger and Monty do it, of course - practice!

The prototype for the code you should write is:

#if defined(__cplusplus)
extern "C" {
#endif

#include <MacTypes.h>

typedef struct Point3DDouble {
 double x;
 double y;
 double z;
} Point3DDouble;

typedef struct Velocity2DDouble {
 double x;
 double y;
} Velocity2DDouble;

typedef struct MyTriangle {
  long pointIndices[3];   /* index of points comprising the triangle */
} MyTriangle;

typedef struct BallPosition {
  double time;
  Point3DDouble pt;
} BallPosition;

void InitGreen(
  Point3DDouble points[], /* green terrain description */
  long numPoints,         /* number of points */
  MyTriangle triangles[], /* triangles comprising the green */
  int numTriangles,       /* number of triangles */
  long pinTriangle,       /* index in triangles[] of the pin on this green */
  long numPracticeHoles,
            /* number of unscored (but timed) holes to practice on this green */
  long numScoredHoles       /* number of holes to be scored on this green */
);
  
void StartHole(   /* called to start play on this hole */
  Point3DDouble ballPosition, /* initial ball position on the green */
  Boolean practice   /* TRUE if this hole is practice */
);

Boolean /* quit */ MakePutt(
  Velocity2DDouble *xyVelocity
   /* return initial ball velocity in the z==0 plane */
);

void BallMovement(
  BallPosition ballPositions[],
                     /* provides ball movement in response to MakePutt */
  int numBallPositions, /* number of ballPositions provided */
  Boolean inHole   /* true if the ball went into the hole */
);

#if defined(__cplusplus)
}
#endif

For each green you play on, your InitGreen routine will be called. It will be provided with the coordinates of numPoints points and with the numTriangles triangles that describe the topography of the green. One of the triangles (triangles[pinTriangle]) will represent the pin position on this hole - you need to move the ball from the starting ballPosition so that it enters this triangle in order to complete the hole. InitGreen will also be given the number of practice holes and the number of scored holes to be played on this green, each with a different initial ballPosition. The practice holes will all be played before any of the nonpractice holes, and the number of practice holes will always be at least as great as the number of nonpractice holes.

For each hole, your StartHole routine will be called with the initial ballPosition for that hole. The practice indicator will be set to TRUE if this is a practice hole. Next, your MakePutt and BallMovement routines will be called repeatedly until you put the ball in the hole (inHole==TRUE) or until you quit (MakePutt returns TRUE). You might quit on a practice hole if you decide you don't need any more practice (saving execution time). You might quit on a nonpractice hole if you decide that the cost of completing the hole exceeds the benefit (see the notes on scoring below).

MakePutt returns the velocity vector you want to impart for this shot. It is important to remember that your stroke velocity is specified in the x-y plane. That velocity will be increased (by 1/cos(slope)) to compensate for terrain angle. As the ball moves, the velocity will accelerated due to the effect of gravity, and decelerated due to the effect of drag.

BallMovement provides you with the results of your shot as a sequence of numBallPositions BallPositions. Each BallPosition has a three-dimensional position and a time tag (in seconds relative to the start of this shot). The inHole flag will tell you whether the ball went into the hole, indicating that the hole is over.

Solutions will be scored based on the number of holes successfully completed, the number of strokes required to complete those holes, and the amount of execution time expended. Each completed nonpractice hole earns 100 points. Each nonpractice stroke reduces the score by 10 points, and each second of execution time (including practice time) costs 10 points. The winner will be the solution that earns the greatest number of total points.

This will be a native PowerPC Challenge, using the latest CodeWarrior environment. Solutions may be coded in C, C++, or Pascal. Solutions in Java will also be accepted this month. Java entries must be accompanied by a test driver that uses the interface provided in the problem statement.

Three Months Ago Winner

Congratulations to Rob Shearer (location unknown) for submitting the fastest solution to the August FlyBy Challenge. The objective was to repeatedly render a scene from a sequence of viewpoints and viewing angles. Both Rob and first-time contestant Joe Strout used QuickDraw3D to do the rendering, and both described their solutions as straightforward. Rob converted the triangles that describe the scene to be rendered into a trimesh. He gained a speed advantage by turning off double buffering in QuickDraw3D, which makes the quality of the animation poor, but which was not prohibited by the problem statement. Restoring double buffering is a one-line code change. As a final comment, I'll note that Rob's code demonstrates some good coding techniques (e.g., modularization, use of assert)

I tested the two programs using a single scene with ~3200 points and ~6000 triangles, rendered from a sequence of ~260 viewpoints. The table below lists, for both of the solutions submitted, the total execution time in milliseconds, the code and data size, and the programming language used. As usual, the number in parentheses after the entrant's name is the total number of Challenge points earned in all Challenges prior to this one..

Name Time (msec) Code SizeData Size Lang
Rob Shearer (14) 232035540 1366 C++
Joe Strout 23873 1632 76 C++

Top Contestants

Listed here are the Top Contestants for the Programmer's Challenge, including everyone who has accumulated 10 or more points during the past two years. The numbers below include points awarded over the 24 most recent contests, including points earned by this month's entrants.

RankNamePoints
1.Munter, Ernst217
2.Saxton, Tom106
3.Maurer, Sebastian70
4.Boring, Randy66
5.Rieken, Willeke51
6.Heithcock, JG39
7.Shearer, Rob34
8.Brown, Pat20
9.Hostetter, Mat20
10. Mallett, Jeff20
11.Nicolle, Ludovic20
12.Murphy, ACC14
13.Jones, Dennis12
14.Hart, Alan11
15.Hewett, Kevin10
16.Selengut, Jared10
17.Smith, Brad10
18.Strout, Joe10
19.Varilly, Patrick10

There are three ways to earn points: (1) scoring in the top 5 of any Challenge, (2) being the first person to find a bug in a published winning solution or, (3) being the first person to suggest a Challenge that I use. The points you can win are:

1st place20 points
2nd place10 points
3rd place7 points
4th place4 points
5th place2 points
finding bug2 points
suggesting Challenge2 points

Here is Rob's winning CHALLENGENAME solution:

FlyBy.cp
Copyright © 1999 Rob Shearer

//  Very simple and straightforward implementation. It was
//  coded beginning to end in under three hours and worked
//  pretty much perfectly on the first build (only bug was
//  (1), below). It won't win any prizes for speed, though.
//
//  Only two caveats:
//  1)  As is documented in FlyByCamera.h, Quickdraw3D has
//    trouble with camera range with very low hither
//    values in relation to their yon values. This code
//    fixes that by pinning hither to a lower bound.
//  2)  FlyByView.h line 37 turns off double buffering.
//    This gives a tiny speed boost, but obviously makes
//    the animation not so nice. If you need pretty
//    animation, turn double buffering on.

#include "GuardedFlyBy.h"
#include <assert.h>
#include "Terrain.h"
#include "FlyByCamera.h"
#include "FlyByView.h"
#include <memory> // for auto_ptr
#include <Types.h>

// Globals are bad.
namespace FlyBy {
  auto_ptr<Terrain>       theTerrain;
  auto_ptr<FlyByCamera> theCamera;
  auto_ptr<FlyByView>     theView;
}

// -----------------------------
//    * InitFlyBy
// -----------------------------
//  Set up our globals and init Quickdraw3D

void
InitFlyBy(  CWindowPtr      theWindow,
      long      numPoints,
      const   TQ3Point3D  thePoints[],
      long      numTriangles,
      const   MyTriangles theTriangles[],
      const   TQ3ViewAngleAspectCameraData
                perspectiveData,
      const   TQ3ColorRGB backgroundColor ) {
  
  assert( (long) Q3Initialize !=
      kUnresolvedCFragSymbolAddress );
  TQ3Status theStatus(Q3Initialize());
  assert(theStatus != kQ3Failure);
  
  using namespace FlyBy;
  theTerrain.reset(new Terrain(numPoints,
                  thePoints,
                  numTriangles,
                  theTriangles ));
  assert(theTerrain.get());
  theCamera.reset(new FlyByCamera(perspectiveData));
  assert(theCamera.get());
  theView.reset(new FlyByView(theWindow,
                theCamera->GetQ3Camera(),
                backgroundColor));
  assert(theView.get());
}

// -----------------------------
//    * GenerateView
// -----------------------------
//  Update the camera placement and render

void
GenerateView(TQ3CameraPlacement viewPoint) {
  using namespace FlyBy;
  assert(theTerrain.get());
  assert(theCamera.get());
  assert(theView.get());
  theCamera->SetPlacement(viewPoint);
  
  theView->RenderModel(theTerrain->GetQ3Group());
}

// -----------------------------
//    * TermFlyBy
// -----------------------------
//  Delete our globals and exit Quickdraw3D

void
TermFlyBy() {
  using namespace FlyBy;
  theTerrain.reset();
  theCamera.reset();
  theView.reset();
  TQ3Status theStatus(Q3Exit());
  assert(theStatus != kQ3Failure);
}

Terrain.h

#ifndef _H_Terrain
#define _H_Terrain

#include <QD3DGeometry.h>
#include <QD3DGroup.h>
#include <QD3DMath.h>
#include "auto_array_ptr.cp"
#include <assert.h>
#include "GuardedFlyBy.h"

class Terrain {
public:
  Terrain(  long        inNumPoints,
        const TQ3Point3D  inPoints[],
        long        inNumTriangles,
        const MyTriangles inTriangles[] )
    : mModel(Q3OrderedDisplayGroup_New()) {
    
    // Allocate arrays for triangles and attributes
    auto_array_ptr<TQ3TriMeshTriangleData> theTriangles(
      new TQ3TriMeshTriangleData[inNumTriangles]
    );
    assert(theTriangles.get() != nil);
    auto_array_ptr<TQ3ColorRGB> theTriColors(
      new TQ3ColorRGB[inNumTriangles]
    );
    assert(theTriColors.get() != nil);
    auto_array_ptr<TQ3Vector3D> theNormals(
      new TQ3Vector3D[inNumTriangles]
    );
    assert(theNormals.get() != nil);
    
    // Init attributes
    TQ3TriMeshAttributeData theTriAttributes[2];
    theTriAttributes[0].attributeType =
      kQ3AttributeTypeDiffuseColor;
    theTriAttributes[0].data = theTriColors.get();
    theTriAttributes[0].attributeUseArray = nil;
    theTriAttributes[1].attributeType =
      kQ3AttributeTypeNormal;
    theTriAttributes[1].data = theNormals.get();
    theTriAttributes[1].attributeUseArray = nil;
    // Loop over inTriangles, filling in triangle
    // and attribute values in TriMesh structures.
    for (long i(0); i < inNumTriangles; ++i) {
      theTriangles[i].pointIndices[0] =
        inTriangles[i].pointIndices[0];
      theTriangles[i].pointIndices[1] =
        inTriangles[i].pointIndices[1];
      theTriangles[i].pointIndices[2] =
        inTriangles[i].pointIndices[2];
      theTriColors[i] =
        inTriangles[i].triangleColor;
      TQ3Vector3D theFirstEdge;
      Q3Point3D_Subtract(
        &(inPoints[inTriangles[i].pointIndices[0]]),
        &(inPoints[inTriangles[i].pointIndices[1]]),
        &theFirstEdge
      );
      TQ3Vector3D theSecondEdge;
      Q3Point3D_Subtract(
        &(inPoints[inTriangles[i].pointIndices[0]]),
        &(inPoints[inTriangles[i].pointIndices[2]]),
        &theSecondEdge
      );
      Q3Vector3D_Cross( &theFirstEdge,
                &theSecondEdge,
                &(theNormals[i]) );
      Q3Vector3D_Normalize( &(theNormals[i]),
                  &(theNormals[i]) );
    }
    
    // Compute bounding box
    TQ3BoundingBox theBox;
    if (inNumPoints > 0) {
      theBox.min = theBox.max = inPoints[0];
      theBox.isEmpty = kQ3False;
    } else {
      theBox.isEmpty = kQ3True;
    }
    for (long i(1); i < inNumPoints; ++i) {
      if (inPoints[i].x < theBox.min.x) {
        theBox.min.x = inPoints[i].x;
      } else if (inPoints[i].x > theBox.max.x) {
        theBox.max.x = inPoints[i].x;
      }
      if (inPoints[i].y < theBox.min.y) {
        theBox.min.y = inPoints[i].y;
      } else if (inPoints[i].y > theBox.max.y) {
        theBox.max.y = inPoints[i].y;
      }
      if (inPoints[i].z < theBox.min.z) {
        theBox.min.z = inPoints[i].z;
      } else if (inPoints[i].z > theBox.max.z) {
        theBox.max.z = inPoints[i].z;
      }
    }
    
    // Init TriMesh data
    TQ3TriMeshData theData;
    theData.triMeshAttributeSet = nil;
    theData.numTriangles = inNumTriangles;
    theData.triangles = theTriangles.get();
    theData.numTriangleAttributeTypes = 2;
    theData.triangleAttributeTypes = theTriAttributes;
    theData.numEdges = 0;
    theData.edges = nil;
    theData.numEdgeAttributeTypes = 0;
    theData.edgeAttributeTypes = nil;
    theData.numPoints = inNumPoints;
    theData.points = const_cast<TQ3Point3D*>(inPoints);
      // Yes, I know: bad form.
    theData.numVertexAttributeTypes = 0;
    theData.vertexAttributeTypes = nil;
    theData.bBox = theBox;
    
    // Create the TriMesh and add it to our model group
    TQ3GeometryObject theGeometry(Q3TriMesh_New(&theData));
    try {
      assert(theGeometry);
      assert(mModel);
      TQ3GroupPosition thePos =
        Q3Group_AddObject(mModel, theGeometry);
      assert(thePos);
    } catch (...) { // Wish for C++ "finally" block...
      Q3Object_Dispose(theGeometry);
      throw;
    }
    Q3Object_Dispose(theGeometry);
  };
  
  ~Terrain() {
    Q3Object_Dispose(mModel);
  };
  
  TQ3GroupObject GetQ3Group() { return mModel; };

private:
  TQ3GroupObject mModel;

  Terrain(const Terrain& rhs);
  Terrain& operator=(const Terrain& rhs);
};

#endif

FlyByCamera.h

#ifndef _H_FlyByCamera
#define _H_FlyByCamera

#include <QD3DCamera.h>
#include <assert.h>

class FlyByCamera {
public:
  FlyByCamera(const TQ3ViewAngleAspectCameraData& inData)
    : mCamera(Q3ViewAngleAspectCamera_New(&inData)) {
    assert(mCamera);
    // Quickdraw3D gets confused when the ratio of
    // hither to yon drops too low. All documentation
    // for this Challenge indicates that 0 will be
    // passed for hither, which causes significant
    // artifacts to appear. We pin hither to a lower
    // limit to prevent this (although the better
    // solution is probably to simply have a more
    // reasonable value of hither passed in).
    if (inData.cameraData.range.hither <
      inData.cameraData.range.yon/10000000) {
      TQ3CameraRange newRange;
      newRange.hither =
        inData.cameraData.range.yon/10000000;
      newRange.yon = inData.cameraData.range.yon;
      TQ3Status theStatus =
        Q3Camera_SetRange(mCamera, &newRange);
      assert(theStatus != kQ3Failure);
    }
  };
  ~FlyByCamera() {
    Q3Object_Dispose(mCamera);
  };
  TQ3CameraObject GetQ3Camera() { return mCamera; };
  void SetPlacement(const TQ3CameraPlacement& inWhere) {
    TQ3Status theStatus =
      Q3Camera_SetPlacement(mCamera, &inWhere);
    assert(theStatus != kQ3Failure);
  };
private:
  TQ3CameraObject mCamera;
  FlyByCamera(const FlyByCamera& rhs);
  FlyByCamera& operator=(const FlyByCamera& rhs);
};

#endif

FlyByView.h

#ifndef _H_FlyByView
#define _H_FlyByView

#include <QD3DView.h>
#include <QD3DDrawContext.h>
#include <QD3DRenderer.h>
#include <assert.h>

class FlyByView {
public:
  FlyByView(  CWindowPtr    inWindow,
        TQ3CameraObject inCamera,
        TQ3ColorRGB   inBGColor )
    : mView(Q3View_New()) {
    assert(mView);
    // Set up the draw context
    // This doesn't seem like the most efficient way
    // to fill in these data structures, but hey...
    TQ3DrawContextData theDrawData;
    theDrawData.clearImageMethod =
      kQ3ClearMethodWithColor;
    theDrawData.clearImageColor.a = 1;
    theDrawData.clearImageColor.r = inBGColor.r;
    theDrawData.clearImageColor.g = inBGColor.g;
    theDrawData.clearImageColor.b = inBGColor.b;
    theDrawData.paneState = kQ3False;
    theDrawData.maskState = kQ3False;
    // NOTE: We explicitly turn off double  buffering
    // for purposes of speed. This makes the animation
    // very ugly. If you want nicer animation then turn
    // double buffering back on.
    theDrawData.doubleBufferState = kQ3False;
    TQ3MacDrawContextData theMacData;
    theMacData.drawContextData = theDrawData;
    theMacData.window = (CWindowPtr) inWindow;
    theMacData.library = kQ3Mac2DLibraryNone;
    theMacData.viewPort = nil;
    theMacData.grafPort = nil;
    TQ3DrawContextObject theContext =
      Q3MacDrawContext_New(&theMacData);
    try {
      assert(theContext);
      TQ3Status theStatus =
        Q3View_SetDrawContext(mView, theContext);
      assert(theStatus != kQ3Failure);
    } catch (...) {
      Q3Object_Dispose(theContext);
      throw;
    }
    Q3Object_Dispose(theContext);
    // Set up the renderer
    TQ3RendererObject theRenderer =
    Q3Renderer_NewFromType(kQ3RendererTypeInteractive);
    try {
      assert(theRenderer);
      TQ3Status theStatus =
        Q3View_SetRenderer(mView, theRenderer);
      assert(theStatus != kQ3Failure);
    } catch (...) {
      Q3Object_Dispose(theRenderer);
      throw;
    }
    Q3Object_Dispose(theRenderer);
    // Set up the camera (which was passed in)
    assert(inCamera);
    TQ3Status theStatus =
      Q3View_SetCamera(mView, inCamera);
    assert(theStatus != kQ3Failure);
    
    // Set up the lighting
    TQ3LightData theData;
    theData.isOn = kQ3True;
    theData.brightness = 1;
    theData.color.r = 1;
    theData.color.g = 1;
    theData.color.b = 1;
    TQ3LightObject theLight =
      Q3AmbientLight_New(&theData);
    try {
      assert(theLight);
      TQ3GroupObject theLights(Q3LightGroup_New());
      try {
        assert(theLights);
        TQ3GroupPosition thePos =
          Q3Group_AddObject(theLights, theLight);
        assert(thePos);
        TQ3Status theStatus =
          Q3View_SetLightGroup(mView, theLights);
        assert(theStatus != kQ3Failure);
      } catch (...) {
        Q3Object_Dispose(theLights);
        throw;
      }
      Q3Object_Dispose(theLights);
    } catch (...) {
      Q3Object_Dispose(theLight);
      throw;
    }
    Q3Object_Dispose(theLight);
  };
  ~FlyByView() {
    Q3Object_Dispose(mView);
  };
  
  void RenderModel(TQ3GroupObject inModel) {
    Q3View_StartRendering(mView);
    do {
      Q3DisplayGroup_Submit(inModel, mView);
    } while ( Q3View_EndRendering(mView)
          == kQ3ViewStatusRetraverse );
  };
private:
  TQ3ViewObject mView;

  FlyByView(const FlyByView& rhs);
  FlyByView& operator=(const FlyByView& rhs);
};
#endif

auto_array_ptr.h

// A "smart pointer" template very similar to the standard
// auto_ptr but using array deletion to delete its pointee.

#ifndef _H_auto_array_ptr
#define _H_auto_array_ptr

#include <size_t.h>
template<class T>
class auto_array_ptr {

public:
  explicit auto_array_ptr(T* p = nil);  
          // Create an auto pointer with
          // ownership of the given object.
  auto_array_ptr(auto_array_ptr<T>& rhs);   
          // Copy constructor sets pointer
          // passed in to nil; new auto pointer
          // assumes ownership of its pointee.
  ~auto_array_ptr();
          // Destructor deletes pointee (with
          // delete[]).
  auto_array_ptr<T>&  operator=(auto_array_ptr<T>& rhs);  
          // Assignment sets pointer passed in
          // to nil, deletes current pointee,
          // and assumes ownership of rhs's old
          // pointee.
  // Emulate pointer/array behavior.
  T&      operator*() const;
  T*      operator->() const;
  T&      operator[](std::size_t inIndex);
  const T&  operator[](std::size_t inIndex) const;
  T*      get() const;
          // Return value of current dumb
          // pointer (for the purpose of
          // comparison).
  T*      release();
          // Relinquish ownership of pointee
          // and return value of current dumb
          // pointer.
  void    reset(T* p = nil);
          // Delete current pointee and assume
          // ownership of the given array.
        
private:
  T*      pointee;
};

#endif

auto_array_ptr.cp

// Code for auto_array_ptr template.
// This file must be #include -ed somewhere in your project
// in order to instantiate the template code.

// This is an #include file, so add guard macros.
#ifndef _CP_auto_array_ptr
#define _CP_auto_array_ptr

#include "auto_array_ptr.h"

// -----------------------------
//    * auto_array_ptr
// -----------------------------
//  Constructor

template<class T>
inline
auto_array_ptr<T>::auto_array_ptr(T* p)
  : pointee(p) {
}

// -----------------------------
//    * auto_array_ptr
// -----------------------------
//  Copy constructor
template<class T>
inline
auto_array_ptr<T>::auto_array_ptr(auto_array_ptr<T>& rhs)
  : pointee(rhs.release()) {
}

// -----------------------------
//    * ~auto_array_ptr
// -----------------------------
//  Destructor calls array delete on pointee

template<class T>
inline
auto_array_ptr<T>::~auto_array_ptr() {
  delete[] pointee;
}

// -----------------------------
//    * operator=
// -----------------------------
//  Assignment operator
template<class T>
inline
auto_array_ptr<T>&
auto_array_ptr<T>::operator=(auto_array_ptr<T>& rhs) {
  if (this != &rhs) reset(rhs.release());
  return *this;
}
// -----------------------------
//    * operator*
// -----------------------------
//  Dereference operator

template<class T>
inline
T&
auto_array_ptr<T>::operator*() const {
  // We could check for nil and throw an exception if
  // necessary, but we don't because (1) it's more
  // efficient not to do so and (2) if we do this array
  // won't act exactly as real arrays do when
  // dereferenced.
  return *pointee;
}

// -----------------------------
//    * operator->
// -----------------------------
//  Member selection operator
template<class T>
inline
T*
auto_array_ptr<T>::operator->() const {
  return pointee;
}

// -----------------------------
//    * operator[]
// -----------------------------
//  Element access operator (non-const version)
template<class T>
inline
T&
auto_array_ptr<T>::operator[](std::size_t inIndex) {
  // We could check for nil and throw an exception if
  // necessary, but we don't because (1) it's more
  // efficient not to do so and (2) if we do this array
  // won't act exactly as real array do when
  // accessed.
  return pointee[inIndex];
}

// -----------------------------
//    * operator[]
// -----------------------------
//  Element access operator (const version)
template<class T>
inline
const T&
auto_array_ptr<T>::operator[](std::size_t inIndex) const {
  // We could check for nil and throw an exception if
  // necessary, but we don't because (1) it's more
  // efficient not to do so and (2) if we do this array
  // won't act exactly as real array do when
  // accessed.
  return pointee[inIndex];
}
// -----------------------------
//    * get
// -----------------------------
//  Returns dumb pointer to pointee

template<class T>
inline
T*
auto_array_ptr<T>::get() const {
  return pointee;
}

// -----------------------------
//    * release
// -----------------------------
//  Relinquish ownership of pointee

template<class T>
inline
T*
auto_array_ptr<T>::release() {
  T* oldPointee(pointee);
  pointee = nil;
  return oldPointee;
}

// -----------------------------
//    * reset
// -----------------------------
//  Delete pointee and assume ownership of the given object

template<class T>
inline
void
auto_array_ptr<T>::reset(T* p) {
  delete[] pointee;
  pointee = p;  
}

#endif

FlyBy.h

#include <QD3D.h>
#include <QD3DLight.h>
#include <QD3DCamera.h>
#include <Windows.h>

#if defined(__cplusplus)
extern "C" {
#endif

typedef struct MyTriangles {
  long pointIndices[3];
  TQ3ColorRGB triangleColor;
} MyTriangles;

void InitFlyBy(
  CWindowPtr theWindow,
  long numPoints,
  const TQ3Point3D thePoints[],
  long numTriangles,
  const MyTriangles theTriangles[],
  const TQ3ViewAngleAspectCameraData  perspectiveData,
    // perspectiveData.cameraData.range.hither  = 0.0;
    // perspectiveData.cameraData.range.yon   = 1000.0
    // perspectiveData.cameraData.viewPort.origin.x = -1.0
    // perspectiveData.cameraData.viewPort.origin.y = 1.0
    // perspectiveData.cameraData.viewPort.width = 2.0
    // perspectiveData.cameraData.viewPort.height = 2.0
    // perspectiveData.fov        = 1.0
    // perspectiveData.aspectRatioXToY  =
    //   (float) (theWindow->portRect.right - theWindow->portRect.left) / 
    //   (float) (theWindow->portRect.bottom - theWindow->portRect.top)
  const TQ3ColorRGB backgroundColor
    // color of background
);
void GenerateView(
  TQ3CameraPlacement    viewPoint
);
void TermFlyBy(
);
#if defined(__cplusplus)
}
#endif

GuardedFlyBy.h

//  Added guard macros to "FlyBy.h"
#ifndef _H_GuardedFlyBy
#define _H_GuardedFlyBy
#include "FlyBy.h"
#endif
 
AAPL
$112.38
Apple Inc.
-0.27
MSFT
$47.75
Microsoft Corpora
+0.23
GOOG
$510.37
Google Inc.
-0.73

MacTech Search:
Community Search:

Software Updates via MacUpdate

calibre 2.13 - Complete e-library manage...
Calibre is a complete e-book library manager. Organize your collection, convert your books to multiple formats, and sync with all of your devices. Let Calibre be your multi-tasking digital librarian... Read more
Mellel 3.3.7 - Powerful word processor w...
Mellel is the leading word processor for OS X and has been widely considered the industry standard since its inception. Mellel focuses on writers and scholars for technical writing and multilingual... Read more
ScreenFlow 5.0.1 - Create screen recordi...
Save 10% with the exclusive MacUpdate coupon code: AFMacUpdate10 Buy now! ScreenFlow is powerful, easy-to-use screencasting software for the Mac. With ScreenFlow you can record the contents of your... Read more
Simon 4.0 - Monitor changes and crashes...
Simon monitors websites and alerts you of crashes and changes. Select pages to monitor, choose your alert options, and customize your settings. Simon does the rest. Keep a watchful eye on your... Read more
BBEdit 11.0.2 - Powerful text and HTML e...
BBEdit is the leading professional HTML and text editor for the Mac. Specifically crafted in response to the needs of Web authors and software developers, this award-winning product provides a... Read more
ExpanDrive 4.2.1 - Access cloud storage...
ExpanDrive builds cloud storage in every application, acts just like a USB drive plugged into your Mac. With ExpanDrive, you can securely access any remote file server directly from the Finder or... Read more
Adobe After Effects CC 2014 13.2 - Creat...
After Effects CC 2014 is available as part of Adobe Creative Cloud for as little as $19.99/month (or $9.99/month if you're a previous After Effects customer). After Effects CS6 is still available... Read more
Evernote 6.0.5 - Create searchable notes...
Evernote allows you to easily capture information in any environment using whatever device or platform you find most convenient, and makes this information accessible and searchable at anytime, from... Read more
Command-C 1.1.7 - Clipboard sharing tool...
Command-C is a revolutionary app which makes easy to share your clipboard between iOS and OS X using your local WiFi network, even if the app is not currently opened. Copy anything (text, pictures,... Read more
Tidy Up 4.0.2 - Find duplicate files and...
Tidy Up is a complete duplicate finder and disk-tidiness utility. With Tidy Up you can search for duplicate files and packages by the owner application, content, type, creator, extension, time... Read more

Latest Forum Discussions

See All

BulkyPix Celebrates its 6th Anniversary...
BulkyPix Celebrates its 6th Anniversary with a Bunch of Free Games Posted by Jessica Fisher on December 19th, 2014 [ permalink ] BulkyPix has | Read more »
Indulge in Japanese cuisine in Cooking F...
Indulge in Japanese cuisine in Cooking Fever’s new sushi-themed update Posted by Simon Reed on December 19th, 2014 [ permalink ] Lithuanian developer Nordcurrent has yet again updated its restaurant simulat | Read more »
Badland Daydream Level Pack Arrives to C...
Badland Daydream Level Pack Arrives to Celebrate 20 Million Downloads Posted by Ellis Spice on December 19th, 2014 [ permalink ] | Read more »
Far Cry 4, Assassin’s Creed Unity, Desti...
Far Cry 4, Assassin’s Creed Unity, Destiny, and Beyond – AppSpy Takes a Look at AAA Companion Apps Posted by Rob Rich on December 19th, 2014 [ permalink ] These day | Read more »
A Bunch of Halfbrick Games Are Going Fre...
A Bunch of Halfbrick Games Are Going Free for the Holidays Posted by Ellis Spice on December 19th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Shift - Photo Filters Designed By You (...
Shift - Photo Filters Designed By You 1.0 Device: iOS Universal Category: Photography Price: $.99, Version: 1.0 (iTunes) Description: | Read more »
Elastic Drums (Music)
Elastic Drums 1.0 Device: iOS iPhone Category: Music Price: $3.99, Version: 1.0 (iTunes) Description: *** Introduction price 3,99$ instead of 7,99$ *** Elastic Drums is a music app with 6 channels of synthesized drum sounds, a step... | Read more »
Fireworks Simulator (Games)
Fireworks Simulator 1.0.8 Device: iOS Universal Category: Games Price: $.99, Version: 1.0.8 (iTunes) Description: *** 50% discount – For a short time only *** You can play Fireworks Simulator on these devices: - iPhone 5, 5s, 5c, 6,... | Read more »
Nicky's Gift (Games)
Nicky's Gift 1.0 Device: iOS Universal Category: Games Price: $.99, Version: 1.0 (iTunes) Description: Everybody! Merry Christmas! There's 48 levels in the game. Let's go! Nicky's Gift | Read more »
The Hit List — Simply Powerful Tasks, To...
The Hit List — Simply Powerful Tasks, To-Dos, Projects, & Reminders 2.0 Device: iOS iPhone Category: Productivity Price: $9.99, Version: 2.0 (iTunes) Description: >> LAUNCH SPECIAL: The Hit List 2 for iPhone is ONLY $9.99... | Read more »

Price Scanner via MacPrices.net

It’s 1992 Again At Sony Pictures, Except For...
Techcrunch’s John Biggs interviewed a Sony Pictures Entertainment (SPE) employee, who quite understandably wished to remain anonymous, regarding post-hack conditions in SPE’s L.A office, explaining “... Read more
Holiday sales this weekend: MacBook Pros for...
 B&H Photo has new MacBook Pros on sale for up to $300 off MSRP as part of their Holiday pricing. Shipping is free, and B&H charges NY sales tax only: - 15″ 2.2GHz Retina MacBook Pro: $1699... Read more
Holiday sales this weekend: MacBook Airs for...
B&H Photo has 2014 MacBook Airs on sale for up to $120 off MSRP, for a limited time, for the Thanksgiving/Christmas Holiday shopping season. Shipping is free, and B&H charges NY sales tax... Read more
Holiday sales this weekend: iMacs for up to $...
B&H Photo has 21″ and 27″ iMacs on sale for up to $200 off MSRP including free shipping plus NY sales tax only. B&H will also include a free copy of Parallels Desktop software: - 21″ 1.4GHz... Read more
Holiday sales this weekend: Mac minis availab...
B&H Photo has new 2014 Mac minis on sale for up to $80 off MSRP. Shipping is free, and B&H charges NY sales tax only: - 1.4GHz Mac mini: $459 $40 off MSRP - 2.6GHz Mac mini: $629 $70 off MSRP... Read more
Holiday sales this weekend: Mac Pros for up t...
B&H Photo has Mac Pros on sale for up to $500 off MSRP. Shipping is free, and B&H charges sales tax in NY only: - 3.7GHz 4-core Mac Pro: $2599, $400 off MSRP - 3.5GHz 6-core Mac Pro: $3499, $... Read more
Save up to $400 on MacBooks with Apple Certif...
The Apple Store has Apple Certified Refurbished 2014 MacBook Pros and MacBook Airs available for up to $400 off the cost of new models. An Apple one-year warranty is included with each model, and... Read more
Save up to $300 on Macs, $30 on iPads with Ap...
Purchase a new Mac or iPad at The Apple Store for Education and take up to $300 off MSRP. All teachers, students, and staff of any educational institution qualify for the discount. Shipping is free,... Read more
iOS and Android OS Targeted by Man-in-the-Mid...
Cloud services security provider Akamai Technologies, Inc. has released, through the company’s Prolexic Security Engineering & Research Team (PLXsert), a new cybersecurity threat advisory. The... Read more
KMI MIDI K-Board Great Gift for Amateur &...
The K-Board is a MIDI Nano keyboard for music creation for iPad, Android, And computers; the easiest way to make music with iPads & Android tablets, and Mac, Windows, or Linux computers. Ultra-... Read more

Jobs Board

Project Manager, *Apple* Financial Services...
**Job Summary** Apple Financial Services (AFS) offers consumers, businesses and educational institutions ways to finance Apple purchases. We work with national and Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.