00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #if defined(__GNUG__) && !defined(__APPLE__)
00013 #pragma implementation
00014 #pragma interface
00015 #endif
00016
00017
00018 #include "wx/wxprec.h"
00019
00020 #ifdef __BORLANDC__
00021 #pragma hdrstop
00022 #endif
00023
00024 #ifndef WX_PRECOMP
00025 #include "wx/wx.h"
00026 #endif
00027
00028 #include "wx/log.h"
00029
00030 #if !wxUSE_GLCANVAS
00031 #error Please set wxUSE_GLCANVAS to 1 in setup.h.
00032 #endif
00033
00034 #include "nviz3d.h"
00035
00036 static GLfloat xrot = 0;
00037 static GLfloat yrot = 0;
00038 static GLfloat zoom = 0;
00039 static float last_x = 0,
00040 last_y = 0;
00041
00042
00043
00044
00045
00046 BEGIN_EVENT_TABLE(Nviz3DCanvas, wxGLCanvas)
00047 EVT_SIZE(Nviz3DCanvas::OnSize)
00048 EVT_PAINT(Nviz3DCanvas::OnPaint)
00049 EVT_ERASE_BACKGROUND(Nviz3DCanvas::OnEraseBackground)
00050 EVT_ENTER_WINDOW( Nviz3DCanvas::OnEnterWindow )
00051 EVT_MOUSE_EVENTS( Nviz3DCanvas::OnMouse )
00052 END_EVENT_TABLE()
00053
00054
00055 Nviz3DCanvas::Nviz3DCanvas(wxWindow *parent, wxWindowID id,
00056 const wxPoint& pos, const wxSize& size,
00057 long style, const wxString& name):
00058 wxGLCanvas(parent, (wxGLCanvas*) NULL, id, pos, size, style, name )
00059 {
00060 m_init = FALSE;
00061 }
00062
00063
00064 Nviz3DCanvas::~Nviz3DCanvas()
00065 {
00066
00067 }
00068
00069
00070 void Nviz3DCanvas::Render()
00071 {
00072
00073
00074 wxPaintDC dc(this);
00075
00076 #ifndef __WXMOTIF__
00077 if (!GetContext()) return;
00078 #endif
00079
00080 SetCurrent();
00081
00082 if (!m_init)
00083 {
00084 InitGL();
00085 m_init = TRUE;
00086 }
00087
00088
00089 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00090
00091 glPushMatrix();
00092 glMatrixMode(GL_MODELVIEW);
00093 glRotatef(yrot, 0.0, 1.0, 0.0);
00094 glRotatef(xrot, 1.0, 0.0, 0.0);
00095 glMatrixMode(GL_PROJECTION);
00096 glTranslatef(0.0, 0.0, zoom);
00097
00098 GLUquadricObj *gl_neuron = gluNewQuadric();
00099 gluSphere(gl_neuron, 1.0, 10, 10);
00100
00101 glPopMatrix();
00102
00103 glFlush();
00104 SwapBuffers();
00105 }
00106
00107
00108 void Nviz3DCanvas::OnEnterWindow( wxMouseEvent& event )
00109 {
00110 SetFocus();
00111 }
00112
00113
00114 void Nviz3DCanvas::OnPaint( wxPaintEvent& event )
00115 {
00116 Render();
00117 }
00118
00119
00120 void Nviz3DCanvas::OnSize(wxSizeEvent& event)
00121 {
00122
00123 wxGLCanvas::OnSize(event);
00124
00125
00126 int w, h;
00127 GetClientSize(&w, &h);
00128 #ifndef __WXMOTIF__
00129 if (GetContext())
00130 #endif
00131 {
00132 SetCurrent();
00133 glViewport(0, 0, (GLint) w, (GLint) h);
00134 }
00135 }
00136
00137
00138 void Nviz3DCanvas::OnMouse(wxMouseEvent &event)
00139 {
00140
00141
00142 static int dragging = 0;
00143
00144 if (event.LeftIsDown())
00145 {
00146 if (!dragging)
00147 {
00148 dragging = 1;
00149 }
00150 else
00151 {
00152 yrot += (event.GetX() - last_x)*1.0;
00153 xrot += (event.GetY() - last_y)*1.0;
00154 Refresh(FALSE);
00155 }
00156 last_x = event.GetX();
00157 last_y = event.GetY();
00158 }
00159
00160
00161 if (event.RightIsDown())
00162 {
00163 if (!dragging)
00164 {
00165 dragging = 0;
00166 }
00167 else
00168 {
00169 xrot = 0.0;
00170 yrot = 0.0;
00171 zoom += (event.GetY() - last_y)*0.25;
00172 Refresh(FALSE);
00173 }
00174 last_y = event.GetY();
00175 }
00176
00177
00178 }
00179
00180 void Nviz3DCanvas::DrawNeuron(GLfloat x, GLfloat y, GLfloat z,)
00181 {
00182 }
00183
00184
00185 void Nviz3DCanvas::OnEraseBackground(wxEraseEvent& event)
00186 {
00187
00188 }
00189
00190
00191 void Nviz3DCanvas::InitGL()
00192 {
00193 SetCurrent();
00194
00195
00196 glMatrixMode(GL_PROJECTION);
00197 glFrustum(-1.0F, 1.0F, -1.0F, 1.0F, 1.0F, 100.0F);
00198
00199
00200 glMatrixMode(GL_MODELVIEW);
00201 glLoadIdentity();
00202 glTranslated(0.0, 0.0, -4.0);
00203
00204 glEnable(GL_DEPTH_TEST);
00205 glEnable(GL_LIGHTING);
00206 glEnable(GL_LIGHT0);
00207 }
00208
00209
00210
00211
00212
00213 BEGIN_EVENT_TABLE(NvizFrame, wxFrame)
00214 EVT_MENU(wxID_EXIT, NvizFrame::OnExit)
00215 END_EVENT_TABLE()
00216
00217
00218 NvizFrame::NvizFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
00219 const wxSize& size, long style)
00220 : wxFrame(frame, -1, title, pos, size, style)
00221 {
00222 glc_nvizcanvas = NULL;
00223 }
00224
00225
00226 void NvizFrame::OnExit(wxCommandEvent &event)
00227 {
00228 Destroy();
00229 }
00230
00231
00232
00233
00234
00235 IMPLEMENT_APP(Nviz3DApp)
00236
00237
00238 bool Nviz3DApp::OnInit(void)
00239 {
00240 wxLog::SetTraceMask(wxTraceMessages);
00241
00242
00243 NvizFrame *frame = new NvizFrame(NULL, "Cube OpenGL Demo", wxPoint(50, 50),
00244 wxSize(400, 300));
00245
00246 #ifdef wx_msw
00247 frame->SetIcon(wxIcon("mondrian"));
00248 #endif
00249
00250
00251 wxMenu *winMenu = new wxMenu;
00252
00253 winMenu->Append(wxID_EXIT, "&Close");
00254 wxMenuBar *menuBar = new wxMenuBar;
00255 menuBar->Append(winMenu, "&Window");
00256
00257 frame->SetMenuBar(menuBar);
00258
00259 frame->glc_nvizcanvas = new Nviz3DCanvas(frame, -1, wxDefaultPosition, wxDefaultSize);
00260
00261
00262 frame->Show(TRUE);
00263
00264 return TRUE;
00265 }