00001
00002 #include <stdio.h>
00003
00004 #include <ocean/GLvish/VRenderObject.hpp>
00005 #include <ocean/plankton/VCreator.hpp>
00006 #include <ocean/plankton/VTime.hpp>
00007 #include <ocean/GLvish/BoundingBox.hpp>
00008
00009 #include <stdio.h>
00010
00011 using namespace Wizt;
00012
00013
00033
00034
00035
00036 class DisplayListObject : public VRenderObject
00037 {
00038 struct MyState : State
00039 {
00040 double complexity;
00041
00042 MyState()
00043 : complexity(0.5)
00044 {}
00045 };
00046
00047 override RefPtr<State> newState() const
00048 {
00049 return new MyState();
00050 }
00051
00052 virtual void render(VRenderContext&Context) const;
00053
00054 public:
00055 TypedSlot<double> Complexity;
00056
00057 DisplayListObject(const string&name, int p, const RefPtr<VCreationPreferences>&VP)
00058 : VRenderObject(name, p, VP)
00059 , Complexity(this, "complexity", 0.5)
00060 {}
00061
00062 ~DisplayListObject()
00063 {}
00064 };
00065
00066 void DisplayListObject::render(VRenderContext&Context) const
00067 {
00068 static GLfloat Red[4] = {0.9, 0.1, 0.1, 1.0 };
00069
00070 int N = 300;
00071 double r = 1.0;
00072
00073 double complexity = 0.5;
00074 Complexity << Context >> complexity;
00075
00076 double dphi = 3.1415/ 10,
00077 zs = 0.1 * complexity;
00078
00079
00080 glEnable( GL_COLOR_MATERIAL );
00081 glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
00082
00083
00084 SubObjectBegin(Context);
00085
00086
00087 vglColor4fv(Context, Red, 0.4);
00088
00089 glEnable(GL_DEPTH_TEST);
00090
00091
00092 RefPtr<MyState> state = myState(Context);
00093
00094
00095 RefPtr<ValueSet> RenderParameterSpace = new ValueSet();
00096
00097
00098 RefPtr<DisplayList> DL;
00099 try
00100 {
00101 DL = Context(*state)(this)( RenderParameterSpace );
00102 }
00103 catch(...)
00104 {}
00105
00106
00107 if (DL && state->complexity == complexity)
00108 {
00109 if (DL->call() )
00110 return;
00111 }
00112
00113
00114 DL = Context[*state][this][ RenderParameterSpace ];
00115 if (!DL) throw "No Display List!?";
00116
00117
00118 state->complexity = complexity;
00119
00120
00121 resetBBox(Context);
00122
00123
00124 glCompile( *DL )
00125 {
00126 glBegin( GL_QUAD_STRIP );
00127 for (int i=0;i<N;i++)
00128 {
00129 double phi0 = i*dphi,
00130 phi1 = (i+1/complexity)*dphi;
00131
00132 point A, B;
00133 A = r*cos(phi0), r*sin(phi0), phi0*zs;
00134 B = r*cos(phi0), r*sin(phi0), phi1*zs;
00135
00136 bivector N;
00137 N = cos(phi0), sin(phi0), 0;
00138
00139
00140 embrace( Context, A );
00141 embrace( Context, B );
00142
00143 glNormal( N );
00144 glVertex( A );
00145 glVertex( B );
00146 }
00147 glEnd();
00148 }
00149
00150
00151 closeBBox(Context);
00152 }
00153
00154 static Ref<VCreator<DisplayListObject> > MyCreator("Tutorial/DisplayListObject", 0);
00155
00156
00157
00158
00159
00160 VISH_DEFAULT_INIT
00161
00162