/* * Modification History * * 2000-December-19 Jason Rohrer * Created. * * 2001-January-9 Jason Rohrer * Changed to use new Primitive3D implementations. * * 2001-January-16 Jason Rohrer * Changed to use new Translate3D class for drawing primitives. * * 2001-January-30 Jason Rohrer * Updated to comply with new Primitive3D interface. * * 2001-January-31 Jason Rohrer * Added definition of M_PI if not automatically defined. * Added a quit key handler. * Added multitexturing to central quad to test multitexture implementations. * Had to recommit because of lost log message. * * 2001-February-2 Jason Rohrer * Fixed a bug in the way textures were generated. * * 2001-February-24 Jason Rohrer * Fixed incorrect delete usage. * * 2001-August-29 Jason Rohrer * Fixed to use new KeyboardHandler interface. */ #ifndef TEST_HANDLER_GL_INCLUDED #define TEST_HANDLER_GL_INCLUDED #include #include #include #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #include "ScreenGL.h" #include "MouseHandlerGL.h" #include "KeyboardHandlerGL.h" #include "SceneHandlerGL.h" #include "PrimitiveGL.h" #include "ObjectGL.h" #include "minorGems/graphics/3d/LathePrimitive3D.h" #include "minorGems/graphics/3d/LandscapePrimitive3D.h" #include "TextureGL.h" #include "LightingGL.h" #include "NoLightingGL.h" #include "DirectionLightingGL.h" #include "MultiLightingGL.h" #include "minorGems/math/geometry/Vector3D.h" #include "minorGems/math/geometry/Angle3D.h" #include "minorGems/graphics/Color.h" #include "minorGems/graphics/RGBAImage.h" #include "minorGems/graphics/filters/BoxBlurFilter.h" #include "minorGems/graphics/filters/ThresholdFilter.h" #include "minorGems/graphics/filters/InvertFilter.h" #include "minorGems/util/random/RandomSource.h" #include "minorGems/util/random/Noise.h" #include "minorGems/graphics/Image.h" /** * Test class for ScreenGL implementation. * * Draws a simple polygon. * * @author Jason Rohrer */ class TestHandlerGL : public MouseHandlerGL, public KeyboardHandlerGL, public SceneHandlerGL { public: TestHandlerGL( RandomSource *inRandSource, int inNumTriangles ); ~TestHandlerGL(); /** * Sets up primitives. Must be called *after* OpenGL context is * constructed. */ void setupPrimitives(); // implement the MouseHandlerGL interface void mouseMoved( int inX, int inY ); void mouseDragged( int inX, int inY ); void mousePressed( int inX, int inY ); void mouseReleased( int inX, int inY ); // implement the KeyboardHandlerGL interface void keyPressed( unsigned char inKey, int inX, int inY ); void specialKeyPressed( int inKey, int inX, int inY ); void keyReleased( unsigned char inKey, int inX, int inY ); void specialKeyReleased( int inKey, int inX, int inY ); // implement the SceneHandlerGL interface void drawScene(); private: RandomSource *mRandSource; int mNumTriangles; Vector3D ***mTriangles; Color ***mColors; PrimitiveGL *mPrimitive; PrimitiveGL *mPrimitive2; PrimitiveGL *mPrimitive3; LightingGL *mLightingA; LightingGL *mLightingB; MultiLightingGL *mLighting; double mCurrentAngle; double mAngleStep; }; TestHandlerGL::TestHandlerGL( RandomSource *inRandSource, int inNumTriangles ) : mRandSource( inRandSource ), mNumTriangles( inNumTriangles ), mTriangles( new Vector3D**[inNumTriangles] ), mColors( new Color**[inNumTriangles] ) { mLightingA = new DirectionLightingGL( new Color( 1.0, 1.0, 1.0 ), new Vector3D( 0, 0, 1 ) ); mLightingB = new DirectionLightingGL( new Color( 0, 0, 1.0 ), new Vector3D( 1, 1, 0 ) ); mLighting = new MultiLightingGL(); mLighting->addLighting( mLightingA ); mLighting->addLighting( mLightingB ); for( int i=0; igetRandomDouble() * 10, mRandSource->getRandomDouble() * 10 - 5, mRandSource->getRandomDouble() * 10 ); mColors[i][j] = new Color( mRandSource->getRandomFloat(), mRandSource->getRandomFloat(), mRandSource->getRandomFloat(), mRandSource->getRandomFloat() ); } } } TestHandlerGL::~TestHandlerGL() { for( int i=0; igetChannel(0), textSize, textSize, fPower, true, mRandSource ); genFractalNoise2d( noiseImage->getChannel(1), textSize, textSize, fPower, true, mRandSource ); genFractalNoise2d( noiseImage->getChannel(2), textSize, textSize, fPower, true, mRandSource ); Image *selection = new Image( textSize, textSize, 1 ); genFractalNoise2d( selection->getChannel(0), textSize, textSize, fPower, true, mRandSource ); BoxBlurFilter *blur = new BoxBlurFilter( 10 ); ThresholdFilter *threshold = new ThresholdFilter( 0.5 ); InvertFilter *invert = new InvertFilter(); selection->filter( threshold ); noiseImage->setSelection( selection ); //noiseImage->filter(invert); delete blur; delete threshold; delete invert; noiseImage->clearSelection(); delete selection; /*for( int t=0; tcopy(); //double *alpha = imageArray[1]->getChannel(3); //int numPixels = imageArray[1]->getWidth() * imageArray[1]->getHeight(); //for( int p=0; psetTransparent( true ); // all passed in args will be destroyed when primitive is destroyed // setup second primitive Vector3D **latheCurve = new Vector3D*[4]; latheCurve[0] = new Vector3D( 0.5, 1, 0 ); latheCurve[1] = new Vector3D( 1, 0.5, 0 ); latheCurve[2] = new Vector3D( 1, -0.5, 0 ); latheCurve[3] = new Vector3D( 0.5, -1, 0 ); noiseImage = new RGBAImage( textSize, textSize ); genFractalNoise2d( noiseImage->getChannel(0), textSize, textSize, fPower, true, mRandSource ); genFractalNoise2d( noiseImage->getChannel(1), textSize, textSize, fPower, true, mRandSource ); genFractalNoise2d( noiseImage->getChannel(2), textSize, textSize, fPower, true, mRandSource ); Primitive3D *lathePrimitive3D = new LathePrimitive3D( 4, latheCurve, 15, 2 * M_PI, noiseImage ); lathePrimitive3D->setTransparent( false ); mPrimitive2 = new PrimitiveGL( lathePrimitive3D ); //mPrimitive2->setBackVisible( true ); // all passed in args will be destroyed when primitive is destroyed noiseImage = new RGBAImage( textSize, textSize ); genFractalNoise2d( noiseImage->getChannel(0), textSize, textSize, fPower, true, mRandSource ); genFractalNoise2d( noiseImage->getChannel(1), textSize, textSize, fPower, true, mRandSource ); genFractalNoise2d( noiseImage->getChannel(2), textSize, textSize, fPower, true, mRandSource ); int landSize = 20; unsigned long *intHeights = new unsigned long[ landSize * landSize ]; genFractalNoise2d( intHeights, landSize, landSize ); double *heights = new double[ landSize * landSize ]; for( int l=0; lr, mColors[p][v]->g, mColors[p][v]->b, mColors[p][v]->a ); glVertex3f( mTriangles[p][v]->mX, mTriangles[p][v]->mY, mTriangles[p][v]->mZ ); } } glEnd(); */ Vector3D *pos = new Vector3D( 0, 0, 10 ); Angle3D *rot = new Angle3D( mCurrentAngle, mCurrentAngle, 0 ); //Angle3D *rot = new Angle3D( 0, 0, 0 ); Transform3D *trans = new Transform3D(); trans->scale( 5 ); trans->rotate( rot ); trans->translate( pos ); //mPrimitive->setBackVisible( false ); mPrimitive->draw( trans, mLighting ); delete rot; delete pos; delete trans; pos = new Vector3D( 0, -10, 10 ); rot = new Angle3D( 0, mCurrentAngle, 0 ); trans = new Transform3D(); trans->scale( 20 ); trans->rotate( rot ); trans->translate( pos ); mPrimitive3->draw( trans, mLighting ); delete rot; delete pos; delete trans; pos = new Vector3D( 0, 5, 0 ); rot = new Angle3D( M_PI, mCurrentAngle, 0 ); trans = new Transform3D(); trans->scale( 20 ); trans->rotate( rot ); trans->translate( pos ); //mPrimitive3->setBackVisible( false ); //mPrimitive3->draw( trans, mLighting ); delete rot; delete pos; delete trans; mCurrentAngle += mAngleStep; } #endif