00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <GU/GU_Detail.h>
00030 #include "VRAY_DemoStamp.h"
00031
00032
00033
00034 namespace HDK_Sample {
00035
00036
00037 class vray_ChildBox : public VRAY_Procedural {
00038 public:
00039 vray_ChildBox(UT_Vector3 ¢er, fpreal size)
00040 : myCenter(center),
00041 mySize(size)
00042 {}
00043 virtual ~vray_ChildBox() {}
00044
00045 virtual const char *getClassName() { return "vray_ChildBox"; }
00046
00047
00048 virtual int initialize(const UT_BoundingBox *)
00049 {
00050 return 0;
00051 }
00052 virtual void getBoundingBox(UT_BoundingBox &box)
00053 {
00054 box.initBounds(myCenter);
00055 box.enlargeBounds(0, mySize);
00056 }
00057 virtual void render()
00058 {
00059 GU_Detail *gdp = allocateGeometry();
00060 gdp->cube(
00061 myCenter.x()-mySize, myCenter.x()+mySize,
00062 myCenter.y()-mySize, myCenter.y()+mySize,
00063 myCenter.z()-mySize, myCenter.z()+mySize);
00064 openGeometryObject();
00065 addGeometry(gdp, 0);
00066 closeObject();
00067 }
00068 private:
00069 UT_Vector3 myCenter;
00070 fpreal mySize;
00071 };
00072 }
00073
00074 using namespace HDK_Sample;
00075
00076
00077 static VRAY_ProceduralArg theArgs[] = {
00078 VRAY_ProceduralArg("minbound", "real", "-1 -1 -1"),
00079 VRAY_ProceduralArg("maxbound", "real", "1 1 1"),
00080 VRAY_ProceduralArg("size", "real", ".1"),
00081 VRAY_ProceduralArg("npoints", "int", "10"),
00082 VRAY_ProceduralArg("seed", "int", "1"),
00083 VRAY_ProceduralArg()
00084 };
00085
00086 VRAY_Procedural *
00087 allocProcedural(const char *)
00088 {
00089 return new VRAY_DemoStamp();
00090 }
00091
00092 const VRAY_ProceduralArg *
00093 getProceduralArgs(const char *)
00094 {
00095 return theArgs;
00096 }
00097
00098 VRAY_DemoStamp::VRAY_DemoStamp()
00099 {
00100 myBox.initBounds(0, 0, 0);
00101 }
00102
00103 VRAY_DemoStamp::~VRAY_DemoStamp()
00104 {
00105 }
00106
00107 const char *
00108 VRAY_DemoStamp::getClassName()
00109 {
00110 return "VRAY_DemoStamp";
00111 }
00112
00113 int
00114 VRAY_DemoStamp::initialize(const UT_BoundingBox *)
00115 {
00116 fpreal val[3];
00117
00118
00119 val[0] = val[1] = val[2] = -1;
00120 import("minbound", val, 3);
00121 myBox.initBounds(val[0], val[1], val[2]);
00122
00123 val[0] = val[1] = val[2] = 1;
00124 import("maxbound", val, 3);
00125 myBox.enlargeBounds(val[0], val[1], val[2]);
00126
00127 if (!import("size", &mySize, 1))
00128 mySize = 0.1;
00129 if (!import("npoints", &myCount, 1))
00130 myCount = 10;
00131 if (!import("seed", &mySeed, 1))
00132 mySeed = 1;
00133
00134 mySize = SYSabs(mySize);
00135
00136 return 1;
00137 }
00138
00139 void
00140 VRAY_DemoStamp::getBoundingBox(UT_BoundingBox &box)
00141 {
00142
00143 box = myBox;
00144
00145
00146 box.enlargeBounds(0, mySize);
00147 }
00148
00149 void
00150 VRAY_DemoStamp::render()
00151 {
00152 int i;
00153 UT_Vector3 c;
00154 unsigned int seed;
00155 float cx, cy, cz;
00156
00157 seed = mySeed;
00158 for (i = 0; i < myCount; i++)
00159 {
00160
00161
00162
00163 cx = SYSfastRandom(seed);
00164 cy = SYSfastRandom(seed);
00165 cz = SYSfastRandom(seed);
00166 c.assign( SYSfit(cx, 0, 1, myBox.xmin(), myBox.xmax()),
00167 SYSfit(cy, 0, 1, myBox.ymin(), myBox.ymax()),
00168 SYSfit(cz, 0, 1, myBox.zmin(), myBox.zmax()) );
00169
00170
00171 openProceduralObject();
00172
00173
00174
00175
00176 addProcedural( new vray_ChildBox(c, mySize) );
00177 closeObject();
00178 }
00179 }