/*
 * 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: TeapotBody.m
 *
 * Contents: A very simple object: the body of a teapot
 *     
 *
 *****************************************************************************/

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

/*****************************************************************************
 *                                                                           *
 * The teapot    definition                                                  *
 *                                                                           *
 *****************************************************************************/
static RtPoint patch1[4][4] = { 
1.4,0,2.25,
1.4,0.784,2.25,
0.784,1.4,2.25,
0,1.4,2.25,

1.3375,0,2.38125,
1.3375,0.749,2.38125,
0.749,1.3375,2.38125,
0,1.3375,2.38125,

1.4375,0,2.38125,
1.4375,0.805,2.38125,
0.805,1.4375,2.38125,
0,1.4375,2.38125,

1.5,0,2.25,
1.5,0.84,2.25,
0.84,1.5,2.25,
0,1.5,2.25
};

static RtPoint patch2[4][4] = { 
0,1.4,2.25,
-0.784,1.4,2.25,
-1.4,0.784,2.25,
-1.4,0,2.25,

0,1.3375,2.38125,
-0.749,1.3375,2.38125,
-1.3375,0.749,2.38125,
-1.3375,0,2.38125,

0,1.4375,2.38125,
-0.805,1.4375,2.38125,
-1.4375,0.805,2.38125,
-1.4375,0,2.38125,

0,1.5,2.25,
-0.84,1.5,2.25,
-1.5,0.84,2.25,
-1.5,0,2.25 
};

static RtPoint patch3[4][4] = { 
-1.4,0,2.25,
-1.4,-0.784,2.25,
-0.784,-1.4,2.25,
0,-1.4,2.25,

-1.3375,0,2.38125,
-1.3375,-0.749,2.38125,
-0.749,-1.3375,2.38125,
0,-1.3375,2.38125,

-1.4375,0,2.38125,
-1.4375,-0.805,2.38125,
-0.805,-1.4375,2.38125,
0,-1.4375,2.38125,

-1.5,0,2.25,
-1.5,-0.84,2.25,
-0.84,-1.5,2.25,
0,-1.5,2.25
};

static RtPoint patch4[4][4] = { 
0,-1.4,2.25,
0.784,-1.4,2.25,
1.4,-0.784,2.25,
1.4,0,2.25,

0,-1.3375,2.38125,
0.749,-1.3375,2.38125,
1.3375,-0.749,2.38125,
1.3375,0,2.38125,

0,-1.4375,2.38125,
0.805,-1.4375,2.38125,
1.4375,-0.805,2.38125,
1.4375,0,2.38125,

0,-1.5,2.25,
0.84,-1.5,2.25,
1.5,-0.84,2.25,
1.5,0,2.25 
};

static RtPoint patch5[4][4] = {
1.5,0,2.25,
1.5,0.84,2.25,
0.84,1.5,2.25,
0,1.5,2.25,

1.75,0,1.725,
1.75,0.98,1.725,
0.98,1.75,1.725,
0,1.75,1.725,

2,0,1.2,
2,1.12,1.2,
1.12,2,1.2,
0,2,1.2,

2,0,0.75,
2,1.12,0.75,
1.12,2,0.75,
0,2,0.75
};

static RtPoint patch6[4][4] = {
0,1.5,2.25,
-0.84,1.5,2.25,
-1.5,0.84,2.25,
-1.5,0,2.25,

0,1.75,1.725,
-0.98,1.75,1.725,
-1.75,0.98,1.725,
-1.75,0,1.725,

0,2,1.2,
-1.12,2,1.2,
-2,1.12,1.2,
-2,0,1.2,

0,2,0.75,
-1.12,2,0.75,
-2,1.12,0.75,
-2,0,0.75
};

static RtPoint patch7[4][4] = {
-1.5,0,2.25,
-1.5,-0.84,2.25,
-0.84,-1.5,2.25,
0,-1.5,2.25,

-1.75,0,1.725,
-1.75,-0.98,1.725,
-0.98,-1.75,1.725,
0,-1.75,1.725,

-2,0,1.2,
-2,-1.12,1.2,
-1.12,-2,1.2,
0,-2,1.2,

-2,0,0.75,
-2,-1.12,0.75,
-1.12,-2,0.75,
0,-2,0.75
};

static RtPoint patch8[4][4] = {
0,-1.5,2.25,
0.42,-1.5,2.25,
0.795,-1.335,2.25,
1.065,-1.065,2.25,

0,-1.75,1.725,
0.495,-1.75,1.725,
0.93,-1.5575,1.75,
1.24375,-1.24375,1.75,

0,-2,1.2,
0.56,-2,1.2,
1.06,-1.78,1.2,
1.42,-1.42,1.2,

0,-2,0.75,
0.56,-2,0.75,
1.06,-1.78,0.75,
1.42,-1.42,0.75
};

static RtPoint patch9[4][4] = {
1.065,-1.065,2.25,
1.335,-0.795,2.25,
1.5,-0.42,2.25,
1.5,0,2.25,

1.24375,-1.24375,1.75,
1.5575,-0.93,1.75,
1.75,-0.495,1.75,
1.75,0,1.725,

1.42,-1.42,1.2,
1.78,-1.06,1.2,
2,-0.56,1.2,
2,0,1.2,

1.42,-1.42,0.75,
1.78,-1.06,0.75,
2,-0.56,0.75,
2,0,0.75
};

static RtPoint patch10[4][4] = {
2,0,0.75,
2,1.12,0.75,
1.12,2,0.75,
0,2,0.75,

2,0,0.3,
2,1.12,0.3,
1.12,2,0.3,
0,2,0.3,

1.5,0,0.075,
1.5,0.84,0.075,
0.84,1.5,0.075,
0,1.5,0.075,

1.5,0,0,
1.5,0.84,0,
0.84,1.5,0,
0,1.5,0
};

static RtPoint patch11[4][4] = {
0,2,0.75,
-1.12,2,0.75,
-2,1.12,0.75,
-2,0,0.75,

0,2,0.3,
-1.12,2,0.3,
-2,1.12,0.3,
-2,0,0.3,

0,1.5,0.075,
-0.84,1.5,0.075,
-1.5,0.84,0.075,
-1.5,0,0.075,

0,1.5,0,
-0.84,1.5,0,
-1.5,0.84,0,
-1.5,0,0
};

static RtPoint patch12[4][4] = {
-2,0,0.75,
-2,-1.12,0.75,
-1.12,-2,0.75,
0,-2,0.75,

-2,0,0.3,
-2,-1.12,0.3,
-1.12,-2,0.3,
0,-2,0.3,

-1.5,0,0.075,
-1.5,-0.84,0.075,
-0.84,-1.5,0.075,
0,-1.5,0.075,

-1.5,0,0,
-1.5,-0.84,0,
-0.84,-1.5,0,
0,-1.5,0
};

static RtPoint patch13[4][4] = {
0,-2,0.75,
1.12,-2,0.75,
2,-1.12,0.75,
2,0,0.75,

0,-2,0.3,
1.12,-2,0.3,
2,-1.12,0.3,
2,0,0.3,

0,-1.5,0.075,
0.84,-1.5,0.075,
1.5,-0.84,0.075,
1.5,0,0.075,

0,-1.5,0,
0.84,-1.5,0,
1.5,-0.84,0,
1.5,0,0
};

static RtPoint patch14[4][4] = {
-1.6,0,1.875,
-1.6,0.3,1.875,
-1.5,0.3,2.1,
-1.5,0,2.1,

-2.3,0,1.875,
-2.3,0.3,1.875,
-2.5,0.3,2.1,
-2.5,0,2.1,

-2.7,0,1.875,
-2.7,0.3,1.875,
-3,0.3,2.1,
-3,0,2.1,

-2.7,0,1.65,
-2.7,0.3,1.65,
-3,0.3,1.65,
-3,0,1.65
};

static RtPoint patch15[4][4] = {
-1.5,0,2.1,
-1.5,-0.3,2.1,
-1.6,-0.3,1.875,
-1.6,0,1.875,

-2.5,0,2.1,
-2.5,-0.3,2.1,
-2.3,-0.3,1.875,
-2.3,0,1.875,

-3,0,2.1,
-3,-0.3,2.1,
-2.7,-0.3,1.875,
-2.7,0,1.875,

-3,0,1.65,
-3,-0.3,1.65,
-2.7,-0.3,1.65,
-2.7,0,1.65
};

static RtPoint patch16[4][4] = {
-2.7,0,1.65,
-2.7,0.3,1.65,
-3,0.3,1.65,
-3,0,1.65,

-2.7,0,1.425,
-2.7,0.3,1.425,
-3,0.3,1.2,
-3,0,1.2,

-2.5,0,0.975,
-2.5,0.3,0.975,
-2.65,0.3,0.7875,
-2.65,0,0.7875,

-2,0,0.75,
-2,0.3,0.75,
-1.9,0.3,0.45,
-1.9,0,0.45
};

static RtPoint patch17[4][4] = {
-3,0,1.65,
-3,-0.3,1.65,
-2.7,-0.3,1.65,
-2.7,0,1.65,

-3,0,1.2,
-3,-0.3,1.2,
-2.7,-0.3,1.425,
-2.7,0,1.425,

-2.65,0,0.7875,
-2.65,-0.3,0.7875,
-2.5,-0.3,0.975,
-2.5,0,0.975,

-1.9,0,0.45,
-1.9,-0.3,0.45,
-2,-0.3,0.75,
-2,0,0.75};

static RtPoint patch18[4][4] = {
1.7,0,1.275,
1.7,0.66,1.275,
1.7,0.66,0.45,
1.7,0,0.45,

2.6,0,1.275,
2.6,0.66,1.275,
3.1,0.66,0.675,
3.1,0,0.675,

2.3,0,1.95,
2.3,0.25,1.95,
2.4,0.25,1.875,
2.4,0,1.875,

2.7,0,2.25,
2.7,0.25,2.25,
3.3,0.25,2.25,
3.3,0,2.25};

static RtPoint patch19[4][4] = {
1.7,0,0.45,
1.7,-0.66,0.45,
1.7,-0.66,1.275,
1.7,0,1.275,

3.1,0,0.675,
3.1,-0.66,0.675,
2.6,-0.66,1.275,
2.6,0,1.275,

2.4,0,1.875,
2.4,-0.25,1.875,
2.3,-0.25,1.95,
2.3,0,1.95,

3.3,0,2.25,
3.3,-0.25,2.25,
2.7,-0.25,2.25,
2.7,0,2.25};

static RtPoint patch20[4][4] = {
2.7,0,2.25,
2.7,0.25,2.25,
3.3,0.25,2.25,
3.3,0,2.25,

2.8,0,2.325,
2.8,0.25,2.325,
3.525,0.25,2.34375,
3.525,0,2.34375,

2.9,0,2.325,
2.9,0.15,2.325,
3.45,0.15,2.3625,
3.45,0,2.3625,

2.8,0,2.25,
2.8,0.15,2.25,
3.2,0.15,2.25,
3.2,0,2.25
};

static RtPoint patch21[4][4] = {
3.3,0,2.25,
3.3,-0.25,2.25,
2.7,-0.25,2.25,
2.7,0,2.25,

3.525,0,2.34375,
3.525,-0.25,2.34375,
2.8,-0.25,2.325,
2.8,0,2.325,

3.45,0,2.3625,
3.45,-0.15,2.3625,
2.9,-0.15,2.325,
2.9,0,2.325,

3.2,0,2.25,
3.2,-0.15,2.25,
2.8,-0.15,2.25,
2.8,0,2.25
};

static RtBound box = { -3, 3.525, -2, 2, 0, 2.38125};

@implementation TeapotBody : 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: "TeapotBody"];
  [self setTitle:"Teapot Body"];
  return self;
}

/*
 *  This method renders the object.
 *  You can use Renderman functions inside
 *  this method. You should begin this method
 *  by if( [super render] ) { ... 
 */
- render
{
  if( [super render] )
    {
      RiTransformBegin();
    
      RiCone(0,1.5,360.0,RI_NULL);
          
      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);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch9, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch10, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch11, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch12, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch13, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch14, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch15, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch16, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch17, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch18, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch19, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch20, RI_NULL);
      RiPatch(RI_BICUBIC,RI_P,(RtPointer) patch21, 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;
}






