///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2006 James M. Lawrence. All rights reserved. // // software: esve-1.0.3 // file: examples/simple3d/simple3d.cxx // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // 2. The origin of this software must not be misrepresented; you must // not claim that you wrote the original software. If you use this // software in a product, an acknowledgment in the product // documentation would be appreciated but is not required. // // 3. Altered source versions must be plainly marked as such, and must // not be misrepresented as being the original software. // // 4. The name of the author may not be used to endorse or promote // products derived from this software without specific prior written // permission. // // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY, // AND WITH NO CLAIM AS TO ITS SUITABILITY FOR ANY PURPOSE. IN NO EVENT // SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM WHATSOEVER MADE IN CONNECTION // TO THIS SOFTWARE. // ///////////////////////////////////////////////////////////////////////// // // Tutorial on Simple_Viewer and on defining three-dimensional objects // for the engine. // #include #include #include #include #include using esve::viewers::dim3::Simple_Viewer ; using esve::engine::dim3::Make_Geom ; using esve::types::rgba ; //////////////////////////////////////////////////////////// // // Square // //////////////////////////////////////////////////////////// class Square { private: double m_hue ; public: Square() : m_hue(0) { } void hue( double a ) { m_hue = a ; } double hue() const { return m_hue ; } virtual ~Square() { } protected: void draw() { rgba color = rgba::from_hsva(m_hue, 1, 1, 1) ; glBegin(GL_QUADS) ; glColor3f(color.red(), color.green(), color.blue()) ; glNormal3d(0.0, 0.0, 1.0) ; glVertex3d( 1.0, 1.0, 0.0) ; glVertex3d(-1.0, 1.0, 0.0) ; glVertex3d(-1.0, -1.0, 0.0) ; glVertex3d( 1.0, -1.0, 0.0) ; glEnd() ; } void compute() { // put significant calculations here, if any } } ; //////////////////////////////////////////////////////////// // // Viewer // //////////////////////////////////////////////////////////// class Viewer : public Simple_Viewer { private: typedef Simple_Viewer super ; // Give Square the appropriate engine hooks. Make_Geom square ; Valuator & hue_valuator ; public: Viewer( int argc, char** argv ) : super(argc, argv, "simple3d"), square(), hue_valuator(create_valuator(0.5, "hue").range(0, 1).step(0.001)) { add_geom(square) ; create_scaling_valuator() ; } protected: bool handle_key_push( Key key, const Keyboard & ) { // return true if key was handled, false if ignored if( key == 'k' ) { std::cout << "k pushed" << std::endl ; return true ; } return false ; } bool handle_valuator( const Valuator & valuator ) { // return true if valuator was handled, false if ignored if( &valuator == &hue_valuator ) { square.hue(valuator.value()) ; return true ; } return false ; } using super::handle_valuator ; } ; //////////////////////////////////////////////////////////// // // main // //////////////////////////////////////////////////////////// int main( int argc, char** argv ) { Viewer viewer(argc, argv) ; return viewer.takeover() ; }