00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <ivfdef/IvfDef.h>
00015
00016 #include <ivfui/IvfApplication.h>
00017 #include <ivfui/IvfWindow.h>
00018
00019 #include <ivf/IvfCamera.h>
00020 #include <ivf/IvfAxis.h>
00021 #include <ivf/IvfComposite.h>
00022 #include <ivf/IvfLighting.h>
00023
00024 #include <ivffile/IvfAc3DReader.h>
00025 #include <ivffile/IvfDxfWriter.h>
00026
00027 #ifdef IVFUI_LIB
00028 #pragma message( "IVFUI_LIB defined" )
00029 #endif
00030
00031 #ifdef IVF_DLL
00032 #pragma message( "IVF_DLL defined" )
00033 #endif
00034
00035 #ifdef IVFUI_API
00036 #pragma message( "IVFUI_API" )
00037 #endif
00038
00039
00040
00041
00042
00043 IvfSmartPointer(CExampleWindow);
00044
00045 class CExampleWindow: public CIvfWindow {
00046 private:
00047 CIvfCameraPtr m_camera;
00048 CIvfCompositePtr m_scene;
00049 CIvfLightPtr m_light;
00050
00051 double m_angleX;
00052 double m_angleY;
00053 double m_moveX;
00054 double m_moveY;
00055 double m_zoomX;
00056 double m_zoomY;
00057
00058 int m_beginX;
00059 int m_beginY;
00060
00061 bool m_rotating;
00062
00063 public:
00064 CExampleWindow(int X, int Y, int W, int H);
00065
00066 virtual void onInit(int width, int height);
00067 virtual void onResize(int width, int height);
00068 virtual void onRender();
00069 virtual void onMouseDown(int x, int y);
00070 virtual void onMouseMove(int x, int y);
00071 virtual void onMouseUp(int x, int y);
00072 virtual bool onTimeout0();
00073 virtual void onKeyboard(int key, int x, int y);
00074 };
00075
00076
00077
00078
00079
00080 CExampleWindow::CExampleWindow(int X, int Y, int W, int H)
00081 :CIvfWindow(X, Y, W, H)
00082 {
00083
00084 }
00085
00086
00087
00088 void CExampleWindow::onInit(int width, int height)
00089 {
00090
00091
00092 m_angleX = 0.0;
00093 m_angleY = 0.0;
00094 m_moveX = 0.0;
00095 m_moveY = 0.0;
00096 m_zoomX = 0.0;
00097 m_zoomY = 0.0;
00098
00099 m_rotating = false;
00100
00101
00102
00103 m_camera = new CIvfCamera();
00104 m_camera->setPosition(-0.0, 3.0, 5.0);
00105 m_camera->setTarget(-0.0, 0.0, 0.0);
00106
00107
00108
00109
00110
00111 m_scene = new CIvfComposite();
00112
00113
00114
00115 CIvfAc3DReaderPtr acReader = new CIvfAc3DReader();
00116
00117
00118
00119 acReader->setFileName("models/ivf.ac");
00120 acReader->setScaling(1.0);
00121
00122
00123
00124 acReader->read();
00125
00126
00127
00128 CIvfShapePtr shape = acReader->getShape();
00129
00130 m_scene->addChild(shape);
00131
00132
00133
00134 CIvfLightingPtr lighting = CIvfLighting::getInstance();
00135 lighting->enable();
00136
00137 m_light = lighting->getLight(0);
00138 m_light->setLightPosition(1.0, 1.0, 1.0, 0.0);
00139 m_light->setDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
00140 m_light->setAmbientColor(0.2f, 0.2f, 0.2f, 1.0f);
00141 m_light->enable();
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 }
00152
00153
00154 void CExampleWindow::onResize(int width, int height)
00155 {
00156 m_camera->setPerspective(45.0, 0.1, 100.0);
00157 m_camera->setViewPort(width, height);
00158 m_camera->initialize();
00159 }
00160
00161
00162 void CExampleWindow::onRender()
00163 {
00164 m_light->render();
00165 m_camera->render();
00166 m_scene->render();
00167 }
00168
00169
00170 void CExampleWindow::onMouseDown(int x, int y)
00171 {
00172 m_beginX = x;
00173 m_beginY = y;
00174 }
00175
00176
00177 void CExampleWindow::onMouseMove(int x, int y)
00178 {
00179 m_angleX = 0.0;
00180 m_angleY = 0.0;
00181 m_moveX = 0.0;
00182 m_moveY = 0.0;
00183 m_zoomX = 0.0;
00184 m_zoomY = 0.0;
00185
00186 if (isLeftButtonDown())
00187 {
00188 m_angleX = (x - m_beginX);
00189 m_angleY = (y - m_beginY);
00190 m_beginX = x;
00191 m_beginY = y;
00192
00193 m_camera->rotatePositionY(m_angleX/100.0);
00194 m_camera->rotatePositionX(m_angleY/100.0);
00195
00196 redraw();
00197 }
00198
00199 if (isRightButtonDown())
00200 {
00201 if (getModifierKey() == CIvfWidgetBase::MT_SHIFT)
00202 {
00203 m_zoomX = (x - m_beginX);
00204 m_zoomY = (y - m_beginY);
00205 }
00206 else
00207 {
00208 m_moveX = (x - m_beginX);
00209 m_moveY = (y - m_beginY);
00210 }
00211 m_beginX = x;
00212 m_beginY = y;
00213
00214 m_camera->moveSideways(m_moveX/100.0);
00215 m_camera->moveVertical(m_moveY/100.0);
00216 m_camera->moveDepth(m_zoomY/50.0);
00217
00218 redraw();
00219 }
00220 }
00221
00222
00223 void CExampleWindow::onMouseUp(int x, int y)
00224 {
00225 m_angleX = 0.0;
00226 m_angleY = 0.0;
00227 m_moveX = 0.0;
00228 m_moveY = 0.0;
00229 m_zoomX = 0.0;
00230 m_zoomY = 0.0;
00231 }
00232
00233
00234 bool CExampleWindow::onTimeout0()
00235 {
00236 if (m_rotating)
00237 {
00238 m_angleX = 0.1;
00239 redraw();
00240 }
00241 return true;
00242 }
00243
00244
00245 void CExampleWindow::onKeyboard(int key, int x, int y)
00246 {
00247 switch (key) {
00248 case 'r' :
00249 if (m_rotating)
00250 m_rotating = false;
00251 else
00252 m_rotating = true;
00253 break;
00254 default:
00255 break;
00256 }
00257 }
00258
00259
00260
00261
00262
00263 int main(int argc, char **argv)
00264 {
00265
00266
00267 CIvfApplicationPtr app = new CIvfApplication(IVF_DOUBLE|IVF_RGB|IVF_STEREO);
00268
00269
00270
00271 CExampleWindowPtr window = new CExampleWindow(0, 0, 512, 512);
00272
00273
00274
00275 window->setWindowTitle("Ivf++ Ac3D file reader example");
00276 window->show();
00277
00278
00279
00280 app->run();
00281
00282 return 0;
00283 }