Main Page   Namespace List   Alphabetical List   Compound List   File List   Compound Members   File Members  

Nviz3DCanvas Class Reference

#include <nviz3d.h>

List of all members.

Public Methods

 Nviz3DCanvas (wxWindow *parent, const wxWindowID id=-1, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name="TestGLCanvas")
 ~Nviz3DCanvas (void)
void DrawNeuron (GLUquadricObj *obj, GLfloat x, GLfloat y, GLfloat z)
void InitGL (void)
void OnEnterWindow (wxMouseEvent &event)
void OnEraseBackground (wxEraseEvent &event)
void OnMouse (wxMouseEvent &event)
void OnPaint (wxPaintEvent &event)
void OnSize (wxSizeEvent &event)
void Render (void)

Private Attributes

bool m_init

Friends

class NVizFrame


Constructor & Destructor Documentation

Nviz3DCanvas::Nviz3DCanvas wxWindow *    parent,
const wxWindowID    id = -1,
const wxPoint &    pos = wxDefaultPosition,
const wxSize &    size = wxDefaultSize,
long    style = 0,
const wxString &    name = "TestGLCanvas"
 

Definition at line 80 of file nviz3d.cpp.

References m_init.

00082                                                             :
00083              wxGLCanvas(parent, (wxGLCanvas*) NULL, id, pos, size, style, name )
00084 {
00085     m_init = FALSE;
00086 }

Nviz3DCanvas::~Nviz3DCanvas void   
 

Definition at line 89 of file nviz3d.cpp.

00090 {
00091     // Nothing Here
00092 }


Member Function Documentation

void Nviz3DCanvas::DrawNeuron GLUquadricObj *    obj,
GLfloat    x,
GLfloat    y,
GLfloat    z
 

Definition at line 95 of file nviz3d.cpp.

References neuron_radius, neuron_slices, and neuron_stacks.

Referenced by Render.

00096 {
00097     glPushMatrix();
00098     glTranslatef(x, y, z);
00099     gluSphere(obj, neuron_radius, neuron_stacks, neuron_slices);
00100     glPopMatrix();
00101 }

void Nviz3DCanvas::InitGL void   
 

Definition at line 104 of file nviz3d.cpp.

Referenced by Render.

00105 {
00106     SetCurrent();
00107 
00108     // set viewing projection
00109     glMatrixMode(GL_PROJECTION);
00110     glFrustum(-1.0F, 1.0F, -1.0F, 1.0F, 1.0F, 100.0F);
00111 
00112     // position viewer
00113     glMatrixMode(GL_MODELVIEW);
00114     glLoadIdentity();
00115     glTranslated(0.0, 0.0, -4.0);
00116 
00117     glEnable(GL_DEPTH_TEST);
00118     glEnable(GL_LIGHTING);
00119     glEnable(GL_LIGHT0);
00120 }

void Nviz3DCanvas::OnEnterWindow wxMouseEvent &    event
 

Definition at line 123 of file nviz3d.cpp.

00124 {
00125     SetFocus();
00126 }

void Nviz3DCanvas::OnEraseBackground wxEraseEvent &    event
 

Definition at line 129 of file nviz3d.cpp.

00130 {
00131   // Do nothing, to avoid flashing.
00132 }

void Nviz3DCanvas::OnMouse wxMouseEvent &    event
 

Definition at line 135 of file nviz3d.cpp.

00136 {
00137 // I think all this dragging stuff is a way to waste a cycle to get a last_x or
00138 // y before drawing. Still not working but good enough for now.
00139     static int dragging = 0;
00140 
00141     if (event.LeftIsDown())
00142     {
00143         if (!dragging)
00144         {
00145             dragging = 1;
00146         }
00147         else
00148         {
00149             camera_x += (event.GetX() - last_x)*(drag_scale_x);
00150             camera_y -= (event.GetY() - last_y)*(drag_scale_y);
00151             Refresh(FALSE);
00152         }
00153         last_x = event.GetX();
00154         last_y = event.GetY();
00155     }
00156     else if (event.RightIsDown())
00157     {
00158         if (!dragging)
00159         {
00160             dragging = 1;
00161         }
00162         else
00163         {
00164             camera_rotate += (event.GetX() - last_x)*(rotate_scale);
00165             camera_zoom  += (event.GetY() - last_y)*(zoom_scale);
00166             Refresh(FALSE);
00167         }
00168         last_x = event.GetX();
00169         last_y = event.GetY();
00170     }
00171     else
00172     {
00173         dragging = 0;
00174         camera_rotate = 0;
00175     }
00176 }

void Nviz3DCanvas::OnPaint wxPaintEvent &    event
 

Definition at line 179 of file nviz3d.cpp.

References Render.

00180 {
00181     Render();
00182 }

void Nviz3DCanvas::OnSize wxSizeEvent &    event
 

Definition at line 185 of file nviz3d.cpp.

00186 {
00187     // this is also necessary to update the context on some platforms
00188     wxGLCanvas::OnSize(event);
00189 
00190     // set GL viewport (not called by wxGLCanvas::OnSize on all platforms...)
00191     int w, h;
00192     GetClientSize(&w, &h);
00193 #ifndef __WXMOTIF__
00194     if (GetContext())
00195 #endif
00196     {
00197         SetCurrent();
00198         glViewport(0, 0, (GLint) w, (GLint) h);
00199     }
00200 }

void Nviz3DCanvas::Render void   
 

Definition at line 203 of file nviz3d.cpp.

References DrawNeuron, gl_neuron_00, gl_neuron_01, gl_neuron_02, gl_neuron_03, gl_neuron_04, gl_neuron_05, InitGL, and m_init.

Referenced by OnPaint.

00204 {
00205     // This is apperantly a dummy to avoid an endless succession of paint
00206     // messages. OnPaint handlers must always create a wxPaintDC.
00207     wxPaintDC dc(this);
00208 
00209 #ifndef __WXMOTIF__
00210     if (!GetContext()) return;
00211 #endif
00212 
00213     SetCurrent();
00214     // init OpenGL once, but after SetCurrent
00215     if (!m_init)
00216     {
00217         InitGL();
00218         m_init = TRUE;
00219     }
00220 
00221     // clear color and depth buffers
00222     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00223 
00224     glPushMatrix();
00225     glMatrixMode(GL_MODELVIEW);
00226     glTranslatef(camera_x, camera_y, camera_zoom);
00227     glMatrixMode(GL_PROJECTION);
00228     glRotatef(camera_rotate, 0.0, 1.0, 0.0);
00229     glMatrixMode(GL_MODELVIEW);
00230 
00231     DrawNeuron(gl_neuron_00 , -2.0, -4.0, 0.0);
00232     DrawNeuron(gl_neuron_01 , 2.0, -4.0, 0.0);
00233     DrawNeuron(gl_neuron_02 , -2.0, 0.0, 0.0);
00234     DrawNeuron(gl_neuron_03 , 2.0, .0, 0.0);
00235     DrawNeuron(gl_neuron_04 , -2.0, 4.0, 0.0);
00236     DrawNeuron(gl_neuron_05 , 2.0, 4.0, 0.0);
00237 
00238     glLineWidth(8);
00239     glBegin(GL_LINES);
00240        glVertex3f(-2.0, -4.0, 0.0);
00241        glVertex3f(-2.0, 0.0, 0.0);
00242     glEnd();
00243 
00244     glPopMatrix();
00245 
00246   glFlush();
00247   SwapBuffers();
00248 }


Friends And Related Function Documentation

friend class NVizFrame [friend]
 

Definition at line 80 of file nviz3d.h.


Member Data Documentation

bool Nviz3DCanvas::m_init [private]
 

Definition at line 97 of file nviz3d.h.

Referenced by Nviz3DCanvas, and Render.


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 19:13:26 2003 for NeReK Documentation by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002