Allow to use space to toggle spinning of the cube in OpenGL sample.
Small enhancement to the cube OpenGL sample. Closes #11545. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65904 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -682,9 +682,10 @@ commands through menu.
|
|||||||
|
|
||||||
@sampleabout{wxGLCanvas}
|
@sampleabout{wxGLCanvas}
|
||||||
|
|
||||||
@li @b cube Draws only a cube to demonstrate how to write a basic wxWidgets OpenGL program.
|
@li @b cube Draws a cube to demonstrate how to write a basic wxWidgets OpenGL program.
|
||||||
@li @b isosurf Draws a surface by reading coordinates from a dat file.
|
Arrow keys rotate the cube. Space bar toggles spinning.
|
||||||
@li @b penguin Draws a rotatable penguin by reading data from a dxf file.
|
@li @b isosurf Draws a surface by reading coordinates from a DAT file.
|
||||||
|
@li @b penguin Draws a rotatable penguin by reading data from a DXF file.
|
||||||
|
|
||||||
@sampledir{opengl}
|
@sampledir{opengl}
|
||||||
|
|
||||||
|
@@ -38,6 +38,16 @@
|
|||||||
#include "../../sample.xpm"
|
#include "../../sample.xpm"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// constants
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// control ids
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
SpinTimer = wxID_HIGHEST + 1
|
||||||
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// helper functions
|
// helper functions
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -283,6 +293,7 @@ TestGLContext& MyApp::GetContext(wxGLCanvas *canvas)
|
|||||||
BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas)
|
BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas)
|
||||||
EVT_PAINT(TestGLCanvas::OnPaint)
|
EVT_PAINT(TestGLCanvas::OnPaint)
|
||||||
EVT_KEY_DOWN(TestGLCanvas::OnKeyDown)
|
EVT_KEY_DOWN(TestGLCanvas::OnKeyDown)
|
||||||
|
EVT_TIMER(SpinTimer, TestGLCanvas::OnSpinTimer)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
TestGLCanvas::TestGLCanvas(wxWindow *parent)
|
TestGLCanvas::TestGLCanvas(wxWindow *parent)
|
||||||
@@ -292,10 +303,11 @@ TestGLCanvas::TestGLCanvas(wxWindow *parent)
|
|||||||
// viewport settings.
|
// viewport settings.
|
||||||
: wxGLCanvas(parent, wxID_ANY, NULL /* attribs */,
|
: wxGLCanvas(parent, wxID_ANY, NULL /* attribs */,
|
||||||
wxDefaultPosition, wxDefaultSize,
|
wxDefaultPosition, wxDefaultSize,
|
||||||
wxFULL_REPAINT_ON_RESIZE)
|
wxFULL_REPAINT_ON_RESIZE),
|
||||||
|
m_xangle(30.0),
|
||||||
|
m_yangle(30.0),
|
||||||
|
m_spinTimer(this,SpinTimer)
|
||||||
{
|
{
|
||||||
m_xangle =
|
|
||||||
m_yangle = 30;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestGLCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
|
void TestGLCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
|
||||||
@@ -318,44 +330,52 @@ void TestGLCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
|
|||||||
SwapBuffers();
|
SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestGLCanvas::OnKeyDown( wxKeyEvent& event )
|
void TestGLCanvas::Spin(float xSpin, float ySpin)
|
||||||
{
|
{
|
||||||
float *p = NULL;
|
m_xangle += xSpin;
|
||||||
|
m_yangle += ySpin;
|
||||||
|
|
||||||
bool inverse = false;
|
Refresh(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestGLCanvas::OnKeyDown(wxKeyEvent& event)
|
||||||
|
{
|
||||||
|
float angle = 5.0;
|
||||||
|
|
||||||
switch ( event.GetKeyCode() )
|
switch ( event.GetKeyCode() )
|
||||||
{
|
{
|
||||||
case WXK_RIGHT:
|
case WXK_RIGHT:
|
||||||
inverse = true;
|
Spin( 0.0, -angle );
|
||||||
// fall through
|
break;
|
||||||
|
|
||||||
case WXK_LEFT:
|
case WXK_LEFT:
|
||||||
// rotate around Y axis
|
Spin( 0.0, angle );
|
||||||
p = &m_yangle;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WXK_DOWN:
|
case WXK_DOWN:
|
||||||
inverse = true;
|
Spin( -angle, 0.0 );
|
||||||
// fall through
|
break;
|
||||||
|
|
||||||
case WXK_UP:
|
case WXK_UP:
|
||||||
// rotate around X axis
|
Spin( angle, 0.0 );
|
||||||
p = &m_xangle;
|
break;
|
||||||
|
|
||||||
|
case WXK_SPACE:
|
||||||
|
if ( m_spinTimer.IsRunning() )
|
||||||
|
m_spinTimer.Stop();
|
||||||
|
else
|
||||||
|
m_spinTimer.Start( 25 );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
event.Skip();
|
event.Skip();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
float angle = 5;
|
void TestGLCanvas::OnSpinTimer(wxTimerEvent& WXUNUSED(event))
|
||||||
if ( inverse )
|
{
|
||||||
angle = -angle;
|
Spin(0.0, 4.0);
|
||||||
|
|
||||||
*p += angle;
|
|
||||||
|
|
||||||
Refresh(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -67,12 +67,16 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void OnPaint(wxPaintEvent& event);
|
void OnPaint(wxPaintEvent& event);
|
||||||
|
void Spin(float xSpin, float ySpin);
|
||||||
void OnKeyDown(wxKeyEvent& event);
|
void OnKeyDown(wxKeyEvent& event);
|
||||||
|
void OnSpinTimer(wxTimerEvent& WXUNUSED(event));
|
||||||
|
|
||||||
// angles of rotation around x- and y- axis
|
// angles of rotation around x- and y- axis
|
||||||
float m_xangle,
|
float m_xangle,
|
||||||
m_yangle;
|
m_yangle;
|
||||||
|
|
||||||
|
wxTimer m_spinTimer;
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user