/*
 * Copyright 1993 by Cub'x Systemes
 * 
 * All Rights Reserved
 *
 * Permission to use, copy, and distribute this software and its
 * documentation for the  purpose of making new intuitiv'3d modules.
 * This copyright notice must appears in all copies that you distribute.
 * The name of Cub'x Systeme should not be used in advertising or publicity
 * without specific, written prior permission. 
 * CUB'X SYSTEMES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 * CUB'X SYSTEMES BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */

/*****************************************************************************
 *
 *  CustomObject module
 *  -------------------
 *
 * File: TeapotTop.m
 *
 * Contents: A very simple object: the top of a teapot
 *     
 *
 *****************************************************************************/

#import "TeapotTop.h"
#import <ri/ri.h>

/*****************************************************************************
 *                                                                           *
 * The teapot top definition                                                 *
 *                                                                           *
 *****************************************************************************/

static RtPoint patch1[4][4] = {
  0,    0,    3,
  0,    0,    3,
  0,    0,    3,
  0,    0,    3,

  0.8,  0,    3,
  0.8,  0.45, 3,
  0.45, 0.8,  3,
  0,    0.8,  3,

  0,    0,    2.7,
  0,    0,    2.7,
  0,    0,    2.7,
  0,    0,    2.7,

  0.2,  0,    2.55,
  0.2,  0.112,2.55,
  0.112,0.2,  2.55,
  0,    0.2,  2.55
};

static RtPoint patch2[4][4] = {
  0,     0,    3,
  0,     0,    3,
  0,     0,    3,
  0,     0,    3,

  0,     0.8,  3,
  -0.45, 0.8,  3,
  -0.8,  0.45, 3,
  -0.8,  0,    3,

  0,     0,    2.7,
  0,     0,    2.7,
  0,     0,    2.7,
  0,     0,    2.7,

  0,     0.2,  2.55,
  -0.112,0.2,  2.55,
  -0.2,  0.112,2.55,
  -0.2,  0,    2.55
};

static RtPoint patch3[4][4] = {
  0,0,3,
  0,0,3,
  0,0,3,
  0,0,3,

  -0.8,  0,     3,
  -0.8,  -0.45, 3,
  -0.45, -0.8,  3,
  0,     -0.8,  3,

  0,0,2.7,
  0,0,2.7,
  0,0,2.7,
  0,0,2.7,

  -0.2,   0,      2.55,
  -0.2,   -0.112, 2.55,
  -0.112, -0.2,   2.55,
  0,      -0.2,   2.55
};

static RtPoint patch4[4][4] = {
  0,0,3,
  0,0,3,
  0,0,3,
  0,0,3,

  0,    -0.8, 3,
  0.45, -0.8, 3,
  0.8,  -0.45, 3,
  0.8,  0,     3,

  0,0,2.7,
  0,0,2.7,
  0,0,2.7,
  0,0,2.7,

  0,-0.2,2.55,
  0.112,-0.2,2.55,
  0.2,-0.112,2.55,
  0.2,0,2.55};

static RtPoint patch5[4][4] = {
  0.2,0,2.55,
  0.2,0.112,2.55,
  0.112,0.2,2.55,
  0,0.2,2.55,

  0.4,0,2.4,
  0.4,0.224,2.4,
  0.224,0.4,2.4,
  0,0.4,2.4,

  1.3,0,2.4,
  1.3,0.728,2.4,
  0.728,1.3,2.4,
  0,1.3,2.4,

  1.3,0,2.25,
  1.3,0.728,2.25,
  0.728,1.3,2.25,
  0,1.3,2.25
};

static RtPoint patch6[4][4] = {
  0,0.2,2.55,
  -0.112,0.2,2.55,
  -0.2,0.112,2.55,
  -0.2,0,2.55,

  0,0.4,2.4,
  -0.224,0.4,2.4,
  -0.4,0.224,2.4,
  -0.4,0,2.4,

  0,1.3,2.4,
  -0.728,1.3,2.4,
  -1.3,0.728,2.4,
  -1.3,0,2.4,

  0,1.3,2.25,
  -0.728,1.3,2.25,
  -1.3,0.728,2.25,
  -1.3,0,2.25
};

static RtPoint patch7[4][4] = {
  -0.2,0,2.55,
  -0.2,-0.112,2.55,
  -0.112,-0.2,2.55,
  0,-0.2,2.55,

  -0.4,0,2.4,
  -0.4,-0.224,2.4,
  -0.224,-0.4,2.4,
  0,-0.4,2.4,

  -1.3,0,2.4,
  -1.3,-0.728,2.4,
  -0.728,-1.3,2.4,
  0,-1.3,2.4,

  -1.3,0,2.25,
  -1.3,-0.728,2.25,
  -0.728,-1.3,2.25,
  0,-1.3,2.25
};

static RtPoint patch8[4][4] = {
  0,-0.2,2.55,
  0.112,-0.2,2.55,
  0.2,-0.112,2.55,
  0.2,0,2.55,
  
  0,-0.4,2.4,
  0.224,-0.4,2.4,
  0.4,-0.224,2.4,
  0.4,0,2.4,
  
  0,-1.3,2.4,
  0.728,-1.3,2.4,
  1.3,-0.728,2.4,
  1.3,0,2.4,
  
  0,-1.3,2.25,
  0.728,-1.3,2.25,
  1.3,-0.728,2.25,
  1.3,0,2.25
};

static RtBound box = { 
  -1.3, 1.3,
  -1.3, 1.3,
  2.25, 3
};

@implementation TeapotTop : CX3DObject
{
}

/*
 *  The init method should set some default values for your instance variables.
 */
- init
{
  [super init];

  CX(scale)  = CY(scale) = CZ(scale) = .1;
  CX(rotate) = -90.0;

  /*
   *  Here set your icon.
   *  You can use any tiff picture placed into the bundle
   */
  [self setIconByName: "TeapotTop"];
  [self setTitle:"Teapot top"];
  return self;
}


/*
 *  This method renders the object.
 *  You can use Renderman function inside
 *  this method. You should begin this method
 *  by if( [super render] ) { ... 
 */
- render
{
  if( [super render] )
    {
      RiTransformBegin();
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch1, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch2, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch3, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch4, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch5, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch6, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch7, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch8, RI_NULL);
      RiTransformEnd();
    }
  return self;
}


/*
 *  This method should return the bounding box of your instance.
 *  You have to implement this method.
 */
- getBoundingBox:(RtBound) aBox
{
  memcpy(aBox, box, sizeof(RtBound));
  return self;
}

/*
 *  This method returns the class of the inspector you want to use
 *  for your new object. You can return nil.
 */
- attributeInspClass
{
  return nil;
}

@end















